//	NOTE :: 
//	COPYING ANYTHING FROM THIS DOCUMENT IS STRICTLY PROHIBITED
//	PAGEFUNCTIONS.JS IS COPYRIGHT (C) 2005 BUYCAR.COM.AU
function	expandRetract(thisDocumentOrig,thisImageOrig)
{
	thisDocument	= document.getElementById(thisDocumentOrig);
	
	if (thisDocument.style.display == "none")
	{
		thisDocument.style.display	= "";
		document[thisImageOrig].src	= "../images/retract.gif";
		return;
	}
	
	if (thisDocument.style.display == "")
	{
		thisDocument.style.display	= "none";
		document[thisImageOrig].src	= "../images/expand.gif";
		return;
	}
}


function	expandRetract_table(thisDocumentOrig,thisImageOrig)
{
	thisDocument	= document.getElementById(thisDocumentOrig);
	
	if (thisDocument.style.display == "none")
	{
		thisDocument.style.display	= "";
		document[thisImageOrig].src	= "../images/retract.gif";
		return;
	}
	
	if (thisDocument.style.display == "")
	{
		thisDocument.style.display	= "none";
		document[thisImageOrig].src	= "../Images/expand.gif";
		return;
	}
}

function	checkPasswords(formVar,variable1Var,variable2Var)
{
	if (document[formVar][variable1Var].value != document[formVar][variable2Var].value)
	{
		alert("Error:\n" +
			  "Passwords Don't Match!");
		document[formVar][variable2Var].value	= "";
		document[formVar][variable1Var].value	= "";
		document[formVar][variable1Var].focus();
	}
}
function	newWindow(fileName,fileWidth,fileHeight) 
{
	window.open("http://buycar.com.au/" + fileName, '382091', "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + fileWidth + ",height=" + fileHeight);
}
function	verifyFields()
{
		if (document.carenquiry.full_name.value && document.carenquiry.email.value)
	{
		document.carenquiry.Submit.disabled = false;
	}
	
	else
	{
		document.carenquiry.Submit.disabled = true;
	}
}

function	checkList()
{
  var radio = false;
	if (document.addlisting.type.value && document.addlisting.year.value && document.addlisting.selling_price.value && document.addlisting.distance.value && document.addlisting.engine.value && document.addlisting.rego.value && document.addlisting.VIN.value  && document.addlisting.readtos.checked)
	{
		document.addlisting.Submit.disabled	= false;
		if (document.addlisting.payment.length == 2)
		{
  		for (i = 0; i < document.addlisting.payment.length; i++)
        if (document.addlisting.payment[i].checked) radio = true;
      if (!radio) document.addlisting.Submit.disabled = true;
    }
	}
	else
	{
		document.addlisting.Submit.disabled	= true;
	}
}

function	checkPartsLocater()
{
  	if (document.partslocater.make.value != ""  && document.partslocater.year.value && document.partslocater.querypersonname.value  && document.partslocater.querypersonemail.value  && document.partslocater.readtos.checked)
	{
		document.partslocater.Submit.disabled	= false;
	}
	else
	{
		document.partslocater.Submit.disabled	= true;
	}
}

function	checkPartList()
{
	if (document.addlisting.type.value != "" && document.addlisting.comments.value && document.addlisting.readtos.checked)
	{
		document.addlisting.Submit.disabled	= false;
	}
	
	else
	{
		document.addlisting.Submit.disabled	= true;
	}
}
function	disableSubmit()
{
	document.addlisting.Submit.disabled		= true;
	document.addlisting.Submit.value		= "Please Wait ...";
	document.addlisting.submit();
}
function	disableBusinessSubmit()
{
	document.register.Submit.disabled		= true;
	document.register.Submit.value		= "Please Wait ...";
	document.register.submit();
}
function	markForDeletion(image)
{
	document.addlisting.deleteimgs.value	= document.addlisting.deleteimgs.value + "," + [image];
	alert("Warning\n" +
		  "This image has now been marked for deletion\n" +
		  "By submitting this form you will REMOVE this image from your listing.");
}
function	removedImage()
{
	alert("Image Successfully Removed!");
	window.close();
}
function	markDeleted(thisDocumentOrig,thisDocumentNew)
{
	thisDocument	= document.getElementById(thisDocumentOrig);
	thisDocumentNew	= document.getElementById(thisDocumentNew);
	
	thisDocument.style.display		= "none";
	thisDocumentNew.style.display	= "";
	return;
}

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	checkComp()
{
	if (document.register.email.value && document.register.full_name.value && document.register.postcode.value && document.register.readfuel.checked)
	{
		document.register.Submit.disabled	= false;
	}
	
	else
	{
		document.register.Submit.disabled	= true;
	}
}

function	checkRegistration()
{
	if (document.register.email.value && document.register.username.value && document.register.pass.value && document.register.confpass.value && document.register.firstname.value && document.register.surname.value && document.register.address.value && document.register.city.value && document.register.state.value && document.register.postcode.value )
	{
		document.register.Submit.disabled	= false;
	}
	
	else
	{
		document.register.Submit.disabled	= true;
	}
}
function checkBusinessRegistration()
{
	if (document.register.category.value && document.register.company.value && document.register.address.value && document.register.suburb.value && document.register.state.value && document.register.postcode.value && document.register.phone.value)
	{
		document.register.Submit.disabled	= false;
	}
	else
	{
		document.register.Submit.disabled	= true;
	}
}
function	deleteUser(usrID,usrName)
{
	if (confirm("Are you SURE you want to remove account\n" +
				"ID " + usrID + " belonging to " + usrName + "?"))
	{
		document.deleteuser.submit();
	}
}
function deleteListing(listingID)
{
	if (confirm("Are you SURE you want to remove listing\n" +
				"ID " + listingID + "?"))
	{
		document.deletelisting.submit();
	}
}
function	confirmPayment(name, amount)
{
	if (confirm("Are you SURE you want to process this payment?\n" +
	      "   Name    : " + name + "\n" +
	      "   Amount : $" + amount))
	{
		document.processform.submit();
	}
}
function	saleType()
{
	elementId		= "LMCT";
	if (document.addlisting.saletype.value == "D")
	{
		document.getElementById(elementId).style.display	= "";
		document.getElementById("lot_no").style.display		= "";
		document.getElementById("stock_no").style.display	= "";
	}
	
	else
	{
		document.getElementById(elementId).style.display	= "none";
		document.getElementById("lot_no").style.display		= "none";
		document.getElementById("stock_no").style.display	= "none";
	}
}
function	registerSaleType()
{
	elementId		= "LMCT";
	if (document.register.saletype.value == "D")
	{
		document.getElementById(elementId).style.display	= "";
	}
	else
	{
		document.getElementById(elementId).style.display	= "none";
	}
}
function	changeSaleType()
{
	elementId		= "LMCT";
	if (document.changedetails.saletype.value == "D")
	{
		document.getElementById(elementId).style.display	= "";
	}
	else
	{
		document.getElementById(elementId).style.display	= "none";
	}
}
function	moreFeatures()
{
	elementId		= "features";
	if (document.addlisting.morefeatures.checked)
	{
		document.getElementById(elementId).style.display	= "";
	}
	
	else
	{
		document.getElementById(elementId).style.display	= "none";
	}
}
function	checkYear()
{
	/*if (document.searchForm.year.value = "Any")
	{
		document.searchForm.year.value	= "";
		return;
	}*/
	
	if (!document.searchForm.year.value)
	{
		document.searchForm.year.value	= "Any";
		return;
	}
}
function changeModel(formName)
{
    var formObject = document.forms[formName];
    if (formName == "addlisting")
    {
      formObject.refresh.value = "true";
    }
    else
    {
      formObject.search.value = "false";
    }
    formObject.submit();
}

function changeModel_search(formName)
{
    var formObject = document.forms[formName];
    if (formName == "searchForm")
    {
      formObject.refresh.value = "true";
    }
    else
    {
      formObject.search.value = "false";
    }
    formObject.submit();
}

function changeModel2(formName)
{
    var formObject = document.forms[formName];
    if (formName == "editlisting")
    {
      formObject.refresh.value = "true";
    }
    else
    {
      formObject.search.value = "false";
    }
    formObject.submit();
}

function changeModel3(formName)
{
    var formObject = document.forms[formName];
    if (formName == "partslocater")
    {
      formObject.refresh.value = "true";
    }
    else
    {
      formObject.search.value = "false";
    }
    formObject.submit();
}


function popupEnquiry(URL) {
 day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=450,left = 406,top = 172');");

}

function closeEnquirypopup(bid) {
    opener.location.href="./viewbusiness.php?bid="+bid;
    opener.focus();
    self.close();
}

