
/*---- CART FUNTIONS START -----------*/
function AddToCart(pid,qty,vid,stock,tax,state)
{
	var quantity = document.getElementById(qty);
	//alert(quantity);
	if(quantity.value > stock)
	{
			alert("Please Select quantity Less Than " + quantity.value);
			return false;
	}
	else
	{
		//alert('adsasdas');
		//return false;
		httpObject =  getHTTPObject();
		var url = "controller/ctl_add_to_cart.php?pid=" + pid + "&qty=" + quantity.value + "&vid=" + vid + "&stock=" + stock + "&tax=" + tax + "&state=" + state;
		//alert(url);
	
		if(httpObject!=null)
		{
				//alert(httpObject);
				httpObject.open("GET",url,true);
				httpObject.send(null);
				httpObject.onreadystatechange = GetReplycart; 
		}
	}
		
	return true;
}
 
function GetReplycart()
{
	 if(httpObject.readyState == 4)
	 {
		//alert(httpObject.responseText);
		window.location.href="cart.php";
	 }
}
/*--------------- Image RoleOver ----------------------*/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*--------------------------------------------------*/
function GetShipping()
{
	
	var shipping = document.getElementById("drp_ship");
	var newhid = document.getElementById("newhid");
	
	var url = "controller/ctl_getshipping.php?shipping=" + shipping.value + "&newhid=" + newhid.value + "&index=" + shipping.selectedIndex;

	httpObject =  getHTTPObject();
	if(httpObject!=null)
	{	
		httpObject.open("GET",url,true);
		httpObject.send(null);
		httpObject.onreadystatechange = GetReplyState1; 
	}
}

function GetReplyState1(){

	 if(httpObject.readyState == 4)
	 {
			
		var	total_bill_td = document.getElementById("grand_bill"); 
		var bill = document.getElementById("newhid");
		var div = document.getElementById('shipping');
		var div2 = document.getElementById('grand_bill');
		div.innerHtml="";
		div.innerHTML = httpObject.responseText;
		
		div2.innerHtml="";
		div2.innerHTML = (parseFloat(httpObject.responseText)  + parseFloat(bill.value));
		//alert(total_bill_td.innerText);
		//total_bill_td.innerHtml="";
		//total_bill_td.innerText = (parseFloat(httpObject.responseText)  + parseFloat(bill.value) );
		//alert(total_bill_td.innerText);
	 }
  
}
function CancelCart()
{
	var url = "controller/ctl_cancel_cart.php?id=1";
	var agree = confirm("Are you sure to cancel?");
		
	httpObject = getHTTPObject();
	if(agree)
	{
		if(httpObject!=null)
		{
			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = GetReplySpl;
		}
	}
	else
	{
		return false;
	}
}
function GetReplySpl(){
 if(httpObject.readyState == 4)
 {

	//alert(httpObject.responseText);
	//var render_conainer = document.getElementById("ddl");
	//render_conainer.innerHTML = httpObject.responseText;
	
	//alert(httpObject.responseText);
	window.location.href="cart.php";
  }
  else
  {
  	//render_conainer.innerHTML = "";
  }
}

function CancelCartGC()
{
	var url = "controller/ctl_cancel_cart_cg.php?id=1";
	var agree = confirm("Are you sure to cancel?");
		
	httpObject = getHTTPObject();
	if(agree)
	{
		if(httpObject!=null)
		{
			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = GetReplyCancelCartGC;
		}
	}
	else
	{
		return false;
	}
}
function GetReplyCancelCartGC(){
 if(httpObject.readyState == 4)
 {

	//alert(httpObject.responseText);
	//var render_conainer = document.getElementById("ddl");
	//render_conainer.innerHTML = httpObject.responseText;
	
	//alert(httpObject.responseText);
	window.location.href="cart.php";
  }
  else
  {
  	//render_conainer.innerHTML = "";
  }
}
/*-------- Update Cart -------------------------------*/
function UpdateCart(cid,qty,stock)
{

	var quantity = document.getElementById(qty);
	var url = "controller/ctl_update_cart.php?cid=" + cid +"&qty=" + quantity.value  +"&stock=" + stock;
		//alert(url)
		httpObject = getHTTPObject();
		if(httpObject!=null)
		{
			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = GetUpdateReply;
			
		}
	return true;
}
function GetUpdateReply(){
 if(httpObject.readyState == 4)
 {

	//alert(httpObject.responseText);
	//var render_conainer = document.getElementById("ddl");
	//render_conainer.innerHTML = httpObject.responseText;
	
	alert(httpObject.responseText);
	window.location.href="cart.php";
  }
  else
  {
  	//render_conainer.innerHTML = "";
  }
}
/*-------------------- RedeemCoupon -----------------------------------------*/
function RedeemCoupon(cid)
{
	var coupon_code = document.getElementById(cid);
	if(coupon_code.value=="")
	{
		alert("Enter Coupon Code");
		return false;
	}
	//alert(coupon_code.value);
	var url = "controller/ctl_redeem_coupon.php?ccode="+coupon_code.value;
	 httpObject = getHTTPObject();
	 
	 if(httpObject!=null)
		{
			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = GetReplyCoupon;
		}
}
function GetReplyCoupon(){
 if(httpObject.readyState == 4)
 {

	alert(httpObject.responseText);
	window.location.href="cart.php";
  }
  else
  {
  	//render_conainer.innerHTML = "";
  }
}
/*------------------------- RemoveFromCart ----------------------------------------------*/
function RemoveFromCart(cid)
{
	
	var agree = confirm("Are you sure to delete from cart?");
	if(agree)
	{
		var url = "controller/ctl_remove_cart.php?cid=" + cid;
		//alert(url)
		window.location.href = url;
	}
	else
	{
		return false;
	}
}

function RemoveFromCartGC(cid)
{
	
	var agree = confirm("Are you sure to delete from cart?");
	if(agree)
	{
		var url = "controller/ctl_remove_cart_GC.php?cid=" + cid;
		//alert(url)
		window.location.href = url;
	}
	else
	{
		return false;
	}
}
/*------------------------------------- ProceedCheckout -----------------------------------------------------*/
function ProceedCheckout()
{
	var shippingmode = document.getElementById("drp_ship");
	if(shippingmode.value == "null")
	{
		alert('Please Select Shipping Mode');
		shippingmode.focus();
		return false;
	}
	var bill = document.getElementById('hiddenbill');
	if(bill.value=="" || bill.value == null)
	{
		alert('You have no itens in your shopping cart');
		return false;
	}
	else
	{	
		var url = "controller/ctl_proceed_checkout.php";
		document.location.href = url;
	}			 
}
 ////-----------------------------------inovice------------------------------////
 
function userbillingedit(uid)
{

	//alert(uid);
	var url = 'editbilling.php?uid=' + uid;
	window.open(url,'userbillingedit', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=900, scrollbars=1');
}
function usershippingedit(uid)
{

	//alert(uid);
	var url = 'editshipping.php?uid=' + uid;
	window.open(url,'usershippingcon', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=900, scrollbars=1');
} 
function paymentedit()
{

	var url = 'editpaymentmode.php';
	window.open(url,'editpaymentmode', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=900, scrollbars=1');
} 
function shippingmodeedit()
{

	//alert(uid);
	var url = 'editshippingmode.php'
	window.open(url,'editshippingmode', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=900, scrollbars=1');
} 
function SelectPaymentMode(payment)
{
	url="controller/ctl_select_payment_mode.php?pm=" + payment;
	alert(url);
	httpObject = getHTTPObject();
	 
	 if(httpObject!=null)
		{
			httpObject.open("GET", url, true);
			httpObject.send(null);
		}
}


/*------------------ Forgot Password -------------------------*/
function forgotpassword()
{

	var url = 'forgot_password.php'
	window.open(url,'Forgot Password', 'menubar=0, location=0, status=0 , resizeable=0, width=200, height=100, scrollbars=0');
} 
//---- GENERAL ------------------------
 function RefreshParent(){
	  window.opener.location.reload();  
	  window.close();
}

function CloseWindow()
{
	window.close();
}
/*----------------------------------------------------------------*/
function SelectPaymentMode(payment)
{
	url="controller/ctl_select_payment_mode.php?pm=" + payment;
	httpObject = getHTTPObject();
	 
	 if(httpObject!=null)
		{
			httpObject.open("GET", url, true);
			httpObject.send(null);
		}
}
/*-------------------------------------------------------------------*/
function GetBilling_State()
{
	
	var billing = document.getElementById("country");
	var url = "controller/ctl_shippingpage_state_for_billing.php?country=" + billing.value;
	
	httpObject =  getHTTPObject();
	if(httpObject!=null)
	{
		//alert(url);
		httpObject.open("GET",url,true);
		httpObject.send(null);
		httpObject.onreadystatechange = GetReplybilling; 
	}
}

function GetReplybilling(){

	 if(httpObject.readyState == 4)
	 {
		
			//alert(httpObject.responseText);
			var div = document.getElementById('statediv')
			div.innerHtml="";
			div.innerHTML = httpObject.responseText;

	 }
  
}
/*---------------------------------------------------------------------------------*/

function GenerateOrder(enc,py,sh)
{
	var url = "controller/ctl_create_order.php?q=" + enc+"&py="+py+"&sh="+sh;
	document.location.href = url;
}


function GenerateGiftCardOrder2(gcid,total_bill)
{

	if(gcid=="")
	{
		alert('Plese Enter Gift Card Number');
		return false;
	}
	else
	{
		var url = "controller/ctl_create_gc_order.php?q="+ gcid.value + "&bill=" + total_bill.value;
		httpObject = getHTTPObject()
		
		if(httpObject!=null)
		{
			alert(url)
			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = GetReplyGc;
		}
	}

}
 
function GetReplyGc2()
{
	if(httpObject.readystate == 4)
	{
		//window.location.href="cart.php";
		alert(httpObject.responseText);
	}
}
/*-------------------------------------------------- USER PROFILE --------------------------------------------------------------*/
function usershipping(sid){

	var url = 'edit_shipping_pro.php?sid=' + sid;
	window.open(url,'usershipping', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=900, scrollbars=0');
} 
function Deleteshippingaddress(id, name){
	var agree = confirm("Are you sure to delete " + name +" Shipping Address?");
	var url = "controller/delete_shippingaddress.php?id=" + id + "&name=" + name;
 
	if(agree)
		window.open(url,'DeleteCategoryWindow', 'menubar=0, location=0, status=0 , resizeable=0, width=350, height=300, scrollbars=1');
		//window.location.href = url;
        //return true; 
	else
		return false;
}
/*function submitform(enc,py,sh)
{
	
	var url = "controller/ctl_create_paypal_order.php?q=" + enc +"&py="+py+"&sh="+sh;
	//window.open(url,'EditCategoryWindow', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=900, scrollbars=1');
	//document.location.href = url;
	//alert('danish');
    document.forms["frm_invoice"].submit();
}*/
// VIEW ORDER DETAILS ---------------------------------------------------------------------------
function ViewOrderDetails(id)
{
	var url = 'orderdetail.php?id=' + id;
	//alert(url);
	window.open(url,'Order Detail Page', 'menubar=0, location=0, status=0 , resizeable=0, width=1024, height=800, scrollbars=0');
} 
// gift certificate Show ------------------------
function giftcertificate()
{

	//alert('Danish');
	var url = 'GC_Desgin.html'
	window.open(url,'giftcertificate', 'menubar=0, location=0, status=0 , resizeable=0, width=556, height=203, scrollbars=1');
} 
