﻿var FormHeading = null; var FormDescription = null; var FormStreetAddress = null; var FormApt = null;
var FormZip = null; var FormButtonSrc = null; var FormFooter = null; var LocalizedHeading = null;
var LocalizeDescription = null; var LocalizeTitle = null; var LocalizeLinkText = null; var LocalizeButtonSrc = null;
var LocalizeFooter = null; var FormReferer = null; var FormButtonText = null; var LocalizeButtonText = null;
var DisplayHeading = null;

//Fix for Firefox
function GetText(elm) {
	var txt = "";
	if (document.all) {
		txt = document.getElementById(elm).innerText;
	} else {
		txt = document.getElementById(elm).textContent;
	}
	return txt;
}


function InitializeLocMod() {

    var objLocModForm = document.getElementById('LocModForm');
    if (objLocModForm != null) {
        objLocModForm.style.display = 'none';
    }
    var objLocModMessage = document.getElementById('LocModMessage');
    if (objLocModMessage != null) {
        objLocModMessage.style.display = 'none';
    }

    
    
	var st = GetCookie("Serviceability", "StreetAddress");
	var apt = GetCookie("Serviceability", "AptNumber");
	var zip = GetCookie("Serviceability", "Zip");
	var citst = GetCookie("Serviceability", "Address");
	if(st && zip)
	{
		var LocCurrent = document.getElementById('LocCurrent');
		var addr = st;

		if(apt)
			addr += ', ' + GetText('LocFormApt') + ' ' + apt;
		addr += '<br/>';
		if(citst != 'false')
		{
			if(citst.indexOf(zip) == 0)
				citst = citst.substring(zip.length);
			if(citst.indexOf('&#160;') == 0)
				citst = citst.substring(6);
			
			addr += citst + ', ';
		}
		addr += zip;
		
		while(addr.indexOf('+') > -1)
			addr = addr.replace('+', ' ');

		while(addr.indexOf('&#160;') > -1)
			addr = addr.replace('&#160;', ' ');
		
		LocCurrent.innerHTML = addr;
		
		//document.getElementById('LocModForm').style.display = 'none';
		SetLocModText('LocHeading', LocalizedHeading);
		SetLocModText('LocDescription', LocalizeDescription);
		SetLocModText('LocTitle', LocalizeTitle);
		SetLocModText('LocLink', LocalizeLinkText);
		SetLocModText('LocFooter', LocalizeFooter);
		SetLocModButton('LocButton', LocalizeButtonSrc);
		
		
		if(LocalizeButtonText != null && LocalizeButtonText != '')
		    document.getElementById("LocButton").alt = LocalizeButtonText;


		document.getElementById('LocMod').style.display = 'block';
		document.getElementById('LocModMessage').style.display = 'block';
}
else {
    document.getElementById('LocMod').style.display = 'block';
    document.getElementById('LocModForm').style.display = 'block';
}

SetLocModText('LocFormHeading', FormHeading);


    SetLocModTextDisplay('LocHeading', DisplayHeading);
    SetLocModTextDisplay('LocFormHeading', DisplayHeading);

	SetLocModText('LocFormDescription', FormDescription);
	SetLocModText('LocFormStreet', FormStreetAddress);
	SetLocModText('LocFormApt', FormApt);
	SetLocModText('LocFormZip', FormZip);
	SetLocModText('LocFormFooter', FormFooter);
	SetLocModButton('LocalizeButton', FormButtonSrc);
	if (FormReferer != null && FormReferer != '') {
	    document.getElementById("Referer").value = FormReferer;
	    if(document.getElementById("LocLink") != null)
	        document.getElementById("LocLink").href = FormReferer;
	    if (document.getElementById("LocShopLink") != null)
	        document.getElementById("LocShopLink").href = FormReferer;
	}
	if(FormButtonText != null && FormButtonText != '')
		document.getElementById("LocalizeButton").title = FormButtonText;
    
    
    
}
function SetLocModText(el, value){var elem = document.getElementById(el);if(elem != null && value != null && value != ''){elem.innerHTML = value;}}
function SetLocModButton(el, value){var elem = document.getElementById(el);if(elem != null && value != null && value != ''){elem.src = value;}}
function ResetLocMod(){document.getElementById('LocModMessage').style.display = 'none';document.getElementById('LocModForm').style.display = 'block';}
function SetLocModTextDisplay(el, value) {
    var elem = document.getElementById(el);
    if (elem != null && value != null && (value != true)) {
        elem.style.display = 'none'; 
             } 
  }

function ValidateLocalizeForm() 
{
    
	var street = document.getElementById('StreetName');
	var zip = document.getElementById('Zip');
	var streetValid = true;
	var zipValid = true;
	var errSt = "solid 1px #f0461e";
	var noErrSt = "solid 1px #c3c3c3";
	var disp = 'none';	
	street.value = street.value.trim();zip.value = zip.value.trim();

	if(street.value.length < 3){streetValid = false;}else if(street.value.indexOf(' ') < 0){streetValid = false;}else if(street.value.indexOf('%') > -1){streetValid = false;}
	if(!streetValid){street.style.border = 	errSt;street.focus();}else{street.style.border = noErrSt;}
	if(Comcast.Validation.ValidateZIP(zip).length > 0){zip.style.border = errSt;zip.focus();zipValid = false;}else{zip.style.border = noErrSt;}
	
	if(!streetValid || !zipValid){disp = 'block';}
	document.getElementById("LocFormError").style.display = disp;
	
	return streetValid && zipValid;
	
	
}

/*from df.js*/


String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function isNull(a) {
    return a === null;
};
