var esTarjeta= false;
var codPais='0';
var titular="";
var numeroTarjeta="";

var windowTitleGlobal;
var titleTextGlobal;
var errorTextGlobal;
var windowRedirectUrl;
var whitespace = " \t\n\r";
var defaultEmptyOK = false;

var cdlvisitor= getCookie("cdlvisitor");
var uNombre=  filterChars(getUNombre());
var uRapida= getURapida();
var uId= getUId();

function getUNombre() {
	uNombre='';
	if (cdlvisitor!=null) {
		var i1= cdlvisitor.indexOf("-");
		if (i1>0) {
			var resto= cdlvisitor.substring(i1+1);
			var i2= resto.indexOf("-");
			if (i2>0) {
				uNombre= resto.substring(i2+1);
			}
		}
	}
	return uNombre;
}

function getURapida() {
	var uRapida='';
	if (cdlvisitor!=null) {
		var i1= cdlvisitor.indexOf("-");
		if (i1>=0) {
			var resto= cdlvisitor.substring(i1+1);
			var i2= resto.indexOf("-");
			if (i2>=0) {
				uRapida= resto.substring(0,i2);
			}
		}
	}
	return uRapida;
}

function getUId() {
	var uId='0';
		if (cdlvisitor!=null) {
		var i1= cdlvisitor.indexOf("-");
		if (i1>=0) {
			uId= cdlvisitor.substring(0,i1);
		}
	}
	return uId;
}

function open_error_window(errorText, titleText, urlRedirect, windowTitle, width, height, left, top)
{
//Use:
//open_error_window(errorText);
//open_error_window(errorText,'title');
//open_error_window(errorText,'title','http://www.casadellibro.com');
//...

var putItThere = null;

var chasm = screen.availWidth;
var mount = screen.availHeight;

if ((urlRedirect== null) || (urlRedirect=='undefined')) {
	windowRedirectUrl='';
} else {
	windowRedirectUrl=urlRedirect;
}

if ((windowTitle == null) || (windowTitle=='undefined')) {
	windowTitleGlobal ='::Casa Del Libro:: - Error';
} else {
	windowTitleGlobal=windowTitle;
}

if ((titleText == null)||(titleText=='undefined')) {
	titleTextGlobal='por favor,<br>compruebe los siguientes campos';
} else {
	titleTextGlobal=titleText;
}

if ((errorText == null)||(errorText=='undefined')) {
	errorText='';
} else {
	errorTextGlobal=errorText;
}

if ((width == null) || (width=='undefined'))
	width ='300';
if ((height == null) || (height=='undefined'))
	height ='300';
if ((left == null) || (left=='undefined'))
	left =((chasm - width - 10) * .5);
if ((top == null) || (top=='undefined'))
	top =((mount - height - 30) * .5);

new_window = open("/cdl/cda/javascript/windowPopUp.html","displayWindow","width="+width+",height="+height+",left="+ left +",top="+ top);
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function goLogo() {
	window.location="http://www.casadellibro.com";
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"));
}

function isInteger (s){
	var i;
	if (isEmpty(s))
		if (isInteger.arguments.length == 1) return defaultEmptyOK;
		else return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}

	return true;
}

function esFechaValida() {
	var mesActual= document.myForm.mesActual.value * 1;
	var anoActual= document.myForm.anoActual.value *1;
	var mesTarjeta= document.myForm.mes[document.myForm.mes.selectedIndex].value * 1;
	var anoTarjeta= document.myForm.ano[document.myForm.ano.selectedIndex].value * 1;
	if (anoTarjeta>anoActual) {
		return true;
	} else {
		if (anoTarjeta==anoActual) {
			if (mesTarjeta>=mesActual) {
				return true;
			} else  {
				return false;
			}
		} else {
			return false;
		}
	}
}

function isEmail(StrObj) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(StrObj)) {
	return true;
} else {
	return false;
}
}

function isEmpty(s){
	return ((s == null) || (s.length == 0));
}


function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}

	// All characters are whitespace.
	return true;
}

function boletinFormFactEnvio() {
	var tipo = "";
	if (document.myForm.tipogeneral.checked) {
		tipo = document.myForm.tipogeneral.value + "|";
	}
	if (document.myForm.tiponoticia.checked) {
		tipo = tipo + document.myForm.tiponoticia.value;
	}
	document.myForm.tipoboletin.value = tipo;
	return true;
}

//de formapago
var esTarjeta= false;
var checked= false;
var titular="";
var numeroTarjeta="";

function activaTarjeta() {
	esTarjeta=true;
}

function desactivaTarjeta() {
	esTarjeta=false;
}

function muestraDatos() {
	document.myForm.titular.value=titular;
	document.myForm.numeroTarjeta.value=numeroTarjeta;
}

/* Funciones de Compra Offline */
function validaTextArea(field,maxlimit){
	if(field.value.length > maxlimit){
		field.blur();
		//open_error_window('El área de texto no puede contener más de '+maxlimit+' caracteres.');
		message='El área de texto no puede contener más de '+maxlimit+' caracteres.';
		field.value=field.value.substring(0,maxlimit-1);
		document.myForm.error_msn.value=message;
	}
}

function capaFactura(nombreCapa){
	if (document.myForm.factura) {
		if (document.myForm.factura.checked) {
			document.getElementById(nombreCapa).style.visibility="visible";
		} else {
			document.getElementById(nombreCapa).style.visibility="hidden";
		}
	}
}

function cambiaIgualFEOff() {
	if (document.myForm.datosEnvio.checked==false) {
		document.myForm.igualfe.value='true';
	} else {
		document.myForm.igualfe.value='false';

	}
	document.myForm.error_msn.value=null;
	document.myForm.action="/compra/pedidoOffline";
	document.myForm.submit();
}

function esTarjetaValidaOff() {
	var index= document.myForm.tarjeta.selectedIndex;
	//visa
	if (eval('document.myForm.tarjeta[index].value')=="3") {
		return isVisa(document.myForm.numeroTarjeta.value);
	//mastercard
	} else if (eval('document.myForm.tarjeta[index].value')=="2") {
		return isMasterCard(document.myForm.numeroTarjeta.value);
	//americanexpress
	} else if (eval('document.myForm.tarjeta[index].value')=="4") {
		return isAmericanExpress(document.myForm.numeroTarjeta.value);
	//dinnersclub
	} else if (eval('document.myForm.tarjeta[index].value')=="1") {
		return isDinersClub(document.myForm.numeroTarjeta.value);
	//cuenta libreria
	} else if (eval('document.myForm.tarjeta[index].value')=="6") {
		return isCuentaLibreria(document.myForm.numeroTarjeta.value);
	} else return false;
}

function esES() {
	var idioma='';
	var isIE= (window.navigator.appName.indexOf('Explorer')>0);
	if (isIE) idioma= navigator.userLanguage.toLowerCase();
	else idioma= navigator.language;
	if ((idioma!='es') && (idioma!='es-es')) return false;
	else return true;
}

function escapeOffLine() {
	document.myForm.solicitud.value=escape(document.myForm.solicitud.value);
	document.myForm.instrucciones.value=escape(document.myForm.instrucciones.value);

	document.myForm.fempresa.value=escape(document.myForm.fempresa.value);
	document.myForm.fnombre.value=escape(document.myForm.fnombre.value);
	document.myForm.fapellidos.value=escape(document.myForm.fapellidos.value);
	document.myForm.fdireccion.value=escape(document.myForm.fdireccion.value);
	document.myForm.fpoblacion.value=escape(document.myForm.fpoblacion.value);
	document.myForm.fprovincia.value=escape(document.myForm.fprovincia.value);
	if (document.myForm.datosEnvio.checked) {
		document.myForm.eempresa.value=escape(document.myForm.eempresa.value);
		document.myForm.enombre.value=escape(document.myForm.enombre.value);
		document.myForm.eapellidos.value=escape(document.myForm.eapellidos.value);
		document.myForm.edireccion.value=escape(document.myForm.edireccion.value);
		document.myForm.epoblacion.value=escape(document.myForm.epoblacion.value);
		document.myForm.eprovincia.value=escape(document.myForm.eprovincia.value);
	}
}

function opera(operacion) {
	if (operacion=="changePais") {
		document.myForm.error_msn.value=null;
		document.myForm.action="/compra/pedidoOffline";
		document.myForm.submit();
	} else if (operacion=="continuar") {
		if ( validarFormOff() ) {
		    boletinFormFactEnvio();
			document.myForm.error_msn.value=null;
			if (document.myForm.factura)
				document.myForm.factura.disabled = false;
			/*if (!esES()) {
				escapeOffLine();
			}*/
			document.myForm.action="/compra/pedidoOfflineConfirmacion";
			document.myForm.submit();
		} else {
			document.myForm.action="/compra/pedidoOffline";
			document.myForm.submit();
		}
	}
}

function borrarDatosOff () {
	document.myForm.reset();
	document.myForm.solicitud.value="";
	borrarDatosFactOff();
	// Añadido: al pulsar la casilla de verificacion "datosEnvio"
	// se crean las correspondientes variables para el formulario.
	// La condición añadida evita que se despliegue un error
	// de JavaScript al intentar borrar el contenido de unas
	// variables que no existen.
	if (document.myForm.datosEnvio.checked==true) {
		borrarDatosEnvioOff()
	}
	document.myForm.instrucciones.value="";
	document.myForm.titular.value = "";
	document.myForm.numeroTarjeta.value = "";
}

function borrarDatosFactOff() {
	document.myForm.fempresa.value="";
	document.myForm.fnombre.value="";
	document.myForm.fapellidos.value="";
	document.myForm.femail.value="";
	document.myForm.fnif.value="";
	document.myForm.fdireccion.value="";
	document.myForm.fpoblacion.value="";
	document.myForm.fprovincia.value="";
	document.myForm.fcp.value="";
	document.myForm.ftelefono.value="";
	document.myForm.fotroTelefono.value="";
}


function borrarDatosEnvioOff() {
	document.myForm.eempresa.value="";
	document.myForm.enombre.value="";
	document.myForm.eapellidos.value="";
	document.myForm.eemail.value="";
	document.myForm.edireccion.value="";
	document.myForm.epoblacion.value="";
	document.myForm.eprovincia.value="";
	document.myForm.ecp.value="";
	document.myForm.etelefono.value="";
	document.myForm.eotroTelefono.value="";
}

//de facturacionenvio
function copiarDatosOff() {
	document.myForm.eempresa.value=document.myForm.fempresa.value;
	document.myForm.enombre.value=document.myForm.fnombre.value;
	document.myForm.eapellidos.value=document.myForm.fapellidos.value;
	document.myForm.eemail.value=document.myForm.femail.value;
	document.myForm.edireccion.value=document.myForm.fdireccion.value;
	document.myForm.epoblacion.value=document.myForm.fpoblacion.value;
	document.myForm.eprovincia.value=document.myForm.fprovincia.value;
	document.myForm.ecp.value=document.myForm.fcp.value;
	document.myForm.etelefono.value=document.myForm.ftelefono.value;
	document.myForm.eotroTelefono.value=document.myForm.fotroTelefono.value;
	if( document.myForm.epais.selectedIndex!=document.myForm.fpais.selectedIndex ) {
		document.myForm.epais.selectedIndex=document.myForm.fpais.selectedIndex;
		sincronizar();
	}
}

function sincronizar(igualfe) {
	opera('changePais');
}

function showTiempo(tMin,tMax,k) {
	var inp;
	for (var i=0; i< document.myForm.numeroMetodos.value;i++) {
		inp=document.getElementById('tiempo'+i);
		if (inp!=null && typeof(inp)!='undefined' && inp.nodeType==1){
			if (k!=i) {
				inp.style.display="none";
			}else{
				inp.style.display="inline";
			}
		}
	}
}

function selecRadio( elRadio, valor, checked ) {
	for( i = 0; i < elRadio.length; i++ ) {
		if( elRadio[i].value == valor ) {
			elRadio[i].checked = checked;
			break;
		}
	}
}

function ocultaDatosOff() {
	desactivaTarjeta();
	titular= document.myForm.titular.value;
	numeroTarjeta= document.myForm.numeroTarjeta.value;
	document.myForm.titular.value="";
	document.myForm.numeroTarjeta.value="";
	document.myForm.tarjeta.selectedIndex=0;
}

function activaChecked() {
	checked=true;
}

function getSelectedRadio(buttonGroup) {
	// returns the array number of the selected radio button or -1 if no button is selected
	if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		for (var i=0; i < buttonGroup.length; i++) {
			if (buttonGroup[i].checked) {
				return true;
			}
		}
	} else {
		if (buttonGroup.checked) {
			return true;
		} // if the one button is checked, return zero
	}
	// if we get to this point, no radio button is selected
	return false;
}

function getSelectedRadioValue(buttonGroup) {
	// returns the array number of the selected radio button or -1 if no button is selected
	if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		for (var i=0; i < buttonGroup.length; i++) {
			if (buttonGroup[i].checked) {
				return buttonGroup[i].value;
			}
		}
	} else {
		if (buttonGroup.checked) {
			return buttonGroup.value;
		} // if the one button is checked, return zero
	}
	// if we get to this point, no radio button is selected
	return -1;
}

function isVisa(cc){
	if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
		return isCreditCard(cc);
	return false;
}

function isMasterCard(cc){
	firstdig = cc.substring(0,1);
	seconddig = cc.substring(1,2);
	if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
		return isCreditCard(cc);
	return false;
}

function isAmericanExpress(cc){
	firstdig = cc.substring(0,1);
	seconddig = cc.substring(1,2);
	if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
		return isCreditCard(cc);
	return false;
}

function isDinersClub(cc){
	firstdig = cc.substring(0,1);
	seconddig = cc.substring(1,2);
	if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
		return isCreditCard(cc);
	return false;
}

function isCuentaLibreria(cc){
	if ((cc.length == 6) || (cc.length == 7))
		return isInteger(cc);
	return false;
}

function isCreditCard(st) {
	if (st.length > 19)
		return (false);

	sum = 0; mul = 1; l = st.length;
	for (i = 0; i < l; i++) {
		digit = st.substring(l-i-1,l-i);
		tproduct = parseInt(digit ,10)*mul;
		if (tproduct >= 10)
			sum += (tproduct % 10) + 1;
		else
			sum += tproduct;
		if (mul == 1)
			mul++;
		else
			mul--;
	}
	if ((sum % 10) == 0)
		return (true);
	else
		return (false);
}

function LTrim(str) {
	return str.replace(/^\s+/g, '');
}
function RTrim(str) {
	return str.replace(/\s+$/g, '');
}
function Trim(str) {
	return LTrim(RTrim(str));
}

function validarFormFactEnvio2(){
	var message="<ul>";
	var valida=true;

	if(isWhitespace(document.myForm.solicitud.value)) {
		message=message+"<li>Solicitud";
		valida=false;
	}

	if ((isWhitespace(document.myForm.fnombre.value)) || (isWhitespace(document.myForm.fapellidos.value)) || (isWhitespace(document.myForm.femail.value)) ||
		(isWhitespace(document.myForm.fdireccion.value)) || (isWhitespace(document.myForm.fpoblacion.value)) || (isWhitespace(document.myForm.fprovincia.value)) ||
		(isWhitespace(document.myForm.fcp.value)) || (isWhitespace(document.myForm.ftelefono.value))) {

			message=message+"<li>Campos obligatorios (*)";
			valida=false;
	} else {
		if (document.myForm.datosEnvio.checked) {
			if ((isWhitespace(document.myForm.enombre.value)) || (isWhitespace(document.myForm.eapellidos.value)) || (isWhitespace(document.myForm.eemail.value)) ||
				(isWhitespace(document.myForm.edireccion.value)) || (isWhitespace(document.myForm.epoblacion.value)) || (isWhitespace(document.myForm.eprovincia.value)) ||
				(isWhitespace(document.myForm.ecp.value)) || (isWhitespace(document.myForm.etelefono.value))) {

				message=message+"<li>Campos obligatorios (*)";
				valida=false;
			}
		}
	}

	if (document.myForm.factura) {
		if (document.myForm.factura.checked) {
			if (isWhitespace(document.myForm.fnif.value)) {
				message=message+"<li>El NIF / CIF es obligatorio";
				valida=false;
			}
		}
	}

	// Para comprobar que el código postal se corresponde con el país/provincia
	document.myForm.fcp.value=Trim(document.myForm.fcp.value);
	var fcpSub=(document.myForm.fcp.value).substring(0,2)+"";

	if(document.myForm.fpais.value=='3'){
		if(!(fcpSub=="07")){
			message=message+"<li>Campos pais y codigo postal no coinciden (*)";
			valida=false;
		}
	}

	if(document.myForm.fpais.value=='4'){
		if(!(fcpSub=="35" || fcpSub=="38" || fcpSub=="52" || fcpSub=="51")){
			message=message+"<li>Campos pais y codigo postal no coinciden (*)";
			valida=false;
		}
	}
	if(fcpSub=="35" || fcpSub=="38" || fcpSub=="52" || fcpSub=="51"){
		if(document.myForm.fpais.value=='2' || document.myForm.fpais.value=='3'){
			message=message+"<li>Campos pais y codigo postal no coinciden (*)";
			valida=false;
		}
	}

  	if ((document.myForm.fpais.value=='3') || (document.myForm.fpais.value=='4')) {
		if (fcpSub.indexOf("52") == 0 || fcpSub.indexOf("51") == 0 || fcpSub.indexOf("35") == 0 || fcpSub.indexOf("38") == 0) {
			// melilla, ceuta, gran canaria, tenerife
			document.myForm.factura.checked = true;
			document.getElementById("capaAsterisco").style.visibility="visible";
		}
	}

	if ((document.myForm.fpais.value=='2') || (document.myForm.fpais.value=='3') || (document.myForm.fpais.value=='4')) {
		if ( (!isInteger(document.myForm.fcp.value)) || (document.myForm.fcp.value.length!=5)) {
			message=message+"<li>Codigo Postal de facturacion";
			valida=false;
		}
	}

	if (document.myForm.datosEnvio.checked) {
		if ((document.myForm.epais.value=='2') || (document.myForm.epais.value=='3') || (document.myForm.epais.value=='4')) {
			if ( (!isInteger(document.myForm.ecp.value)) || (document.myForm.ecp.value.length!=5)) {
				message=message+"<li>Codigo Postal de envio";
				valida=false;
			}
		}
	}

	if ((!isWhitespace(document.myForm.femail.value)) && (!isEmail(document.myForm.femail.value))) {
		message=message+"<li>Email de Facturacion";
		valida=false;
	}
	if ((document.myForm.datosEnvio.checked) && (!isWhitespace(document.myForm.eemail.value)) && (!isEmail(document.myForm.eemail.value))) {
		message=message+"<li>Email de Envio";
		valida=false;
	}
	if (!valida) {
		message="<ul>"+message+"</ul>";
		document.myForm.error_msn.value=message;
		return false;
	} else return true;
}

/* Función de alerta */
function alertaRoja(c){
	alert(c);
}

function formatFloat (s) {
	var maxFraction= 2;
	var dotSeen= false;
	var k=0;
	var result="";
	var str=new String(s);

	for (var i = 0; (i < str.length) && (k <= maxFraction); i++){
		var c = str.charAt(i);
		if ((c == '.') || (dotSeen)) {
			dotSeen=true;
			k=k+1;
		}
		result=result+c;
	}
	return result;
}

function onClickTipo(k) {
	for (var i=0; i< document.myForm.numeroChkTipos.value;i++) {
		if (k!=i) {
			eval('document.myForm.tipoPago'+i+'.checked=false');
		} else {
			eval('document.myForm.tipoPago'+i+'.checked=true');
		}
	}
}

function processClicks() {
	return false;
}

/* Funciones para formaPago */
function hayTarjetaSeleccionada() {
	var index= document.myForm.tarjeta.selectedIndex;
	if (eval('document.myForm.nombreTarjeta'+index+'.value')=="") {
		return false;
	} else {
		return true;
	}
}

function ReplaceChar(String, OldChar, NewChar){
	for(n=0; n< String.length; n++){
		if (String.charAt(n) == OldChar) String = String.substring(0,n) + NewChar + String.substring(n+1,String.length);
	}
	return String;
}

function filterChars(cadena) {
	var str= cadena;
	str=ReplaceChar(str,'Ñ','&Ntilde;');
	str=ReplaceChar(str,'ñ','&ntilde;');
	str=ReplaceChar(str,'Á','&Aacute;');
	str=ReplaceChar(str,'É','&Eacute;');
	str=ReplaceChar(str,'Í','&Iacute;');
	str=ReplaceChar(str,'Ó','&Oacute;');
	str=ReplaceChar(str,'Ú','&Uacute;');
	str=ReplaceChar(str,'á','&aacute;');
	str=ReplaceChar(str,'é','&eacute;');
	str=ReplaceChar(str,'í','&iacute;');
	str=ReplaceChar(str,'ó','&oacute;');
	str=ReplaceChar(str,'ú','&uacute;');
	str=ReplaceChar(str,'¿','&iquest;');
	str=ReplaceChar(str,'¡','&iexcl;');
	str=ReplaceChar(str,'-','&macr;');
	str=ReplaceChar(str,'Ç','&Ccedil;');
	str=ReplaceChar(str,'ç','&ccedil;');
	str=ReplaceChar(str,'Ü','&Uuml;');
	str=ReplaceChar(str,'ü','&uuml;');
	str=ReplaceChar(str,'À','&Agrave;');
	str=ReplaceChar(str,'à','&agrave;');
	return str;
}

/*Pedido offline*/
function validarFormOff() {
	//valida los metodos de envio
	var solic=0
	var exist=0;
	var nan=0;
	var factu=0;
	var index=-1;
	var esTarjeta=false;
    var message='';

	if( !validarFormFactEnvio2() ) {
		return false;
	}

	if (document.myForm.factura) {
		if (document.myForm.factura.checked) {
			if (isWhitespace(document.myForm.fnif.value)) {
				message='<li>El NIF / CIF es obligatorio</li>';
				document.myForm.error_msn.value=message;
				return false;
			}
		}
	}

	//fin valida los campos del formulario de facturacion, direccion,tlf, etc..
	if (document.myForm.metodoEnvioChk.length == undefined){
		exist=1;
	}else{
        for (var i=0; i< document.myForm.metodoEnvioChk.length;i++) {
            if (document.myForm.metodoEnvioChk[i].checked){
                exist=1;
                break;
            }
        }
    }
    if (exist==0) message=message+'<li>M&eacute;todo de Env&iacute;o.</li>';

	for (var i=0; i< document.myForm.numeroChkTipos.value;i++) {
		var p= eval('document.myForm.tipoPago'+i+'.checked');
		if (p==true) {
			exist=1;
			index=i;
		}
	}

	if (exist==0) {
		message= message + '<li>Medio de Pago</li>';
	}else{
		if(eval('document.myForm.tipoPago'+index+'.value')=="7") {
            esTarjeta=true;
        }else{
            esTarjeta=false;
        }
    }

	if(index>=0 && esTarjeta){
		if (isWhitespace(document.myForm.titular.value) ) {
			message += '<li>Titular de la Tarjeta.</li>';
		}
		if( document.myForm.tarjeta[document.myForm.tarjeta.selectedIndex].value == -1 ) {
			message += '<li>Tipo de Tarjeta.</li>';
		} else {
			if( !esTarjetaValidaOff() ) {
				message += '<li>N&uacute;mero de la Tarjeta.</li>';
			}
		}
		if( !esFechaValida() ) {
			message += '<li>Fecha de caducidad.</li>';
		}
	}
    if (message!=''){
        document.myForm.error_msn.value='<ul>'+message+'</ul>';
        return false;
    }
	return true;
}

function limpiar() {
	deleteCookie("cart","/","");
}

function getNextSibling(startBrother){
	endBrother=startBrother.nextSibling;
	while(endBrother!=null && endBrother.nodeType!=1){
		endBrother = endBrother.nextSibling;
	}
	return endBrother;
}
function getFirstChild(startNode){
	var m=0;
	var hijo;
	if (startNode.hasChildNodes()){
		hijo=startNode.childNodes[0];
		while(m<(startNode.childNodes.length-1) && startNode.childNodes[m].nodeType!=1){
			m++;
			hijo=startNode.childNodes[m];
		}
	}
	return hijo;
}
function ocultar(obj){
if (esNodo(obj))
	obj.style.visibility="hidden";
}
function deshabPagos(){
    var index=0;
    var encon=false;
    var pagosNoPer="";
	if (document.myForm.metodoEnvioChk.length == undefined){
		encon=true;
		index=0;
	}else{
		for (var i=0;i<document.myForm.metodoEnvioChk.length;i++){
			if (document.myForm.metodoEnvioChk[i].checked){
				index=i;
				encon=true;
				break;
			}
		}
	}
    if (encon){
        pagosNoPer=eval('document.myForm.deshabTipPago'+index).value;
        if (!isEmpty(pagosNoPer)){
            var divPrin=document.getElementById("contTiposPago");
            if (esNodo(divPrin)){
                var nodoArray=divPrin.childNodes;
                var nodoAux;
                var idDiv="";
                for (var i=0;i<nodoArray.length;i++){
                    nodoAux=nodoArray[i];
                    if (esNodo(nodoAux) && !isEmpty(nodoAux.id) && nodoAux.id.length>9 && nodoAux.id.indexOf("contTPago")>-1){
                        idDiv=nodoAux.id.substring(nodoAux.id.indexOf("contTPago")+9);
                        if (pagosNoPer.indexOf("#"+idDiv+"#")>-1){
                            nodoAux.style.display="none";
                        }else{
                            nodoAux.style.display="block";
                        }
                    }
                }
            }
        }
    }
    encon=false;
    var numTiposPago=document.myForm.numeroChkTipos.value;
    var padreCheck;
    var objInp;
    for (i=0;i<numTiposPago;i++){
        objInp=eval('document.myForm.tipoPago'+i);
        if (objInp.checked){
            encon=true;
            index=i;
            padreCheck=objInp.parentNode;
            break;
        }
    }
    if (!encon || !esNodo(padreCheck) || (esNodo(padreCheck) && padreCheck.style.display=="none")){
        if (esNodo(padreCheck) && padreCheck.style.display=="none"){
            eval('document.myForm.tipoPago'+index).checked=false;
        }
        var optCheck=false;
        for (i=0;i<numTiposPago && !optCheck;i++){
            objInp=eval('document.myForm.tipoPago'+i);
            if (esNodo(objInp) && esNodo(objInp.parentNode) && objInp.parentNode.style.display=="block"){
                optCheck=true;
                objInp.checked=true;
                if (objInp.value=="7"){
                    activaTarjeta();
                }else{
                    desactivaTarjeta();
                }
                break;
            }
        }
    }
    document.myForm.recargoapli.value=0;
}
function esNodo(nodo){
    if (nodo!=null && typeof(nodo)!='undefined' && nodo.nodeType==1){
        return true;
    }else{
        return false;
    }
}