// JavaScript Document

// 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;
}

// stock image swap for view page
function swapstock (target, fname) {
	document[target].src = "StockImages/" + 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(stock) {
	msg = "Are you sure you want to remove this vehicle listing?";
	if(confirm(msg)) {
		window.location='remove.php?stock=' + stock;
	} 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';
	}
}

