// JavaScript Document
/*-----------------------------------------------------------------
autoBoss Version 1.0
autoBoss is © Copyright 2004 Michael Sams.  All Rights Reserved.

THE WRITTEN AND GRAPHICAL CONTENT OF AUTOBOSS IS FULLY PROTECTED 
BY THE UNITED STATES COPYRIGHT LAWS AND IS CONSIDERED A TRADE 
SECRET BELONGING TO THE COPYRIGHT HOLDER.

ANY UNAUTHORIZED REPRODUCTION OR DISTRIBUTION OF AUTOBOSS IN PART
OR IN ITS ENTIRETY IS STRICTLY PROHIBITED.
-----------------------------------------------------------------*/

// verify required fields
function checkrequired(form) {
	var pass = true;
	for(i = 0; i < form.length; i++) {
		var tempobj = form.elements[i];
		if(tempobj.alt == "required") {
			if(tempobj.value == '') {
				pass = false;
				break;
			}
		}
	}
	if(!pass) {
		alert("Please enter the required information.");
		tempobj.focus(); // set focus to missing field
		return false;
	}
	else { return true; } 
}

// image swap for view page
function swap(target, fname) {
	document[target].src = "images/" + fname;
}

// make sure at least one search criteria has been provided
function checksearch(form) {
	var count = 0;
	
	for(i = 0; i < form.length; i++) {
		var tempobj = form.elements[i];
		if(tempobj.value == '') {
			count++;
		}
	}
	i-=2;
	if(count == i) {
		alert("You have not entered any search criteria.");
		return false;
	}
	else {
		//alert("You DID enter search criteria." + count + "  " + i);
		return true;
	} 
}

// confirm removal of vehicle listing
function verify_removal(ccode) {
	msg = "Are you sure you want to remove this vehicle listing?";
	if(confirm(msg)) {
		window.location='remove.php?ccode=' + ccode;
	} else {
		return false;
	}
}

// confirm removal of image from vehicle listing
function verify_image(imageid, ccode) {
	msg = "Are you sure you want to remove this image?";
	if(confirm(msg)) {
		window.location='removeimg.php?id=' + imageid + '&ccode=' + ccode;
	} else {
		return false;
	}
}

// display invalid stock number message
function invalid_stock(stock) {
	msg = "The stock number " + stock + " appears to be invalid.";
	if(confirm(msg)) {
		window.location='cpanel.php';
	} else {
		window.location='cpanel.php';
	}
}
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function switchModello(){
	var modelloEsistente = document.getElementById('modelloEsistente');
	var modelloNuovo = document.getElementById('modelloNuovo');
	var modelloField  = document.getElementById('modelloField');
	if (modelloEsistente.style.display == "none" ) {
		modelloEsistente.style.display = "";
		modelloNuovo.style.display = "none";
		modelloField.value = "modello";
	} else {
		modelloEsistente.style.display = "none";
		modelloNuovo.style.display = "";
		modelloField.value = "modellonew";
	}
}

function riservaTrattativa() {
	var trattativaRiservata = document.getElementById('trattativaRiservata');
	var prezzo = document.getElementById('prezzo');
	var trattabile = document.getElementById('trattabile');
	var riservataWarning = document.getElementById('riservataWarning');
	var rigaTrattabile = document.getElementById('rigaTrattabile');
	
	if (trattativaRiservata.checked) {
		prezzo.disabled = true;
		trattabile.disabled = true;
		riservataWarning.style.display = "";
		rigaTrattabile.style.display = "none";
	} else {
		prezzo.disabled = false;
		trattabile.disabled = false;
		riservataWarning.style.display = "none";
		rigaTrattabile.style.display = "";
	}
}

function switchImmatricolazione(){
	var nonImmatricolata = document.getElementById('nonImmatricolata');
	var immatricolazionemm = document.getElementById('immatricolazionemm');
	var immatricolazioneyy  = document.getElementById('immatricolazioneyy');
	var km = document.getElementById('km');

	if (nonImmatricolata.checked) {
		immatricolazionemm.disabled = true;
		immatricolazioneyy.disabled = true;
		km.disabled = true;
	} else {
		immatricolazionemm.disabled = false;
		immatricolazioneyy.disabled = false;
		km.disabled = false;
	}
}