// ********************************************* JScript File ***********************************************

//  DEVELOPED BY    : Rajinder Sidhu
//  Date		    : April 05, 2008 
//  Purpose	        : This JScript file is used to validating requestforquote.aspx page controls

// **********************************************************************************************************

    var rules=new Array();
    rules[0]='ctl00_MainContent_txtCustomerFName|required|Please enter your first name';
    rules[1]='ctl00_MainContent_txtCustomerLName|required|Please enter your last name';
    
    rules[2]='ctl00_MainContent_txtCustomerCity|required|Please enter your city name';
    rules[3]='ctl00_MainContent_txtCustomerCity|alphaspace|City name must contain valid characters';
    
    rules[4]='ctl00_MainContent_txtCustomerEmail|required|Please enter your e-mail';
    rules[5]='ctl00_MainContent_txtCustomerEmail|email|Please enter valid e-mail';
    
    rules[6]='ctl00_MainContent_txtCustomerAddress|required|Please enter your address';
    rules[7]='ctl00_MainContent_txtCustomerAddress|maxlength|255|Address can be maximum 255 characters long';
    
    rules[8]='ctl00_MainContent_txtCustomerZip|required|Please enter your zip code';
    rules[9]='ctl00_MainContent_txtCustomerZip|integer|Please enter correct zip code';
    
    rules[10]='ctl00_MainContent_txtCustomerPhone|required|Please enter your phone number';
    rules[11]='ValidatePhone("ctl00_MainContent_txtCustomerPhone")|custom';
    
    rules[12]='validateFCKContent1("ctl00_MainContent_fckMailDesc")|custom';
    rules[13]='validateCheckBoxes()|custom'; 

    rules[14] = 'ValidateFax("ctl00_MainContent_chkFax","ctl00_MainContent_txtCustomerFax")|custom';
    rules[15] = 'StateCheck("ctl00_MainContent_txtCustomerState")|custom';

    function ValidateFax(obj1, obj2)
    {
        if(document.getElementById(obj1).checked == true)
        {
            if(isNull(document.getElementById(obj2).value))
            {
                return 'Please Enter Fax Number'
            }
            else
            {
                if(!AbortNonRequiredCharactersFaxNumber('aspnetForm','ctl00_MainContent_txtCustomerFax','`~^|#$%&*_+|;:><?')) 
                return 'Fax number must contain valid characters';
            }
        }
       
    }

    function ValidatePhone(obj1, obj2)
    {
        if(!AbortNonRequiredCharactersFaxNumber('aspnetForm','ctl00_MainContent_txtCustomerPhone','`~^|#$%&*_+|;:><?')) 
            return 'Phone number must contain valid characters';
    }
    
    function StateCheck(obj1)
    {
        var LIntIndex
        LIntIndex = document.aspnetForm.ctl00_MainContent_ddlCustomerCountry.selectedIndex;
        //alert(LIntIndex);
    	
        if(LIntIndex!=0)
        {
            if(isNull(document.getElementById(obj1).value))
            {
                return 'Please Enter State'
            }
            else
            {
                if(!AbortNonRequiredCharactersFaxNumber('aspnetForm','ctl00_MainContent_txtCustomerState','`~^-()|#$%&*_+|;:><?')) 
                return 'State name must contain valid characters';
            }
        }
    }

	function AbortNonRequiredCharactersFaxNumber(AStrFormName,AStrTextFieldName,AStrInValidString)
	{
	
		var LIntCtr
		var LStrTextFieldRef
		var LStrTextFieldValue
		LStrTextFieldRef = eval("document." + AStrFormName + "." + AStrTextFieldName)
		LStrTextFieldValue = LStrTextFieldRef.value
		
		if (LStrTextFieldValue.indexOf("''") != -1 || LStrTextFieldValue.indexOf('"') != -1)
		{
			LStrTextFieldRef.focus()
			return false;
		}
		
		for(LIntCtr=0; LIntCtr < LStrTextFieldValue.length; LIntCtr++)
		{
			LChrTextFieldValue = LStrTextFieldValue.charAt(LIntCtr)
			//alert(LChrTextFieldValue);
			//alert(AStrInValidString.indexOf(LChrTextFieldValue));
			if (AStrInValidString.indexOf(LChrTextFieldValue) != -1)
			{
				LStrTextFieldRef.focus()
				return false;
			}
		}
		return true;
	}


function validateFCKContent1(obj1)
{
    var oEditor1 = FCKeditorAPI.GetInstance(obj1) ;
    var browserName=navigator.appName;
     if (browserName=="Microsoft Internet Explorer") 
     {
          var content = oEditor1.EditorDocument.body.innerHTML;  //IE
     }
     else
     {
           var content = oEditor1.EditorDocument.body.textContent;  //firefox
     }
    if(content.length <= 0)
    {
        return "Please describe to the best of your knowledge the work you would like to have performed";
    }
    else
    {
    }
}
    
//==============================================================
//To check that atleast one check box is selected
function validateCheckBoxes()
{
    
    //var check1 = document.aspnetForm.ctl00_MainContent_chkemail.checked;
    //var check2 = aspnetForm.ctl00_MainContent_chkfax.checked;
    //var check3 = aspnetForm.ctl00_MainContent_chkPhone.checked;
    var check1 = document.getElementById("ctl00_MainContent_chkEmail").checked;
    var check2 = document.getElementById("ctl00_MainContent_chkFax").checked;
    var check3 = document.getElementById("ctl00_MainContent_chkPhone").checked;
    if(check1 == false && check2 == false && check3 == false)
    {
        return "Please select how would you like to receive quote!!";
    }
}

//========================================================================================
//If selected Cuntry is U.S.A, dropdown of States is shown.
//Else a textbox to enter name of the state

function ShowTextBoxState()
{
    //alert('First call');
    var LIntIndex
    LIntIndex = document.aspnetForm.ctl00_MainContent_ddlCustomerCountry.selectedIndex;
    //alert(LIntIndex);
	
    if(LIntIndex!=0)
    {
        //alert('If called');
        document.getElementById("RowDisplayStatelst").style.display='none';
        document.getElementById("RowDisplayStateText").style.display='';
    }
    else
    {
        //alert('Else called');
        document.getElementById("RowDisplayStatelst").style.display='';
        document.getElementById("RowDisplayStateText").style.display='none';
    }	
}
//============================================================================