/* JavaScript Document
  @ Author : Syed Sameer Naqvi
  @ Date : 10/04/2005
  @ Institute: Karachi Institute of Information Technology
*/
	/*
	function used to validate the Content with Regular Expression
	param fld = field's Object
	return :true / false
	*/
	function valid(fld) // varying number of arguments
	{
	  var i;
	  // scan regular expressions
	  //third argument of valid method is Regular expression
	  for (i=1;i<valid.arguments.length;i++) 
		{
		var rx;
		rx=new RegExp(valid.arguments[i]);
		if (rx.exec(fld.value)!=null ) 
		   return true;  // ok
		}
	  // no matches...
	  //alert(errm);
	  
	  return false;
	}
	
	 /*
	 function to validate the contents of text only Fields
	 param fld = field's Object
	 return true/false
	*/
	function validateName(fld)
	{
	  rv=valid(fld,"^ *[a-zA-Z ]+$");
	  return rv;
	}
	 
	function validateNameAndNumber(fld)
	{
	  rv=valid(fld,"^ *[a-zA-Z0-9 ]+$");
	  return rv;
	}
	
	function validateNameNumberDot(fld)
	{
	  rv=valid(fld,"^ *[a-zA-Z0-9. ]+$");
	  return rv;
	}
	
	function validateNumber(fld)
	{
	  rv=valid(fld,"^ *[0-9 ]+$");
	  return rv;
	}
	/*
	function to validate the contents of Telephone number Fields
	param fld = field's Object
	return true/false
	*/
	  function validatePhone(fld)
	  {
		rv=valid(fld,"^ *[0-9 ()-]+$");
		  
		return rv;
	  } 
	  /*
	 function to validate the contents of email Fields
	 param fld = field's Object
	 return true/false
	*/
	  function validateEmail(fld)
	  {
	  rv=valid(fld,"^ *[-a-zA-Z0-9_]+\.?[-a-zA-Z0-9_]+@[-a-zA-Z0-9_]+\\.[a-zA-Z][a-zA-Z][a-zA-Z]?\.?[a-zA-Z]+$");
				  
	  return rv;
	  }
	  
	  function validateFloatNumber(fld)
	  {
	  rv=valid(fld,"^ *[0-9 ]+\.?[0-9 ]+$");
				  
	  return rv;
	  }
	  
	  var isError = false;//variable used as a flag to determine there was any error or not
			  
	
	
	//function to check whether the field object's value is empty  
			
	function isEmpty(field){
		if(field.value=="" ) return true;
		else	return false;
	}
	/*
	function to set focus back on field with error also clear the contents of this field
	*/
	
	function setFocus(field) {
		field.value = "";
		field.focus();
		isError =true;
	}
	
	 
	/*
	//	function to validate credit card number
	*/
	function validateCreditCard(fld)
	{
	  rv=valid(fld, "^ *([0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9])$");
	  return rv;
	} 
	
	
	// functions for trim


function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}