

function fnNextPage(frmname,hdnname,intVal)

	{	
		//function to increment the counter and goto next page
		hdnname.value = intVal;		
		frmname.submit();
	}


function fnSort(frmname,hdnname,strCol,hdnSortCol)
	{	//function to increment the counter and goto next page
		
		if (trimString(hdnSortCol.value) == 1)	
		{
			hdnSortCol.value = '0';	
		}
		else
		{
			hdnSortCol.value = '1';
		}
		
		if (isEmpty(hdnSortCol.value) == false)
		{
			hdnSortCol.value = '1';
		}
		
		hdnname.value = strCol;		
		frmname.submit();
	}
function fnDelete(frmname,hdnPage,hdnname)
{var i;
      	for(i=0; i< frmname.elements.length; i++)
		{
			if(frmname.elements[i].type == 'checkbox')
			{
			if((frmname.elements[i].checked && frmname.elements[i].name == 'chkall'))
				{   if (window.confirm("Are you sure to Delete") == true)
					{
						hdnPage.value = 1;
						hdnname.value = 'D';
						frmname.submit();
						return true;
					}
					else
					{
						return false;
					}
				}
			}
		}
		alert("Please select an Item to delete.");
		return false;
	}

function fnchkall(frmname)
	{	// function to select all the check boxes incase of 'select all'
		if (! frmname.chkall.length)
		{
			frmname.chkall.checked = frmname.chkselect.checked;
		}
		for(i=0; i< frmname.chkall.length; i++)
			{
				frmname.chkall[i].checked = frmname.chkselect.checked;
			}

	}


function fnDetails(frmname,hidID,strId,strFile)
	{	
		hidID.value = strId;
		frmname.action = strFile;
		frmname.submit();				
	}


function isEmpty(value)
{
   if (trimString(value)=="") 
   {
    
	return false;
   }
  return true;
}

function trimString (str)
	{
		str = this != window? this : str;
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}



function fnFile(frmFile,strType,strUrl)
	{
	if (isEmpty(frmFile.txtFile.value) == false)
	{

	mywindow=window.open(strUrl + '?filetype='+strType, '', 'height=180,width=300,left=330,top=143');
	}
	else
		{
			if (window.confirm("File has already been uploaded. Do you want to continue") == true)
		{	mywindow=window.open(strUrl + '?filetype='+strType, '', 'height=180,width=300,left=330,top=143');
}
	
		}

	}




	function fnValidEmail(strEmail)
	{
	var emailStr= new String(strEmail);
	
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	var invalid = " ";
	var ok = "yes";
	if (emailStr !="")
	{
		if (matchArray==null)
		{
			alert("Please enter a valid Email Address")
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null)
		{
			alert("Please enter a valid Email Address")
			return false
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null)
		{
			for (var i=1;i<=4;i++)
			{
				if (IPArray[i]>255)
				{
					alert("Destination IP address in the Email Address is invalid")
					return false
				}
			}
			return true
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null)
		{
		     alert("The domain name is not valid");
			 return false  
		}
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
		{
			alert("The Email Address must end in a three-letter domain, or two letter country")
			return false
		}
		if (len<2)
		{
			var errStr="The Email Address is missing a hostname"
			alert(errStr)
			return false
		}
		for (var i=0; i < emailStr.length; i++)
			{       
			    temp = "" + emailStr.substring(i, i+1);
			    if (invalid.indexOf(temp) == "1")
			        ok = "no";
			}
		if (ok == "no")
		{
		    alert("Please enter a valid Email Address");
		    return false
		}
		if(emailStr.length>255)
		{
		    alert('Email Address can contain at most 255 characters');
		    return false
		}
	}
	
	}




//**************** empty filed validation*******
function fnIsEmpty(strTemp) {
	for (i=0; i < strTemp.length; i++) {
    	chTemp = strTemp.charAt(i);
		if ( (chTemp != " ") && (chTemp != "\n") && (chTemp != "\t") && (chTemp != "\r"))
        	return false;
	}
	return true;
}

//********Number field validation****************
			function isNu(value)
			{
	    	    var start = 0;
	    		for (i=start; i<value.length; i++)
			    {
					if(value.charAt(i) < "0")
					{
						return false;
					}
					if(value.charAt(i) > "9")
					{
						return false;
					}
		    	}
			    return true;
			}
			//********Number field validation****************
		
			//********Empty field validation***************
			function empty(val)
			{
				while(''+val.charAt(0)==' ')
				{
					val=val.substring(1,val.length);
				}
				return (val.length==0);
			}
			//********Empty field validation***************
			

/********* specialCheck which checks for single quote,double quote, less than & greater than  ******/
function specialCheck(txtField)
{
	//txtfield = phoneTxt;
	if(txtField.indexOf('"') != -1 || txtField.indexOf("'") != -1 || txtField.indexOf('<') != -1 || txtField.indexOf(">") != -1)
	{
		return false;
	}
	else return true;
			
}


/********* Accepts only alphanumeric _and ' '   *******/

function fnIsValidName(strTemp) {
 	var temp=strTemp;
	//this will accept only charactors and ' '
	var Name=/^[A-Za-z0-9\_\s]+$/g;
	if(temp.match(Name))return true;
	else return false;
}


/********* Accepts only numeric _ / - x ( ) and space  *******/

function fnIsValidPhone(strTemp) {
 	var temp=strTemp;
	//this will accept only numbers and _ / - x ( ) 
	var Name=/^[x0-9\_\/\-\(\)\s]+$/g;
	if(temp.match(Name))return true;
	else return false;
}


function fnIsValidZip(strTemp) {
 	var temp=strTemp;
	//this will accept only charactors and 
	var Name=/^[0-9-\s]+$/g;
	if(temp.match(Name))
	{
		if (temp.length < 5) return false
		if (temp.length > 10) return false
		if (temp.indexOf('-',0) != -1 && temp.indexOf('-',1) != 5) return false
		if (temp.length	> 5)
		{
			if (temp.length != 10) return false
			if (temp.substr(5,1) != '-') return false
			if (temp.indexOf('-',0) != -1 && temp.indexOf('-',0) != 5) return false
			if (temp.indexOf('-',6) != -1) return false
		
		}
		return true;		
	}
	else return false;

	
}


//**********Checks if all the values are numeric***************
function fnIsNumeric(strTemp){
	var reInteger = /^\d+$/
	if(trim(strTemp).match(reInteger))return true;
	else return false;	
}



//**********trims leading and trailing spaces***************
function trim(strText) { 
	// this will get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
	strText = strText.substring(1, strText.length);

	// this will get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);

	return strText;
} 



//********Checks if the field contains an aplhanumeric value************
function fnIsAlphanumeric(userfield){
	var strTemp = userfield;
	var Name = /^[A-Za-z\s]+$/g
	if(strTemp.match(Name))return false;
	else return true;
}

/********Login ID validation************/
function IsValidLogin(txtfield ,msgString){
	txtfield.value = trim(txtfield.value);
	var strTemp = txtfield.value;
	if(fnIsEmpty(strTemp)){
		alert("Please enter "+msgString);
		//alert("Please enter Username");
		txtfield.value="";
		txtfield.focus();
		return false;
	}else if(strTemp.indexOf(" ") != -1){
		alert(msgString+ " must be a minimum of 4 alpha/numeric characters and a maximum of 29. The use of an underscore (_) is acceptable");
		txtfield.focus();
		return false;
	}else if(!fnIsValidUserId(strTemp)){
		//alert(msgString+" cannot have any special characters");
		alert(msgString+" must be a minimum of 4 alpha/numeric characters and a maximum of 29. The use of an underscore (_) is acceptable");
		txtfield.focus();
		return false;	
	}
	return true;
}

/********* Accepts only characters,int,'_','-', . , ' '    *******/

function fnIsValidUserId(strTemp) {
 	var temp=strTemp;
	//this will accept only characters,int,'_','-', . , ' ' 
	var Name=/^[A-Za-z0-9\-\_\.]+$/g;
	if(temp.match(Name))return true;
	else return false;
}

/************ Password Validation ***********/
function IsValidPassword(txtfield, msgString){
	txtfield.value = trim(txtfield.value);
	strTemp = txtfield.value;
	if(fnIsEmpty(strTemp)){
		alert("Please enter "+msgString);
		//alert("Please enter a Password");
		txtfield.value = "";
		txtfield.focus();
		return false;
	}else if(strTemp.indexOf(" ") != -1){
		alert(msgString+ " must be a minimum of 4 alpha/numeric characters and a maximum of 20. No spaces or special characters are permitted");
		txtfield.focus();
		return false;
	}else if(!fnIsValidPassword(strTemp)){
//		alert(msgString+" cannot have any special characters");
		alert(msgString+" must be a minimum of 4 alpha/numeric characters and a maximum of 20. No spaces or special characters are permitted");
		txtfield.focus();
		return false;
		
	}
	return true;
}

/********* Accepts only characters,int   *******/

function fnIsValidPassword(strTemp) {
 	var temp=strTemp;
	//this will accept only characters,int 
	var Name=/^[A-Za-z0-9]+$/g;
	if(temp.match(Name))return true;
	else return false;
}


/***********UserName Validation************/

function IsValidUserName(txtfield, msgString){
	txtfield.value = trim(txtfield.value);
	strTemp = txtfield.value;
	if(fnIsEmpty(strTemp)){
		alert("Please enter "+msgString+".");		
		txtfield.value = "";
		txtfield.focus();
		return false;
	}else if(!fnIsValidUserName(strTemp)){
		alert(msgString+" cannot have any special characters");
	
		txtfield.focus();
		return false;	
	}
	
	return true;
}

/********* Accepts only characters,space, '.'  *******/

function fnIsValidUserName(strTemp) {
 	var temp=strTemp;
	//this will accept only characters,space, . , ' '
	var Name=/^[A-Za-z\s\.]+$/g;	
	if(temp.match(Name))return true;
	else return false;
}

