
// General Settings & Variables
///////////////////////////////////////////

	// Generic Website Title
		var siteTitle = document.title;

	// The Window Object
		var w = window;
		
		
// Category Slider Settings
///////////////////////////////////////////
	var I_CategorySlideHeight = 30;
		

// AJAX Functions & Variables
///////////////////////////////////////////

	// Create AJAX Request Object
		
		var XMLHTTPREQUEST_MS_PROGIDS = new Array(
		  "Msxml2.XMLHTTP.7.0",
		  "Msxml2.XMLHTTP.6.0",
		  "Msxml2.XMLHTTP.5.0",
		  "Msxml2.XMLHTTP.4.0",
		  "MSXML2.XMLHTTP.3.0",
		  "MSXML2.XMLHTTP",
		  "Microsoft.XMLHTTP"
		);

		function createRequestObj() {
			var httpRequest = null;
			
			// Create the appropriate HttpRequest object for the browser.
			if (window.XMLHttpRequest != null) {
				httpRequest = new XMLHttpRequest();
			} else if (window.ActiveXObject != null) {
				// Must be IE, find the right ActiveXObject.
				var success = false;
				for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++) {
					try {
						httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
						success = true;
					}
					catch (ex){
						
					}
				}
			}

			// Display an error if we couldn't create one.
			if (httpRequest == null) {
			
			}
			return httpRequest;
		}
		
	// Set Variable Equal to Request Object
		var contentOBJ = createRequestObj();
	
// Validation Functions
///////////////////////////////////////////
	function checkEmail(emailEntryValue){
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		var checkResult;
		
		if(filter.test(emailEntryValue)){
			checkResult = true;
		}else{
			//alert("SORRY! Your email address is invalid.");
			checkResult = false;
		}
		return (checkResult)
	}
	
	function IsNumeric(I_Number) {
		var S_ValidChars = "0123456789.";
		var B_IsNumber = true;
		var I_Char;

		for (i = 0; i < I_Number.length && B_IsNumber == true; i++) { 
			I_Char = I_Number.charAt(i); 
			if (S_ValidChars.indexOf(I_Char) == -1) {
				B_IsNumber = false;
			}
		}
		return B_IsNumber;
	}

// CART ADD Functions
///////////////////////////////////////////
function AddToCart(O_FormPost, S_OptionID, S_ReferenceID, S_BundleID) {
	var postStr = "";
	
	postStr = "OptionID=" + S_OptionID + "&ReferenceID=" + S_ReferenceID + "&BundleID=" + S_BundleID;
	SendAdd("/cartadd.asp", postStr);
}

function SendAdd(cURL, params) {
	// http://www.matthom.com/archive/2006/05/15/scary-ajax-error/feedback/#1000
	contentOBJ.open("post", cURL, true);
	contentOBJ.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	contentOBJ.setRequestHeader("Content-length", params.length);
	//IE6 BREAKS contentOBJ.setRequestHeader("Connection", "close");
	contentOBJ.onreadystatechange = CartResponse;
	contentOBJ.send(params);
}

function CartResponse() {
	var O_CartResponse = document.getElementById("cart_add");
	
	if (contentOBJ.readyState == 4) {
		var resContent = contentOBJ.responseText;
		
		// Error Class on Span
		if (resContent.substring(0,36) == "<strong id=\"cart_msg\" class=\"error\">") {
			O_CartResponse.className = "error";
		}else{
			O_CartResponse.className = "";
		}
		
		if (O_CartResponse.innerHTML != resContent) {
			O_CartResponse.innerHTML = "";
		
			O_CartResponse.innerHTML = resContent;
		}
		
		if (B_InProgress == false) {
			O_CartResponse.style.display = "none";
			//document.getElementById("cart_msg").style.visibility = "hidden";
		}
		CheckCart();
	}		
}

function CheckCart() {
	contentOBJ.open("post", "/cartstatus.asp", true);
	contentOBJ.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	contentOBJ.setRequestHeader("Content-length", 0);
	//IE6 BREAKS contentOBJ.setRequestHeader("Connection", "close");
	contentOBJ.onreadystatechange = loadCart;
	contentOBJ.send("");
}

function loadCart() {

	var O_CartItems = document.getElementById("itemNum");
	if (contentOBJ.readyState == 4) {
		var resContent = contentOBJ.responseText;
		O_CartItems.innerHTML = "";
		O_CartItems.innerHTML = resContent;
		
		AnimStart("cart_msg");
	}	
}

// Div Flashing functions
///////////////////////////////////////////

var I_AnimTime = 10;
var I_HeightLimit = 0;
var I_Height = 0;
var B_InProgress = false;
var I_BlinkTime = 300;
var I_BlinkCount = 0;
var I_BlinkLimit = 3;

function AnimStart(O_Element) {
	if (B_InProgress == false) {
		I_BlinkCount = 0;
		I_Height = 0;
		B_InProgress = true;
		document.getElementById("cart_add").style.visibility = "hidden";
		document.getElementById("cart_add").style.display = "";
		I_HeightLimit = document.getElementById("cart_add").offsetHeight;
		document.getElementById(O_Element).style.height = I_Height+"px";
		document.getElementById("cart_add").style.visibility = "visible";
		setTimeout("AnimeIn('"+O_Element+"')", I_AnimTime);
	}
}

function AnimeIn(O_Element) {
	if (I_Height < I_HeightLimit) { 
		I_Height += 3;
		document.getElementById(O_Element).style.height = I_Height+"px";
		setTimeout("AnimeIn('"+O_Element+"')", I_AnimTime);
	} else {
		setTimeout("Blink('"+O_Element+"')", 1000);
	}
}

function AnimeOut(O_Element) {
	if (I_Height > 0) { 
		I_Height -= 3;
		document.getElementById(O_Element).style.height = I_Height+"px";
		setTimeout("AnimeOut('"+O_Element+"')", I_AnimTime);
	} else {
		document.getElementById(O_Element).style.display = "none";
		B_InProgress = false;
	}
}

function Blink(O_Element) {
	var O_Curent = document.getElementById(O_Element);
	if (I_BlinkCount < I_BlinkLimit) {
		I_BlinkCount++;
		if (O_Curent.style.visibility == "hidden") {
			O_Curent.style.visibility = "visible";
			setTimeout("Blink('"+O_Element+"')", I_BlinkTime);
		} else {
			O_Curent.style.visibility = "hidden";
			setTimeout("Blink('"+O_Element+"')", I_BlinkTime);
		}
	} else {
		O_Curent.style.visibility = "visible";
		setTimeout("AnimeOut('"+O_Element+"')", 2000);
	}
	
}

// Browsers Check Functions
///////////////////////////////////////////

var isIE6 = false;
var isIE7 = false;
var isIE = false;

if(navigator.appName.indexOf("Internet Explorer") != -1){
	var IE_temp = navigator.appVersion.split("MSIE");
	var IE_version = parseFloat(IE_temp[1]);
	
	isIE = true;
	
	if (IE_version == 7){
		isIE7 = true;
	}
	if (IE_version == 6){
		var isIE6 = true;
	}
}

// Menu Float Functions
///////////////////////////////////////////
var I_TopOffset = 0;
var I_OrgMenuOffset = 0;
var O_Menu;
var I_ScrollTop = 0;

function floatMenuIE6() {
	// Meno Object
	O_Menu = document.getElementById("menu");
	
	// Find Position from top
	I_TopOffset = O_Menu.offsetTop;
	I_OrgMenuOffset = findTop(O_Menu);
	
	// Set CSS
	O_Menu.style.setExpression("top", "(I_TopOffset + (ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)) + 'px'");
	
	// Start Menu Check
	floatMenu();
}

function floatMenu() {
	O_Menu = document.getElementById("menu");
	
	if (!isIE6) {
		O_Menu.style.position = "absolute";
		O_Menu.style.margin = "0 0 0 799px";
		O_Menu.style.overflow = "hidden";
		I_OrgMenuOffset = findTop(O_Menu);
	}  
	
	window.onscroll = checkMenu;
	checkMenu();
	setInterval(checkMenu, 20);
}

	

function checkMenu() {
	var I_MenuOffSet = 0;
	
	O_Menu = document.getElementById("menu");
	
	if (document.documentElement.scrollTop) {
		I_ScrollTop = document.documentElement.scrollTop;
	} else {
		I_ScrollTop = document.body.scrollTop;
	}
	
	if (!isIE6) {
		if (I_ScrollTop > I_OrgMenuOffset && O_Menu.style.position != "fixed") {
			O_Menu.style.visibility = "hidden";
			O_Menu.style.position = "fixed";
			O_Menu.style.margin = "-" + I_OrgMenuOffset + "px 0 0 799px";
			O_Menu.style.visibility = "visible";
		} else if (I_ScrollTop < I_OrgMenuOffset && O_Menu.style.position != "absolute") {
			O_Menu.style.position = "absolute";
			O_Menu.style.margin = "0 0 0 799px";
			O_Menu.style.overflow = "hidden";
		}
	} else {
		if (I_ScrollTop > I_OrgMenuOffset) {
			I_TopOffset = -I_OrgMenuOffset;
		} else if (I_ScrollTop < I_OrgMenuOffset) {
			I_TopOffset = - I_ScrollTop;
		}
	}
	
}

function findTop(O_Element) {
	var I_Curtop = 0;
	if (O_Element.offsetParent) {
		do {
			I_Curtop += O_Element.offsetTop;
			} while (O_Element = O_Element.offsetParent);
	}
	
	return I_Curtop;
		
}

// IE Cart & Menu Display fixes
///////////////////////////////////////////

function Ie6Fixes() {

	var I_MenuAdj = 0;
	var I_MenuHeight = document.getElementById("menu").offsetHeight;
	
	if(document.getElementById("menu").getElementsByTagName("p")[0]){
		I_MenuAdj = document.getElementById("menu").getElementsByTagName("p")[0].offsetTop;
	}else{
		I_MenuAdj = document.getElementById("menu").getElementsByTagName("h3")[0].offsetTop;
	}

	I_MenuHeight = I_MenuHeight - I_MenuAdj;
	
	
	
	document.getElementById("menu").innerHTML = "<div id=\"ieMenuBG\"><div id=\"ieMenuTop\"></div><div id=\"ieMenuEnd\"><div></div></div></div>" + document.getElementById("menu").innerHTML;
	
	
	/* Set the height */
	document.getElementById("ieMenuBG").style.height = I_MenuHeight+"px";
	
	/* Move The Nav Up */
	document.getElementById("ieMenuBG").style.marginBottom = "-" + (I_MenuHeight + I_MenuAdj) + "px";
	
	/* Adjust for a Top Margin */
	document.getElementById("ieMenuBG").style.marginTop = I_MenuAdj + "px";
	
	/* Set height of top piece minus 100px */
	document.getElementById("ieMenuTop").style.height = I_MenuHeight-100 +"px";
}


// Holiday Pop Up

var O_Window;

function HolidayPopUp() {
	var I_Width = 480;
	var I_Height = 340;
	
	I_Width = screen.width;
	I_Height = screen.height;
	
	var I_WindowWidth = 560;
	var I_WindowHeight = 250;

	var I_LeftPos = (I_Width-I_WindowWidth)/2;
	var I_TopPos = (I_Height-I_WindowHeight)/2;

	
	O_Window = window.open('/holidayNotice.html','Holiday_PopUp','height='+I_WindowHeight+',width='+I_WindowWidth+',top='+I_TopPos+',left='+I_LeftPos);
	if (window.focus) {
		O_Window.focus();
	}
}

function HolidayCheck() {
	if (document.getElementById("holidayNotice")) {
		document.getElementById("holidayNotice").onclick = function(){
			HolidayPopUp();
			return false;
		}
	}
}

addDOMLoadEvent(HolidayCheck);
// End Holiday Pop Up


// IE6 only fix menu position
if (isIE6) {

	// PNG Adjust
	addDOMLoadEvent(Ie6Fixes);
	
	// Float Menu
	addDOMLoadEvent(floatMenuIE6);
} else {         
	
	// Float Menu
	addDOMLoadEvent(floatMenu);
}

