// JavaScript Document
var hpflashCookie = "citationhp";

function cookieDelete(name){
	var expdate = new Date ();
	expdate.setTime = expdate.getTime()-1;
	document.cookie = name + "=; path='/'; expires=" + expdate.toGMTString();
}

function cookieRead(Name){
	var cookieValue = "";
	var search = Name + "=";
	if(document.cookie.length > 0){ 
		offset = document.cookie.indexOf(search);
		if (offset != -1){ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function cookieWrite(Name, Value, Hours){
	var expire = "";
	if(Hours != null){
		expire = new Date((new Date()).getTime() + Hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = Name + "=" + escape(Value) + expire;
}

function cookieWriteFull(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

//Cross Browser Object Retrieval
function getObject(objectID){
	if (document.all!=null){
		return document.all[objectID];
	} else if (document.getElementById){
		return document.getElementById(objectID);
	}
}

function toggleHomePage(){
	$('#footerMods').css('visibility', 'visible');
	var flashVersion = getObject("flashContent");
	var htmlVersion = getObject("htmlContent");
	if (cookieRead(hpflashCookie) == ""){
		htmlVersion.style.display = "none";
		flashVersion.style.display = "block";
		cookieWriteFull(hpflashCookie, "viewed");
	} else {
		htmlVersion.style.display = "block";
		flashVersion.style.display = "none";
		scrollerStartAuto();
	}
}

function showDIV(divID) {
    var divPop = document.getElementById(divID);
    divPop.style.display = "block";
}

function hideDIV(divID) {
    var divPop = document.getElementById(divID);
    divPop.style.display = "none";
}

function showHidePartners(divID) {
	div = document.getElementById("alliance_" + divID);
	text = document.getElementById("alliance_" + divID + "_link");
	if(div.style.display == "none") {
		div.style.display = "inline";
		text.innerHTML = "COLLAPSE <img src='/App_Themes/CitationAir/images/partner_arrow_up.gif'  border='0'>";
			
			
	}
	else {
		div.style.display = "none";
			if (document.images)
			text.innerHTML = "READ MORE <img src='/App_Themes/CitationAir/images/partner_arrow_right.gif' border='0'>";
	}
}

function validate() {
		
		var validUser = true
		$('form input.validate, form select.validate, form input[type="checkbox"]').each(function(x){	
			validateobj($(this))			  
		})
		$('form input.validate, form select.validate, form input[type="checkbox"]').each(function(x){	
		var lblID	
		if($(this).attr('id').lastIndexOf('Email') != - 1 || $(this).attr('id').lastIndexOf('ConfirmEmail') != - 1){
				lblID = $(this).attr('id').substring(0,$(this).attr('id').lastIndexOf("_")) + "_FieldLabel" ;
			}
			else {
				lblID = $(this).attr('id') + "_FieldLabel" ;
		}
		if($(this).data('valid')==false){
			$("#" + lblID).css('color','#f00');
			$("#error").css('display','block');
				validUser=false
			}
		else {
			$("#" + lblID).css('color','#000')
			$("#error").css('display','none');
		}
		})
		return validUser;
	}
//validation function
function validateobj(obj){
	if($(obj).attr('id').lastIndexOf('Email') != - 1 || $(obj).attr('id').lastIndexOf('ConfirmEmail') != - 1){
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if($(obj).val()=='' || !emailReg.test($(obj).val())){
			$(obj).data('valid',false)
			return false
		}
		if($(obj).attr('id').lastIndexOf('ConfirmEmail') != - 1 && $(obj).val()!=$('#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_contactUs_BizForm_viewBiz_ctl00_Email_txtEmailInput').val()){
				$(obj).data('valid',false)
				return false
			}
	}else if($(obj).attr('id').lastIndexOf('ZipCode') != - 1){
		var zipReg =/^\d{5}(-\d{4})?$/;
		if($(obj).val()=='' || !zipReg.test($(obj).val())){
			$(obj).data('valid',false)
			return false
		}
	}else{
		//console.log($(obj).val());
		if($(obj).val()==''){
			
			$(obj).data('valid',false)
			return false
		}
		if($(obj).attr('id').lastIndexOf('Terms') != - 1 && !$(obj).is(':checked')) {
			
			$(obj).data('valid',false)
			return false
			
		}
	}
	$(obj).data('valid',true)
	return true
	
}//end function

