function MM_swapImgRestore() { //v3.0
	
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_findObj(n, d) { //v4.01
  
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_swapImage() { //v3.0
  
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}


function check(form_name,form_feilds_mynames,form_feilds_names){  
	var key="";
	var focus1="";
	var msg="Following are the mandatory fields!!\n";
	var Field = "";
	msg+="Cannot be left blank\n\n";

	for(k=0;k<form_name.length;k++){

		for(j=0;j<form_feilds_names.length;j++){

			if(form_name[k].name == form_feilds_names[j]){
			
				if(trimString(form_name[k].value) == ""){
					key+="\n "+form_feilds_mynames[j];
					focus1+=","+k;
				}
			}
		}
	}
	if(key!=""){

		key = key.substring(2);

		focus1 = focus1.substring(1);

		Field=focus1.substring(0,focus1.indexOf(","));
		//alert("Field == "+Field);

		if(Field==""){

			Field=focus1.substring(focus1.length,focus1.indexOf(","));
		}
		
		alert("Cannot Submit !!\n\n"+ msg+key);
		//		alert("Field == "+form_name[Field]);

		form_name[Field].focus();
		
		return false;
	}

	return true;
}



function checkAddContacts(formNm,actiontype)
{
	form_feilds_mynames = new Array("First Name", "Last Name", "Email");
	form_feilds_names = new Array("txtFname", "txtLname", "txtEmail");
	if(!check(formNm,form_feilds_mynames,form_feilds_names))
	{
	//	return false;
	}
	else if(checkEmail(formNm.txtEmail.value))
	{
		alert("Cannot Submit!!\n\nInvalid Email.\n");
		formNm.txtEmail.focus();
	//	return false;
	}
	else
	{
		formNm.action_type.value=actiontype;
		formNm.submit();
	}
}

function checkAddGuest(formNm,actiontype)
{
	form_feilds_mynames = new Array("First Name", "Last Name", "Email");
	form_feilds_names = new Array("txtFname", "txtLname", "txtEmail");
	if(!check(formNm,form_feilds_mynames,form_feilds_names))
	{
	//	return false;
	}
	else if(checkEmail(formNm.txtEmail.value))
	{
		alert("Cannot Submit!!\n\nInvalid Email.\n");
		formNm.txtEmail.focus();
	//	return false;
	}
	else
	{
		formNm.action_type.value=actiontype;
		formNm.submit();
	}
}


function MM_validateForm() { //v4.0
	alert("IN HERE");
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;

function checkEmail(fieldvalue){
	if(remail.test(fieldvalue))
		return false;
	else
		return true;
}

function trimString(str)
{
	while (str.charAt(0) == ' ')
		str = str.substring(1);
  	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);
  	return str;
}

function checkphone(e)
{

	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}

	keychar = String.fromCharCode(key);

	if ( (key>=48 &&  key<=57) || (key==46) || (key==45) || (key==34) || (key==39) || (key==32) ||(key==43))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function openimagepop(path,imagefilename)
{
	window.open("popimage.html?picimage="+path+imagefilename,'ViewImage',"scrollbars=no,menubar=no,width=782,height=180");
}


var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e)
{
	if (ie5&&dragapproved&&event.button==1)
	{
		document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
	}
	else if (ns6&&dragapproved)
	{
		document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
	}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.display="none" //extra
tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height,top1,left1)
{
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scrollbars=1")
else{
document.getElementById("dwindow").style.display=''
document.getElementById("dwindow").style.width=initialwidth=width+"px"
document.getElementById("dwindow").style.height=initialheight=height+"px"
document.getElementById("dwindow").style.left=left1+""
document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+top1+"px" : iecompattest().scrollTop*1+top1+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("src","restore.gif")
document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("src","max.gif")
document.getElementById("dwindow").style.width=initialwidth
document.getElementById("dwindow").style.height=initialheight
}
document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=null;
document.getElementById("dwindowcontent").style.display="" //extra
}

