	
function ie6Hack() {
	var Browser = {
	  Version: function() {
		var version = 999; // we assume a sane browser
		if (navigator.appVersion.indexOf("MSIE") != -1)
		  version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		return version;
	  }
	}
	
	if (Browser.Version() < 7) {
	  document.getElementById('mainContainer').style.height = "100%";
	  document.getElementById('sideInfoBar').style.top = "240px";
	  document.getElementById('cartDisplay').style.top = "380px";
	}
}

function checkCookie() {
	var cookie = document.cookie;
	var cookieStart = cookie.indexOf('login'); /*Find start of login cookie in IE*/
	if (cookieStart != -1){
			var cookiedata = cookie.slice(cookieStart).split('=');
			var user = cookiedata[1].split('%7C');
			if (user[1].match(/^\d+$/)){
				user[0] = user[0].replace(/%20/gi, " ");
				document.loginForm.username.value = ucfirst(user[0]);
				document.loginForm.password.value = user[1];
				document.loginForm.Submit.value = "Log Out »";
				document.loginForm.logDirection.value = "logout";
				document.getElementById('createAccountText').innerHTML = "";			
			}	
	}
	ie6Hack();					 
}

function login() {
		var cookie = document.cookie;
		if (cookie !=""){		/*Delete existing cookie to prevent customer logging in with two accounts at same time*/
			document.cookie = "login= ; expires=-1; path=/"
		}	
		document.loginForm.returnURL.value = window.location;
		//document.loginForm.submit();
}

function ucfirst(str) {     
	var firstLetter = str.substr(0, 1);     
	return firstLetter.toUpperCase() + str.substr(1); 
}

function searchBrands() {
	 var selected = document.getElementById('brandsDropBox')[document.getElementById('brandsDropBox').selectedIndex].value;
	 if (selected){
		selected = selected.replace(/&nbsp; /gi, "");
		location = "/cgi-bin/catalog.pl?brand="+selected;
		}
}
function searchCategories() {
	 var selected = document.getElementById('catsDropBox')[document.getElementById('catsDropBox').selectedIndex].value;
	 if (selected){
		selected = selected.replace(/&nbsp; /gi, "");
		location = "/cgi-bin/catalog.pl?cat1="+selected;
		}
}

function slideOpenMenu(layer){		//first part closes all open layers then opens the one clicked.
		var allDIVS = document.getElementsByTagName('DIV');
		var slideThis = document.getElementById(layer);
		var currentState = slideThis.style.height;
		var el, i = 0, howmany = 0;
		while (el = allDIVS.item(i++)){
		 if (el.id.substr(0,5) == 'layer'){
			 document.getElementById(el.id).style.height = "22px";
			}
		}	 			
		if (currentState == "auto"){
				slideThis.style.height = "22px";
		}else{
				slideThis.style.height = "auto";
				slideThis.style.background = "url(/images/bullet_right.png) no-repeat";	
		}		
}

function showItemDetails(sku) {
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		scrollTop = scrollTop + 101;
		document.getElementById('itemDetails').style.top = scrollTop+"px";
		document.getElementById('itemDetails').style.visibility = "visible";
		document.getElementById('itemDetailsBackground').style.visibility = "visible";
		var script = "itemDetails";
		showDetails(sku);
}
function hideItemDetails() {
		document.getElementById('itemDetails').style.visibility = "hidden";
		document.getElementById('itemDetailsBackground').style.visibility = "hidden";
		document.getElementById('itemDetailsTable').innerHTML = ""; //clear data
}
function showDetails (sku) {
		var rnd = Math.floor(Math.random()*1000001); //create a dummy variable to add to url, to stop IE caching AJAX pages
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
					if (xmlhttp.status == 200){	
							var response = xmlhttp.responseText;
							document.getElementById('itemDetailsTable').innerHTML = response;
					}else{
							document.getElementById('itemDetailsTable').innerHTML = "<h2>Sorry, I can't find the details for this item at the moment.<br><br><a href='javascript:hideItemDetails()'>Click here to try again.</a></h2>";
					}			
			}
		}

		xmlhttp.open("GET","/cgi-bin/itemDetails.pl?" + sku + '&' + rnd,true);
		xmlhttp.send(null);				
}
function enlargeImg(sku) {
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		//scrollTop = scrollTop + 10;
		document.getElementById('largeImage').style.top = scrollTop+"px";
		document.getElementById('largeImage').style.visibility = "visible";
		var rnd = Math.floor(Math.random()*1000001); //create a dummy variable to add to url, to stop IE caching AJAX pages
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
					if (xmlhttp.status == 200){	
							var response = xmlhttp.responseText;
							document.getElementById('largeImage').innerHTML = response;
					}else{
							document.getElementById('largeImage').innerHTML = "NON RETURN ERROR";
					}			
			}
		}

		xmlhttp.open("GET","/cgi-bin/largeImage.pl?" + sku + '&' + rnd,true);
		xmlhttp.send(null);
}
function hideLargeImage() {
		document.getElementById('largeImage').style.visibility = "hidden";
		document.getElementById('largeImage').innerHTML = ""; //Clear previous image
}

function showAddToCart(sku, modal) {
		//document.getElementById('addedToCart').innerHTML = ""; //clear previous text
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		scrollTop = scrollTop + 200;
		document.getElementById('addedToCart').style.top = scrollTop+"px";
		document.getElementById('addedToCart').style.visibility = "visible";
		document.getElementById('addedToCartBackground').style.visibility = "visible";
		//var script = "itemDetails";
		addToCart(sku, modal);
}
function hideAddToCart() {
		document.getElementById('addedToCart').style.visibility = "hidden";
		document.getElementById('addedToCartBackground').style.visibility = "hidden";
		document.getElementById('addedToCart').innerHTML = ""; //clear data so animated gif is not constantly running in background
}

function addToCart(sku, modal) {
		if (modal == 1){	//decide if add to cart is coming from main screen or from item details modal window
			var qty = document.getElementById("modalQty"+sku).value;
		}else{	
			var qty = document.getElementById("qty"+sku).value
		}	
		var rnd = Math.floor(Math.random()*1000001); //create a dummy variable to add to url, to stop IE caching AJAX pages
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
					if (xmlhttp.status == 200){	
							var response = xmlhttp.responseText;
							document.getElementById('addedToCart').innerHTML = response;
							var t=setTimeout("hideAddToCart()",1400);
							updateCartDisplay();
					}else{
							document.getElementById('addedToCart').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='5'> <tr> <td colspan='2' height='20'></td> </tr> <tr> <td width='150'> <div align='center'> <img src='/images/warning.png' width='48' height='48'> </div> </td> <td width='600'><font size='4' face='Arial, Helvetica, sans-serif'>Sorry, that item did not get added to your cart properly.<br> Please try again.</font></td> </tr> <tr> <td colspan='2'> <div align='right'> <a href='javascript: hideAddToCart();'><font face='Arial, Helvetica, sans-serif'>Close Message</font></a> </div> </td> </tr> </table>";
					}			
			}
		}

		xmlhttp.open("GET","/cgi-bin/cart.pl?" + qty + '&' + sku + '&' + rnd,true);
		xmlhttp.send(null);
}

function updateCartDisplay() {
		var rnd = Math.floor(Math.random()*1000001); //create a dummy variable to add to url, to stop IE caching AJAX pages
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
					if (xmlhttp.status == 200){
							var response = xmlhttp.responseText;
							document.getElementById('cartDisplay').innerHTML = response;
					}			
			}
		}

		xmlhttp.open("GET","/cgi-bin/cartDisplay.pl?" + rnd,true);
		xmlhttp.send(null);
}

function queryDelete(items) {
		if (items != 0) {
			var answer = confirm ("DELETE EVERYTHING IN YOUR CART?");
			if (answer){
				window.location = "/cgi-bin/cart.pl?delete";
			}else{
				return ;
			}
		}else{
			return;
		}	
}
function deleteItem(sku){
		window.location = "/cgi-bin/cart.pl?deleteItem&"+sku;
}
function changeQty(sku){
		var qty = document.getElementById(sku).value;
		window.location = "/cgi-bin/cart.pl?changeQty&"+sku+"&"+qty;
}
function DoNav(theUrl) {
  document.location.href = theUrl;
}
function queryOrderNumber() {
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		scrollTop = scrollTop + 201;
		document.getElementById('modalWindow').style.top = scrollTop+"px";
		document.getElementById('modalWindow').style.visibility = "visible";
		document.getElementById('modalWindowBackground').style.visibility = "visible";
		var code =  "<table width='80%' align='center' border='0' cellspacing='2' cellpadding='0' class='topNavBar'>\
        <tr> <td height='50' colspan='3'>&nbsp;</td></tr>\
		<tr>\
          <td class='blueText'>Would you like to add a reference/purchase order number?</td>\
          <td width='50'><div align='center'><a href='#' class='topNavBar' onClick='addOrderRef(); return false;'>Yes</a></div></td>\
          <td width='50'><div align='center'><a href='#' class='topNavBar' onClick='askIfDropship(); return false;'>No</a></div></td>\
        </tr>\
        <tr> <td height='50' colspan='3'>&nbsp;</td></tr>\
      </table> ";
	document.getElementById('modalWindowTable').innerHTML = code;
	
}
function addOrderRef() {
		var code =  "<table width='80%' align='center' border='0' cellspacing='0' cellpadding='0' class='topNavBar'>\
        <tr> <td height='50' colspan='4'>&nbsp;</td></tr>\
		<tr>\
          <td width='150' class='blueText'>Reference number:</td>\
          <td width='200'><div align='center'><input type='text' name='refNo' id='refNo'></div></td>\
		  <td width='100'><div align='center'><a href='#' class='topNavBar' onClick='window.refNo = document.getElementById(\"refNo\").value, askIfDropship(); return false;'>Continue</a></div></td>\
		  <td>&nbsp</td>\
        </tr>\
        <tr> <td height='50' colspan='4'>&nbsp;</td></tr>\
      </table>";
	  	document.getElementById('modalWindowTable').innerHTML = code;
		document.getElementById('refNo').focus();		
}
function askIfDropship() {
		var code =  "<table width='80%' align='center' border='0' cellspacing='0' cellpadding='0' class='topNavBar'>\
        <tr> <td height='50' colspan='3'>&nbsp;</td></tr>\
		<tr>\
          <td class='blueText'>Do you want your order dropshiped to your customer?</td>\
          <td width='50'><div align='center'><a href='#' class='topNavBar' onClick='addDSAddress(); return false'>Yes</a></div></td>\
          <td width='50'><div align='center'><a href='#' class='topNavBar' onClick='placeOrder(); return false;'>No</a></div></td>\
        </tr>\
        <tr> <td height='50' colspan='3'>&nbsp;</td></tr>\
      </table> ";
	document.getElementById('modalWindowTable').innerHTML = code;		
}
function addDSAddress() {
		var code =  "<table width='90%' align='center' border='0' cellspacing='0' cellpadding='0' class='topNavBar'>\
	  <tr> <td height='50' colspan='2' class='blueText'>Name and address to deliver to including phone number if possible.</td>  </tr>\
	  <tr>\
		<td class='blueText'><div align='center'>  <textarea name='dsAddress' cols='50' rows='10' id='dsAddress'></textarea> </div></td>\
		<td width='100'><div align='center'><a href='#' class='topNavBar' onClick='window.dsAddress = document.getElementById(\"dsAddress\").value, placeOrder(); return false;'>Place  Order</a></div></td>\
	  </tr>\
	  <tr> <td height='50' colspan='2'>&nbsp;</td></tr>\
	</table>";
	  	document.getElementById('modalWindowTable').innerHTML = code;
		document.getElementById('dsAddress').focus();		
}	
function placeOrder() {
		var address = window.dsAddress;
		if (address) {address = address.replace(/\n\r?/g, '+')};
		window.location = "/cgi-bin/placeOrder.pl?"+window.refNo+"&"+address;
}

function showHistory() {
		//document.getElementById('addedToCart').innerHTML = ""; //clear previous text
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		scrollTop = scrollTop + 20;
		document.getElementById('addedToCart').style.top = scrollTop+"px";
		document.getElementById('addedToCart').style.visibility = "visible";
		document.getElementById('addedToCartBackground').style.visibility = "visible";
		//addToCart(sku);
		displayHistory();
}
function hideHistory() {
		document.getElementById('addedToCart').style.visibility = "hidden";
		document.getElementById('addedToCartBackground').style.visibility = "hidden";
		document.getElementById('addedToCart').innerHTML = ""; //clear data so animated gif is not constantly running in background
}
function displayHistory() {
		var rnd = Math.floor(Math.random()*1000001); //create a dummy variable to add to url, to stop IE caching AJAX pages
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
			//alert ("STATE:"+xmlhttp.readyState +"\nSTATUS:"+xmlhttp.status);
					if (xmlhttp.status == 200){
							var response = xmlhttp.responseText;
							document.getElementById('addedToCart').innerHTML = response;
					}			
			}
		}

		xmlhttp.open("GET","/cgi-bin/history.pl?" + rnd,true);
		xmlhttp.send(null);
}		
function zoomLogo(posx, posy, logo, brand) {		
		document.getElementById('logoZoom').style.visibility = "visible";
		document.getElementById('logoZoom').style.left = posx+"px";
		document.getElementById('logoZoom').style.bottom = posy+"px";
		document.getElementById('logoZoom').innerHTML = "<img src='/images/logos/" +logo+ ".jpg' width='120' height='120' title='" +brand+ "' onClick='javascript:window.location=\"/cgi-bin/catalog.pl?brand=" +brand+ "\" ' style='cursor:pointer'>";						
}
function hideZoomLogo() {
	document.getElementById('logoZoom').style.visibility = "hidden";
}
