// JavaScript Document


function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 3000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + ExpireDate.toGMTString());
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

document.getElementsByAttribute = function(attribute, value, tagName, parentElement) {
	var children = ($(parentElement) || document.body).getElementsByTagName((tagName || '*'));
	return $A(children).inject([], function(elements, child) {
		var attributeValue = child.getAttribute(attribute);
		if(attributeValue != null) {
			if(!value || attributeValue == value) {
				sessionelement = child;
			}
		}
	});
}

//GOTOPAY
myflag=false;
myaddflag=false;

function show_shoppingCart() {
	if (document.all) {
		$("divShoppingCart").style.top = "170px";
	}
	else {
		$("divShoppingCart").style.top = "172px";	
	}
	$("divShoppingCart").style.display = "block";
	$("divShoppingCart").style.visibility = "visible";	
	$("imgArrow").src = "imagess/shopping_cart_down.gif";	
	$("imgArrow").lowsrc = "imagess/shopping_cart_up.gif";		
}

function hide_shoppingCart() {
	$("divShoppingCart").style.display="none";
	$("imgArrow").src = "imagess/shopping_cart_up.gif";
}

function check_shoppingCart() {
	try {
		if ($("divShoppingCart").style.display!="none") {			
			setTimeout('if (myflag == false && myaddflag == false) {$("divShoppingCart").style.display="none";$("imgArrow").src = "imagess/shopping_cart_up.gif";}',500);
		}
	}
	catch(e) {}
}

function add_to_shoppingCart(index, id, info){
			show_shoppingCart();
		myaddflag=true;	
		var txtQty = (document.frmAddToCart.txtProductQty.length==null) ? document.frmAddToCart.txtProductQty : document.frmAddToCart.txtProductQty[index];
		document.frmToCart.productID.value = id;
		document.frmToCart.fldquantity.value = txtQty.value;
			if(info)document.frmToCart.fldAdditionalInfo.value = (document.frmAddToCart.txtCakeProperties.length==null) ? document.frmAddToCart.txtCakeProperties.value : document.frmAddToCart.txtCakeProperties[index].value;
			//Esta parte esta incluida para cuando se compre algun producto que requiera fecha de seleccion, pues ahora se escoge en la pagina del producto.
			if(document.frmAddToCart.cmbDeliveryDate!=null&&document.frmAddToCart.cmbDeliveryDate.value!=""&&document.frmAddToCart.cmbDeliveryTime!=null&&document.frmToCart.deliveryDate!=null&&document.frmToCart.deliveryTime!=null){
				document.frmToCart.deliveryDate.value=document.frmAddToCart.cmbDeliveryDate.value;
				document.frmToCart.deliveryTime.value=document.frmAddToCart.cmbDeliveryTime.value;
			}
			document.frmToCart.submit();
			setTimeout("myaddflag=false;myflag=false",5000);
}

function add_to_shoppingCartOferta(index, id, info){
			show_shoppingCart();
		myaddflag=true;	
		var txtQty = (document.frmAddToCart.txtProductQty.length==null) ? document.frmAddToCart.txtProductQty : document.frmAddToCart.txtProductQty[index];
		document.frmToCart.productID.value = id;
		document.frmToCart.fldquantity.value = txtQty.value;
			if(info)document.frmToCart.fldAdditionalInfo.value = (document.frmAddToCart.txtCakeProperties.length==null) ? document.frmAddToCart.txtCakeProperties.value : document.frmAddToCart.txtCakeProperties[index].value;
			//Esta parte esta incluida para cuando se compre algun producto que requiera fecha de seleccion, pues ahora se escoge en la pagina del producto.
			if(document.frmAddToCart.cmbDeliveryDate!=null&&document.frmAddToCart.cmbDeliveryDate.value!=""&&document.frmAddToCart.cmbDeliveryTime!=null&&document.frmToCart.deliveryDate!=null&&document.frmToCart.deliveryTime!=null){
				document.frmToCart.deliveryDate.value=document.frmAddToCart.cmbDeliveryDate.value;
				document.frmToCart.deliveryTime.value=document.frmAddToCart.cmbDeliveryTime.value;
			}
			document.frmToCart.submit();
			setTimeout("myaddflag=false;myflag=false",5000);
			document.frmAddToCart.action='ofertaCombo6.asp';
			document.frmAddToCart.submit();
}

//STEP BY STEP
function show_step_preeview(step,top,left,ieleft,language) {
	$('step_preeview_img1').style.display='none';	
	$('step_preeview_img2').style.display='none';	
	$('step_preeview_img3').style.display='none';	
	$('step_preeview_img4').style.display='none';		
	$('step_preeview_img'+step).style.display='block';	
	$('step_preeview').style.marginTop=top+'px'; 
	if (document.all) {
		$('step_preeview').style.marginLeft=ieleft+'px';
	}
	else {	
		$('step_preeview').style.marginLeft=left+'px';		
	}	
	switch (step) {
		case 1 : 
			if (language == 'spa') {
				$('step_preeview_txt').innerHTML='IDENTIFICARSE';
			}
			else {
				$('step_preeview_txt').innerHTML='LOGIN';				
			}
		break;
		case 2 : 
			if (language == 'spa') {
				$('step_preeview_txt').innerHTML='SELECCIONAR DESTINATARIO';
			}
			else {
				$('step_preeview_txt').innerHTML='SELECT RECIPIENT';				
			}		
		break;
		case 3 : 
			if (language == 'spa') {
				$('step_preeview_txt').innerHTML='FINALIZAR COMPRA';
			}
			else {
				$('step_preeview_txt').innerHTML='COMPLETE PURCHASE';				
			}		
		break;
		case 4 : 
			if (language == 'spa') {
				$('step_preeview_txt').innerHTML='PAGAR...';
			}
			else {
				$('step_preeview_txt').innerHTML='PAY...';				
			}		
		break;		
	}
	
	$('step_preeview').style.display='block';	
}
//ESTO ES DE LOS AVISOS
var advice_flag = false;
var advice_id = 0;
function show_advise() {
	if (advice_flag) {
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });	
		$('advise').setStyle({ height: document.body.clientHeight + 'px', display: 'block' });
		$('advise_box').setStyle({ display: 'block', visibility: 'hidden' });
		$('advise_box').setStyle({ marginTop: parseInt(document.documentElement.clientHeight/2-$('advise_box').offsetHeight/2) + 'px', display: 'block', visibility: 'visible' });
	}
	try {slideshow_event()	} catch(e) {}
}

function hide_advise() {	
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
	$('advise').setStyle({ display: 'none' });
	$('advise_box').setStyle({ display: 'none' });	
}

function clean_advise() {
	if(advice_id!=0) {
		new Ajax.Request('cleanAdvices.asp?aId='+advice_id,{method: 'get', onComplete: function() {hide_advise()}});
	}
	else {
		new Ajax.Request('cleanAdvices.asp',{method: 'get', onComplete: function() {hide_advise()}});		
	}
}

function open_advise(aElement) {
	if(document.all) {
		aElement.childNodes[0].firstChild.src='imagess/mail_read.gif';
	}
	else {
		aElement.childNodes[1].firstChild.src='imagess/mail_read.gif';
	}
	aElement.style.fontWeight="normal";	
	if(document.all) {
		$("text_advice").innerHTML = aElement.childNodes[3].innerHTML;
		$("title_advice").innerHTML = aElement.childNodes[1].innerHTML;
	}
	else {
		$("text_advice").innerHTML = aElement.childNodes[7].innerHTML;
		$("title_advice").innerHTML = aElement.childNodes[3].innerHTML;
	}
	advice_id = aElement.id;
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });	
	$('advise').setStyle({ height: document.body.clientHeight + 'px', display: 'block' });
	$('advise_box').setStyle({ display: 'block', visibility: 'hidden' });
	$('advise_box').setStyle({ marginTop: parseInt(document.documentElement.clientHeight/2-$('advise_box').offsetHeight/2) + 'px', display: 'block', visibility: 'visible' });
}
//ESTO ES DEL LOGIN


function HomeLogoff() {
	setCookie('sessionTokenID', '', 0);
	window.location.href="logoff.asp";
}

