
/************************************************************
function : LTrim(strText)
usage    : for removing blank spaces from left of a string
inputs   : string.
output   : string without spaces on its left
e.g      : LTrim("  abc  ") = "abc  "
************************************************************/
function LTrim(strText)
{
	while (strText.substring(0,1) == ' ')
			strText = strText.substring(1, strText.length);
	return strText;
} 


/************************************************************
function : RTrim(strText)
usage    : for removing blank spaces from right of a string
inputs   : string.
output   : string without spaces on its right
e.g      : RTrim("  abc  ") = "  abc"
************************************************************/
function RTrim(strText)
{
	while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
	return strText;
}
	

/************************************************************
function : Trim(strText)
usage    : for removing blank spaces from right and left of a string
inputs   : string.
output   : string without spaces on its right and left
e.g      : Trim("  abc  ") = "abc"
**************************************************************/
function Trim(strText)
{
	return RTrim(LTrim(strText));
}



/************************************************************
function : IsNumeric(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns false, "-12" returns true
************************************************************/
function IsNumeric(strNum)
{
	
	if(strNum.indexOf(".")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 

/************************************************************
function : IsDigit(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns false, "-12" returns false
************************************************************/
function IsDigit(strNum)
{
	
	if(strNum.indexOf(".")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 


/************************************************************
function : IsDecimal(strNum)
usage    : to determine whether given string is decimal
inputs   : string.
output   : true if it is decimal, false otherwise.
e.g      : "123" returns true, "abc" returns false, "12.34" returns true,"-12.34" returns true
************************************************************/
function IsDecimal(strNum)
{
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 




/**************************************************************
function : CheckPhone(p1,p2,p3)
usage    : To check phone number of the form ###-###-####
inputs   : three textbox fields used as input to phone number, str is message to be displayed
output   : returns true if phone number is valid; otherwise returns false
e.g      : 123-345-6789 is valid phone number
**************************************************************/
function CheckPhone(p1,p2,p3,str)
{
	if (p1.value=="" & p2.value=="" & p3.value=="")
	{
		return true;
	}
	if(p1.value.length!=3)
	{
		alert(str);
		p1.select();
		p1.focus();		
		return false;
	}	
	if(!IsDigit(p1.value))
	{
		alert(str);
		p1.select();
		p1.focus();
		return false;
	}
	if(p2.value.length!=3)
	{
		alert(str);
		p2.select();
		p2.focus();		
		return false;
	}	
	if(!IsDigit(p2.value))
	{
		alert(str);
		p2.select();
		p2.focus();
		return false;
	}
	if(p3.value.length!=4)
	{
		alert(str);
		p3.select();
		p3.focus();		
		return false;
	}
	if(!IsDigit(p3.value))
	{
		alert(str);
		p3.select();
		p3.focus();
		return false;
	}
	
	return true;
}

function IsMoney(strNum)
{
	
	//if(strNum.indexOf(".")!=-1)
	//{
	//	return false;
	//}
	var blnFlag=0
	var intLen=strNum.length
	if ( strNum.charAt(0)==".")
	{		
		return false
	}
	if (strNum.charAt(intLen-1)==".")
	{		
		return false
	}
	for (var i=0;i<intLen;i++)
	{
		if (strNum.charAt(i)==".")
		{
			blnFlag=blnFlag+1
		}
	}
	if (blnFlag>1)
	{		
		return false
	}
	if(strNum.indexOf("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 

/************************************************************
function : CheckZip(p1,p2,str)
usage    : To check Zip number of the form #####-####
inputs   : two textbox fields used as input to zip number, str is message to be displayed
output   : returns true if zip number is valid; otherwise returns false
e.g      : 12334-6789 is valid Zip Number
************************************************************/

function CheckZip(p1,p2,str)
{
	if (p1.value=="" & p2.value=="")
	{
		return true;
	}
	if(p1.value.length!=5)
	{
		alert(str);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value))
	{
		alert(str);
		p1.select();
		p1.focus();
		return false;
	}
	if(p2.value.length!=4)
	{
		alert(str);
		p2.select();
		p2.focus();		
		return false;
	}	
	if(!IsDigit(p2.value))
	{
		alert(str);
		p2.select();
		p2.focus();
		return false;
	}
	
	return true;
}


/************************************************************
function : CheckEmail(strMail)
usage    : To check Validity Of Email
inputs   : string containing mail address
output   : returns true if email is valid; otherwise returns false
e.g      : abc@xyz.com is valid Email Address.

***********************************************************

function CheckEmail(strMail)
{
	var strMessage;
	strMessage="Invalid E-Mail Address"
	if (strMail.value=="")
	{
		return true;
	}
	var intLen=strMail.value.length
	var blnFlag=0
	if (strMail.value.charAt(0)=="@" || strMail.value.charAt(0)==".")
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	if (strMail.value.charAt(intLen-1)=="@" || strMail.value.charAt(intLen-1)==".")
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	for (var i=0;i<intLen;i++)
	{
		if (strMail.value.charAt(i)=="@")
		{
			blnFlag=blnFlag+1
		}
	}
	if (blnFlag>=0 && blnFlag<1 || blnFlag>1)
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	strSplit=(strMail.value).split("@")
	intSptLen=strSplit[1].length
	var intCnt=0
	for(var j=0;j<intSptLen;j++)
	{
		if (strSplit[1].charAt(j)==".")
		{
			intCnt=intCnt+1
		}
	}
	if (intCnt<=0)
	{
		alert(strMessage)
		strMail.select()
		strMail.focus()
		return false
	}
	return true
}
*/
function CheckEmail(strMail)
 { 
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strMail.value))
{
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
strMail.focus();
strMail.select();
return (false)
}

/**************************************************************
function : CheckTaxID(p1,strMessage)
usage    : To check TaxID of the form ##-#######
inputs   : string containing taxid
output   : returns true if taxid is valid; otherwise returns false
e.g      : 12-3456789 is valid tax id
**************************************************************/
function CheckTaxID(p1,strMessage)
{
	var strMessage;
	if (p1.value=="")
	{
		return true;
	}
	if(p1.value.length!=10)
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(0,2)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(2,3)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(3)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
return true;
}

/**************************************************************
function : CheckSSN(p1,strMessage)
usage    : To check SSN number of the form ###-##-####
inputs   : string containing ssn number
output   : returns true if ssn number is valid; otherwise returns false
e.g      : 123-34-6789 is valid phone number
**************************************************************/
function CheckSSN(p1,strMessage)
{
	var strMessage;
	if (p1.value=="")
	{
		return true;
	}
	if(p1.value.length!=11)
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(0,3)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(3,4)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(4,6)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(6,7)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(7)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
return true;
}

///this function is used to check if value in textbox is empty
function CheckBlank(p,strMessage)
{
	if(Trim(p.value)=="")
	{
		alert(strMessage);
		p.select();
		p.focus();
		return false;
	}
	return true;
}
///Date Validation function
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

////////////////////////////////////////////////////////
//////////////////    Checking for the special character in the string   //////////////////////////////////     
///////////////////////////////////////////////////////
function SpecialCharEmail(str)
{
  var chk1 = "!#$%^*()+=|\~`{} []:'<>?/";
  
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid email");
			return false;
		}

   }
   return true;
}

///////////Functions For Check All Facility Start


	
	////////////////////
	//URL VALIDATION
	///////////////////	
	
function IsValidURL(urlString)
 {
	var urlReg = "^(file|http|https|ftp):\\/\\/([a-zA-Z0-9]*\\.)?[a-zA-Z0-9-]*\\.[a-zA-Z0-9]*(\\.[a-zA-Z0-9]*)?\\/?$";
	var regex = new RegExp(urlReg);
	var okURL = regex.test(urlString);
	return okURL;
 }
 ///////////////////////////////////
/////URL Validation
////////////////////////////////////
function ValidUrl(str)
{
	re = /^(file|http|https|ftp):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc)$/i
	if (!re.test(str)) 
     {
           alert ("Please Enter Proper Site URL");          
           return false;
       }
      return true; 
      }
 
 //////////////
///Validation of file  either image(*.gif of *.jpg) file or not
//////////////// 

function ValidImage(x)
{		
				var y=x.value;					
				var imglen=y.length;
				var imgdotpos=y.lastIndexOf(".");
				var imgext=y.substring(imgdotpos+1,imglen);
								
				if((imgext!="jpg")&& (imgext!="gif") && (imgext!="JPG")&& (imgext!="GIF"))
				{
					alert("Company Logo Image Must Be Of Type .jpg Or .gif")
					x.select();
					x.focus();
					return false;
				}
	}	
	
//Validation For XML File

function ValidXMLFile(x)
{		
				var y=x.value;					
				var imglen=y.length;
				var imgdotpos=y.lastIndexOf(".");
				var imgext=y.substring(imgdotpos+1,imglen);
								
				if((imgext!="xml")&& (imgext!="XML"))
				{
					alert("Job File Must be Of Type .xml")
					x.select();
					x.focus();
					return false;
				}
	}	

	
	//Checking for the special character in the string
function SpecialChar(str)
{
  var chk1 = "!@#$%^*()-+=|\~`{}[]:'<>?/";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid entry");
			return false;
		}

   }
   return true;
}
function isNumInStr(s)

{   var i;

    if (isEmpty(s)) 
       if (isNumDigit.arguments.length == 1) return defaultEmptyOK;
       else return (isNumDigit.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (IsDigit(c)) 
        return false;
    }

    // All characters are numbers. 
    return true;
}
/*
function SpecialCharEmail(str)
{
  var chk1 = "!#$%^*()+=|\~`{} []:'<>?/";
  
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please Enter Valid Email");
			return false;
		}

   }
   return true;
}*/
function SpecialChar1(str)
{
  var chk1 = "!@$%^+=|\~`{}[]:<>?";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid entry");
			return false;
		}

   }
   return true;
}
function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || IsDigit(c) ) )
        return false;
    }

    // All characters are numbers.
    return true;
}
//New Function for Phone Number Dipen shah 09222005

function CheckPhoneNew(p1,str)
{
  var chk1 = "1234567890,-#";
  for(var i=0;i<p1.value.length;i++)
   {
	var ch=p1.value.charAt(i);
		if(ch==" ")
			return true;
	var rtn1=chk1.indexOf(ch);
	if (rtn1 == -1)
		{
			alert(str);
			p1.select();
			p1.focus();
			return false;
		}
   }
   return true;	
}