/* ---------- PAGE LOAD FUNCTIONS ---------- */

var isIE = (navigator.appName == "Microsoft Internet Explorer");
var ieVersion = navigator.appVersion;
var hasFocus = true;
var active_element;

if (!document.getElementById) document.location.href = "noView.php";

isIE7 = "MSIE 7.0";
version = navigator.appVersion;
//if (version.indexOf(isIE7) > -1) document.location.href = "noView.php";


function init() {
	setStepArea();
	setInfoFrame();
	if (loaderImage.complete && loaderImage.height) { 
		changeImage('imgLoading', loaderImage.src);
	}
	sessionTimeOut();
}


function setStepArea()
{
	
	// get container dims
	IQBodyW = getElemDimensions("IQBody", "w");
	IQBodyH = getElemDimensions("IQBody", "h");
	
	// get header dims
	IQHeaderW = getElemDimensions("IQHeader", "w");
	IQHeaderH = getElemDimensions("IQHeader", "h");
	
	// get tabs dims
	IQTabsW = getElemDimensions("IQTabs", "w");
	IQTabsH = getElemDimensions("IQTabs", "h");
	
	// get footer dims
	IQFooterW = getElemDimensions("IQFooter", "w");
	IQFooterH = getElemDimensions("IQFooter", "h");
	
	// get contentTD dims
	IQContentTDW = getElemDimensions("IQContentTD", "w");
	IQContentTDH = getElemDimensions("IQContentTD", "h");
	
	// get content dims
	IQContentArea = 		document.getElementById("IQContent");
	newHeight =				IQBodyH - (IQHeaderH + IQFooterH + IQTabsH);
	
	if (IQContentArea.style)
	{
		IQContentArea.style.height = 	newHeight + "px";
		IQContentArea.style.display = 	"block";
	}
}


function setInfoFrame()
{
	// get container dims
	dIFrame = getElemDimensions("divInfoFrame", "w");
	dIFrame = getElemDimensions("divInfoFrame", "h");
	
	// get header dims
	iTitleH = getElemDimensions("divInfoTitle", "w");
	iTitleH = getElemDimensions("divInfoTitle", "h");
	
	infoIFrame = document.getElementById("infoContent");
	iNewHeight = Math.round((dIFrame * .90) - iTitleH);
	
	if (infoIFrame) infoIFrame.style.height = iNewHeight + "px";
}


/* ---------- GO FUNCTIONS ---------- */
function goTo(where) { document.location.href = where; }

function goTop()
{
	if (window.scrollTo) window.scrollTo(0,0);
}




/* ---------- LOADER FUNCTIONS ---------- */
function doLoader()
{
	loader = 	document.getElementById("divLoader");
	content = 	document.getElementById("divContent");
		
	loader.style.visibility = "hidden";
	loader.style.display = "none";
	content.style.visibility = "visible";
	content.style.display = "block";
}





/* ---------- DIV FUNCTIONS ---------- */

function killContent()
{
	loader = 	document.getElementById("divLoader");
	content = 	document.getElementById("divContent");
		
	loader.style.visibility = "visible";
	loader.style.display = "block";
	content.style.visibility = "hidden";
	content.style.display = "none";
}


function showDiv(divID)
{

	var myDiv = 		document.getElementById(divID);
	
	if (myDiv)
	{
		myDiv.style.visibility = 	"visible";
		myDiv.style.display = 		"block";
	}

}
function hideDiv(divID)
{

	var myDiv = 		document.getElementById(divID);
	
	if (myDiv)
	{
		myDiv.style.visibility = 	"hidden";
		myDiv.style.display = 		"none";
	}

}





/* ---------- INFO FRAME FUNCTIONS ---------- */



function launchInfoFrame(infoSection, StyleID, DealerID)
{

	var infoURL = "";
	var infoTitle = "";
	
	if (infoSection == "Disclaimer") infoURL = "viewDisclaimer.php?dealer=" + DealerID;
	if (infoSection == "About") infoURL = "viewAbout.php?dealer=" + DealerID;
	if (infoSection == "Legal") infoURL = "viewLegal.php?dealer=" + DealerID;
	if (infoSection == "Suggestions") { infoSection = "Feature Request Form"; infoURL = "viewSuggestionForm.php?dealer=" + DealerID; }
	if (infoSection == "Bug") { infoSection = "Bug Report"; infoURL = "viewBugForm.php?dealer=" + DealerID; }
	if (infoSection == "Standard Features") infoURL = "viewStyleStandards.php?dealer=" + DealerID + "&StyleID=" + StyleID;
	if (infoSection == "Technical Specifications") infoURL = "viewStyleSpecs.php?dealer=" + DealerID + "&StyleID=" + StyleID;
	if (infoSection == "Photos") infoURL = "viewStylePhotos.php?dealer=" + DealerID + "&StyleID=" + StyleID;
	infoTitle = infoSection;
	openInfoFrame(infoTitle, infoURL);
}


function openInfoFrame(infoTitle, infoFrameURL)
{

	titleBox = 		document.getElementById("infoFrameTitle");
	iFrame =		document.getElementById("infoContent");
	iFrameDiv = 	document.getElementById("divInfoFrame");
	
	if (iFrameDiv)
	{
		titleBox.innerHTML = 			infoTitle;
		iFrameDiv.style.visibility = 	"visible";
		iFrameDiv.style.display = 		"block";
		iFrame.src =					infoFrameURL;
	}

}

function closeInfoFrame(Division)
{
	iFrame = 		document.getElementById("infoFrame");
	iFrameDiv = 	document.getElementById("divInfoFrame");
	iFrame =		document.getElementById("infoContent");
	
	if (iFrameDiv)
	{
		iFrameDiv.style.visibility = 	"hidden";
		iFrameDiv.style.display = 		"none";
		iFrame.src =					"viewLoader.php?div=" + Division;
	}
}


function sizeInfoFrame()
{

}





function sessionTimeOut() {
	setTimeout ("startOver()", 300000);
}

function loadImages(imgArray)
{
	if (imgArray[0])
	{
		var imageLoad = new Array();
		for (x=0; x < imgArray.length; x++)
		{
			imageLoad[x] = 		new Image();
			imageLoad[x].src = 	imgArray[x];
		}
	}
}



/* ---------- BTN FUNCTIONS ---------- */

function btnOver(which) {
	btn = document.getElementById(which);
	if (btn) {
		btn.style.backgroundColor = "#cedeea";
	}
}

function btnOut(which) {
	btn = document.getElementById(which);
	if (btn) {
		btn.style.backgroundColor = "";
	}
}

function btnDn(which) {
	btn = document.getElementById(which);
	if (btn) {
		btn.style.backgroundColor = "#3c7fb1";
	}
}

function changeBtn(btnID, state)
{
	btn = document.getElementById("btn_" + btnID);
	if (btn)
	{
		btnLeft =		document.getElementById("btnLeft_" + btnID);
		btnBg =			document.getElementById("btnBg_" + btnID);
		btnRight =		document.getElementById("btnRight_" + btnID);
			
		if (state == "on")
		{
			btnLeft.src =	"img/bg/btn/btn-left-on.gif";
			btnRight.src =	"img/bg/btn/btn-right-on.gif";
			btnBg.style.backgroundImage = "url('img/bg/btn/btn-bg-on.gif')";
		}
		else
		{
			btnLeft.src =	"img/bg/btn/btn-left.gif";
			btnRight.src =	"img/bg/btn/btn-right.gif";
			btnBg.style.backgroundImage = "";
		}
	}
}

function doEdit(which) {
	edit = document.getElementById(which);
	if (edit)
	{
		src = 	edit.src;
		isOn =	src.indexOf("-on");
		
		if (isOn > 0)
		{
			newSrc = src.replace("-on.png", ".png");
		}
		else
		{
			newSrc = src.replace(".png", "-on.png");
		}
		
		edit.src = newSrc;
	}
}



/* ---------- ROW OPTION FUNCTIONS ---------- */

function rowOver(which) {
	row = document.getElementById(which);
	if (row) {
		row.style.backgroundColor = "#fdf0de";
	}
}

function rowOut(which) {
	row = document.getElementById(which);
	if (row) {
		row.style.backgroundColor = "";
	}
}

function rowClickDn(which) {
	row = document.getElementById(which);
	if (row) {
		row.style.backgroundColor = "#f2edf1";
		row.style.cursor =			"wait";
	}
}

function rowClickUp(which) {
	row = document.getElementById(which);
	if (row) {
		row.style.backgroundColor = "";
	}
}


/* ---------- TAB FUNCTIONS ---------- */


function stepTabOver(which, src)
{
	tab = document.getElementById("stepTab_" + which);
	if (tab)
	{
		tab.style.backgroundImage =  "url(" + src + ")";
	}
}

function stepTabOut(which, src)
{
	tab = document.getElementById("stepTab_" + which);
	if (tab)
	{
		tab.style.backgroundImage = "url(" + src + ")";
	}
}





function doRowTab(which, tabs) 
{
	closeAllTabs(tabs);
	rowTabOn(which, tabs);
	rowTabImg(which, "on");
}


function doAllTabs(which, tabs)
{
	closeAllTabs(tabs);
	showAllTabs(tabs)
	rowTabImg(which, "on");
}


function rowTabOn(which, tabs)
{
	row = document.getElementById("row_" + which);
	if (row) {
		row.style.visibility = "visible";
		row.style.display = "block";
	}
}

function rowTabOff(which)
{
	row = document.getElementById("row_" + which);
	if (row) {
		row.style.visibility = "hidden";
		row.style.display = "none";
		rowTabImg(which, "off");
		rowTabImg("0", "off")
	}
}

function rowTabImg(which, state)
{
	tabL = document.getElementById("l_" + which);
	tabR = document.getElementById("r_" + which);
	tabB = document.getElementById("bg_" + which);
	tabLink = document.getElementById("tl_" + which);
	
	if (state == "on")
	{
		tabL.src = "img/misc/tabs/l.png";
		tabR.src = "img/misc/tabs/r.png";
		tabB.style.backgroundImage = "url('img/misc/tabs/bg.png')";
		
		tabLink.style.fontWeight = "bold";
		tabLink.style.fontSize = "14px";
		tabLink.style.color = "#000000";
		
	} else {
		tabL.src = "img/invis.gif";
		tabR.src = "img/invis.gif";
		tabB.style.backgroundImage = "url('img/invis.gif')";
		
		tabLink.style.fontWeight = "normal";
		tabLink.style.fontSize = "12px";
		tabLink.style.color = "#000000";
	}
	
}

function closeAllTabs(TABS)
{
	if (TABS.length) for (x=0; x < TABS.length; x++) if (TABS[x]) rowTabOff(TABS[x]);
}

function showAllTabs(TABS)
{
	if (TABS.length) for (x=0; x < TABS.length; x++) if (TABS[x]) rowTabOn(TABS[x]);
}


/* ---------- IMAGE FUNCTIONS ---------- */

function showLoad(whichImg) {
	thisImg = whichImg;
	whichImg = document.getElementById(whichImg);
	
	if (document.getElementById("divLoading"))
	{
		document.getElementById("divLoading").style.visibility = "visible";
		document.getElementById("divLoading").style.display = "block";
		if (whichImg) {
			changeImage(thisImg, "img/misc/loading.gif");
		}
	}
	
}


function changeImage(whichImg, newImg) {
	whichImg = document.getElementById(whichImg);
	
	if (whichImg)
	{
		whichImg.src = newImg;
	}
	
}

function changeModelImage(newImage)
{
	
	modelImage = document.getElementById('modelImage');
	
	if (modelImage)
	{
		modelImage.style.backgroundImage = newImage;
		alert(modelImage.style.backgroundImage);
	}
	
}

/* ---------- POSITION FUNCTIONS ---------- */

function findPosX(obj) {
    
	var curleft = 0;
	obj = document.getElementById(obj);
   
	if (obj)
	{
		if (obj.offsetParent) {
	        while (1) {
	            curleft+=obj.offsetLeft;
	            if (!obj.offsetParent) {
	                break;
	            }
	            obj=obj.offsetParent;
	        }
	    } else if (obj.x) {
	        curleft+=obj.x;
	    }
	}
    return curleft;
}


function findPosY(obj) {
    
	var curtop = 0;
	obj = document.getElementById(obj);
   
	if (obj)
	{
		if (obj.offsetParent) {
	        while (1) {
	            curtop+=obj.offsetTop;
	            if (!obj.offsetParent) {
	                break;
	            }
	            obj=obj.offsetParent;
	        }
	    } else if (obj.y) {
	        curtop+=obj.y;
	    }
	}
    return curtop;
}



/* ---------- DIMENSION FUNCTIONS ---------- */



function getDocDimentions(WorH)
{

	 var viewportwidth;
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	 
	 viewport = (WorH == "w") ? viewportwidth : viewportheight;
	
	 return viewport;
}





function setViewport(height, width)
{

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      window.innerWidth = width;
	      window.innerHeight = height;
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       document.documentElement.clientWidth = width;
	       document.documentElement.clientHeight = height;
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		document.getElementsByTagName('body')[0].clientWidth = width;
		document.getElementsByTagName('body')[0].clientHeight = height;
	 }
	
}

function getElemDimensions(Elem, WorH) {
	var dim;
	if (document.getElementById)
	{
		var elem = document.getElementById(Elem);
	}
	
	else
	{
		var elem = document.all[Elem];
	}
	
	if (elem)
	{
		if (WorH == "h")
		{
			dim = elem.style.pixelHeight;
			if (!dim) dim = elem.offsetHeight;
		}
		
		else if (WorH == "w")
		{
			dim = elem.style.pixelWidth;
			if (!dim) dim = elem.offsetWidth;
		}
	}
	
	return dim;
}

function isset(varname)
{
  return(typeof(window[varname])!='undefined');
}




/* ---------- FORM FUNCTIONS ---------- */
function submitForm(formID)
{
	formID = document.getElementById(formID);
	if (formID)
	{
		goTop();
		formID.submit();
		showLoad();
	}
}

function setBuildValue(boxID, boxVal)
{
	box = document.getElementById(boxID);
	if (box)
	{
		box.value = boxVal;
	}
	else
	{
		alert("Error!\n\nBox not found.");
	}
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}