﻿/* Begin Contact Popup */
var _isFirstNameRequired = true, _isLastNameRequired = true, _isPhoneNumberRequired = true;

function ContactPopupShow(url, evt, isFirstNameRequired, isLastNameRequired, isPhoneNumberRequired) {
	var div = document.getElementById('InventoryContact');
	div.style.top = mY(evt) - 42 + 'px';
	div.style.left = mX(evt) - 350 + 'px';
	div.style.visibility = 'visible';
	div.action = url;
	_isFirstNameRequired = isFirstNameRequired;
	_isLastNameRequired = isLastNameRequired;
	_isPhoneNumberRequired = isPhoneNumberRequired;
	return;
}

function ContactPopupHide() {
	var div = document.getElementById('InventoryContact');
	div.style.visibility = 'hidden';
	return;
}

function ContactPopupConfirmationShow() {
	var div = document.getElementById('InventoryContactConfirmation');
	var divOrig = document.getElementById('InventoryContact');
	div.style.top = divOrig.style.top;
	div.style.left = divOrig.style.left;
	div.style.visibility = 'visible';
	return;
}

function ContactPopupConfirmationHide() {
	var div = document.getElementById('InventoryContactConfirmation');
	div.style.visibility = 'hidden';
	return;
}

function validateContactInfo() {
	if(validateContactInformation(_isFirstNameRequired, _isLastNameRequired, _isPhoneNumberRequired)) {
		document.getElementById('InventoryContact').submit();
		ContactPopupConfirmationShow();
		ContactPopupHide();
		return true;
	} else {
		alert('You must enter a proper value in the following fields:\n' + errorMessage);
		return false;
	}
}
/* End Contact Popup */

/* Begin Zip Code Change Popup */
var zipChangeDelay = null;
var zipChangeDelayTime = 3000;

function ZipCodeChangePopupShow(zipCode,evt) {
	document.getElementById('ZipCodeChangeBox').value = zipCode;
	var div = document.getElementById('ZipCodeChange');
	div.style.top = mY(evt) - 90 + 'px';
	div.style.left = mX(evt) - 20 + 'px';
	div.style.visibility = 'visible';
	return;
}

function ZipCodeChangePopupHide() {
	var div = document.getElementById('ZipCodeChange');
	div.style.visibility = 'hidden';
	return;
}

function onZipCodeChangePopupHover() {
	if (zipChangeDelay) clearTimeout(zipChangeDelay);
	return;
}

function onZipCodeChangePopupOut() {
	zipChangeDelay = setTimeout('ZipCodeChangePopupHide()', zipChangeDelayTime);
	return;
}
/* End Zip Code Change Popup */

function responseFromInventorySubmitContact(result, context) {
	var fileref=document.createElement('div')
	fileref.innerHTML = result;
	document.getElementById("CustomHtmlPlaceholder").appendChild(fileref)
}

function setPageSize(rows, refreshURL) {
	var expire = new Date();
	expire.setTime (expire.getTime() + (2592000000)); //30 days from now!
	document.cookie = 'EBizAutosBuyersSiteCookiePageSize=' + rows + ';expires=' + expire.toGMTString() + ';path=/';
	UpdatePageSize(rows);
	//window.location.href = refreshURL;
	setTimeout('window.location.href = ' + '\'' +  refreshURL + '\'', 200);
}

function OnPageSizeUpdate(res) {
}
/*   Popup Cpo       */
function RefreshPopupCpo(el, evt, popupId, dx, dy, url) {
	if (insidePopup || insideLogo) {
		showPopupCpo(el, evt, popupId, dx, dy, url);
	} else {
		hidePopup(popupId, 1000, '');
	}
}

function showPopupCpo(el, evt, popupId, dx, dy, url) {
	if (!insidePopup) {
		var div = document.getElementById(popupId);
		var link = document.getElementById(popupId + 'DetailLink');
		
		if (div != currentPopup || div.style.visibility == 'visible') {
			if (null != currentPopup) {
				currentPopup.style.visibility = 'hidden';
				currentPopup = null;
			}
			div.style.left = (findPos(el)[0] + el.offsetWidth / 2 + dx) + 'px';
			div.style.top = (findPos(el)[1] + el.offsetHeight / 2 + dy) + 'px';
			div.style.visibility = 'visible';
			
			link.href=url;
			currentPopup = div;
			}
		}	
	clearTimeout(popupTimer);
}