// JavaScript Document
/*****************************************************
*This function is used to trim blank spaces.
****************************************************/

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

/*******************************************************
*This function will return true if string construct by alphabets
* otherwise it returns false.
*********************************************************/
// Alphabets function
function isNotAlphabets(str)
{
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
		{
			return true;
		}
	}
	return false;
}


//email validation

/*****************************************************************************
 * DHTML email validation script. 
 ****************************************************************************/
function emailAddressValidation(strValue) {
 	var atTheRate   = "@";
	var dotOperator = ".";
	var indetxOfatTheRate = strValue.indexOf(atTheRate);
	var indexOfDot  = strValue.indexOf(dotOperator);
	var strLength   = strValue.length;
	//To check position of "@" charactor. 
	if(indetxOfatTheRate == -1 || indetxOfatTheRate == 0 || indetxOfatTheRate == strLength-1){
		alert("Invalid E-mail ID");
		return false;
	}
 	
	//To check position of "." charactor.
	if(indexOfDot == -1 || indexOfDot ==  0 || indexOfDot == strLength-1){
		alert("Invalid E-mail ID");
		return false;
	}
	
	//To check "@" charactor is more then one.
	if(strValue.indexOf(atTheRate, indetxOfatTheRate+1) != -1){
		alert("Invalid E-mail ID");
		return false;	
	}
	
	
	//To check "." charactor should not be lastpostion of string befor "@" charator as well as first position after "@".
 	if(strValue.substring(indetxOfatTheRate-1,indetxOfatTheRate) == dotOperator || strValue.substring(indetxOfatTheRate+1,indetxOfatTheRate+2) == dotOperator ){
		alert("Invalid E-mail ID");
		return false;
	}
	
	//To check "." charactor afte @ charactor
	if(strValue.indexOf(dotOperator,indetxOfatTheRate+2) == -1){
		alert("Invalid E-mail ID");
		return false;
	}
	
	//To check empty spaces.
	if(strValue.indexOf(" ") != -1){
		alert("Invalid E-mail ID");
		return false;
	}
	return true;
 }


/*******************************************************
*This function return true if string contains integer 0-9
**********************************************************/
function isInteger(strValue){
	var iLength = strValue.length;
	for(var i =0; i < iLength; i++){
		var strSubstr = strValue.substring(i,i+1);
		if(strSubstr < "0" || strSubstr > "9"){
			
			return false;
		}	
	}
	return true;	
}
 
/*******************************************************
*This function return false if string format is (120-933-1234)
**********************************************************/
function isValidPhone(strValue){
	var iLength = strValue.length;
	var strSubstr = strValue.substring(0,3);
		if(!isInteger(strSubstr))
			return true;
	strSubstr = strValue.substring(3,4);
		if(strSubstr != "-")
			return true; 
	strSubstr = strValue.substring(4,7);
		if(!isInteger(strSubstr))
			return true;
	strSubstr = strValue.substring(7,8);
		if(strSubstr != "-")
			return true; 
	strSubstr = strValue.substring(8,12);
		if(!isInteger(strSubstr))
			return true;
	return false;
}


/*****************************************************************
*This method is used to check a web address validation
*********************************************************************/
function checkWebAddress(strWebAdd){
	var strLength = strWebAdd.length;
			if(strLength < 9)			
			return false;
	
		strSub   = strWebAdd.substring(0,7);
		if(strSub == "http://")
			if(check_dot(strWebAdd.substring(7,strLength)) > 0)
			    return true;
	return false;
}

function check_dot(strWebAdd){
	var strLength = strWebAdd.length;
	//var dotIndex  = strWebAdd.indexOf('.');
	var iCount = 0;
	if(strWebAdd.charAt(0) == '.')
		return 0;
	if(strWebAdd.charAt(strLength-1) == '.')
		return 0;
	for(var i=0; i< strLength; i++){
		var ch = strWebAdd.substring(i,i+1);
		if(ch == ".")
			iCount++;		
	}
	
	return iCount;

}

function checkDecemal(strVal){
	var strlength = strVal.length;
	var iCount = 0;
	var dotOperator = ".";
	if((strVal.indexOf(dotOperator)+1) ==  strlength) 
		return false;
	for(var i =0; i < strlength; i++){
		var ch = strVal.substring(i,i+1);
		if(ch == ".")
			iCount++;
		else
			if(ch < "0" || ch > "9")
				return false;	
		if(iCount == 2)
			return false;			
	}
	return true; 	
}
