/***********************************************
* JavaScript for Autocar Book Store
***********************************************/


var evt = null;
var popupVal = "01";


// From QuirksMode
// http://www.quirksmode.org/js/dhtmloptions.html
function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function switchLogInVisible(){
	var x = new getObj('loginBox');
	if ( x.style.display == "none" || x.style.display == "")
	{
		x.style.display = "block";
		document.loginForm.acUser.focus();
	} else {
		x.style.display = "none";
	}
}

function makeLogInVisible(){
	var x = new getObj('loginBox');
	x.style.display = "block";
	document.loginForm.acUser.focus();
}

function switchAdminVisible(){
	var x = new getObj('adminBox');
	if ( x.style.display == "none" || x.style.display == "")
	{
		x.style.display = "block";
	} else {
		x.style.display = "none";
	}
}

function switchBrowseVisible(){
	$('browseBox').toggle();
	y = 0
	while (y < currentModels.length){
		$('browseSub' + currentModels[y]).hide();
		y++;
	}
}

function switchSubBrowseVisible(input){
	y = 0
	while (y < currentModels.length){
		$('browseSub' + currentModels[y]).hide();
		y++;
	}
	$('browseSub' + input).show();
}

function disableShipping(status) {
	if (status == true) {
		window.document.checkoutForm.shipping_fname.disabled=false;
		window.document.checkoutForm.shipping_lname.disabled=false;
		window.document.checkoutForm.shipping_title.disabled=false;		
		window.document.checkoutForm.shipping_company.disabled=false;
		window.document.checkoutForm.shipping_address1.disabled=false;
		window.document.checkoutForm.shipping_address2.disabled=false;
		window.document.checkoutForm.shipping_city.disabled=false;
		window.document.checkoutForm.shipping_state.disabled=false;
		window.document.checkoutForm.shipping_country.disabled=false;
		window.document.checkoutForm.shipping_postal_code.disabled=false;
		window.document.checkoutForm.shipping_phone.disabled=false;
		window.document.checkoutForm.shipping_email.disabled=false;
	} else {
		window.document.checkoutForm.shipping_fname.value=window.document.checkoutForm.billing_fname.value;
		window.document.checkoutForm.shipping_fname.disabled=true;
		window.document.checkoutForm.shipping_lname.value=window.document.checkoutForm.billing_lname.value;
		window.document.checkoutForm.shipping_lname.disabled=true;
		window.document.checkoutForm.shipping_title.value=window.document.checkoutForm.billing_title.value;
		window.document.checkoutForm.shipping_title.disabled=true;
		window.document.checkoutForm.shipping_company.value=window.document.checkoutForm.billing_company.value;
		window.document.checkoutForm.shipping_company.disabled=true;
		window.document.checkoutForm.shipping_address1.value=window.document.checkoutForm.billing_address1.value;
		window.document.checkoutForm.shipping_address1.disabled=true;
		window.document.checkoutForm.shipping_address2.value=window.document.checkoutForm.billing_address2.value;
		window.document.checkoutForm.shipping_address2.disabled=true;
		window.document.checkoutForm.shipping_city.value=window.document.checkoutForm.billing_city.value;
		window.document.checkoutForm.shipping_city.disabled=true;
		window.document.checkoutForm.shipping_state.value=window.document.checkoutForm.billing_state.value;
		window.document.checkoutForm.shipping_state.disabled=true;
		window.document.checkoutForm.shipping_country.value=window.document.checkoutForm.billing_country.value;
		window.document.checkoutForm.shipping_country.disabled=true;
		window.document.checkoutForm.shipping_postal_code.value=window.document.checkoutForm.billing_postal_code.value;
		window.document.checkoutForm.shipping_postal_code.disabled=true;
		window.document.checkoutForm.shipping_phone.value=window.document.checkoutForm.billing_phone.value;
		window.document.checkoutForm.shipping_phone.disabled=true;
		window.document.checkoutForm.shipping_email.value=window.document.checkoutForm.billing_email.value;
		window.document.checkoutForm.shipping_email.disabled=true;
	}
}


/***********************************************
* Functions for Showing a Price.
***********************************************/

function showPrice(priceSpot) {

	var a = "";

	try{
		a = new getObj('priceprinted');
		a.style.display = "none";
	}catch(err){}
	a = new getObj('pricecd');
	a.style.display = "none";
	a = new getObj('pricedvd');
	a.style.display = "none";
	a = new getObj('pricedownload');
	a.style.display = "none";
	
	a = new getObj('price' + priceSpot);
	a.style.display = "block";
}


/***********************************************
* Functions for Showing Browse Stuff.
***********************************************/

function startPage(inputVal) { 
	popupVal = inputVal;
	document.onmousemove = followMe;
	//var evt = (evt) ? evt : ((window.event) ? event : null);
	var object = new getObj('popup' + popupVal);
	object.style.visibility = 'visible';
}

function stopPage() { 
	document.onmousemove = null;
	//var evt = (evt) ? evt : ((window.event) ? event : null);
	var object = new getObj('popup' + popupVal);
	object.style.visibility = 'hidden';
}

function followMe(evt) {
	var object = new getObj('popup' + popupVal);
	
	var contentCoords = $('trueContentDiv').viewportOffset();
	var contentLeft = contentCoords[0];
	var contentTop = contentCoords[1];

	var posx = 0;
	var posy = 0;
	if (!evt) var evt = window.event;
	
	posx = evt.clientX;
	posy = evt.clientY;
	
	if (evt.pageX || evt.pageY)
	{
		// Firefox and Safari
		posx -= 3;
		posy -= 30;
	}
	
	object.style.left = posx + 14 - contentLeft + 'px';
	object.style.top = posy + 4 - contentTop + 'px';	

	return;
}

/***********************************************
* Functions for Book Preview.
***********************************************/

function swapPreview(inputVal) { 
	imgVal = inputVal;
	var object = document.getElementById('previewImg');
	object.src = 'images/pubs/'+imgVal;
}

function showPreview(inputVal) {
	imgVal = inputVal;
	imgArray = imgVal.split(".jpg");
	window.open('images/pubs/'+imgArray[0]+'.full.jpg', '', 'width=500,height=700,toolbar=0,resizable=1');
}