﻿// JavaScript Document
var SHOP_frame;
SHOP_CheckIframe();

var sp;
function CreateSP(){
	if(!window.sp){
		sp = new ServiceProxy("../json-rpc.asp");
		//alert("ok");
	}
}

YY_MENSAJE = "The information is incomplete or incorrect.";



function SHOP_AddToCart(codProducto){
		var div = $('productPicture_'+codProducto);
		var codColor="";
		codColor = (div && div.codColor)? ("&codColorAgregado="+div.codColor) :"" ;
		SHOP_frame.location.href = "/SHOP_shoppingCart.asp?addProduct=true&codProducto="+codProducto+codColor;
		Element.scrollTo(SHOP_frame);
		($('SHOP_tblContent')||$('divShoppingCart')).update("<div class='updatingShoppingCart'>updating shopping cart...</div>");
		//alert(SHOP_frame.location.href);
}

function SHOP_RemoveFromCart(codSHOP_CartProduct){
		var query = SHOP_frame.location.href.QueryString();
		var hideCheckout = query.ExplodeQueryString().hideCheckout;

		SHOP_frame.location.href = "/SHOP_shoppingCart.asp?delProduct=true&codSHOP_CartProduct="+codSHOP_CartProduct+"&hideCheckout="+hideCheckout;
}

function SHOP_ChangeQuantity(cant,codSHOP_CartProduct){
		var query = SHOP_frame.location.href.QueryString();
		var hideCheckout = query.ExplodeQueryString().hideCheckout;

		SHOP_frame.location.href = "/SHOP_shoppingCart.asp?cant="+cant+"&codSHOP_CartProduct="+codSHOP_CartProduct+"&hideCheckout="+hideCheckout;
}

function SHOP_CheckIframe(){
	if (document.getElementById('ifrShoppingCart') ){
		SHOP_frame = document.getElementById('ifrShoppingCart').contentWindow.document;
		//alert("SHOP_frame 2:"+SHOP_frame);
	}
	else SHOP_frame = document;

}

function SHOP_ChangeColor(codColor,codSHOP_CartProduct){
		SHOP_frame.location.href = "/SHOP_shoppingCart.asp?codColor="+codColor+"&codSHOP_CartProduct="+codSHOP_CartProduct;
}

function SHOP_ChangeSize(size,codSHOP_CartProduct){
		SHOP_frame.location.href = "/SHOP_shoppingCart.asp?size="+escape(size)+"&codSHOP_CartProduct="+codSHOP_CartProduct;
}



function SHOP_ShowHideCart(){
		SHOP_frame.location.href = "/SHOP_shoppingCart.asp?showHideCart=true";
}

function SHOP_Onload(){
	SHOP_CheckIframe();
	CopyContent(MM_findObj('divShoppingCart',$('ifrShoppingCart').contentWindow.document),'divShoppingCart');
}


function ChangeProductPicture(codProducto, lnkFoto,codColor){
	var div = $('productPicture_'+codProducto);
	if(!div) return;
	if(!div.cachePic) {
		div.cachePic = new Image();
		//document.body.appendChild(div.cachePic);
	}
	
	var size = Number(div.getAttribute("size"))||2;
	if(codColor) div.codColor =codColor;
	div.cachePic.div = div;
	div.cachePic.onload=function(){
		this.div.style.backgroundImage = "url('"+this.src+"')";
	}
	setTimeout(function(){
		div.cachePic.src = "/sizepic.asp?lnkFoto="+escape("/db/productos/"+lnkFoto)+"&size="+size;
	},10);
	
}

function LoginExitoso(){
	alert("login exitoso");
}