 //==========================================================================

// Declare patterns for different Regular Expression

var PatternsDict = new Object()


// mathes telephone no.
PatternsDict.telpat  = "^(\d{10}|(\d{3}-\d{3}-\d{4}))?$"

// matches numeric
PatternsDict.numericpat  = "^\d*$" // Any number is allowed, but are optional

// matches white space
PatternsDict.whitespacepat = /\s+/

// matches zip code
PatternsDict.zippat = "^(\d{5}|\d{9}|(\d{5}-\d{4}))?$"

// matches IP address
PatternsDict.IPpat = "^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$"

// matches hex number
PatternsDict.hexpat = "^([a-fA-F0-9]+)?$"

// matches any alphanumeric character,hyphen(-) or an underscore(_)
// including white space
PatternsDict.validpat = "^[a-zA-Z0-9-_]+$"

// matches required field
PatternsDict.requiredpat = "^((/\s+)|'')?$"

// matches character
 PatternsDict.charpat = /^[a-zA-Z]+$/

// mathes email
var emailpat = /^[A-Za-z0-9\-_\.]+@+[A-Za-z0-9\-\.]+\.+[A-Za-z]{2,10}$/

// matches unsigned float
var ufloatpat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

// matches signed float
var sfloatpat = /^(((\+|\-)?\d+(\.\d*)?)|((\+|\-)?(\d*\.)?\d+))$/



// End of pattern declaration
//=================================================================================

function CheckEmpty(frm,thecontrol)
	{
		var objForm1 = document.frm;
		var txtName1 = eval("document."+frm+"."+thecontrol);
		if (txtName1.value=="")
		{
			alert ("This field can't be Blank");
			txtName1.focus();
			return false;
		}
		else
		{
			return true
		}
	}
	

function CheckSelect(frm1,thecontrol1)
	{
		 var objForm2 = document.frm1;
		 var SelName1 = eval("document."+frm1+"."+thecontrol1);
		 
		 if (SelName1.value=="")
		{
			alert ("Please Select The Field");
			SelName1.focus();
			return false;
		}
		else
		{
			return true
		}
	}



function SelectFile(frm2,thecontrol2)
	{
		 var objForm3 = document.frm2;
		 var SelFile = eval("document."+frm2+"."+thecontrol2);
		 if (SelFile.value=="")
		{
			alert ("Please Select A File To Upload");
			SelFile.focus();
			return false;
		}
		else
		{
			return true
		}
	}


function SelectFolder(frm3,thecontrol3)
	{
		 var objForm3 = document.frm3;
		 var SelFile = eval("document."+frm3+"."+thecontrol3);
		 if (SelFile.value=="")
		{
			alert ("Please Select A File To Upload");
			SelFile.focus();
			return false;
		}
		else
		{
			return true
		}
	}

// mathes email
//var emailpat = /^[A-Za-z0-9\-_\.]+@+[A-Za-z0-9\-\.]+\.+[A-Za-z]{2,10}$/

// Check for valid email format

function isEmail(Object,msg)
 {

   	var strInput   = new String(Object.value)
	var objregExp  = emailpat

   if(objregExp.test(strInput))

     {
       return true

     }
     alert(msg)
     Object.focus()
     return false

 }

// Checks for white space

function isWhitespace(Object,msg)

 {
   var strInput   = new String(Object.value)

   var objregExp  = new RegExp(PatternsDict.whitespacepat)

   if(objregExp.test(strInput))
     {
		if (msg != null)
		  alert(msg);
		return true
     }

   return false;

 }


  // Check for numeric field

 function isNumeric(Object,length,msg) 
   {

     var strInput = new String(Object.value)


     if(strInput.length > 0 && !isWhitespace (Object))
      {
       if(strInput.length < length)
        {
         alert("Field must be " + length + " characters long")
         Object.focus()
         return false
        }

       for(i = 0; i < strInput.length; i++)
        {
         if(strInput.charAt(i) < '0' ||  strInput.charAt(i) > '9')
		 
          {
           alert(msg)
           Object.focus()
           return false
          }
        }
     }
      return true
   }





// Checks a character type field

function isChar(Object,msg)
 {

   var strInput = new String(Object.value)
   alert (strInPut);
   if (trim(strInput) == "")

     {
        return true;
     }

   var objregExp  = new RegExp(PatternsDict.charpat)

   if(objregExp.test(strInput))

     {

       return true;

     }

     alert(msg);
     Object.focus();
     return false;

 }

function checkSingleQuote(txtName)
{
	 var str1	=	txtName.value
	
	for (var i = 0; i < str1.length; i++) 
	{
		var ch = str1.substring(i, i + 1);
		if (ch=="'") 
		{
			alert("Single quote is not allowed");
			txtName.focus();
			return false;
		}
	}
	return true;
}



function convert(num)
{
	var 	amount=	num.value;
	var len		=	amount.length;
	var decPos	=	amount.lastIndexOf(".");
	
	 numAfterDec	=	amount.substr(decPos+1,len);
	 numBeforeDec	=	new Number(amount.substr(0,decPos));
	 
	 if (amount!="0.00" && isNaN(amount))
	{	num.value	=	"0.00";
		return;
	}	
	 
	 if (numAfterDec.length==1)
		numAfterDec	=	numAfterDec+"0";
	 if (decPos<0)
	 {
		num.value	=	new Number(amount)+".00";
	 }
	 else 
	 {
		if (numAfterDec!="")
			num.value	=	numBeforeDec+"."+numAfterDec.substr(0,2);
		else
			num.value	=	numBeforeDec+".00";
	 }	
}

function isMaxLength(eleName,maxLen,label)
		{
			var eleValue	=eleName.value
			if (eleValue=="")
			return true;
			if (eleValue.length>maxLen)
			{
				alert("Please enter "+maxLen+" characters only in "+label);
				eleName.focus();
				return false;
			}
		}
function CheckList(thecontrol1,label)
	{
		 //var objForm2 = document.frm1;
		// var SelName1 = eval("document."+frm1+"."+thecontrol1);
		 var SelName1 = thecontrol1;
		 if (SelName1.value=="")
		{
			alert ("Please Select "+label);
			SelName1.focus();
			return false;
		}
		else
		{
			return true
		}
	}
		
		
function dateDiff(datefrom,dateto)
			{
			
		var diff  = new Date();
		var nod;
		
		diff.setTime(Math.abs(dateto.getTime() - datefrom.getTime()));
		var timediff = diff.getTime();
		var weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
		timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
		var days1 = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
		timediff -= days1 * (1000 * 60 * 60 * 24);
		var hours = Math.floor(timediff / (1000 * 60 * 60)); 
		timediff -= hours * (1000 * 60 * 60);
		var mins = Math.floor(timediff / (1000 * 60)); 
		timediff -= mins * (1000 * 60);
		var secs = Math.floor(timediff / 1000); 
		timediff -= secs * 1000;
		nod=weeks*7+days1;
		noh=nod*24;
		if (nod<=0)
			nod=1;
		
		return(nod)		
			}
		/****************************************************************************************
		' Purpose 		    : Validates Number
		' Input Parameters 	: textBox element name, Element Description
		' Output Parameters : false
		' Function calls 	: None
		' Called by		    :
		' String Table/Code   None
		' Domain Name :
		' Dependency		: None
		'*****************************************************************************************/
	function isValidNumber(eleName,label)
	{	
		var checkOK = "0123456789";
		var checkStr = eleName.value;
	  	var allValid = true;
	  	var decPoints = 0;
	  	var allNum = "";
	  	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;
				}
				if (ch != ",")
					allNum += ch;
		  }
			  if (!allValid)
			  {
				alert("Please enter only digit characters in "+label);
				eleName.select();
				return (false);
		}
	}
		/****************************************************************************************
		' Purpose 		    : Validates Telephone Number
		' Input Parameters 	: textBox element name, Element Description
		' Output Parameters : false
		' Function calls 	: None
		' Called by		    :
		' String Table/Code   None
		' Domain Name :
		' Dependency		: None
		'*****************************************************************************************/
		function isValidTelNo(eleName,label)
		{
			var checkOK = "+0123456789-,() ";
			var checkStr = eleName.value;
			var allValid = true;
			var decPoints = 0;
			var allNum = "";
			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;
				}
				if (ch != ",")
				allNum += ch;
			}
			
			if (!allValid)
			{
				alert("Please enter only digit characters in "+label);
				eleName.value="";
				eleName.focus();
				return (false);
			}
			else
			{
				return (true)
			}
		}
	/****************************************************************************************
	' Purpose 		    : validates email id
	' Input Parameters 	: textBox element name
	' Output Parameters : false
	' Function calls 	: None
	' Called by		    :
	' String Table/Code   None
	' Domain Name :
	' Dependency		: None
	'*****************************************************************************************/	
		function isValidEmail(name,label)
		{
		//---------------------E-mail-----------------------------   
		   
			var verify=999;
			var email_value,temp_value,dot_val,dot_str,temp_length,temp_string;
			email_value=new String();
			temp_value=new String();
			dot_val=new String("@.");
			dot_str=new String(".");
			var   score_str=new String("~`!#$%^&*)(|}?></*; :',\+=}][{");
			email_value=name.value
			for(temp_length=0;temp_length<score_str.length;temp_length++){
				 temp_string=score_str.charAt(temp_length);
					if(email_value.indexOf(temp_string.toString()) != -1)
						verify=-111;}
						
			if(email_value.length < 7)
				{verify=-111;}
		   
			else 
				if(email_value.indexOf("@")==-1)
					{verify=-111;}
				else 
					if(email_value.indexOf("@")==0)
						{verify=-111;}
			
					else 
						if(email_value.indexOf(".")==-1)
							{verify=-111;}
						
						else  
							if(email_value.indexOf("@")==(email_value.length-1))
								{verify=-111;}
				 
							else 
								if(email_value.indexOf(dot_str.toString())==(email_value.length-1))
									{verify=-111;}
								 else 
									{temp_value=email_value.substr(email_value.indexOf("@")+1);
									if(temp_value.indexOf("@") != -1)
										{verify=-111;}
									else  
										if(email_value.indexOf(dot_val.toString())!= -1)
											{verify=-111;}
										else  
											{temp_value=email_value.substr((email_value.length-3));
											if(temp_value.indexOf("@")!=-1)
												{verify=-111;}
												else {temp_value=email_value.substr(email_value.indexOf("@")+1);
													if((temp_value.length - temp_value.indexOf(dot_str.toString())) <2)
														{verify=-111;}
									 }}}
				 
		   if(verify==-111)
		   {
				
				verify=0;
				alert("Invalid "+label);
				name.select();   
				name.focus();
				return false;
		   }
		}	
			
	/****************************************************************************************
	' Purpose 		    : To check for single quotes )
	' Input Parameters 	: textBox element name
	' Output Parameters : false
	' Function calls 	: None
	' Called by		    :
	' String Table/Code   None
	' Domain Name :
	' Dependency		: None
	'*****************************************************************************************/	
	function checkSingleQuote(txtName,label)
		{
				
			
			//var checkOK = new Array("<",">","'","%",";","=");
			var checkOK = new Array("<",">","%","=");
			var checkStr = txtName.value;
			var allValid = true;
			
			for (j = 0;  j < checkOK.length;  j++)
			{
				if(checkStr.lastIndexOf(checkOK[j])>=0)
				{
					allValid=false;
					break;
				}
			}
							
			if (allValid==false) 
			{
				alert("Special characters [< >  %  = --] not allowed in "+label);
				txtName.focus();
				return false;
			}
				
		}

/****************************************************************************************
	' Purpose 		    : To check blank fields
	' Input Parameters 	: textBox element name
	' Output Parameters : false
	' Function calls 	: None
	' Called by		    :
	' String Table/Code   None
	' Domain Name :
	' Dependency		: None
	'*****************************************************************************************/
	function isBlankField(eleName,label)
	{
		// trim Function to remove Spaces   Added by  Mr Bibhuti
		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
		eleName.value=eleName.value.trim();
		if (eleName.value=="")
		{
			var eleType	=	eleName.type;
			
			if (eleType=="text" || eleType=="textarea")
			alert("Please enter "+label);
			else
			alert("Please select "+label);
			
			eleName.focus();
			return false;
		}
	}		
	
/**********************************************************************************
Function Name	:	isVaildLength
Purpose			:	This Function is used to trim the white space characters.

Parametrs		:	par	=>	Name of the Control

Function calls	:
Return types	:
***********************************************************************************
String Table/Code domain name	:
Dependency						:
***********************************************************************************/
	
	function isVaildLength(eleName,maxLen,label)
	{
		var eleValue	=eleName.value;
		if (eleValue.length>maxLen)
		{
			alert(label+" must be within "+maxLen+" characters");
			eleName.focus();
			return false;
		}
	}

/****************************************************************************************
	' Purpose 		    : To check upload file
	' Input Parameters 	: textBox element name
	' Output Parameters : false
	' Function calls 	: None
	' Called by		    :
	' String Table/Code   None
	' Domain Name :
	' Dependency		: None
	'*****************************************************************************************/
	function isValidFile(eleName,allowedList,label)
	{
		
		photo	=	eleName.value;
		photo	=	photo.toLowerCase();
		for (var i=0;i<=allowedList.length;i++)
		{
			var pos	=	photo.lastIndexOf(allowedList[i]);
			if (pos>0 )
			break;
		}
		
		if (pos<0 && photo!="")
		{
			alert("Please upload "+label+" only");
			eleName.select();
			eleName.focus();
			return false;
		}
	}
	



/**********************************************************************************
Function Name	:	trim
Purpose			:	This Function is used to trim the white space characters.

Parametrs		:	par	=>	Name of the Control

Function calls	:
Return types	:
Added By 		:	Mr Bibhuti
***********************************************************************************
String Table/Code domain name	:
Dependency						:
***********************************************************************************/
function trim(par)
{
	var i;
	var y;	
	y=par.length;
	ret='';
	for (i=0;i<y;i++)
	{
		if (par.charAt(i)!=' ')
		{
			ret=ret+par.charAt(i);
		}
	}
	return ret;
}

/******* ADDED BY PRADYUT ON 30-AUGUST-2007 to Check minimum length of the field***/
function isVaildMinLength(eleName,minLen,label)
{
var eleValue =eleName.value;
if (eleValue.length<minLen)
{
alert(label+" must be minimum "+minLen+" characters");
eleName.focus();
return false;
}
}


