var tabOpen = new Image();
    tabOpen.src = "/images/tab_open_0.gif";
var tabClose = new Image();
    tabClose.src = "/images/tab_close_0.gif";
var tabCart = new Image();
    tabCart.src = "/images/tab_cart_0.gif";
var tab = new Image();
    tab.src = "/images/tab_00.gif";



function getTime() {

	var o = null;
	var i = 0;
	cSecond++;
	SecondsUntilCutoff--;

	if(SecondsUntilCutoff<0) { SecondsUntilCutoff=86399; }

	if(cSecond>59) { cMinute++; cSecond=0; }
	if(cMinute>59) { cHour++; cMinute=0; }
	if(cHour>=24) { cHour=0; }	

	if(document.all) { o = document.all("instocktime"); }
	else if(document.getElementById) { o = document.getElementById("instocktime"); }

	if(o!=null) { o.innerHTML = formatTime(cHour,cMinute,cSecond)+" EST"; }

	o=null;
	if(document.all) { o = document.all("instockcountdown"); }
	else if(document.getElementById) { o = document.getElementById("instockcountdown"); }
	if(o!=null) { o.innerHTML = secondsToTime(SecondsUntilCutoff); }

	setTimeout("getTime();",1000);
}

function getSOTime() {

	var o = null;
	var i = 0;
	cSecondSO++;
	SecondsUntilCutoffSO--;

	if(SecondsUntilCutoffSO<0) { SecondsUntilCutoffSO=86399; }

	if(cSecondSO>59) { cMinuteSO++; cSecondSO=0; }
	if(cMinuteSO>59) { cHourSO++; cMinuteSO=0; }
	if(cHourSO>=24) { cHourSO=0; }	

	if(document.all) { o = document.all("specialordertime"); }
	else if(document.getElementById) { o = document.getElementById("specialordertime"); }

	if(o!=null) { o.innerHTML = formatTime(cHourSO,cMinuteSO,cSecondSO)+" EST"; }

	o=null;
	if(document.all) { o = document.all("specialordercountdown"); }
	else if(document.getElementById) { o = document.getElementById("specialordercountdown"); }
	if(o!=null) { o.innerHTML = secondsToTime(SecondsUntilCutoffSO); }

	setTimeout("getSOTime();",1000);
}

function secondsToTime(noseconds) { 

	nohours = Math.floor(noseconds/3600); 
	noseconds -= (Math.floor(noseconds/3600))*3600; 
	nominutes = Math.floor(noseconds/60); 
	noseconds -= (Math.floor(noseconds/60))*60; 

	return nohours+"h "+nominutes+"m "+noseconds+"s remaining";

} 


function formatTime(h,m,s) {

	if(h>=24) { h=h-24; }
	if(h==0) { h=12; }
	if(h<0) { h=12+h; }

	var minute = [m].toString();
	var second = [s].toString();

	if(minute.length==1) { minute = "0"+minute; }
	if(second.length==1) { second = "0"+second; }

	if(h>=12) { AMPM=" PM"; } else { AMPM=" AM"; }
	if(h>12) { hour=h-12; } else { hour=h.toString(); }
	//hour=h.toString();

	return hour+":"+minute+":"+second+AMPM;
}




function showDecorators(o) {

	var oM = null;
	var oM2 = null;

	if(document.all) {
		oM = document.all("DecoratorsMenu0");
		oM2 = document.all("DecoratorsMenu1");
	}
	else if(document.getElementById) {
		oM = document.getElementById("DecoratorsMenu0");
		oM2 = document.getElementById("DecoratorsMenu1");
	}

	//turn off all menus
	turnOffMenus();

	//turn on decorator menu images
	var tabL = new Image();
	    tabL.src = "/images/tab_01.gif";
	var tabR = new Image();
	    tabR.src = "/images/tab_10.gif";

	document.images["mimg2"].src = tabL.src;
	document.images["mimg3"].src = tabR.src;

	//turn on decorator cell class
	if(document.all) {
	document.all("mcell2").className = "Tab1";
	}
	else if(document.getElementById) {
	document.getElementById("mcell2").className = "Tab1";
	}

	//show decorator sub menu
	if(oM!=null || oM2!=null) {
		if(oM!=null) { oM.style.display = "block"; }
		return false;
	} else {
		return true;
	}

}


function turnOffMenus() {

	var i;
	var mimg = null;
	var mcell = null;

	var tabOpen = new Image();
	    tabOpen.src = "/images/tab_open_0.gif";
	var tabClose = new Image();
	    tabClose.src = "/images/tab_close_0.gif";
	var tabCart = new Image();
	    tabCart.src = "/images/tab_cart_0.gif";
	var tab = new Image();
	    tab.src = "/images/tab_00.gif";


	//turn off all menu images
	document.images["mimg1"].src = tabOpen.src;
	document.images["mimg2"].src = tab.src;
	document.images["mimg3"].src = tab.src;
	document.images["mimg4"].src = tab.src;
	document.images["mimg5"].src = tab.src;
	document.images["mimg6"].src = tabClose.src;
	document.images["mimg7"].src = tabCart.src;
	document.images["mimg8"].src = tabClose.src;

	//turn off cell classes

	for(i=1;i<=6;i++) {
		if(document.all) {
		document.all("mcell"+i).className = "Tab0";
		}
		else if(document.getElementById) {
		document.getElementById("mcell"+i).className = "Tab0";
		}
	}
}



function checkQty(o,ordermax) {



	var val = "";
	var len = o.value.length;

	//Remove all non-numeric

    	for(i=0;i<len;i++) {
		charatA = o.value.charAt(i);
		charat0 = o.value.charCodeAt(i);
       		if(charat0 >= 48 && charat0 <= 57) { val=val+charatA; }
	}
	o.value=val;
		
	//Now check for maximum allowable order qty

	if(ordermax!="" || ordermax==0) {
		if(!isNaN(parseInt(val))) {
			if (parseInt(val) > ordermax) {
				/*
				alert('You have requested a quantity that is greater than the amount in-stock.\rYour quantity will be set to the maximum available.');
	
				if(ordermax==0) {
				o.value="";
				}
				else {
				o.value=ordermax;
				}

				*/

				if(!confirm('You have requested a quantity that is greater than the amount in-stock.\rAs a result, this item may trigger a back-order.\n\nClick OK to continue with this quantity\nClick Cancel to set your quanity to the maximum available')) {
				o.value=ordermax;
				}

				return true;
			}
			else {
			return true;
			}
		}
	}
}


function checkQtyMult(o,ordermultiple) {

	var val = "";
	var len = o.value.length;

	//Remove all non-numeric

    	for(i=0;i<len;i++) {
		charatA = o.value.charAt(i);
		charat0 = o.value.charCodeAt(i);
       		if(charat0 >= 48 && charat0 <= 57) { val=val+charatA; }
	}
	o.value=val;
		
	//Now check that order qty is a multiple of "order multiple"

	if(ordermultiple!="") {
		if(!isNaN(parseInt(val))) {

			if (parseInt(val) % ordermultiple != 0) {

				alert('You have requested a quantity that is not in the required multiple.\rYour quantity will be set to the closest value.');
	
				if(ordermultiple==0) {
				o.value="";
				}
				else {
					if((parseInt(val) % ordermultiple) <= (ordermultiple/2)) {
						o.value=parseInt(val)-(ordermultiple+(parseInt(val) % ordermultiple))+ordermultiple;
					} else {
						o.value=parseInt(val)+(ordermultiple-(parseInt(val) % ordermultiple));
					}

				}
				return false;
			}
			else {
			return true;
			}
		}
	}
}



function hdlEnter() {
if(event.keyCode==13) { event.keyCode=9; }
}

function hdlSubmit(o) {
if(event.keyCode==13) { return false; } else { return true; }
}


var actvLastStart = 0;
var actvLastEnd = 0;
var numOfFields = 0;


function deactivateFooters(end) {

	if(end > numOfFields) {
		numOfFields = end;
	}

	var i;
	var o;

	for(i=1;i<=numOfFields;i++) {

		o = null;
		
		if(document.all) { o = document.all("MxF"+i); }
		else if(document.getElementById) { o = document.getElementById("MxF"+i); }

		if(o!=null) { o.className = "MxFAoff"; }
	}
}

function actv(start,end) {

	// to activate matrix footers

	var i;
	var o;

//alert("start:"+start+"\nend:"+end+"\nactvStart:"+actvLastStart+"\nactvEnd:"+actvLastEnd);

	//see if we changed rows
	if(start<actvLastStart || end>actvLastEnd) {

		actvLastStart = start;
		actvLastEnd = end;

		//deactivate all
		deactivateFooters(numOfFields);

		//activate current row
		for(i=start;i<=end;i++) {

			o = null;
		
			if(document.all) { o = document.all("MxF"+i); }
			else if(document.getElementById) { o = document.getElementById("MxF"+i); }

			if(o!=null) { o.className = "MxFA"; }
		}

	}
}


function colorSelectAll(end,b) {

	var i;
	var o;

	for(i=1;i<=end;i++) {

		o = null;
		
		if(document.all) { o = document.all("color"+i); }
		else if(document.getElementById) { o = document.getElementById("color"+i); }

		if(o!=null) { o.checked = b; }
	}
}

function showColorFilter() {
	
	var o = null;
		
	if(document.all) { o = document.all("colorFilter"); }
	else if(document.getElementById) { o = document.getElementById("colorFilter"); }

	if(o!=null && o.style) {
		if(o.style.display=="none") {
			o.style.display="block";
		} else {
			o.style.display="none";
		}
	}
}

function showLargeImage(id) {
	
	var o = null;
		
	if(document.all) { o = document.all(id); }
	else if(document.getElementById) { o = document.getElementById(id); }

	if(o!=null && o.style) {
		if(o.style.display=="none") {
			o.style.display="block";
		} else {
			o.style.display="none";
		}
	}
}


var popWindow = null;

function popwindow(url,width,height) {
	var midX = (screen.width/2)-(width/2);
	var midY = (screen.height/2)-(height/2);
	popWindow = window.open (''+[url]+'','popwin', "width="+[width]+",height="+[height]+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,top="+midY+",left="+midX+",screenX="+midX+",screenY="+midY+"");
	popWindow.focus();

}


