
function buildAJAX(dest, theFormName) { 
	theForm = document.forms[theFormName]; 
    var vars = '' 
    for (e=0;e<theForm.elements.length;e++) { 
        if (theForm.elements[e].name!='') { 
            var name = theForm.elements[e].name; 
            vars+=(vars=='')?'':'&' 
            vars+= name+'='+escape(theForm.elements[e].value); 
        } 
    } 
    vars+="\n"; 
	// initiate ajax xmlhttp request	
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
		if(xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				alert("Your browser does not support AJAX!");
				return false;				
			}
		}
	}

	//alert(dest + "?" + vars);
	
	// send away....
	xmlhttp.open("GET", dest + "?" + vars, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-2");
	xmlhttp.send(null);
} 


function buildSimpleAJAX(dest) { 
	// initiate ajax xmlhttp request	
	if(window.XMLHttpRequest){
		xmlhttp2=new XMLHttpRequest();
		if(xmlhttp2.overrideMimeType){
			xmlhttp2.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				alert("Your browser does not support AJAX!");
				return false;				
			}
		}
	}
	// send away....
	xmlhttp2.open("GET", dest, true);
	xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-2");
	xmlhttp2.send(null);
} 


function sendAjax(dest) { 
	// initiate ajax xmlhttp request	
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
		if(xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				alert("Your browser does not support AJAX!");
				return false;				
			}
		}
	}

	
	// send away....
	xmlhttp.open("GET", dest, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-2");
	xmlhttp.send(null);
} 


function send_bitch_email(dest, theFormName) {
	buildAJAX(dest, theFormName);
	document.getElementById("sendButton").style.backgroundImage = "url(/images/sending_small.gif)";
	var t2=setTimeout("document.getElementById('standard').style.display = 'block'",1200);
	var t1=setTimeout("document.getElementById('bitchAbout').style.display = 'none'",1200);
	var t3=setTimeout("document.getElementById('sendButton').style.backgroundImage = 'url(/images/send_message_small.gif)'",1300);
}


function send_buddy_email(dest, theFormName) {
	buildAJAX(dest, theFormName);
	document.getElementById("sendButton2").style.backgroundImage = "url(/images/sending_small.gif)";
	var t2=setTimeout("document.getElementById('standard').style.display = 'block'",1200);
	var t1=setTimeout("document.getElementById('informBuddy').style.display = 'none'",1200);
	var t3=setTimeout("document.getElementById('sendButton2').style.backgroundImage = 'url(/images/send_message_small.gif)'",1300);
}


function send_blog_email(dest, theFormName, id) {
	buildAJAX(dest, theFormName);
	document.getElementById("sendButton_" + id).style.backgroundImage = "url(/images/sending_small.gif)";
	var t2=setTimeout("document.getElementById('emailBlogDiv_" + id + "').style.display = 'none'",1200);
	var t3=setTimeout("document.getElementById('sendButton_" + id + "').style.backgroundImage = 'url(/images/send_message_small.gif)'",1200);
}


function unsubscribe(dest, theFormName) {
	buildAJAX(dest, theFormName);
	document.getElementById("subscribeText").innerHTML = "Saving...";
	var t1=setTimeout("document.getElementById('subscribeText').innerHTML = '<b>Sorry to see you go.</b>'",1200);
	if(document.getElementById("unsubscribeBox")) {
		var t2=setTimeout("document.getElementById('unsubscribeBox').style.display = 'none'", 1200);
	}
}


function addToWishlist(dest, theFormName) {
	buildAJAX(dest, theFormName);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4) {
	  	  buildSimpleAJAX('/scripts/calculate_wishlist.php');
			xmlhttp2.onreadystatechange=function() {
				if(xmlhttp2.readyState==4) {
				  document.getElementById("wishlistTotalSpan").innerHTML = "(" + xmlhttp2.responseText + ")";
				}
			}
		}
    }	

	document.getElementById("alertCartBubble").style.display = "block";
	document.getElementById("alertCartBubble").style.position = "absolute";
	document.getElementById("alertCartBubble").style.top = '42px';
	document.getElementById("alertCartBubble").style.right = '350px';
	document.getElementById("alertCartBubble").innerHTML = 'That item has been added to your wishlist';	
	var t2=setTimeout("document.getElementById('alertCartBubble').style.position = 'relative'",2100)	
	var t2=setTimeout("document.getElementById('alertCartBubble').style.display = 'none'",2100)	

}

function addToCart(dest, theFormName, price) {
	buildAJAX(dest, theFormName);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4) {
	  	  buildSimpleAJAX('/scripts/calculate_cart.php');
		  document.getElementById("sizesDiv").innerHTML = xmlhttp.responseText;
		  document.getElementById("checkoutButt").style.backgroundImage = ("url(/images/checkout_on.gif)");
			xmlhttp2.onreadystatechange=function() {
				if(xmlhttp2.readyState==4) {
				 // document.getElementById("globalCart").innerHTML = xmlhttp2.responseText;
				 var response = xmlhttp2.responseText.split('|');
				 document.getElementById("spanItems").innerHTML = response[0];
				 document.getElementById("spanPrice").innerHTML = response[1];
				}
			}
		}
    }	
	//itemsTotal = parseInt(document.getElementById("spanItems").innerHTML);
	//itemsTotal++;
	//document.getElementById("spanItems").innerHTML = itemsTotal;
	//p = document.getElementById("spanPrice").innerHTML.split("$");
	//itemCost = price.split("$");
	//totalPrice = parseInt(p[1]) + parseInt(itemCost[1]);
	//document.getElementById("spanPrice").innerHTML = "$" + formatPrice(totalPrice);

	document.getElementById("alertCartBubble").style.display = "block";
	document.getElementById("alertCartBubble").style.position = "absolute";
	document.getElementById("alertCartBubble").style.top = '42px';
	document.getElementById("alertCartBubble").style.right = '268px';
	document.getElementById("alertCartBubble").innerHTML = 'That item has been added to your cart';	
	var t2=setTimeout("document.getElementById('alertCartBubble').style.position = 'relative'",2100)	
	var t2=setTimeout("document.getElementById('alertCartBubble').style.display = 'none'",2100)	

}


function formatPrice(amount) {
var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;

}


function moveToCart(dest, theFormName) {
	buildAJAX(dest, theFormName);
}


function voteForBlog(dest, iconID) {
	// initiate ajax xmlhttp request	
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
		if(xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				alert("Your browser does not support AJAX!");
				return false;				
			}
		}
	}
	// send away....
	xmlhttp.open("GET", dest, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-2");
	xmlhttp.send(null);	
	
	document.getElementById("voteIcon_" + iconID).innerHTML = "Thanks";
	document.getElementById("voteIcon_" + iconID).className = "voted";
	document.getElementById("voteIcon_" + iconID).style.backgroundImage = "url(http://fabnob.com.au/images/thumbsup_disabled.gif)";
}



function formatNumber(myNum, numOfDec) 
{ 
var decimal = 1 
for(i=1; i<=numOfDec;i++) 
decimal = decimal *10 
var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec) 
return(myFormattedNum) 
} 
