/*
 	External Utility scripts 
	Author: Ivan Alexander
	Version: 1.0
	Updated: March 21, 2005
	© 2005, Manheim Auctions
*/

/*  Selects from a single Select All checkbox an array of Checkboxes that all have an 
	identical ID that is supplied to the script */
function selectAllCheckboxes(itemID, controlID) {
	boxes = document.getElementsByName(itemID);
	count = boxes.length;
	flag = controlID.checked;
	for (i = 0; i < count; i++) {
		boxes[i].checked = flag;
	}
}

/* Clears and resets the Select All checkbox if any member checkbox is unchecked */
function clearSelectAll(controlID) {
	control = document.getElementsByName(controlID);
	flag = control[0].checked;
	if (flag) {
		control[0].checked = 0;
	}
}

/* Opens an Alert popup to display vehicle VIN with extra alert text, if it is supplied */
function showvin(fullvin, alertText) {
	if (!(alertText)){
		str = "Full VIN: " + fullvin;
		alert(str);
	} else {
		str = alertText + "\n\nFull VIN: " + fullvin;
		alert(str);
	}
}

windowFlag = 0;

/* Opens a non-scrollable window with the specified width and height in the center of the screen */
function openWindow(URL, wide, high, windowID){
    scrnX = screen.availWidth;
    scrnY = screen.availHeight;
    leftPos = (scrnX - wide)/2;
    topPos = (scrnY - high)/2;
    str = "status=no,toolbar=no,scrollbars=no,resizable=no,width=" + wide + ",height=" + high + ",screenX=" + leftPos + ",screenY=" + topPos + ",left=" + leftPos + ",top=" + topPos;
	if (windowFlag && !(dialog.closed)){
		dialog.close();
	}
	dialog = window.open(URL,windowID,str);
	windowFlag = 1;
}

/* Opens a scrollable window with the specified width and height in the center of the screen */
function openScrollingWindow(URL, wide, high, windowID){
    scrnX = screen.availWidth;
    scrnY = screen.availHeight;
    leftPos = (scrnX - wide)/2;
    topPos = (scrnY - high)/2;
    str = "status=no,toolbar=no,scrollbars=yes,resizable=no,width=" + wide + ",height=" + high + ",screenX=" + leftPos + ",screenY=" + topPos + ",left=" + leftPos + ",top=" + topPos;
	if (windowFlag && !(dialog.closed)){
		dialog.close();
	}
	dialog = window.open(URL,windowID,str);
	windowFlag = 1;
}

/*  Ad Manager Vehicle Registration confirmation popup */
function selectVehicle(year, makeModel, fullvin, form){
	str = "Are you sure you want to register this\n" + year + " " + makeModel + " with a VIN of\n" + fullvin + "?";
	if (confirm(str)){
		document.forms[form].submit();
	}
}

/*  Ad Manager Lane Registration confirmation popup */
function selectLane(year, makeModel, auction, lane, date, form){
	str = "Are you sure you want to register this " + year + "\n" + makeModel + " to " + auction + "\nfor Lane/Run " + lane + " for sale date " + date +"?";
	if (confirm(str)){
		document.forms[form].submit();
	}
}

/* Delete Object confirmation popup */
function confirmDelete(object, form){
	str = "Are you sure you want to delete this " + object + "?";
	if (confirm(str)){
		document.forms[form].submit();
	}
}

/* Show/Hide object functions */
function show(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.display='block';
}

function hide(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.display='none';
}