var oldfindQty, oldfindAmount;
var preLoadingCart = new Image();
preLoadingCart.src = "http://site.hairretail.com/images/loadingAnimation-final-new.gif";

function getQty(val){
document.getElementById('vwquantity').value = val;
}
  var http_requestnew = false;
  var mFrame;
  var mSpan;
   function makeRequestnew(url, parameters) {
        http_requestnew = false;
		http_requestnew = new XMLHTTP();
        if (http_requestnew.overrideMimeType) {
           http_requestnew.overrideMimeType('text/html');
        }
      	if (!http_requestnew) {
        	alert('Cannot create XMLHTTP instance');
         	return false;
      	}
	  	var uri = url + parameters;
                mFrame = "myframe" + parameters;
                
               // alert(mFrame);
	  	http_requestnew.onreadystatechange = function() {
mSpan = "myspan" + parameters;	
//alert('http_requestnew.readyState: '+http_requestnew.readyState);
//alert('http_requestnew.status: '+http_requestnew.status);
   		if (http_requestnew.readyState == 0)	{
			if(document.getElementById(mSpan))	
			{
			document.getElementById(mSpan).innerHTML = "<p style=\"color:red;\"> Adding to cart...(Not Initialized)</p>"; //uninitialized
			}
		}
		if(http_requestnew.readyState == 1)	{
			/*if(document.getElementById(mSpan))	
			{
			document.getElementById(mSpan).innerHTML = "<p style=\"color:red;\"> Adding to cart (loading)...</p>"; //loading
			}*/
		}
		if(http_requestnew.readyState == 2)	{
			//document.getElementById(mSpan).innerHTML = "<p style=\"color:red;\"> Adding to cart...</p>"; //loaded
		}
		if(http_requestnew.readyState == 3)	{
			//document.getElementById(mSpan).innerHTML = "<p style=\"color:red;\"> Adding to cart...</p>"; //interactive
		}
		if (http_requestnew.readyState == 4 || http_requestnew.readyState == "complete") {
             if (http_requestnew.status == 302 || window.location.href.indexOf("http")==-1) {
				checkCookienew(oldfindQty, oldfindAmount);
         	} else {
				alert('There was a problem with the request.');
         	}
 		}
	};
   http_requestnew.open('POST', uri, true);
   http_requestnew.send(null);
   }
function getele(eleid,ajaxcontent){
	  oldfindQty=GetCookie("CartTQty");
	  oldfindAmount=GetCookie("SubTotal");
	 // alert('oldfindQty: '+oldfindQty+' oldfindAmount: '+oldfindAmount);
      var ele=document.getElementById(eleid);
	  document.getElementById(ajaxcontent).innerHTML='<img src="http://site.hairretail.com/images/loadingAnimation-final-new.gif" style="vertical-align:middle; display:inline;">&nbsp;<span style="font-size:12px; vertical-align:middle; display:inline;">Please wait!... while we add the product to cart.</span>';
	//document.getElementById(ajaxcontent).innerHTML='<div style="padding:2px; border:1px solid #04919F; background-color:#D7FDFA; width:128px;"><img src="http://site.hairretail.com/images/loadingAnimation-final.gif" style="vertical-align:middle; display:inline;"></div>';
      makeRequestnew('http://order.store.yahoo.net/cgi-bin/wg-order?yhst-81757188548682+', ele.value);
}
function getAlert(){
//u=setTimeout("checkCookienew()",1000);
//alert("From getalert()");
}

function checkCookienew(oq, oa)
{
	newfindQty=GetCookie("CartTQty");
	newfindAmount=GetCookie("SubTotal");
	if(newfindQty && newfindQty!=null && newfindAmount && newfindAmount!=null && newfindQty!="NaN" && newfindAmount!="NaN")
	{
		if(oq && oa &&(newfindQty!=oq) && (newfindAmount!=oa))
		{
				//clearTimeout(u);
				if(Number(newfindQty) ==1){
					document.getElementById("fqty").innerHTML=newfindQty;
				}else{
					document.getElementById("fqty").innerHTML=newfindQty;
				}
				document.getElementById("famt").innerHTML=newfindAmount;
				document.getElementById('myOnPageContent').innerHTML='';
				document.getElementById('myOnPageContent').innerHTML='<input src="http://lib.store.yahoo.net/lib/yhst-81757188548682/addtocart.gif" type="image" value="Order">';
				showCart();
		}
		else{
			setTimeout("checkCookienew(oldfindQty,oldfindAmount);",5000);
		}
	}else{
			setTimeout("searchforCookienew();",5000);	
	}	
}

function searchforCookienew(){
	freshfindQty=GetCookie("CartTQty");
	freshfindAmount=GetCookie("SubTotal");
		if(freshfindQty && freshfindQty!="" && freshfindQty!=null && freshfindQty!='NaN' && freshfindAmount && freshfindAmount!="" && freshfindAmount!=null && freshfindAmount!='NaN'){
			//clearTimeout(u);
			if(Number(freshfindQty) ==1){
					document.getElementById("fqty").innerHTML=freshfindQty;
			}else{
					document.getElementById("fqty").innerHTML=freshfindQty;
			}
			document.getElementById("famt").innerHTML=freshfindAmount;	
			document.getElementById('myOnPageContent').innerHTML='';
			document.getElementById('myOnPageContent').innerHTML='<input src="http://lib.store.yahoo.net/lib/yhst-81757188548682/addtocart.gif" type="image" value="Order">';
				showCart();
	}else{
		setTimeout("searchforCookienew();",5000);	

	}
}