//Javascript-------------------------------
//trim function
 function Trim(TRIM_VALUE){

        	if(TRIM_VALUE.length < 1){
        		return"";
        	}
        	TRIM_VALUE = RTrim(TRIM_VALUE);
        	TRIM_VALUE = LTrim(TRIM_VALUE);


            	if(TRIM_VALUE==""){
            		return "";
            	}


                	else{
                		return TRIM_VALUE;
                	}
            }


                function RTrim(VALUE){
                	var w_space = String.fromCharCode(32);
                	var v_length = VALUE.length;
                	var strTemp = "";


                    	if(v_length < 0){
                    		return"";
                    	}
                    	var iTemp = v_length -1;


                        	while(iTemp > -1){
                        		if(VALUE.charAt(iTemp) == w_space){}


                            		else{
                            			strTemp = VALUE.substring(0,iTemp +1);
                            			break;
                            		}
                            		iTemp = iTemp-1;
                            	}
                            	return strTemp;
                        }


                            function LTrim(VALUE){
                            	var w_space = String.fromCharCode(32);


                                	if(v_length < 1){
                                		return"";
                                	}
                                	var v_length = VALUE.length;
                                	var strTemp = "";
                                	var iTemp = 0;


                                    	while(iTemp < v_length){
                                    		if(VALUE.charAt(iTemp) == w_space){}


                                        		else{
                                        			strTemp = VALUE.substring(iTemp,v_length);
                                        			break;
                                        		}
                                        		iTemp = iTemp + 1;
                                        	}
                                        	return strTemp;
                                    }
                                    
                                    
// end trim function                                    

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 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;
         }
      }
   return IsNumber;
   
   }

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) && ch!=" ") 
		{
			return true;
		}
	}
	return false;
}
function checkMailId(mailids)
{


var sd = mailids.value;
var ids = sd.split(",");


for(var j=0; j<ids.length; j++)
{
		str=ids[j];
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		//alert(str);
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid "+str+"E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid "+str+"E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid "+str+"E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1)
		{
		    alert("Invalid "+str+"E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		    alert("Invalid "+str+"E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		{
		    alert("Invalid "+str+"E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1)
		{
		    alert("Invalid "+str+"E-mail ID")
		    return false
		 }
}

return true;
}


//phone validation

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{

	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()-, ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;

s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s));
}

function chk(varval,phnoval){
	if (varval=="ph")
	{
		var Phone=phnoval;
		msg="Phone";
	}
	if (varval=="mob")
	{
		var Phone=phnoval;
		msg="Mobile";
	}
	if (varval=="fax")
	{
		var Phone=phnoval;
		msg="Fax";
	}
	
	
	if (checkInternationalPhone(Phone.value)==false)
	{
		alert("Please Enter a Valid "+msg+ " Number");
		Phone.focus()
		return false
	}
	return true
 }
