// JScript File

// Constant Variables

	var gintMaxTextAreaLength = 1024;
	
//--------------To Open PopUp--------------------
var strWindowName;
strWindowName = '';
function CallOpenPopUp(Url)
{
	if (screen.width == "800")
	{
		winStatus = window.open(Url,strWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=900,height=670,scrollbars=yes,resizable=no,top=19,left=30')
	}
	else
	{
		winStatus = window.open(Url,strWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=900,height=670,scrollbars=yes,resizable=no,top=19,left=30')
	}
}

//--------------To Open Small PopUp--------------------
var strSmallWindowName;
strSmallWindowName = '';
function CallOpenSmallPopUp(Url)
{
	if (screen.width == "800")
	{
		winStatus = window.open(Url,strSmallWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=315,height=325,scrollbars=yes,resizable=no,top=290,left=290')
	}
	else
	{
		winStatus = window.open(Url,strSmallWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=315,height=325,scrollbars=yes,resizable=no,top=290,left=290')
	}
}

	
//-- Common Function to Trim the empty space in front and back value of each ctrl.
function fnStripBlanks(ObjCtrl)
{
 	    var newString;
	    var i;
	    var j;
	    var blank;
	    blank = " ";
	    newString = "";
	    aString = ObjCtrl.value;	
	    if(aString == null) aString = " ";
	    for (i=0; i<aString.length; i++)
	    { 
		    if (aString.charAt(i) != blank && aString.charCodeAt(i)!= 13 && aString.charCodeAt(i) != 10 )
		    {
			    break;
		    }
	    }
	    for (j=aString.length-1; j>=0; j--)
	    {
		    if (aString.charAt(j) != blank   && aString.charCodeAt(j)!= 13 && aString.charCodeAt(j) != 10 )
		    {
				    break;
		    }
	    }
	    
	    newString = aString.substring(i,j+i+1)
		return newString;
}

//-- Common Function to validate where the ctrl(for all the ctrl) is left empty or not selected.
function fnCheckIsEmpty(ObjCtrl,strTitle)
{
	var bStringEmpty = true;
	var strValue = ObjCtrl.value;
	var strType = ObjCtrl.type;
	strType = strType.toUpperCase();

	if(strType == "TEXT" || strType == "TEXTAREA" || strType == "PASSWORD")
	{
		if( strValue != null )
		{
			//getting the length of the string
			var nLength = strValue.length
		
			//checking the length of the contents of the text box
			if(nLength > 0)
			{
				for(i=0;i<nLength;i++)
				{
					if (strValue.charAt(i) != " " && strValue.charAt(i) != "\t" && strValue.charCodeAt(i) != 13 && strValue.charCodeAt(i) != 10 )
					{
						bStringEmpty = false;
						break;
					}
				}
			}
		}
		if (bStringEmpty)
		{
			 alert("Please enter your " + strTitle + ".");
			 ObjCtrl.focus();
		}
	}
	else if(strType == "SELECT-ONE")
	{
		if(ObjCtrl.selectedIndex > 0)
		{
			bStringEmpty = false;
		}
		if (bStringEmpty)
		{
			 alert("Please select a " + strTitle + ".");
			 ObjCtrl.focus();
		}
	}
	
	return bStringEmpty;
}

//CheckIsEmpty
function fnCheckIsSetEmpty(ObjCtrl)
{
	var bStringEmpty = true;
	var strValue = ObjCtrl.value;
	var strType = ObjCtrl.type;
	strType = strType.toUpperCase();

	if(strType == "TEXT" || strType == "TEXTAREA")
	{
		if( strValue != null )
		{
			//getting the length of the string
			var nLength = strValue.length
		
			//checking the length of the contents of the text box
			if(nLength > 0)
			{
				for(i=0;i<nLength;i++)
				{
					if (strValue.charAt(i) != " " && strValue.charAt(i) != "\t" && strValue.charCodeAt(i) != 13 && strValue.charCodeAt(i) != 10 )
					{
						bStringEmpty = false;
						break;
					}
				}
			}
		}
	}
	else if(strType == "SELECT-ONE")
	{
		if(ObjCtrl.selectedIndex > 0)
		{
			bStringEmpty = false;
		}
	}
	
	return bStringEmpty;
}

//-- Common Function to validate where the ctrl value has valid Numbers.
function fnCheckNumber(ObjCtrl,strTitle)
{
	
	var strTmp = ObjCtrl.value;
	
	var valid = "0123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<strTmp.length; i++)
	{
		temp = ""+ strTmp.substring(i, i+1);
				
		if (valid.indexOf(temp) == -1) 
		{
			ok = "no";
			break;
		}
	}
	if (ok == "no")
	{  
		alert("Please enter only numbers in " + strTitle +".");
		ObjCtrl.focus();
		return false;
	}	
	return true;
} 

//Check Zero
function fnCheckZero(ObjCtrl,strTitle)
{
    var strTmp = ObjCtrl.value;
	
	var valid = "123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<strTmp.length; i++)
	{
		temp = ""+ strTmp.substring(i, i+1);
				
		if (valid.indexOf(temp) == -1) 
		{
			ok = "no";
			break;
		}
	}
	if (ok == "no")
	{  
		alert("Please enter only positive numbers in " + strTitle +".");
		ObjCtrl.focus();
		return false;
	}	
	return true;
}     

//-- Common Function to validate where the ctrl value has valid Decimal Numbers.
function fbCheckDecimalNumber(ObjCtrl,strTitle)
{
				
		var strTmp = ObjCtrl.value;
	
		var valid = "0123456789.";
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only numbers in " + strTitle +".");
			ObjCtrl.focus();
			return false;
		}	
		return true;
}
        
//-- Common Function to validate where the ctrl value has valid Phone Numbers with Plus sign and etc.
function fnCheckPhoneNumberPlus(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;
	
		var valid = "1234567890 +()-" ;
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only numbers, space, brackets, hyphen and plus in " + strTitle + ".")
			ObjCtrl.focus();
			return false;
		}	

		return true;
}

//-- Common Function to validate where the ctrl value has valid Phone Numbers.
function fnCheckPhoneNumber(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;
	
		var valid = "1234567890 " ;
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only numbers and space in " + strTitle + ".")
			ObjCtrl.focus();
			return false;
		}	
		return true;
}
        
        
//-- Common Function to validate where the ctrl value has valid EmailID.
function fnCheckEmail(ObjCtrl, strTtile,strType)
{
        if (strType =="No")
		{
		var strValue = ObjCtrl;
		}
		else
		{
		var strValue = ObjCtrl.value;
		}
		var filter  = /^([a-zA-Z0-9_\.\-'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(strValue))
		{
			alert("E-mail ID should be of the form - name@company.com or name@company.co.country in " + strTtile + ". Please try again.");
			if (strType !="No")
			{
			ObjCtrl.focus();
			}
			return false;			
		}  
		return true;			        
}	


//-- Common Function to validate where the ctrl value has valid Name.
function fnCheckName(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;  	
		
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ;
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				alert("Please enter only alphabetic characters and space in " + strTitle + ".");
				ObjCtrl.focus();
				return false;
				break;
			}
		}
		return true;   	
}

//-- Common Function to validate where the ctrl value has valid Name.
function fnCheckFLName(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;  	
		
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' " ;
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				alert("Please enter only alphabetic characters,single quote and space in " + strTitle + ".");
				ObjCtrl.focus();
				return false;
				break;
			}
		}
		return true;   	
}

//-- Common Function to validate where the ctrl value has valid specified length.
function fnCheckMaxLength(ObjCtrl,intLength,strTitle)
{
		var sourcetextlen = ObjCtrl.value.length;
		if (sourcetextlen > intLength)
		{
			alert("Please enter only a maximum of " + intLength + " characters in " + strTitle + "." );
			ObjCtrl.focus();
			return false;
		}
		return true;
}

//-- Common Function to validate where the ctrl value has atleast specified length.
function fnCheckMinLength(ObjCtrl,intLength,strTitle)
{
		var sourcetextlen = ObjCtrl.value.length;
		if (sourcetextlen < intLength)
		{
			alert("Please enter atleast a minimum of " + intLength + " characters in " + strTitle + "." );
			ObjCtrl.focus();
			return false;
		}
		return true;
}

//-- Common Function to validate where the ctrl value has valid Name.
function fnCheckFirstLetterAlbhabet(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;  		
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-'_,. ";
		var Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";		
		var temp;
		var FirstChar = strTmp.substring(0,1);					
		if (Char.indexOf(FirstChar) == -1)
		{
			alert("Please enter only alphabets as first character in " + strTitle + ".");
			ObjCtrl.focus();
			return false;			
		}	
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);					
			if (valid.indexOf(temp) == -1) 
			{
				alert("Please enter only alphabetic characters, numbers, space, hyphen, underscore, apostrophe, comma and dot in " + strTitle + ".");
				ObjCtrl.focus();
				return false;
				break;
			}			
		}				
		return true;    	
}

//--Commom function to convert first character as Capital letter
function fnFirstCharCaps(Field)    
{	
	var tmpStr;

	tmpStr=Field.value;
	tmpStr = fnStripBlanks(Field);
	Field.value=tmpStr;
	
	tmpStr = tmpStr.substr(0,1).toUpperCase() + tmpStr.substr(1,tmpStr.length);
	Field.value=tmpStr;
}
//-- Common Function to validate where the ctrl value has valid Alphabets.
function fnCheckAlphabet(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;  	
		
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				alert("Please enter only alphabetic characters in " + strTitle + ".");
				ObjCtrl.focus();
				return false;
				break;
			}
		}
		return true;   	
}

//-- Common Function to validate where the ctrl value has valid Alpha Numeric.
function fnCheckAlphaNumeric(ObjCtrl,strTitle)
{
	
		var strTmp = ObjCtrl.value;
		var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only alphabetic characters and numbers in " + strTitle +".");
			ObjCtrl.focus();
			return false;
		}	
		return true;
}


//checkAlphaNumericPassword
function fnCheckAlphaNumericPassword(ObjCtrl,strTitle)
{
	
		var strTmp = ObjCtrl.value;
		var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Your password must be of at least 7 characters and a mix of alphabetic and numeric characters.  Please type a different password.");
			ObjCtrl.focus();
			return false;
		}	
		var validnum = "0123456789";
		var oknum = "no";
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
			if (validnum.indexOf(temp) != -1 ) 
			{
				oknum = "yes";
				break;
			}
		}
		if (oknum == "no")
		{  
			alert("Your password must be of at least 7 characters and a mix of alphabetic and numeric characters.  Please type a different password.");
			ObjCtrl.focus();
			return false;
		}
		var validAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var okAlpha = "no";
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
			if (validAlpha.indexOf(temp) != -1 ) 
			{
				okAlpha = "yes";
				break;
			}
		}
		if (okAlpha == "no")
		{  
			alert("Your password must be of at least 7 characters and a mix of alphabetic and numeric characters.  Please type a different password.");
			ObjCtrl.focus();
			return false;
		}
		return true;
}

//-- Common Function to validate where the ctrl value has valid Alpha Numeric.
function fnCheckAlphaNumericSpecialChars(ObjCtrl,strTitle)
{
	
		var strTmp = ObjCtrl.value;
		var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz $%^/\&!@#*()-_=+,.'";
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only alphabetic characters, numbers and $%^&!@#*()-_=+,.'/\ in" + strTitle +".");
			ObjCtrl.focus();
			return false;
		}	
		return true;
}

//-- Common Function to validate where the ctrl value has valid Zip Code.
function fnCheckZipCode(ObjCtrl,strTitle)
{
		var strTmp = ObjCtrl.value;
		var intBlankOccurance = 0;
		var strAlertMsg;
		var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ";
		var temp;
	
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
	
			if (valid.indexOf(temp) == -1)
			{
				return false;
				break;
			}
			else
			{
				if(temp == " ")
				{
					intBlankOccurance = intBlankOccurance + 1;
				}
			}
		}
		if (intBlankOccurance > 1)
		{
			alert("Please enter only alphabetic characters, numbers and space in " + strTitle + ".");
			ObjCtrl.focus();
			return false;
		}
		else
			return true;
}	

//checkDecimalNumber
function fnCheckDecimalNumber(ObjCtrl,strTitle)

{     

      var strTmp = ObjCtrl.value;      

      var valid = "0123456789.";
      var ok = "yes";
      var temp;
      var intDotCnt = 0;
      

      for (var i=0; i<strTmp.length; i++)
      {
            temp = ""+ strTmp.substring(i, i+1);                       

            if (valid.indexOf(temp) == -1) 
            {
                  ok = "no";
                  break;
            }
            if (temp == '.')

                  intDotCnt = intDotCnt + 1;

            if (intDotCnt > 0 && temp == ',')

                  intDotCnt = 100;

            if (i == 0 && temp == ',')

                  intDotCnt = 100;

            if (i == strTmp.length -1 && (temp == ',' || temp == '.'))

                  intDotCnt = 100;
      }

      if (strTmp.indexOf("-") > 0)
            intDotCnt = 100;
         

      if (ok == "no")
      {  
            alert("Please enter only numbers and decimal in " + strTitle +".");
            ObjCtrl.focus();
            return false;
      }     

      if (intDotCnt > 1)
      {
            alert("Please enter a valid decimal value in " + strTitle +".");
            ObjCtrl.focus();
            return false;
      }

      return true;

}

//-- Common Function to validate where the ctrl value has valid Alpha Numeric.
function fnCheckAlphaNumericandSpace(ObjCtrl,strTitle)
{
	
		var strTmp = ObjCtrl.value;
		
		var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ;
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only alphabetic characters, numbers and space in " + strTitle +".");
			ObjCtrl.focus();
			return false;
		}	
		return true;
}

//-- Common Function to validate where the  value has valid Alpha Numeric, Number, Space, , Hyphen, Ambersand & Single Quote.
function fnCheckAlphaNumericSpaceHyphenAmbersandSingleQuote(ObjCtrl,strTitle)
//checkAlphaNumericSpaceHyphenAmbersandSingleQuote
{
	
		var strTmp = ObjCtrl.value;
		
		var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -&'" ;
		var ok = "yes";
		var temp;
		for (var i=0; i<strTmp.length; i++)
		{
			temp = ""+ strTmp.substring(i, i+1);
					
			if (valid.indexOf(temp) == -1) 
			{
				ok = "no";
				break;
			}
		}
		if (ok == "no")
		{  
			alert("Please enter only alphabetic characters, numbers, space, single quote, ampersand and hyphen in " + strTitle +".");
			ObjCtrl.focus();
			return false;
		}	
		return true;
}


//products & services popup
var strBigWindowName;
strBigWindowName = '';
function CallOpenBigPopUp(Url)
{
	if (screen.width == "800")
	{
		winStatus = window.open(Url,strBigWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=675,height=325,scrollbars=yes,resizable=no,top=290,left=290')
	}
	else
	{
		winStatus = window.open(Url,strBigWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=675,height=325,scrollbars=yes,resizable=no,top=290,left=290')
	}
}



// popup for TCRMS
var strTcrmsWindowName;
strTcrmsWindowName = '';
function callTcrms(Url)
{
	if (screen.width == "800")
	{
		winStatus = window.open(Url,strTcrmsWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=650,height=660,scrollbars=yes,resizable=no,top=25,left=200')
	}
	else
	{
		winStatus = window.open(Url,strTcrmsWindowName,'menubar=no,toolbar=no,location=no,hotkeys=no,status=no,copyhistory=no,width=650,height=660,scrollbars=yes,resizable=no,top=25,left=200')
	}
}
