//////////////////////////////////////////////////////////////
// variables declared on the server for use in this js code //
// var jsTxtZipCodeID                                       //
// var jsDdInsuranceTypeID                                  //
//                                                          //   
// var jsTxtZipCodeAgentID                                  //
// var jsTxtAddressAgentID                                  //
// var jsTxtCityAgentID                                     //
// var jsDdStateAgentID                                     //
//                                                          //
// var lblErrInvalidZipID                                   //
// var isErrorOnID                                          //
//////////////////////////////////////////////////////////////
// variables declared on small quote control                //
// var jsTxtZipCodeSQID                                     //
// var jsDdInsuranceTypeSQID                                //
//                                                          //   
// var lblErrInvalidZipSQID                                //
//////////////////////////////////////////////////////////////
// variables declared in this file below                    //
    var jsTxtZipCode
    var jsDdInsuranceType
  
    var jsTxtZipCodeAgent
    var jsTxtAddressAgent
    var jsTxtCityAgent
    var jsDdStateAgent
    
    var invalidZipError;
    
    var jsTxtZipCodeSQ
    var jsDdInsuranceTypeSQ
    
    var invalidZipErrorSQ
    
    var zipPattern = /\d{5}/;
    var ddInsurReplacement;
    var insurPrompt;
    
    var ddInsurReplacementSQ;
    var insurPromptSQ;
   
    var cityPattern = /[^\a-\z\A-\Z\s]/;
    var ddStateReplacement;
    var statePrompt;
    
    var zipQuoteErrorOn;
    var zipAgentErrorOn;
    var addressErrorOn;
    var cityErrorOn;
    
    var zipQuoteErrorOnSQ;
//////////////////////////////////////////////////////////////

function initVariables()
{
    jsTxtZipCode = document.getElementById(jsTxtZipCodeID);
    jsDdInsuranceType = document.getElementById(jsDdInsuranceTypeID);    
  
    jsTxtZipCodeAgent = document.getElementById(jsTxtZipCodeAgentID);
    jsTxtAddressAgent = document.getElementById(jsTxtAddressAgentID);
    jsTxtCityAgent = document.getElementById(jsTxtCityAgentID);
    jsDdStateAgent = document.getElementById(jsDdStateAgentID);       
    
    invalidZipError = document.getElementById(lblErrInvalidZipID);
    
    zipQuoteErrorOn = document.getElementById(zipQuoteErrorOnID);
    zipAgentErrorOn = document.getElementById(zipAgentErrorOnID);
    addressErrorOn = document.getElementById(addressErrorOnID);
    cityErrorOn = document.getElementById(cityErrorOnID);
        
}

function initVariablesSQ()
{
    jsTxtZipCodeSQ = document.getElementById(jsTxtZipCodeSQID);
    jsDdInsuranceTypeSQ = document.getElementById(jsDdInsuranceTypeSQID);
    
    invalidZipErrorSQ = document.getElementById(lblErrInvalidZipSQID);
    
    zipQuoteErrorOnSQ = document.getElementById(zipQuoteErrorOnSQID);
}

function showHideTextPrompt(textBox, prompt, error)
{
  if (textBox.value == prompt || textBox.value == error)
	{
	    if (textBox.value == error)
	    {
	        Sys.UI.DomElement.removeCssClass(textBox, 'error');	        
	    }
	    textBox.style.color='black';
	    textBox.value = "";
	}
	else if (textBox.value == "")
	{
	    textBox.value = prompt;	    
	}
}

function errorCheck()
{
    if (zipQuoteErrorOn.value == 'yes')
    {
        showZipQuoteErrorOn();
    }
    else
    {
        showZipQuoteErrorOff();
    }
    
    if (zipAgentErrorOn.value == 'yes')
    {
        showZipAgentErrorOn();
    }
    else
    {
        showZipAgentErrorOff();
    }
    
    if (cityErrorOn.value == 'yes')
    {
        showCityErrorOn();
    }
    else
    {
        showCityErrorOff();
    }
    
    if (addressErrorOn.value == 'yes')
    {
        showAddressErrorOn();
    }
    else
    {
        showAddressErrorOff();
    }
}

function errorCheckSQ()
{
    if (zipQuoteErrorOnSQ.value == 'yes')
    {
        showZipQuoteErrorOnSQ();
    }
    else
    {
        showZipQuoteErrorOffSQ();
    }
}

function setupSelectStartQuoteInsuranceType()
{
    selectRestyle(jsDdInsuranceType);
    ddInsurReplacement = jsDdInsuranceType.previousSibling;    
    insurPrompt = jsDdInsuranceType.parentNode.previousSibling.previousSibling;
    insurancePromptOn(jsTxtZipCode, ddInsurReplacement, insurPrompt)

}

function setupSelectStartQuoteInsuranceTypeSQ()
{
    selectRestyle(jsDdInsuranceTypeSQ);
    ddInsurReplacementSQ = jsDdInsuranceTypeSQ.previousSibling;
    insurPromptSQ = jsDdInsuranceTypeSQ.parentNode.previousSibling.previousSibling;
    insurancePromptOn(jsTxtZipCodeSQ, ddInsurReplacementSQ, insurPromptSQ);
}

function insurancePromptOn(txtZip, ddSelectReplaced, prompt)
{
    if (txtZip.value == 'Enter ZIP Code' || txtZip.value == 'Enter A Valid Zip Code' || txtZip.value == '' || txtZip.value.match("Introduzca") || txtZip.value == "Introduzca su c&oacute;digo postal")
    {
        prompt.className = 'promptInsur';   
        ddSelectReplaced.style.display = 'none';
        return true;
    }
    else
    {
        prompt.className = 'hidePrompt';     
        ddSelectReplaced.style.display = 'block'; 
        return false;       
    }
}

function setupFindAgentAddress()
{
    if (jsTxtZipCodeAgent.value == 'Enter ZIP Code' || 
        jsTxtZipCodeAgent.value == 'Please enter a valid ZIP Code' ||
        jsTxtZipCodeAgent.value == '')
    {
        jsTxtAddressAgent.className = 'smallDisabled';
        jsTxtAddressAgent.disabled = true;
    }
    else
    {
        jsTxtAddressAgent.className = 'small';
        jsTxtAddressAgent.disabled = false;
    }
}

function setupSelectFindAgentState()
{
    selectRestyle(jsDdStateAgent);
    ddStateReplacement = jsDdStateAgent.previousSibling;
    statePrompt = jsDdStateAgent.parentNode.previousSibling.previousSibling; 
    statePromptOn();
}


function validateTxtZipCode(txtZipCode)
{     
    if (!insurancePromptOn(jsTxtZipCode, ddInsurReplacement, insurPrompt)){                     
        if (!txtZipCode.value.match(zipPattern))
        {
            // zip must be 5 numbers between 0-9        
            disableSelectRestyle(ddInsurReplacement, jsDdInsuranceType);
            jsDdInsuranceType.disabled = true;           
        }
        else
        {
            // zip pattern satisfied enable insurance dropdown                    
            enableSelectRestyle(ddInsurReplacement, jsDdInsuranceType);
            jsDdInsuranceType.disabled = false;
        }
    }
	
}

function validateZipCode()
{
   var pattern = /[^\d]/g;
   var zipCode = event.keyCode;
    
   return /^(\d)$/.test(String.fromCharCode(zipCode) );
}

function validateTxtZipCodeSQ(txtZipCode)
{     
    if (!insurancePromptOn(jsTxtZipCodeSQ, ddInsurReplacementSQ, insurPromptSQ)){                     
        if (!txtZipCode.value.match(zipPattern))
        {
            // zip must be 5 numbers between 0-9       
            disableSelectRestyle(ddInsurReplacementSQ, jsDdInsuranceTypeSQ);
            jsDdInsuranceTypeSQ.disabled = true;           
        }
        else
        {
            // zip pattern satisfied enable insurance dropdown                    
            enableSelectRestyle(ddInsurReplacementSQ, jsDdInsuranceTypeSQ);
            jsDdInsuranceTypeSQ.disabled = false;
        }
    }
	
}

function validateTxtZipCodeAgent(txtZipCode)
{              
    if (!txtZipCode.value.match(zipPattern))
    {
        // zip must be 5 numbers between 0-9
        jsTxtAddressAgent.className = 'smallDisabled';
        jsTxtAddressAgent.disabled = true;          
    }
    else
    {
        // zip pattern satisfied enable insurance dropdown                    
        jsTxtAddressAgent.className = 'small';
        jsTxtAddressAgent.disabled = false;   
    }	
}



function showZipQuoteErrorOn()
{ 
    invalidZipError.className = 'zipError';
}

function showZipQuoteErrorOff()
{
    invalidZipError.className = 'zipErrorHide';
}

function showZipAgentErrorOn()
{ 
    jsTxtZipCodeAgent.className = 'error';
}

function showZipAgentErrorOff()
{
    jsTxtZipCodeAgent.className = '';
}


function showZipQuoteErrorOnSQ()
{ 
    invalidZipErrorSQ.className = 'zipError';
}

function showZipQuoteErrorOffSQ()
{
    invalidZipErrorSQ.className = 'zipErrorHide';
}

function StartAQuoteValidation(txtZip, error)
{    
    if (txtZip.value.match(zipPattern))
    {  
        error.className = 'zipErrorHide';
        if (zipQuoteErrorOn != null)
        {
            zipQuoteErrorOn.value = 'no';
        }
        if (zipQuoteErrorOnSQ != null)
        {
            zipQuoteErrorOnSQ.value = 'no';
        }
        return true;
    }
    else
    {
        error.className = 'zipError';
        return false;
    }
    
}

function FindAnAgentValidationZipStreet(txtZipAgent)
{         	
    // zip isn't 5 didgits, display error
    if (!txtZipAgent.value.match(zipPattern))
    {
        txtZipAgent.value = 'Please enter a valid ZIP Code';
        if (!Sys.UI.DomElement.containsCssClass(txtZipAgent, 'error'))
            txtZipAgent.className = 'error';
        return false;	        
    }
    zipAgentErrorOn.value = 'no'
    return true;   
}

function FindAnAgentValidationCityState(txtCityAgent)
{        
    return (txtCityAgent.value != "" && txtCityAgent.value != "City" && !txtCityAgent.value.match(cityPattern));    
}

function Showbox(DivID,DivState)
{
	if (document.getElementById){
		document.getElementById(DivID).style.display = DivState;
	}
	else {
	document[DivID].style.display = DivState;
	}
}

function setOpacity(elem, amount)
{
    elem.style.opacity = amount;
    elem.style.filter  = "alpha(opacity=" + (amount*100) + ")";     
}