// JavaScript Document
/* null checking */
function check_fieldsUser(form_name,f_name,d_name,c_array)
{

    var incre=0;
        
    for (incre=0; incre<c_array; incre++)
    {
        var frm="document."+form_name+"."+f_name[incre]+".value";
        var foc="document."+form_name+"."+f_name[incre];
        var password               = "document."+form_name+".txtPassword.value";
        var cnfpassword               = "document."+form_name+".txtCnfPassword.value";
				
        //var zipcode				   = "document."+form_name+".txtZIP.value";
				
        //var Phone				   = "document."+form_name+".txtPhone.value";
				
        var firstname			   = "document."+form_name+".txtFirstName.value";

        var lastName			   = "document."+form_name+".txtLastName.value";
				
        if(trimSpacesUser(eval(frm))=="")
        {
            alert(d_name[incre]  + ' ' + appendString);
            var foc_field=eval(foc);
            foc_field.focus();
            return false;
        }
		

       /* if ((special(eval(frm)) == true) && (f_name[incre]=='txtUserName'))
        {
            alert(d_name[incre]+msgHasSpecialCharacters);
            var foc_field=eval(foc);
            foc_field.focus();
            return false;
        }*/

        if(eval(password)!="" && eval(cnfpassword)!="")
            {
                if(eval(password)!=eval(cnfpassword))
                    {
                        alert("Password mismatch");
                        var foc_field=eval(foc);
                        $("#password").focus();
                        return false;
                    }
            }
		 
      /*  if(f_name[incre]=='txtFirstName')
        {
            if(!(containsAlphabets(eval(firstname))))
            {
                alert("Enter a valid firstname");
                var foc_field=eval(foc);
                foc_field.focus();
                return false;
            }
        }
        if(f_name[incre]=='txtLastName')
        {
            if(!(containsAlphabets(eval(lastName))))
            {
                alert("Enter a valid lastname");
                return false;
            }
        }*/
		
    /*
		var zip_country	   = document.getElementById("billCountrySelect").value;
		
		if(zip_country == "US" || zip_country == "UM")
		{
		 if(eval(zipcode)!='' && validateZIP(eval(zipcode)))
					{	
						alert("Enter valid zip code");
                            return false;
					}
		}
					
					
		
		if(f_name[incre]=='txtPhone')
		{
			
			var regexObj = /^[0-9-(+)]+$/; //^[a-zA-z]+$/
			var phone=trimSpaces(eval(Phone));
			if (!regexObj.test(phone))
			{
				alert("Invalid Phone number");
				return false;
			}
				   

		}
					
					if(eval(Phone)!='' &&  eval(Phone)==0)
					{	
						alert("Enter valid phone number ");
                            return false;
					}
		*/
                
    }
    return true;
}

function check_fieldsOnly(form_name,f_name,d_name,c_array)
{

    var incre=0;

    for (incre=0; incre<c_array; incre++)
    {
        var frm="document."+form_name+"."+f_name[incre]+".value";
        var foc="document."+form_name+"."+f_name[incre];
       

        if(trimSpacesUser(eval(frm))=="")
        {
            alert(d_name[incre] + appendString);
            var foc_field=eval(foc);
            foc_field.focus();
            return false;
        }



       

    

    }
    return true;
}


function check_login(form_name,f_name,d_name,c_array)
{

    var incre=0;
        
    for (incre=0; incre<c_array; incre++)
    {
        var frm="document."+form_name+"."+f_name[incre]+".value";
        var foc="document."+form_name+"."+f_name[incre];
        var password               = "document."+form_name+".txtPassword.value";
        var confirmPassword        = "document."+form_name+".txtConfirmPassword.value";
				
   				
               
        if(trimSpacesUser(eval(frm))=="")
        {
            alert(d_name[incre]+appendString);
            var foc_field=eval(foc);
            foc_field.focus();
            return false;
        }
		
		
		
       /* if (special(eval(frm)) == true)
        {
            alert(d_name[incre]+msgHasSpecialCharacters);
            var foc_field=eval(foc);
            foc_field.focus();
            return false;
        }*/
                
    }
    return true;
}

function validateZIP(field) {
    var valid = "0123456789-";
    var hyphencount = 0;

    if (field.length!=5 && field.length!=10) {
        //alert("Please enter your 5 digit or 5 digit+4 zip code.");
        return true;
    }
    for (var i=0; i < field.length; i++) {
        temp = "" + field.substring(i, i+1);
        if (temp == "-") hyphencount++;
        if (valid.indexOf(temp) == "-1") {
            //alert("Invalid characters in your zip code.  Please try again.");
            return true;
        }
        if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
            //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
            return true;
        }
    }

}

function special(strString) 
{
    var iChars = "!#$%^&*()+=[]\\\';,/{}|\":<>?~";
    var data =strString;
    for (var i = 0; i < data.length; i++) {
        if (iChars.indexOf(data.charAt(i)) != -1) {
            //alert ("Your string has special characters. \nThese are not allowed.");
            return true;
        }
    }
}
 


function trimSpacesUser(stringValue) 
{
    // Checks the first occurance of spaces and removes them
    for(i = 0; i < stringValue.length; i++)
    {
        if(stringValue.charAt(i) != " ")
        {
            break;
        }
    }
	
    if(i > 0)
    {
        stringValue = stringValue.substring(i);
    }
	
    // Checks the last occurance of spaces and removes them
    strLength = stringValue.length - 1;
    for(i = strLength; i >= 0; i--)
    {
        if(stringValue.charAt(i) != " ")
        {
            break;
        }
    }
	
    if(i < strLength)
    {
        stringValue = stringValue.substring(0, i + 1);
    }
	
    // Returns the string after removing leading and trailing spaces.
    return stringValue;
}

function containsAlphabets(checkString) {
    var tempString="";
    var regExp = /^[A-Za-z]$/;
    if(checkString != null && checkString != "")
    {
        for(var i = 0; i < checkString.length; i++)
        {
            if (!checkString.charAt(i).match(regExp))
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
    return true;
}

function checkEmail(emailString)
{
    splitVal = emailString.split('@');
	
    if(splitVal.length <= 1)
    {
        alert("Please Enter A Valid Email Address !!");
        return false;
    }
    if(splitVal[0].length <= 0 || splitVal[1].length <= 0)
    {
        alert("Please Enter A Valid Email Address !!");
        return false;
    }
	
    splitDomain = splitVal[1].split('.');
    if(splitDomain.length <= 1)
    {
        alert("Please Enter A Valid Email Address !!");
        return false;
    }
	
    if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1)
    {
        alert("Please Enter A Valid Email Address !!");
        return false;
    }
    return true;
}

function checkMail(email)
{
    var str1=email;
    var arr=str1.split('@');
    var eFlag=true;
    if(arr.length != 2)
    {
        eFlag = false;
    }
    else if(arr[0].length <= 0 || arr[0].indexOf(' ') != -1 || arr[0].indexOf("'") != -1 || arr[0].indexOf('"') != -1 || arr[1].indexOf('.') == -1)
    {
        eFlag = false;
    }
    else
    {
        var dot=arr[1].split('.');
        if(dot.length < 2)
        {
            eFlag = false;
        }
        else
        {
            if(dot[0].length <= 0 || dot[0].indexOf(' ') != -1 || dot[0].indexOf('"') != -1 || dot[0].indexOf("'") != -1)
            {
                eFlag = false;
            }

            for(i=1;i < dot.length;i++)
            {
                if(dot[i].length <= 0 || dot[i].indexOf(' ') != -1 || dot[i].indexOf('"') != -1 || dot[i].indexOf("'") != -1 || dot[i].length > 4)
                {
                    eFlag = false;
                }
            }
        }
    }
    return eFlag;
}


// Function To Check Whether The Value Entered Is A Non Negative Float 

function check_numeric(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 to check the email id 
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_EMAIL_ADDRESS)
        return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert(INVALID_EMAIL_ADDRESS)
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert(INVALID_EMAIL_ADDRESS)
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
        alert(INVALID_EMAIL_ADDRESS)
        return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert(INVALID_EMAIL_ADDRESS)
        return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
        alert(INVALID_EMAIL_ADDRESS)
        return false
    }

    if (str.indexOf(" ")!=-1){
        alert(INVALID_EMAIL_ADDRESS)
        return false
    }

    return true
}
	
function clearText(thefield){
    if (thefield.defaultValue==thefield.value)
        thefield.value = ""
}

function checkAlphaNumerics(checkString) {
    var regExp = /^[A-Za-z0-9]$/;
    if(checkString!= null && checkString!= "")
    {
        for(var i = 0; i < checkString.length; i++)
        {
            if (!checkString.charAt(i).match(regExp))
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
    return true;
}



