

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function CheckValidation(fieldList)
{
	
		var field=new Array();
		field=fieldList.split("~");
	 
		var counter=0;
		for(i=0;i<field.length;i++) {
			
			if(document.getElementById(trim(field[i])).value=="") {
 
				document.getElementById(field[i]).style.backgroundColor="#ffffb9";
				counter++;
			} else {
				document.getElementById(field[i]).style.backgroundColor="#FFFFFF";	
			}
		}
		if(counter>0) {
				alert("The Field mark as yellow could not left empty");
				return false;
				
		}
		else
		{
			 
			return Validatemail();
		}
   
	}
function echeck(str) {
 
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function Validatemail( ){
  var emailID=document.addcategory.TxtEmailAddress;
	 
	//if ((emailID.value==null)||(emailID.value=="")){
		//alert("Please Enter your Email ID")
		//emailID.focus()
		//return false
	//}
	 
	if (echeck(emailID.value)==false)
		{
		emailID.value="";
		emailID.focus();
		return false
		}
	return true
 }

	 



function chTextin()
{
var txt=document.getElementById('TxtSearch').value;
if(txt=="i am looking for")
{
document.getElementById('TxtSearch').value=''; 
}
}


function addCommasNoSpecialCharacters(oObj, e){
    var KeyID = e.keyCode? e.keyCode : e.charCode

    if (KeyID == 9 || KeyID == 16)
        return oObj.value;
	
	try{
		var sValue = oObj.value;
		 
		var sNewVal = '';
				
		//===[ m.squires - GS-6907 Checking for a decimal point and displaying alert to
		//===				interrupt user input to prevent them from type the rest of the decimal value
		//===				This interruption prevent a the user from type the value 1.11, which would 
		//===				show up as 111, without the interruption

		sValue = sValue.replace(/[^0-9,.]/g,"");	//remove non numeric values - a two digit decimal value is allowed
		
		
		//Remove Leading Zeros, If more than 1
		if (oObj.value.length > 1) {
			while (oObj.value.indexOf("0") == 0){
				sValue = sValue.replace('0',"")
				break;
			}
		}
		if (oObj.value.length > 1) {
			for (idx=1; idx < oObj.maxLength; idx++){
				if(oObj.value.charAt(idx) == "0" && oObj.value.charAt(0) == "0"){
					sValue = sValue.replace(oObj.value.charAt(idx),"")
				}
				else break;
			}

			if(oObj.value.charAt(0) == "0" && oObj.value.charAt(1) != "0") {
				sValue = sValue.replace(oObj.value.charAt(0),"")
			}           
		}
		
		// attempting to remove extra characters that may have slipped in.
		if (oObj.maxLength && oObj.maxLength > 0){
			if (sValue.length > parseInt(oObj.maxLength)){ 
				sValue = sValue.substr(0,oObj.maxLength-(parseInt(oObj.maxLength/3))) //MaxLength must = 4, 7 or 10 
			}
		}
		
		index = 0
		compVal = ""
		decVal = ""
		
		// Set the value for compVal		
		while ((index < sValue.length) && (oObj.value.charAt(index) != ".")){
				
				if (oObj.value.charAt(index) != ","){
				    compVal = compVal + sValue.substr(index,1);
				}
				index = index + 1;
			
		}
		
		// Set the value for decVal
		if (oObj.value.charAt(index) == "."){
		    
		        decVal = oObj.value.charAt(index) + oObj.value.charAt(index+1) + oObj.value.charAt(index+2);
		      
		}		      
					
		if(compVal > 99){
		    
			var nCommas = parseInt((compVal.length / 3))
			
			if ((compVal.length % 3) == 0){
				//subtract extra comma that can occur if modulus = 0 
				--nCommas
			}	
						
			if (nCommas > 0){

					for (n = nCommas; n > 0; n--){		//add comma(s)
						sNewVal =  sNewVal + ',' + compVal.substr((compVal.length-(n*3)),3);
					}//add remaining
				    
					sNewVal =  compVal.substr(0,((compVal.length-(nCommas*3)) / 1)) + sNewVal;
					
					sNewVal = sNewVal + decVal;
					oObj.value = sNewVal;
				}
			else{
					oObj.value = compVal + decVal;
			}		
				
		}
		else{
			oObj.value = sValue;
		}   
			return (oObj.value);
	}
	catch(exception){
		//do nothing
	}
}



function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
		 alert("Please Enter a Valid Phone Number");
         }
		 else
		  {
			 return Validatemail();
		  }
      }
   return IsNumber;
   
   }




