
/****************************************************************************************
Product         : PowerVolt Website Phase I.
Copyright	    : Edify Technologies Inc.
Source          : QuoteItems.js
Created Date    : 12/09/2008
Modified Date   : 07/27/2009
Author          : Justin Arun
Version         : 1.0.0
Description     : JavaScript file for validating QuoteItems page

CR / Issue No      Modified By       Modified On       Version         Reason
****************************************************************************************/

function ValidateBillingContactInformation() {

    try {
        var errorCode;
        firstErrorControl = "";

        errMsg = "<tr><td class='errormsg'></td></tr>";        
        if (ValidateRequired("txtFirstName", emptyFirstName))
            ValidateSpecialChars("txtFirstName", invalidFirstName, "name");
            
         if (ValidateRequired("txtLastName", emptyLastName))
            ValidateSpecialChars("txtLastName", invalidLastName, "name");
        
        if (ValidateRequired("txtEmail", emptyEmail))
            ValidateEmail("txtEmail", invalidEmail);

        ValidateRequired("txtAddress1", emptyAddress1);

        if (ValidateRequired("txtCity", emptyCity))
            ValidateSpecialChars("txtCity", invalidCity, "name");

        ValidateDropDown("ddlState", emptyState);
        if (document.getElementById(clientID + "ddlState").value == 598) {
            if (ValidateRequired("txtOtherState", emptyStateText))
                ValidateSpecialChars("txtOtherState", invalidStateText, "name");
        }
        
        ValidateDropDown("ddlCountry", selectCountry);
        if (ValidateRequired("txtPinCode", emptyZipCode))
			if(ValidateSpecialChars("txtPinCode", invalidZipCode, "all"));    
				ValidateZipCodeLength("txtPinCode", invalidZipCodeLength); 

        if (ValidateRequired("txtPhone1", emptyPhoneNo))
			if(ValidatePhone("txtPhone1", invalidPhoneNo))        
				ValidatePhoneLength("txtPhone1", invalidPhoneNoLength);  

        //Commented & Added by saravanan dated on 04/22/2009
        //Bug Id:353  
        //if (ValidateRequired("txtFaxNo1", emptyFaxNo1))
        if (document.getElementById(clientID + "txtFaxNo1").value != "") 
        {
            ValidatePhone("txtFaxNo1", invalidFaxNo1);
        }
        else 
        {
            document.getElementById(clientID + "txtFaxNo1").style.backgroundColor = "";
        }

        //ValidateRequired("txtApplication", emptyApplication);

        //ValidateRequired("txtIndustries", emptyIndustries);        

        if (firstErrorControl != '') {
            SetControlFocus(firstErrorControl);
            errMsg = "<table border='0' width='674px' cellspacing='0' cellpadding='0' class='validation'>" + errMsg + "</table>";
            document.getElementById('divErrorMessage').innerHTML = errMsg;
            return false;
        }
        else {
            document.getElementById('divErrorMessage').innerHTML = "";
            document.getElementById('img').style.display = "block";
            return true;
        }
    }
    catch (e) {        
        alert(emptyQuoteContact);
    }
}

function ValidatePlaceOrderInformation() 
{
    try {
        var errorCode;
        firstErrorControl = "";

        errMsg = "<tr><td class='errormsg'></td></tr>";        
        if (ValidateRequired("txtBillFirstName", emptyFirstName))
            ValidateSpecialChars("txtBillFirstName", invalidFirstName, "name");
        
        if (ValidateRequired("txtBillLastName", emptyLastName))
            ValidateSpecialChars("txtBillLastName", invalidLastName, "name");
        
        if (ValidateRequired("txtBillEmail", emptyEmail))
            ValidateEmail("txtBillEmail", invalidEmail);

        ValidateRequired("txtBillAddress1", emptyAddress1);
       
        if (ValidateRequired("txtBillCity", emptyCity))
            ValidateSpecialChars("txtBillCity", invalidCity, "name");
            
        ValidateDropDown("ddlBillState", emptyState);
        if (document.getElementById(clientID + "ddlBillState").value == 598) {
            if (ValidateRequired("txtBillOtherState", emptybillStateText))
                ValidateSpecialChars("txtBillOtherState", invalidbillStateText, "name");
        }
        
        ValidateDropDown("ddlBillCountry", selectCountry);
        
        if (ValidateRequired("txtBillZipCode", emptyZipCode))
			if(ValidateSpecialChars("txtBillZipCode", invalidZipCode, "all"));    
				ValidateZipCodeLength("txtBillZipCode", invalidZipCodeLength); 
	     
	    if (ValidateRequired("txtBillPhone", emptybillPhoneNo))
			if(ValidatePhone("txtBillPhone", invalidbillPhoneNo))        
				ValidatePhoneLength("txtBillPhone", invalidbillPhoneNoLength);
				
		if (document.getElementById(clientID + "txtBillFax").value != "") 
        {
            ValidatePhone("txtBillFax", invalidbillFaxNo);
        }
        else 
        {
            document.getElementById(clientID + "txtBillFax").style.backgroundColor = "";
        } 
        
        ValidateRequired("txtShipAddress1", emptyshipAddress1);
        
        if (ValidateRequired("txtShipCity", emptyshipCity))
            ValidateSpecialChars("txtShipCity", invalidshipCity, "name");
            
        ValidateDropDown("ddlShipState", emptyshipState);
        if (document.getElementById(clientID + "ddlShipState").value == 598) {
            if (ValidateRequired("txtShipOtherState", emptyshipStateText))
                ValidateSpecialChars("txtShipOtherState", invalidshipStateText, "name");
        }
         
        ValidateDropDown("ddlShipCountry", selectshipCountry);
        
        if (ValidateRequired("txtShipZipCode", emptyshipZipCode))
			if(ValidateSpecialChars("txtShipZipCode", invalidshipZipCode, "all"));    
				ValidateZipCodeLength("txtShipZipCode", invalidshipZipCodeLength);
		
		if (ValidateRequired("txtShipPhone", emptyshipPhoneNo))
			if(ValidatePhone("txtShipPhone", invalidshipPhoneNo))        
				ValidatePhoneLength("txtShipPhone", invalidshipPhoneNoLength);
				
		CheckMaxlength("txtShipComments", "200", maxPOMessage);

        if (firstErrorControl != '') {
            SetControlFocus(firstErrorControl);
            errMsg = "<table border='0' width='674px' cellspacing='0' cellpadding='0' class='validation'>" + errMsg + "</table>";
            document.getElementById('divErrorMessage').innerHTML = errMsg;
            return false;
        }
        else {
            document.getElementById('divErrorMessage').innerHTML = "";
            document.getElementById('img').style.display = "block";
            return true;
        }
    }
    catch (e) {        
        alert(emptyQuoteContact);
    }
}


function ValidateCrossReference() {

    try {
        var errorCode;
        firstErrorControl = "";

        errMsg = "<tr><td class='errormsg'></td></tr>";

        ValidateRequired("txtPartNo", emptyPartNo);            

        if (firstErrorControl != '') {
            SetControlFocus(firstErrorControl);
            errMsg = "<table border='0' width='730px' cellspacing='0' cellpadding='0' class='validation'>" + errMsg + "</table>";
            document.getElementById('divErrorMessage').innerHTML = errMsg;
            return false;
        }
        else {
            document.getElementById('divErrorMessage').innerHTML = "";            
            return true;
        }
    }
    catch (e) {
        alert(emptyQuotePartNo);
    }
}


//Validation for RQPartNo.aspx
// Added by Saravanan dated on 06/08/2009 - Bug Id : 456
function ValidateRQPartNo() {

    try {
        var errorCode;
        firstErrorControl = "";
        errMsg = "<tr><td class='errormsg'></td></tr>";

        ValidateRequired("txtSearchPartNo", emptyPartNo);            

        if (firstErrorControl != '') {
            SetControlFocus(firstErrorControl);
            errMsg = "<table border='0' width='677px' height='20px' padding-top='10px' margin-left='0px' cellspacing='0' cellpadding='0' class='validation'>" + errMsg + "</table>";
            document.getElementById('divErrorMessage1').innerHTML = errMsg;
            if(document.getElementById(clientID +'divErrorMessage')!=null)
                document.getElementById(clientID +'divErrorMessage').style.display = "none";
            return false;
        }
        else {
            document.getElementById('divErrorMessage1').innerHTML = "";
            if(document.getElementById(clientID +'divErrorMessage')!=null)
                document.getElementById(clientID +'divErrorMessage').style.display = "none";          
            return true;
        }
    }
    catch (e) {
        alert(emptyQuotePartNo);
    }
}

//Validation for ProductStocks.aspx

function SelectProductStocks(SelectedPartNo)
{   
    var controlID= clientID +SelectedPartNo;
    if(document.getElementById(controlID).className == "prdMeroonBold")
    {
        document.getElementById(controlID).className ="prdBlackNorm";
        var strValue = "," + document.getElementById(controlID).innerHTML;
        var strValue1 = document.getElementById(clientID+"hdnSelectPartnumbers").value;
        if(strValue1.indexOf(strValue) != -1)
            document.getElementById(clientID+"hdnSelectPartnumbers").value=strValue1.replace(strValue,'');
    }
    else
    {
        document.getElementById(controlID).className = "prdMeroonBold" 
        document.getElementById(clientID+"hdnSelectPartnumbers").value += ","+document.getElementById(controlID).innerHTML;
    }  
    
    return false;
}


//Validation for CustomizeProduct.aspx
function ValidateCustomizeProduct()
{
    try {
        var errorCode;
        firstErrorControl = "";
        errMsg = "<tr><td class='errormsg'></td></tr>";

        if(ValidateRequired("txtRating", emptyCustomRating))
            ValidateSpecialChars("txtRating", invalidCustomRating, "numberdecimal")
        
        if(ValidateRequired("txtPrimaryVoltage", emptyPrimaryVoltage))
            ValidateSpecialChars("txtPrimaryVoltage", invalidPrimaryVoltage, "primaryvoltage") 
            
        if(ValidateRequired("txtSecondaryVoltage", emptySecondaryVoltage))
            ValidateNumbers("txtSecondaryVoltage", invalidSecondaryVoltage)                                    

        if (firstErrorControl != '') {
            SetControlFocus(firstErrorControl);
            errMsg = "<table border='0' width='675px' height='20px' padding-top='10px' margin-left='0px' cellspacing='0' cellpadding='0' class='validation'>" + errMsg + "</table>";
            document.getElementById('divErrorMessage').innerHTML = errMsg;
            
            return false;
        }
        else {
            document.getElementById('divErrorMessage').innerHTML = "";                    
            return true;
        }
    }
    catch (e) {
        //alert(emptyQuotePartNo);
    }
}


//QuoteItems page Contact Information
function DisplayContactInformation(str, strFocus)
{      
    if(str=='0')
    {
        if (document.getElementById(clientID + 'divRequestQuoteContactInformation') != null) 
        {
            document.getElementById(clientID + 'divRequestQuoteContactInformation').style.display = "block";
            //added by maharajan for bug id       
            var getId = clientID + 'txtFirstName';            
            setTimeout("controlFocus('"+getId+"','"+strFocus+"')",200);
        }
    }
    else
    {
        if (document.getElementById(clientID + 'divPlaceOrderInformation') != null) 
        {
            document.getElementById(clientID + 'divPlaceOrderInformation').style.display = "block";             
            var getId = clientID + 'txtBillFirstName';            
            setTimeout("controlFocus('"+getId+"','"+strFocus+"')",200);             
                  
        }
    }
    return false;
}

function controlFocus(getId,strFocus)
{
    if(strFocus == '0')
    {
        if(document.getElementById(getId)!=null)
            document.getElementById(getId).focus();    
    }
}

function confirmDeletion() 
{
    return confirm('Are you sure to Cancel the Cart Items?')
}