function setClassDivLoop(prefix, divId, first, classNo, classYes) {
    var div;
    var more = true;
    for (i= first; more; i++) {
        div= document.getElementById(prefix + i);
        if (div) {
                div.className = classNo;
        } else {
                more = false;
        }
    }
    div= document.getElementById(prefix+divId);
    if (div) {
        div.className = classYes;
    }
}

function showHideDivLoop(prefix, divId, first) {
    var div;
    var more = true;
    for (i= first; more; i++) {
        div= document.getElementById(prefix + i);
        if (div) {
                div.style.display= "none";
        } else {
                more = false;
        }
    }
    div= document.getElementById(prefix+divId);
    if (div) {
        div.style.display= "block";
    }
}

function openTopLabel(indexMain, indexSub) {
    setClassDivLoop('auc_tl_'+indexMain, indexSub, 1, 'auc-top-label-close', 'auc-top-label-open');
    showHideDivLoop('auc_tl_content_'+indexMain, indexSub, 1);
}

function changeTopLabelClass(indexMain, indexSub, classNo, classYes) {
    setClassDivLoop('auc_tl_'+indexMain, indexSub, 1, 'auc-top-label-close', 'auc-top-label-open');
    setClassDivLoop('auc_tl_content_'+indexMain, indexSub, 1, classNo, classYes);
}

function openTopLabelHigh(indexMain, indexSub) {
    setClassDivLoop('auc_tl_'+indexMain, indexSub, 1, 'auc-top-label-close-high', 'auc-top-label-open-high');
    showHideDivLoop('auc_tl_content_'+indexMain, indexSub, 1);
}

function changeTopLabelClassHigh(indexMain, indexSub, classNo, classYes) {
    setClassDivLoop('auc_tl_'+indexMain, indexSub, 1, 'auc-top-label-close-high', 'auc-top-label-open-high');
    setClassDivLoop('auc_tl_content_'+indexMain, indexSub, 1, classNo, classYes);
}

/**
* Displays different views of images
* Initialize the thumbImage and the bigImage array before calling this method!
*/
function changeVehiclePic(pic, view) {
    var bg;
    var div;
    div = document.getElementById("auc-vehicle-details-picture-"+pic);
    var isValid;
    var index = (pic-1)*3+view;
    if (div) {
        bg = thumbImage[index];
        div.style.backgroundImage = 'url("'+bg+'")';
        isValid = true;
    } else {
        isValid = false;
    }
	if (isValid)
	{
	    div = document.getElementById("auc-vehicle-details-popup-content");
	    if (div) {
	    		var zoomStyle;
	        bg = bigImage[index];
	        if (bg == "null") {
	        	zoomStyle = "hidden";
	        } else {
		        div.style.backgroundImage = 'url("'+bg+'")';
	        	zoomStyle = "visible";
		      }
	    		div = document.getElementById("auc-vehicle-details-picture-zoom-"+pic);
	    		if (div) {
	    			div.style.visibility = zoomStyle;
	    		}
	    }
	}
    return isValid;
}

function resetVehiclePix() {
    var i = 0;
    var more = true;
    while (more) {
        i++;
        more = changeVehiclePic(i, 0);
    }
}

function showVehicleDetailsPopup() {
    var div = document.getElementById("auc-vehicle-details-popup");
    if (div) {
        div.style.display= "block";
    }
}

function hideVehicleDetailsPopup() {
    var div = document.getElementById("auc-vehicle-details-popup");
    if (div) {
        div.style.display= "none";
    }
}


/**
* alert message stuff
*/
function showAlertMessage(alertText)
{
	var newText = '';
	while (newText != alertText) {
		newText = alertText;
		alertText = alertText.replace("\r\n", "<br />");
		alertText = alertText.replace("\n", "<br />");
		alertText = alertText.replace("\r", "<br />");
	}
	document.getElementById('alertText').innerHTML = alertText;	
	document.getElementById('alertBoxLayer').style.display='block';
	document.getElementById('alertButton').style.display='block';
	var h = document.getElementById('alertText').clientHeight;
	if (h != 0) {
		document.getElementById('alertBox').style.height = (h+48)+"px";
		var h1 = document.getElementById('alertBox').clientHeight;
	}
	if (window.reDisplaySelectboxes)
	{
		reDisplaySelectboxes();
	}
}
function hideAlertMessage()
{
	document.getElementById('alertBoxLayer').style.display='none';
	document.getElementById('alertButton').style.display='none';
	document.getElementById('confirmButton').style.display='none';
	if (window.reDisplaySelectboxes)
	{
		reDisplaySelectboxes();
	}
	
	
	if(window.hideCorpAlertMessage) {
		hideCorpAlertMessage();
	}
	

	
	
}
function conflictWithAlertLayer(left, width, top, height)
{
	var layerLeft = document.getElementById('alertBox').offsetLeft;
	var layerTop = document.getElementById('alertBox').offsetTop + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	var layerWidth = document.getElementById('alertBox').offsetWidth;
	var layerHeight = document.getElementById('alertBox').offsetHeight;
	//window.status = ((layerLeft < left && layerTop < top && layerLeft + layerWidth > left && layerTop + layerHeight > top) 				 + " " + 				(layerLeft < left + width && layerTop < top && layerLeft + layerWidth > left + width && layerTop + layerHeight > top) 				 + " " + 				(layerLeft < left + width && layerTop < top + height && layerLeft + layerWidth > left + width && layerTop + layerHeight > top + height) 				 + " " +  (layerLeft < left && layerTop < top + height && layerLeft + layerWidth > left && layerTop + layerHeight > top + height) + " " + layerTop+ " " + top + " "  + height);

	return (layerLeft < left && layerTop < top && layerLeft + layerWidth > left && layerTop + layerHeight > top
			||
			layerLeft < left + width && layerTop < top && layerLeft + layerWidth > left + width && layerTop + layerHeight > top
			||
			layerLeft < left + width && layerTop - 18 < top + height && layerLeft + layerWidth > left + width && layerTop + layerHeight > top + height
			||
			layerLeft < left && layerTop - 18 < top + height && layerLeft + layerWidth > left && layerTop + layerHeight > top + height
			);
	//return document.getElementById('alertBoxLayer').style.display == 'block';
}

var answer = 0;
function showConfirmBox(alertText, continueCommandParameter)
{
	//alert("showConfirmBox:" + alertText + "\ncontinueCommandParameter:" + continueCommandParameter);
	if (answer != 0)
	{
		hideAlertMessage();
		var realAnswer = answer;
		answer = 0;
		return realAnswer;
	}
	okClicked = false;
	cancelClicked = false;
	document.getElementById('alertText').innerText = alertText;
	document.getElementById('alertBoxLayer').style.display='block';
	document.getElementById('confirmButton').style.display='block';
	if (window.reDisplaySelectboxes)
	{
		reDisplaySelectboxes();
	}
	setTimeout("eval('" + continueCommandParameter + "')", 500);
	return 0;
}
//window.confirm = showConfirmBox;
