// JavaScript Document
function LeftSearch(flag,id,strurl)
{
	if(strurl !="gallery.php")
	{
		if(flag=="A")
		{
			document.location.href=SITE+"/gallery/";
		}
		else if(flag=="SP" || flag=="AP" || flag=="AAT")
		{
			document.location.href=SITE+"/gallery/"+flag;
		}
		else
			document.location.href=SITE+"/gallery/"+flag+"/"+id;
	}
	else
	{
		if(flag=="A")
		{
			xmlhttpPost_gallery('','',0);//document.location.href="gallery.php";
		}
		else if(flag=="SP" || flag=="AP" || flag=="AAT")
		{
			xmlhttpPost_gallery(flag,'',0);//document.location.href="gallery.php?flag="+flag;
		}
		else
		{
			xmlhttpPost_gallery(flag,id,0);//document.location.href="gallery.php?flag="+flag+"&id="+id;
		}
	}
}


// JavaScript Document
function LeftSearch2(strurl)
{
	document.location.href=strurl;	
}

function xmlhttpPost_gallery(flag,idval,start)
{
	/*alert(flag)
	alert(idval)
	alert(start)*/
	
	document.getElementById("tdGallery").innerHTML="<img src='images/loading_small.gif' >";
	var xmlHttpReq_gallery = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq_gallery = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq_gallery = new ActiveXObject("Microsoft.XMLHTTP");
    }
	
	var strURL="gallery_resultajax.php?startval="+start;
	if(idval != "")
	{
		strURL +="&id="+idval;
	}
	if(flag !="")
	{
		strURL +="&flag="+flag;
	}
	//alert(strURL);
	self.xmlHttpReq_gallery.open('POST', strURL, true);
    self.xmlHttpReq_gallery.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
	self.xmlHttpReq_gallery.onreadystatechange = function() 
    {	
		if (self.xmlHttpReq_gallery.readyState == 4) {
			update_gallerystatus(self.xmlHttpReq_gallery.responseText);
        }
    }
    self.xmlHttpReq_gallery.send(null);
}
// End of Change Display Status
function update_gallerystatus(strText)
{
	document.getElementById("tdGallery").innerHTML=strText;
}
function chksrch(url)
{
	if(document.getElementById("searchbox").value=="")
	{
		alert("Please Enter Search Value");
		document.getElementById("searchbox").focus();
		return false;
	}
	else
	{
		var srch=document.getElementById("searchbox").value;
		LeftSearch('S',srch,url);
	}
/*	document.getElementById("srchhid").value=1;
	document.getElementById("srchfrm").submit();
	return true;  */
}
function removeitem(flag,orderid,idval,currency)
{
	
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('POST',SITE+"/deleteitem.php?flag="+flag+"&oid="+orderid+"&id="+idval, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
	self.xmlHttpReq.onreadystatechange = function() 
    {	
		if (self.xmlHttpReq.readyState == 4) {
			//alert(self.xmlHttpReq.responseText);
			update_Cart(self.xmlHttpReq.responseText,currency);
        }
    }
    self.xmlHttpReq.send(null);
}
function update_Cart(str,currency)
{
		var tempstr=str.split("==");
		var subtotalorg=document.getElementById("TdSubTotalVal").innerHTML.replace(",", "");
		var subtotal=subtotalorg.substr(4);
		var totalorg=document.getElementById("TdTotalVal").innerHTML.replace(",", "");
		var total=totalorg.substr(4);
		var temp1=parseFloat(subtotal)-parseFloat(tempstr[1].replace(",", ""));
		var temp2=parseFloat(total)-parseFloat(tempstr[1].replace(",", ""));
		
		if(temp1 ==0)
		{
			temp2=0;
			document.getElementById("TdShippingVal").innerHTML=currency +" "+ temp2.toFixed(2);
			window.location.href=SITE+'/cart.php';
		}
		
		document.getElementById("TdSubTotalVal").innerHTML=currency +" "+ temp1.toFixed(2);
		document.getElementById("TdTotalVal").innerHTML=currency +" "+temp2.toFixed(2);
		document.getElementById("TdProducName"+tempstr[0]).style.display="none";
		document.getElementById("TdView"+tempstr[0]).style.display="none";
		document.getElementById("TdItemCode"+tempstr[0]).style.display="none";
		document.getElementById("TdRemove"+tempstr[0]).style.display="none";
		document.getElementById("TdPrice"+tempstr[0]).style.display="none";
		document.getElementById("TdAmount"+tempstr[0]).style.display="none";
		window.location.href=SITE+'/cart.php';
}
function FunOrderCase(amuletid,caseid)
{
	//alert(amuletid);
	//alert(caseid);
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('POST',SITE+"/ordercase.php?aid="+amuletid+"&cid="+caseid, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
	self.xmlHttpReq.onreadystatechange = function() 
    {	
		if (self.xmlHttpReq.readyState == 4) {
			//alert(self.xmlHttpReq.responseText);
			//update_Cart(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);
}
function set_currency(url,val)
{
	if(val != '' && val != '01'){
		window.location.href=SITE+'/set_currency.php?cur='+val+'&strurl='+url;
		return true;
	}
	else
	return false;
}
function set_temple(url,val)
{
	if(val != '' && val != '01'){
		window.location.href=SITE+'/set_currency.php?tmp='+val+'&strurl='+url;
		return true;
	}
	else
	return false;
}
function set_monk(url,val)
{
	if(val != '' && val != '01'){
		window.location.href=SITE+'/set_currency.php?mnk='+val+'&strurl='+url;
		return true;
	}
	else
	return false;
}

