// JavaScript Document

// GLOBAL VARS

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus();
}

var dealerWin=0;
function dealerPopUp(dealerLocation){
	var URLStr = 'dealers_' + dealerLocation + '.htm';
	var left = 100;
	var top = 100;
	var width = 450;
	var height = 400;
  if(dealerWin)
  {
    if(!dealerWin.closed) dealerWin.close();
  }
  dealerWin = open(URLStr, 'dealerPopUp', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	dealerWin.focus();
}

var dealerWin=0;
function dealerPopUp2(dealerLocation){
	var URLStr = 'dealersPop.php?state=' + dealerLocation;
	var left = 100;
	var top = 100;
	var width = 500;
	var height = 400;
  if(dealerWin)
  {
    if(!dealerWin.closed) dealerWin.close();
  }
  dealerWin = open(URLStr, 'dealerPopUp', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	dealerWin.focus();
}

var pricelistWin=0;
function pricelistPopUp(model){
	var URLStr = 'pricelist_' + model + '.htm';
	var left = 100;
	var top = 100;
	var width = 615;
	var height = 600;
  if(pricelistWin)
  {
    if(!pricelistWin.closed) pricelistWin.close();
  }
  pricelistWin = open(URLStr, model, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	pricelistWin.focus();
}

var detailsWin=0;
function detailsPopUp(dealerLocation){
	var URLStr = dealerLocation;
	var left = 100;
	var top = 100;
	var width = 600;
	var height = 500;
  if(detailsWin)
  {
    if(!detailsWin.closed) detailsWin.close();
  }
  detailsWin = open(URLStr, 'detailsWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	detailsWin.focus();
}

var zoomWin=0;
function zoomPopUp(dealerLocation){
	var URLStr = dealerLocation;
	var left = 100;
	var top = 100;
	var width = 600;
	var height = 650;
  if(zoomWin)
  {
    if(!zoomWin.closed) detailsWin.close();
  }
  zoomWin = open(URLStr, 'detailsWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	zoomWin.focus();
}

var trikeWin=0;
function trikePopUp(postID, tWidth, tHeight){
	var URLStr = "closeUp.php?id="+postID;
	var left = 100;
	var top = 100;
	var width = 20+ tWidth;
	var height = 50+ tHeight;
  if(trikeWin)
  {
    if(!trikeWin.closed) trikeWin.close();
  }
  trikeWin = open(URLStr, 'trikeWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	trikeWin.focus();
}


function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

var zoomImage = "img/Red_trike_rear_view3_zoom.jpg";

function switchImageWithZoom(imgName, imgSrc, myZoomImg) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
			zoomImage = myZoomImg;
    }
  }
}

var zoomImage = "img/Red_trike_rear_view3_zoom.jpg";

function switchImageWithZoom2(imgName, imgSrc, myZoomImg) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
			zoomImage = myZoomImg;
    }
  }
}

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

// This function is for the PriceList.
function updateTotal() {

  var temptotal = new Number(document.pricelist.baseprice.value);
	var numItems = document.pricelist.item.length;
	for (var x=0; x<numItems; x++){
		if (document.pricelist.item[x].checked) {
			var tempPrice = new Number(document.pricelist.item[x].value)
			temptotal = temptotal + tempPrice;
		}
	}
	document.pricelist.total.value = temptotal;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validateNewPost(isc){
	if(""==document.forms.isc.example.value){
		alert("Please select a Make.");
		document.forms.isc.example.focus();
		return false;
	}
	if(""==document.forms.isc.stage2.value){
		alert("Please select a Model.");
		document.forms.isc.stage2.focus();
		return false;
	}
	if(""==document.forms.isc.stage3.value){
		alert("Please select a Year.");
		document.forms.isc.stage3.focus();
		return false;
	}
	if(""==document.forms.isc.stage4.value){
		alert("Please select a Color.");
		document.forms.isc.stage4.focus();
		return false;
	}
	if(""==document.forms.isc.price.value){
		alert("Please enter a Price.");
		document.forms.isc.price.focus();
		return false;
	}
	return true;
}

function validateWelcome(welcome){
	if(""==document.forms.welcome.dealerUser.value){
		alert("Please enter a Username.  This Username is the email address that received this invitation.");
		document.forms.welcome.dealerUser.focus();
		return false;
	}
	if(""==document.forms.welcome.dealerPass.value){
		alert("Please enter a Password.");
		document.forms.welcome.dealerPass.focus();
		return false;
	}
	if(""==document.forms.welcome.confirmPass.value){
		alert("Please re-type the same password in the second blank.");
		document.forms.welcome.confirmPass.focus();
		return false;
	}
	if(document.forms.welcome.dealerPass.value != document.forms.welcome.confirmPass.value){
		alert("Passwords do not match.  Please try again.");
		document.forms.welcome.dealerPass.value = '';
		document.forms.welcome.confirmPass.value = '';
		document.forms.welcome.dealerPass.focus();
		return false;
	}
	return true;	
}

function validateBrochure(requestBrochure){
	if(""==document.forms.requestBrochure.name.value){
		alert("Please enter your name.");
		document.forms.requestBrochure.name.focus();
		return false;
	}
	if(""==document.forms.requestBrochure.email.value){
		alert("Please enter an email.");
		document.forms.requestBrochure.email.focus();
		return false;
	}	
	return true;
}

function deleteConfirmation(){
	return confirm("Are you sure you want to delete this record?");
}