if (typeof(scrollTop)=="undefined")  {
	var scrollTop = 0;
}

function addtocart(whichdiv, pid, shipping, noadding, myoptions, myamounteuro, quantityid, forcequantity, forcerotator, loc){
		
		// remember the scroll position 
		var scrollTop = $(window).scrollTop();
			
		if (forcequantity == 0) {
			var quantity = document.getElementById(quantityid).value;
		}
		else {
			var quantity = forcequantity;
		}
		
		// extract the option 
		if (myoptions != 0) {
			var myoption = document.getElementById("options_"+myoptions).value;
			var optionargs = "&options=" + myoption;
		}
		else {
			var optionargs = "";
		}
		
		if (loc == 1){
			var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?viewcart_layer_only=1&pid=" + pid + "&shipping=" + shipping + "&noadding=" + noadding + "&quantity=" + quantity + "&backto=" + scrollTop + optionargs;
			moveWindow();
		}
		else {
			var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?view_cart_full=1&pid=" + pid + "&shipping=" + shipping + "&noadding=" + noadding + "&quantity=" + quantity + "&backto=" + scrollTop + optionargs;
		}
		
		opaquebackground(forcerotator);
		var b = loadFragmentInToElement(args, whichdiv, forcerotator);
}

function deletecart(whichdiv, loc, forcerotator) {
	if (confirm("Are you sure you want to clear your cart?")){
		if (loc ==1) {
			var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?viewcart_layer_only=1&ClearCart=sure";
		}
		else {
			var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?view_cart_full=1&ClearCart=sure";		
		}
		moveWindow();
	
		var b = loadFragmentInToElement(args, whichdiv, forcerotator);
	
		if (loc == 0) {
			hidecheckoutbuttons();
		}	
		viewcarttiny_update();
	}
}

function hidecheckoutbuttons() {
	document.getElementById('checkoutbuttons').style.visibility = "hidden";
	document.getElementById('securebuttons').style.visibility = "hidden";	
	document.getElementById('securebuttons2').style.visibility = "hidden";		
	viewcarttiny_update();
}

function dropfromcart(whichdiv, pid, loc, forcerotator, bypass, howmany) {
	if (bypass == 1 || confirm("Are you sure you want to delete this item from your cart?")) {
		if (loc == 1){
			var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?viewcart_layer_only=1&action=dropall&pid=" + pid;
		}
		else {
			var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?view_cart_full=1&action=dropall&pid=" + pid;		
		}
		moveWindow();
	
		var b = loadFragmentInToElement(args, whichdiv, forcerotator);
		viewcarttiny_update();
		if (howmany == 1) {
			hidecheckoutbuttons();
		}
	}
}

function showcart(whichdiv,forcerotator, loc) {
	if (loc == 1) {
		var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?viewcart_layer_only=1";
	}
	else {
		var args = "http://www.gammonvillage.com/shop/viewcart_guts.cfm?view_cart_full=1";
	}
	moveWindow();
	opaquebackground(forcerotator);
	var b = loadFragmentInToElement(args, whichdiv, forcerotator);
}

function viewcarttiny_update() {
	var args = "http://www.gammonvillage.com/shop/common/view_cart_tiny.cfm";
	var b = loadFragmentInToElement(args, 'viewcarttiny', 0);
}	

// move browser focus to top of window
function moveWindow (){
	//window.location.hash="#top";
	$.scrollTo( { top:0, left:0}, 0 );
}

function changequantity(whichdiv, pid, quantityid, loc) {
	var quantity = document.getElementById(quantityid).value;
	dropfromcart(whichdiv, pid, loc, 0, 1);
	
	if (quantity != 0) {
		addtocart(whichdiv, pid, 0, 0, 0, 0, quantityid, quantity, 0, loc);
	}
	else {
		showcart(whichdiv,0,loc);
	}
	viewcarttiny_update();
}

function showupdate(whichdiv, pid, updateid, loc) {
	var updateid = document.getElementById(updateid);
	updateid.style.visibility = "visible";
}

function hideupdate(whichdiv, pid, updateid, loc) {
	var updateid = document.getElementById(updateid);
	updateid.style.visibility = "hidden";
}

function opaquebackground(forcerotator) {
	if (document.getElementById("selectBox") != null) {
		document.getElementById("selectBox").style.visibility = "hidden";
	}
	if (forcerotator == 1) {
	var z = document.getElementById('storeLogo').style.zIndex;
	document.getElementById('gc-overlay').style.zIndex = z-1;
	var m = document.getElementById('shopping_cart');
	var x = eval("getX(document.getElementById('centerColumn'));");
	var w = GetWidth();
	if (document.getElementById("zoomimage") != null) {
		if (w <= 1024) {
			x = x - 50;
		}
	}
	var y = eval("getY(document.getElementById('centerColumn'));");
	m.style.left = x + "px"; 
	m.style.width = "764px";
	m.style.top = y + "px";
	var o = document.getElementById('gc-overlay');
	var h = eval("getY(document.getElementById('footer'));");
	if (document.getElementById("superzoom") == null) {
		w = w - 20;
	}
	else {
		if (w <= 1024) {
			w = w + (1024 - w + 275);
		}
	}
	o.style.height = h + "px";
	o.style.width = w + "px";
	o.style.display = 'block';
	}
}

function hidecart(element_id,backto) {
	document.getElementById('gc-overlay').style.display = 'none'; 
	var element = document.getElementById(element_id);
	element.style.visibility = "hidden";
	if (document.getElementById("selectBox") != null) {
		document.getElementById("selectBox").style.visibility = "visible";
	}
	if (backto > 0) {
		$.scrollTo( backto, 0 );
	}
}

function popwindow(whichsupplier) {
	window.open('ground_shipping.cfm?s=' + whichsupplier,'GroundMap','left=20,top=20,width=560,height=570,toolbar=0,resizable=1');
}

function sendwishlist(x) {
	with(document.email_product) {
		var missing = false;
		var msg ="Please make sure all the proper fields are filled.";	

		if(uword.value == "") {missing=true; msg="You must enter the code word.";}
		if (x == 2) {
			if(emailFriendaddress.value == "") {missing=true; msg="You must enter your email address.";}
		}
		else {
			if(emailFriendaddress.value == "") {missing=true; msg="You must enter your friend's email address.";}
		}
		if(emailSubject.value == "") {missing=true; msg="You must enter a subject.";}
		if(emailMyName.value == "") {missing=true; msg="You must enter your name to send an email to a friend.";}
	
		if (missing) {
			alert(msg);
			return false;
		}
		
		if (x == 1) {
			document.email_product.action = "/shop/common/email_product_info_send.cfm";
		}
		else if (x == 2) {
			document.email_product.action = "/shop/common/email_when_instock.cfm";
		}
		else {
		 	document.email_product.action = "email_wishlist_send.cfm";
		}
	 	document.email_product.submit();
	}
}

function setEmailFriend () {
	hideall();
	document.getElementById('emailfriendform').style.height='430px';
	document.email_product.action = 'http://www.gammonvillage.com/shop/common/email_product_info_send.cfm';
	document.getElementById('emailfriendtitle').innerHTML = "<div align='center' style='margin:10px'><strong>Email this product information to a friend</strong></div>";
	document.getElementById('emailtitle').innerHTML = "Friend's Email Address:";
	document.getElementById('submitbutton').innerHTML = "<span>Send Product Info</span>";
	//document.getElementById('submitbutton').setAttribute("onclick", "return sendwishlist(1)");
	document.getElementById('submitbutton').onclick = function() { sendwishlist(1); };
	document.getElementById('emailMyName').value = "";
	document.getElementById('emailSubject').value = document.getElementById('oldsubject').value;
	var mylist = "emailfriendtitle,the_title,yourname,friendemail,secondfriend,captcha";
	var valueArray = mylist.split(",");
	for(var i=0; i<valueArray.length; i++){
	  document.getElementById(valueArray[i]).style.display='block';
	}
}

function setStockNotify () {
	document.getElementById('emailfriendform').style.display='block';
	document.getElementById('emailfriendform').style.height='280px';
	hideall();
	document.email_product.action = 'http://www.gammonvillage.com/shop/common/email_when_instock.cfm';
	document.getElementById('emailfriendtitle').innerHTML = "<div align='center' style='margin:10px'><strong>Email me when item is back in stock</strong></div>";
	document.getElementById('emailtitle').innerHTML = "Your Email Address:";
	document.getElementById('submitbutton').innerHTML = "<span>Submit Reminder</span>";
	// document.getElementById('submitbutton').setAttribute("onclick", "return sendwishlist(2)");
	document.getElementById('submitbutton').onclick = function() { sendwishlist(2); };
	document.getElementById('emailMyName').value = "MyName";
	document.getElementById('emailSubject').value = "MySubject";
	var mylist = "emailfriendtitle,the_title,friendemail,captcha";
	var valueArray = mylist.split(",");
	for(var i=0; i<valueArray.length; i++){
	  document.getElementById(valueArray[i]).style.display='block';
	}	
}

function hideall () {
	var mylist = "emailfriendtitle,the_title,yourname,friendemail,secondfriend,captcha";
	var valueArray = mylist.split(",");
	for(var i=0; i<valueArray.length; i++){
	 	document.getElementById(valueArray[i]).style.display='none';
	}
}

function showall () {
	var mylist = "emailfriendtitle,the_title,yourname,friendemail,secondfriend,captcha";
	var valueArray = mylist.split(",");
	for(var i=0; i<valueArray.length; i++){
	    document.getElementById(valueArray[i]).style.display='block';
	}
}

function changeboards(a,b,list,boutique){
	// modified May 11 2009 FTW 
	var valueArray = list.split( "," );
	var nameArray = new Array();
	for(var i=0; i<valueArray.length; i++){
  		//do something by accessing valueArray[i];
		//alert(valueArray[i]);
		nameArray[i] = getCheckedValue(document.forms['board'].elements['b_' + valueArray[i]]);
	}
	
	// var price = getCheckedValue(document.forms['board'].elements['b_1']);
	// var style = getCheckedValue(document.forms['board'].elements['b_3']);
	// var checksize = getCheckedValue(document.forms['board'].elements['b_17']);
	// var args = "http://www.gammonvillage.com/shop/common/showboards.cfm?p=" + price + "&t=" + style + "&c=" + checksize;
	var args = "http://www.gammonvillage.com/shop/common/showboards.cfm?n=" + valueArray + "&v=" + nameArray + "&myboutiqueid=" + boutique;
	var b = loadFragmentInToElement(args, 'showboards',1);
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function saveAjaxSection() {
	var currentContent = document.getElementById( "showboards" ).innerHTML ;
	document.getElementById( "ajaxSaveField" ).value = currentContent ;
}
	
function reloadAjaxPanels(){
	var previousContent = document.getElementById( "ajaxSaveField" ).value ;
	if ( previousContent.length > 0 ) {
		document.getElementById( "showboards" ).innerHTML = previousContent ;
	}
}

function loadFragmentInToElement(fragment_url, element_id, rotator) {
		var rotatorstyle = "position:relative; top:120px; left:300px;";
		var rotatoraddendum = "";
		if (document.getElementById(element_id) != null) {
			var element = document.getElementById(element_id);
			if (element.id == 'showboards') {
				var rotatorstyle = "position:relative; top:0px; left:0px; padding:25px;";
				var rotatoraddendum = "<div class='srchtitle'>Searching...</div>";
			}
		}
		if (rotator == 1) {
			element.innerHTML = rotatoraddendum + '<img src="http://www.gammonvillage.com/shop/images/rotate.gif" border="0" width="64" height="64" style="' + rotatorstyle + '">';
			element.style.visibility = "visible";
		}
		if (rotator == 1) {
			setTimeout( "finish('" + fragment_url +"','" + element_id +"','" + rotator + "');", 1); 
		}
		else {
			finish(fragment_url, element_id, rotator);
		}
}
	
function finish(fragment_url, element_id, rotator) {
	if (document.getElementById(element_id) != null) { 
		var element = document.getElementById(element_id);
		var xmlhttp = new ajax.x();
		xmlhttp.open("GET", fragment_url);
		xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				element.innerHTML = xmlhttp.responseText;
				if (rotator == 1) {
					viewcarttiny_update();
				}
			}
		}
		xmlhttp.send(null);
	}
}

function getX(obj){
        return obj.offsetLeft + (obj.offsetParent ? getX(obj.offsetParent) : obj.x ? obj.x : 0);
}
function getY(obj){
        return (obj.offsetParent ? obj.offsetTop + getY(obj.offsetParent) : obj.y ? obj.y : 0);
}


function GetWidth()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}

function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function nothing() {
		// nop;
}

