function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 WinOpen(sURL)
{
	var reportWin;
	reportWin = window.open(sURL,'','toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=400,left=0,top=0');
}

//Set center aligned window properties
//22 Aug 2005		Akhilesh Sharma			To set properties for center aligned window.
	var scrHeight = screen.height;
	var scrWidth = screen.width;
	var winHeight = 400;
	var winWidth = 750;
	var xLoc = (scrWidth/2) - (winWidth/2);
	var yLoc = (scrHeight/2) - (winHeight/2);
	var winProperties = "width=" + winWidth + ",height=" + winHeight + ", left=" + xLoc + ", top=" + yLoc + ",scrollbars=yes, resizable=yes";
//Set center aligned window properties ends


//Function to validate name, last name etc.
//Valid characters are (abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`)
function validateName(str)
{
	if((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 96 || event.keyCode > 122) && (event.keyCode != 32)) 
	{
		//alert("InValid");
		//alert(event.keyCode);
		event.returnValue = false;
	}
	else
	{
		//alert(event.keyCode);
		//alert("Valid");
		event.returnValue = true;
	}
}

function validateUsername(str)
{
	str = trimStr(str)
	if(str.length < 6) 
	{
		alert("Username can not be less than 6 characters.");
		return false;
	}
	else
	{
		return true;
	}
}


function validatePassword(str)
{
	str = trimStr(str)
	if(str.length < 6) 
	{
		alert("Password can not be less than 6 characters.");
		return false;
	}
	else
	{
		return true;
	}
}


//Valid characters are (abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`)
function validateNumeric(str)
{
	//alert(event.keyCode);
	//return false;
	if((event.keyCode < 48 || event.keyCode > 57)) 
	{
		//alert("InValid");
		//alert(event.keyCode);
		event.returnValue = false;
	}
	else
	{
		//alert(event.keyCode);
		//alert("Valid");
		event.returnValue = true;
	}
}


function validateDate(dt)
{//validate the date in Javascript.
 //The input date requires to have / as the separator.
 //Example of the input date: 1/31/2002
 var idt, ndt, temp, temp1;
 idt = Date.parse(dt);
 temp = new String(dt);
 if (isNaN(idt))
	return(false);
 else if (temp.indexOf("/")<1 || temp.lastIndexOf("/") <= temp.indexOf("/"))
	return(false);
 else{
	ndt = new Date(dt);
	iYear = ndt.getFullYear();
	iDate = ndt.getDate();
	iMonth = ndt.getMonth();
	//alert((iMonth+1) + "/" + iDate + "/" + iYear);
	temp1 = temp.split("/");
	oMonth = temp1[0];
	oDate = temp1[1];
	oYear = temp1[2];
	//alert(oMonth + "/" + oDate + "/" + oYear);
	if ((iMonth+1) != oMonth || iDate != oDate || iYear != oYear)
		return(false);
	else
		return(true);
	}		
}

function checkNumeric(checkStr)
{
  var checkOK = "0123456789";  
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
    return (allValid);
}

function checkRepeat (checkStr)
{
//check that a string is not a string of similar characters e.g. 1111
	var checkOk = true;
	for (i = 0;  i < checkStr.length - 1;  i++)
	{
		if (checkStr.charAt(i) != checkStr.charAt(i+1))
		{
			checkOk = false;
			break;
		}
	}
	
	return (checkOk);

}

function validateZipCode (zip)
{
//a valid zip code would be 5 digits or 5 digits a dash then 4 more digits
	if (zip.length == 5)
	{
		return (checkNumeric(zip));
	}
	else if (zip.length == 10)
	{
		if (checkNumeric(zip.substring(0,5)) && zip.substring(5,6) == "-" && checkNumeric(zip.substring(6,9)))
			return (true);
		else
			return (false);
	}
	else
	{
		return (false);	
	}
			
}

function validateEmail(email)
{
//a valid email would have only one @ and one . after the @ in the string.
 var iAtF = 0;
 var iDotF = 0;
 var iDotL = 0;
 var iSpace = 0;

 iAtF = String(email).indexOf("@");
 iAtL = String(email).lastIndexOf("@");
 if (iAtF < 1 )
	return (false);
 if (iAtF != iAtL)
	return(false);
	
 iDotL = String(email).lastIndexOf(".");
 if (iDotL < iAtF + 2)
	return(false);

 iSpace = String(email).indexOf(" ");
 if (iSpace > 0 )
	return(false);
		
 return(true);
}

//remove the preceeding and ending spaces from a string.
function trimStr(str)
{var i, pBegin, pEnd, strTemp
 //find the preceeding spaces
 for (i = 0 ; i < String(str).length; i++)
 {if (String(str).charAt(i) != " ")
	{pBegin = i;
	 break;
	}
 }
 
 //find ending spaces
 for (i = String(str).length -1; i >= 0; i--)
 {if (String(str).charAt(i) != " ")
	{pEnd = i;
	 break;
	} 
 }
 
 //the new string.
 strTemp = String(str).substr(pBegin, pEnd - pBegin +1 );
 return (strTemp);
}