CART = "http://"+host+"/core-cart/";

var ppCart = {
	
	"setCookie" : function(form){
		
		
		
		_form = function(x) { return document.forms[form].elements[x].value; };
		
		//::get value
		
		pcode = _form("product_code");
		
		pname = escape(_form("product_name"));
		
		pprice = escape(_form("product_price"));
		
		pcategory = _form("product_category");
		
		pquantity = parseInt(_form("quantity"));
				
		/*var with_dongle;
				
		if(document.getElementById("box"+form.substr(6))){
			with_dongle = document.getElementById("box"+form.substr(6)).checked;
		}
		else{
			with_dongle = 0;
		}*/
				
		//::call ajax
		
		if(!isNaN(pquantity)){
		
			/*var loadAjax = {
											
							"query" : "pid=03071989&pcode="+pcode+"&pname="+pname+"&pprice="+pprice+"&pcategory="+pcategory+"&pquantity="+pquantity+"&dongle="+with_dongle,
							
							"method" : "post",
							
							"page" :"core-cart/shopping.set.session.cart.php",
							
							"response" : "text",
							
							"callback" : function(dom){
												document.getElementById("load_main").style.display = "none";
												document.forms[form].submit();
									
										},
										
							"loadfxn" : function(){
												document.getElementById("load_main").style.display = "block";
										}
						};
			artis.ajax.call(loadAjax);*/
			
			document.forms[form].submit();
			
		}
		else{
			
			alert("How many do you want to order?");
			
			document.forms[form].elements["quantity"].focus();
			
		}
	
	},
	
	"updateCart": function(x,y){
		
		quantity = superFxn._create_object(x,"id").value;
		id = x.substr(0,x.search(/-/g));
		dongle = y;
		
		var loadAjax = {
				
							"mtd" : "post",
							
							"param" : "pid=03071989&pquantity="+quantity+"&id="+id+"&dongle="+dongle,
							
							"pg" : CART+"shopping.update.cart.php",
							
							"parsing" : "text",
							
							"type" : null,
							
							"callback" : function(dom){
						
												$("#ajaxLoader").slideUp();
												
												superFxn._create_object("shoppingItemList","id").innerHTML = dom;			
													
										},
										
							"fallback" : function(){
								
												$("#ajaxLoader").slideDown();
												
										}
						}
									 
		superFxn.pmyAjax.call(loadAjax);
		
	},
	
	"removeFromCart": function(x,y){

		id = x.substr(0,x.search(/-/g));

		var loadAjax = {
				
							"mtd" : "post",
							
							"param" : "pid=03071989&id="+id+"&dongle="+y,
							
							"pg" : CART+"shopping.remove.cart.php",
							
							"parsing" : "text",
							
							"type" : null,
							
							"callback" : function(dom){
						
												$("#ajaxLoader").slideUp();
												
												superFxn._create_object("shoppingItemList","id").innerHTML = dom;			
													
										},
										
							"fallback" : function(){
								
												$("#ajaxLoader").slideDown();
												
										}
						}
									 
		superFxn.pmyAjax.call(loadAjax);
		
	}
	
}
function priceAdjust(id,price){
	
	var strippedPrice = price.replace(/[^0-9^.]/g,"");
	
	
	
	if(tgt.checked){
		document.getElementById("price"+id).innerHTML = price;
		document.getElementById("prod_price"+id).value = strippedPrice;
		document.getElementById("dongle"+id).value = true;
	}
	else{
		document.getElementById("price"+id).innerHTML = document.getElementById("orig"+id).value;
		document.getElementById("prod_price"+id).value = strippedPrice;
		document.getElementById("dongle"+id).value = false;
	}
}

function verify(s){
	if(s < 1) {
		alert("Your cart is empty!");
	}
	else{
		window.location = CART+"checkout.php";
	}
}

function verifyCart(type){
	
	var form = function(e) { return document.forms["cartPP"].elements[e].value; };
	
	var fn = escape(form("first_name").toLowerCase());
	var mi = escape(form("mi").toLowerCase());
	var ln = escape(form("last_name").toLowerCase());
	var da = escape(form("address1").toLowerCase());
	var pn = escape(form("pn"));
	var mn = escape(form("mn"));
	var email = escape(form("email"));
	var address = escape(form("address1").toLowerCase());
	var country = form("country");
	var city = escape(form("city").toLowerCase());
	var postal = escape(form("postal"));	
	type == 2 ? merchant = "paypal" : merchant = "moneybooker";
	
	var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	
	if(fn == "" || ln == "" || da == "" || pn == "" || email == "" || address == "" || country == "#" || city == "" || postal == ""){
		alert("All fields with (*) must be filled up");
	}
	else{
		if(reg.test(email)){
			
			
			var loadAjax = {
											
							"query" : "pid=03071989&fn="+fn+"&mi="+mi+"&ln="+ln+"&pn="+pn+"&mn="+mn+"&email="+email+"&address="+address+"&city="+city+"&postal="+postal+"&country="+country+"&merchant="+merchant+"",
							
							"method" : "post",
							
							"page" : "core-cart/inventory.cart.php",
							
							"response" : "text",
							
							"callback" : function(dom){
											//document.cookie = "ppcid=;expires=Mon, 7 March 1989 20:47:11 UTC; path=/";
											if(type == 2){ document.forms["cartPP"].action= "https://www.paypal.com/cgi-bin/webscr"; }
											else{ document.forms["cartPP"].action = "https://www.moneybookers.com/app/payment.pl"; }
											document.forms["cartPP"].submit();
											
										},
										
							"loadfxn" : function(){
										}
						};
			artis.ajax.call(loadAjax);
			
			//alert(loadAjax.query);
			
			//document.forms["cartPP"].submit();
		}
		else{
			alert("Invalid email account.");
		}
	}
}


function updateCart(id){
	var val = document.getElementById(id).value;
	window.location = CART+"cart.update.php?id="+id+"&quantity="+val;
}

function deleteCart(id){
	window.location = CART+"cart.delete.php?id="+id;
}
