/*<![CDATA[*/
function IEHoverPseudo() {

	var navItems = document.getElementById("primary-nav").getElementsByTagName("li");
	
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { this.className += " over"; }
			navItems[i].onmouseout=function() { this.className = "menuparent"; }
		}
	}

}
window.onload = IEHoverPseudo;
/*]]>*/

function changestyle(objRow,className) {
	document.getElementById(objRow).className=className;
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function confirm_action(qty,text) {
	var c = 'false';
	
	if(qty == 1)
		c = confirm("Add 1 item to your "+text+"?");
	else if(qty > 1)
		c = confirm("Add "+qty+" items to your "+text+"?");
	
	return c
}

var preloadFlag = true;

function updateBasket(id, shop) {
	shop = shop || "";
	
	if(shop) 
		text = "Wedding List";
	else
		text = "Bag";
		
	var qty = 0
	var gift_wrap = 'false'
	qty = document.getElementById('first_item_quantity_'+id).value
	
	if(document.getElementById('gift_wrap_'+id))
		gift_wrap = document.getElementById('gift_wrap_'+id).checked
	
	if(confirm_action(qty, text) != 'false')
		updateBasketCore(id, qty, gift_wrap, shop);
	else
		alert('Please enter a quantity');
	
	
}

function updateBasketCore(id, qty, gift_wrap, shop){

	var d = new Date();
	var t = d.getTime();

	//var searchstring=document.getElementById('search').value;
	var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = '/shopping_basket_contents.php?id='+id+'&qty='+qty+'&gift_wrap='+gift_wrap+'&shop='+shop+'&IE_Hack='+t; //This is the path to the file we just finished making *
	    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
	    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ //Make sure there is something in the content variable
                	document.getElementById(shop+'shopping_basket').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}

function removeItem(item) 
{
	//get the current quantity
	qty = document.getElementById(item).value;
	//decrease the quantity by 1 if not already 0
	qty -= 1;	
	//change the select box and hidden input
	document.getElementById(item).value = qty;
	document.getElementById('changeQuantities').value = 'changeQuantities';
	//submit the form using update basket
	document.go_shopping.submit();
}


function changeShopCategory(categoryID)
{
	//alert(categoryID);
	//put the cat id into the form
	document.shop_items.selected_category.value = categoryID;
	
	//alert("Element:"+document.getElementById('selected_category').value);
	
	//submit the form
	document.getElementById('shop_items').submit();
}

function doSubmit(command)
{
	document.getElementById('action').name = command;
	document.getElementById('action').value = command;
	//alert(document.getElementById('action').name);
	document.getElementById('shop_items').submit();
}



function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
    if (screen.width > '1024') {
    obj.style.left = "46%";
    } else  {
    obj.style.left = "43%";
    }
}



/* 
The JavaScript Source!! http://javascript.internet.com/forms/character-counter.html
Created by: Steve | http://jsmadeeasy.com/ 
*/
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

function toCount(entrance,exit,text,characters) {
  var entranceObj=getObject(entrance);
  var exitObj=getObject(exit);
  var length=characters - entranceObj.value.length;
  if(length <= 0) {
    length=0;
    text='<span class="disable"> '+text+' </span>';
    entranceObj.value=entranceObj.value.substr(0,characters);
  }
  exitObj.innerHTML = text.replace("{CHAR}",length);
}







