/*
 	External Utility scripts 
	Author: Ivan Alexander
	Version: 1.0
	Updated: August 2, 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();
	}
}

/* Generic confirmation popup */
function confirmDelete(msg, form){
	if (confirm(msg)){
		document.forms[form].submit();
	}
}

/* Prints the concatenated value of two passed form fields to a page object specified by ID */
function printFormText(sourceForm, sourceField0, sourceField1, targetID)	{
	formPointer = document.forms[sourceForm];
	document.getElementById(targetID).innerHTML = formPointer.elements[sourceField0].value + " " + formPointer.elements[sourceField1].value;
}

/* Show/Hide object functions */
function show(object) {
	if (document.getElementById && document.getElementById(object) != null) {
		document.getElementById(object).style.visibility = 'visible';
	}
}

function hide(object) {
	if (document.getElementById && document.getElementById(object) != null) {
		document.getElementById(object).style.visibility = 'hidden';
	}
}

/* Check for Flash Plugin */
var hasFlash = function(){
	var nRequiredVersion = 6;	
	
	if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
		/*	If executed, the VBScript above checks for Flash and sets the hasFlash variable. 
			If VBScript is not supported it's value will still be undefined, so we'll run it though another test
			This will make sure even Opera identified as IE will be tested */
		if(window.hasFlash != null){
			return window.hasFlash;
		};
	};
	
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		return parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1)) >= nRequiredVersion;
	};
	
	return false;
}();