// PANELS FUNCTIONS /////////////////////////////////////////////////////
var intervalResults = new Array();
			
function showAllPanels(){
	/*
	fadePanel('RightContentsHeaderTop',0,99,'IN',100);
	fadePanel('RightContentsHeaderBottom',0,99,'IN',100);
	fadePanel('RightContents',0,99,'IN',100);
	fadePanel('RightContentsFooter',0,99,'IN',100);
	*/
}
function hideAllPanels(){
/*
	fadePanel('RightContentsHeaderTop',99,0,'OUT',25);
	fadePanel('RightContentsHeaderBottom',99,0,'OUT',25);
	fadePanel('RightContents',99,0,'OUT',25);
	fadePanel('RightContentsFooter',99,0,'OUT',25);
	*/
}

/*
function fadePanel(elementID,currentOpacity,targetOpacity,fadeDirection,theInterval) {
	var theElement = document.getElementById(elementID).style;
	var theID      = elementID;
	var fadeDone   = "NO";
	
	if (fadeDirection == "IN") {
		if (currentOpacity <= targetOpacity) {
			theOpacity = (currentOpacity + 5);
		} else {
			clearInterval(intervalResults[theID]);
			var fadeDone = "YES";
		}
	}	
	if (fadeDirection == "OUT"){
		if (currentOpacity >= targetOpacity) {
			theOpacity = (currentOpacity - 5);
		} else {
			clearInterval(intervalResults[theID]);
			var fadeDone = "YES";
		}
	}
	if (fadeDone == "NO") {
		theElement.opacity = (theOpacity / 100);
		//theElement.filter  = "alpha(opacity=" + theOpacity + ")";
	
		clearInterval(intervalResults[theID]);
		intervalResults[theID] = setInterval("fadePanel('" + theID + "'," + theOpacity + "," + targetOpacity + ",'" + fadeDirection + "')",theInterval);
	}
}
*/

function changeText() {
	hideAllPanels();
	document.getElementById("RightContents").innerHTML = "New Content";
	//fadePanel("RightContents",0,99,"IN",100);
}

function emptyModelField() {
	document.modelForm.SearchNum.value = "";
}
function emptyPartNumField() {
	document.qsbox.partnumber.value = "";
}

// MENUS FUNCTIONS ////////////////////////////////////////////////////////////////
function doMenu(whichMenu,whichAction) {
	//document.getElementById('CurrentSpecialsMenu').style.visibility='hidden';
	//document.getElementById('CustomerServiceMenu').style.visibility='hidden';
	//document.getElementById('MyAccountMenu').style.visibility='hidden';
	if (document.getElementById(whichMenu)) {		
		if (whichAction == "SHOW") {
			document.getElementById(whichMenu).style.visibility='visible';
		}
		if (whichAction == "HIDE") {
			document.getElementById(whichMenu).style.visibility='hidden';
		}
	}	
}

function doPBMenu(whichMenu,whichAction) {
	/*if (document.all){
		var theOffset    = 55;
		var MAKEColWidth = document.all['MAKEBttns'].offsetWidth;
		document.all[whichMenu].style.posLeft = (MAKEColWidth + theOffset);
	} else {
		var theOffset    = 350;
		var MAKEColWidth = document.getElementById('MAKEBttns').style.posRight;
		document.getElementById(whichMenu).style.posLeft = (MAKEColWidth + theOffset);
	}
	*/
	if (whichAction == "SHOW") {
		document.getElementById(whichMenu).style.visibility='visible';
	}
	if (whichAction == "HIDE") {
		document.getElementById(whichMenu).style.visibility='hidden';
	}
}

// Multi View Panel Functions
	function doMultiView(whichPanel,whichPic,imageList,description,whichAction){
		var imageListArray  = imageList.split(",");
		var bigPic          = document.getElementById("BigPicCell");
		var thumbs          = document.getElementById("ThumbsCell");
		var desc            = document.getElementById("DescriptionCell");
		var panel           = document.getElementById('MultiViewPanel');
		var theWindowHeight = getWindowHeight();
		var thumbCell       = "";
		var thumbImage      = "";
		var thumbSkirt      = "";
		
		bName = navigator.appName;
		MSIE  = navigator.appVersion.indexOf("MSIE");
		bVer  = navigator.appVersion.substr((MSIE+5),3);
			
		if (whichAction == "SHOW") {
			// Insert the Big Picture
			if (whichPic == 0) {
				theLargeImage = imageListArray[whichPic] + "_F.jpg";
			} else {
				theLargeImage = imageListArray[whichPic];
			}
			bigPic.style.backgroundImage = "url(LargeProductImages/" + theLargeImage + ")";
			bigPic.innerHTML = "<img src='images/pixel.gif' width='500' height='500' border='0'>";
			
			// Empty the Thumbnails
			for (n=1;n<=9;n++){
				thumbCell  = document.getElementById("thumb" + n);
				thumbSkirt = document.getElementById("skirt" + n);
				
				thumbCell.innerHTML  = "";
				thumbSkirt.innerHTML = "";
			}
			
			// Insert the Thumbnails
			theCode = "";
			if (imageListArray.length > 2) {
				theCode = theCode + "<font class='ResultsLarge'><font color='999999'><center>"
				theCode = theCode + "Click the thumbnails to see<br>the other views.</center></font></font>";
			}
			if (imageListArray.length > 2) {
				for (i=1;i<=(imageListArray.length-1);i++){
					if (imageListArray[i] == theLargeImage) {
						theBorder = 2;
					} else {
						theBorder = 0;
					}
					
					thumbCell  = document.getElementById("thumb" + i);
					thumbSkirt = document.getElementById("skirt" + i);
					thumbImage = imageListArray[i];
					
					thumbCell.innerHTML = "<img src='LargeProductImages/" + thumbImage + "' width='75' height='75' border='" + theBorder + "'>";
					
					theCode = "";
					theCode = theCode + "<a href='javascript:changeMultiView(\"" +  i + "\",\"" + imageList + "\");'>";
					theCode = theCode + "<img src='images/pixel.gif' width='75' height='75' border='0'>";
					theCode = theCode + "</a>";
					thumbSkirt.innerHTML = theCode;
				}
			}
			
			// Insert the Description
			theCode = "";
			theCode = "<div align='right'><a class='ViewAll' href='javascript:doMultiView(\"MultiViewPanel\",\"\",\"\",\"\",\"HIDE\");' >Close</a><br /><br /><br /></div><font class='ResultsLarge'>" + imageListArray[0] + "<br />" + unescape(description) + "</font><br><br><br><br><br><br><br><br><br><br><br><br>";
			desc.innerHTML = theCode;
			
			// Style the Panel
			// Set the top and height for IE 6
			panel.style.top = (theWindowHeight-110) + 'px';
			
			// Set the top and height for IE7
			if (bName == "Microsoft Internet Explorer" && bVer == 7) {
				panel.style.top = (theWindowHeight-235) + 'px';
			}
			
			panel.style.width  = '755px';
			panel.style.zIndex = '100000';
			panel.style.height = '510px';

			
			// Show the Panel
			panel.style.visibility = 'visible';
		}
		if (whichAction == "HIDE") {
			panel.style.zIndex     = '0';
			panel.style.visibility = 'hidden';
			
			document.getElementById(whichPanel).style.width ='0px';
			document.getElementById(whichPanel).style.height='0px';
		}
	}
	function changeMultiView(whichImage,imageList) {
		imageListArray = imageList.split(",");
		
		// Change the Large Image
		theLargeImage = imageListArray[whichImage];
		
		document.getElementById("BigPicCell").style.backgroundImage = "url(LargeProductImages/" + theLargeImage + ")";
		document.getElementById("BigPicCell").innerHTML             = "<img src='images/pixel.gif' width='500' height='500' border='0'>";
		
		// Change the Thumbnails
		theCode = "";
		if (imageListArray.length > 2) {
			theCode = theCode + "<font class='ResultsLarge'><font color='999999'><center>"
			theCode = theCode + "Click the thumbnails to see<br>the other views.</center></font></font>";
		}
		if (imageListArray.length > 2) {
			for (i=1;i<=(imageListArray.length-1);i++){
				if (imageListArray[i] == theLargeImage) {
					theBorder = 2;
				} else {
					theBorder = 0;
				}
				
				thumbCell  = document.getElementById("thumb" + i);
				thumbSkirt = document.getElementById("skirt" + i);
				thumbImage = imageListArray[i];
					
				thumbCell.innerHTML = "<img src='LargeProductImages/" + thumbImage + "' width='75' height='75' border='" + theBorder + "'>";
					
				theCode = "";
				theCode = theCode + "<a href='javascript:changeMultiView(\"" +  i + "\",\"" + imageList + "\");'>";
				theCode = theCode + "<img src='images/pixel.gif' width='75' height='75' border='0'>";
				theCode = theCode + "</a>";
				thumbSkirt.innerHTML = theCode;
					
				//theCode = theCode + "<a href='javascript:changeMultiView(\"" +  i + "\",\"" + imageList + "\");'>";
				//theCode = theCode + "<img src='LargeProductImages/" + imageListArray[i] + "' width='75' height='75' border='" + theBorder + "' style='margin-left:2px;margin-right:2px;'></a>";
			}
		}
		//document.getElementById("ThumbsCell").innerHTML = theCode;
	}

function getWindowHeight() {
	var windowHeight = 0;
	var scrollY = 0;
	
    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
     }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    } else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    } else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
    
	if (typeof(window.innerHeight) == 'number') {
		// Safari 3 uses this one
		windowHeight = (scrollY + ((window.innerHeight/2)-300));
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			// IE 7 Uses this one
			windowHeight = (document.documentElement.scrollTop + ((document.documentElement.clientHeight/2)-200));
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = (document.body.scrollTop + (document.body.clientHeight/2));
			}
		}
	}
	return windowHeight;
}

// RESULTS TABLE CHECK IF PART SELECTED
	var isPartSelected = "NO";

	function isSomethingSelected() {
		if (isPartSelected == "NO") {
			alert("Please select a part to Add to the Order.");
		} else {
			//alert("Sending Order...");
			document.resultsForm.submit();
		}
	}

// FEATURED PART TABLE CHECK IF PART SELECTED
	var isanFPPartSelected = "NO";

	function isanFPSelected() {
		if (isanFPPartSelected == "NO") {
			alert("Please select a part to Add to the Order.");
		} else {
			//alert("Sending Order...");
			document.fpForm.submit();
		}
	}
			
	
// DATE ///////////////////////////////////////////////////////////
	var today = new Date();
	
	function nameDay() {
		var arg1 = nameDay.arguments;
		for (var i=0; i < arg1.length; i++) {this[i]=arg1[i];}
		this.length = arg1.length;
	}
	
	function nameMonth() {
		var arg2 = nameMonth.arguments;
		for (var i=0; i < arg2.length; i++) {this[i]=arg2[i];}
		this.length = arg2.length;
	}

	function getString(date,format) {
		switch(format) {
			case 'whole' : var day = new nameDay("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
			case 'short' : var day = new nameDay("Sun", "Mon", "Tue","Wed", "Thu", "Fri","Sat");
			case 'number': var day = "";					
		}
		switch(format) {			
			case 'whole' : var month = new nameMonth("January","February","March","April","May","June","July","August","September","October","November","December");
			case 'short' : var month = new nameMonth("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
			case 'number': var month = new nameMonth("01","02","03","04","05","06","07","08","09","10","11","12");
		}
		var yy    = date.getYear();
		var year  = (yy < 1000) ? yy + 1900 : yy;
	  	
	  	switch(format) {
			case 'whole' : return day[date.getDay()] + ", " + month[date.getMonth()] + " " + date.getDate() + ", " + year;
			case 'short' : return day[date.getDay()] + ", " + month[date.getMonth()] + " " + date.getDate() + ", " + year;
			case 'number': return month[date.getMonth()] + "/" + date.getDate() + "/" + year;
		}
	}
	
	function printDate(format) {
		document.write(getString(today,format));
	}
	
	
// WINDOW OPENERS //////////////////////////////////////////////////////////
	function winFixed(fileName,windowName,W,H) {
		window.open(fileName,windowName,'scrollbars=no,resizable=no,status=no,toolbar=no,width=' + W + ',height=' + H + ',screenX=235,screenY=0,top=0,left=235')
	}
	
	function winScroll(fileName,windowName,W,H) {
		var bodyW = 480, bodyH = 340;

		if (document.all) {
  			/* the following is only available after onLoad */
   			bodyW = document.body.clientWidth;
   			bodyH = document.body.clientHeight;
		}
		else if (document.layers) {
			bodyW = window.innerWidth;
   			bodyH = window.innerHeight;
		}

		var popW = W, popH = H;
		var leftPos = (bodyW - popW)/2, topPos = (bodyH - popH)/2;

		//window.open('page,html','popup','width=' + popW + ',height='+popH+',top='+topPos+','left='+leftPos);
		popWin = window.open(fileName,windowName,'scrollbars=yes,resizable=yes,status=yes,toolbar=yes,width=' + popW + ',height=' + popH + ',screenX=' + leftPos + ',screenY=' + topPos + ',top=' + topPos + ',left=' + leftPos)
	}
