var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function LZ(x) {return(x<0||x>9?"":"0")+x}

function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=now.getDate();
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";

	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					month=i+1;
					if (month>12) { month -= 12; }
					i_val += month_name.length;
					break;
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return false; }
			}
		else { if (date > 28) { return false; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return false; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh+=12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}
	
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}


function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}

function isNotEmptyAlert(field) {
	var inputStr = field.value
	if (inputStr == "" || inputStr == null) {
		alert("This field requires an entry.")
		field.focus()
		field.select()
		return false
	}
	return true
}

function isNotEmpty(field) {
	var inputStr = Trim(field.value)
	if (inputStr == "" || inputStr == null) {
		return false
	}
	return true
}

function isNumberAlert(field) {
	if (isNotEmpty(field)) {
		var inputStr = Trim(field.value)
		for (var i = 0; i < inputStr.length; i++) {
			var oneChar = inputStr.substring(i, i + 1)
			if (oneChar < "0" || oneChar > "9") {
				alert("Please make sure entries are numbers only.")
				field.focus()
				field.select()
				return false
			}
		}
		return true
	}
	return false
}

function isNumber(field) {
	if (isNotEmpty(field)) {
		var inputStr = Trim(field.value)
		for (var i = 0; i < inputStr.length; i++) {
			var oneChar = inputStr.substring(i, i + 1)
			if (oneChar < "0" || oneChar > "9") {
				return false
			}
		}
		return true
	}
	return false
}

function isFloat(field) {
	if (isNotEmpty(field)) {
		var inputStr = Trim(field.value)
		for (var i = 0; i < inputStr.length; i++) {
			var oneChar = inputStr.substring(i, i + 1)
			if ((oneChar < "0" || oneChar > "9") && (oneChar != '.')) {
				return false
			}
		}
		return true
	}
	return false
}

// funciones afiliados
function afi_validar() {
	var myErrorText='';
	if (document.login.login.value=="") {
		myErrorText+='Usuario<br>';
	}
	if (document.login.password.value=="") {
		myErrorText+='Contraseña<br>';
	}

	if(myErrorText!='')	{
		open_error_window(myErrorText);
	} else {
		document.login.submit();
	}
}

function afi_cambiarIdioma (aHost) {
	var url;
	aLocale = document.loginidioma.idioma.options[document.loginidioma.idioma.selectedIndex].value;
	url = aHost + "/afiliados/loginafiliados";
	window.location = url;
}

function afi_abrir (pagina, aLocale) {
	var width, height, new_window;
	var chasm, mount, left, top;

	chasm = screen.availWidth;
	mount = screen.availHeight;

	width = 600;
	height = 500;
	
	left =((chasm - width - 10) * .5);
	top =((mount - height - 30) * .5);

	new_window = open("/afiliados/"+pagina,"displayWindow","scrollbars=yes,width="+width+",height="+height+",left="+ left +",top="+ top);
}

// fin funciones afiliados

function validarOpinion() {	
	myErrorText='';		
        var tipo='';
        if (document.envio.nombre.value=="") {
            myErrorText+='Nombre<br>';
        }
	if (!isEmail(document.envio.email.value)) {
            myErrorText+='E-mail<br>';
        }
	var check=0;
	for (var i=0; i < document.envio.valoracion.length;i++) {      
		if (document.envio.valoracion[i].checked) 
                    check=1;
	}
	if (check==0) {	
            myErrorText+='Valoración<br>';
        }
	if (document.envio.critica.value=="") {
                myErrorText+='Opini&oacute;n<br>';
        }
	if (myErrorText!='') {
             document.envio.error_msn.value=myErrorText; 	
            document.envio.action=document.envio.url.value;
            document.envio.submit();
	} else {
                if (document.envio.tipogeneral.checked) tipo = document.envio.tipogeneral.value + "|";
		if (document.envio.tiponoticia.checked) tipo = tipo + document.envio.tiponoticia.value;	
		document.envio.tipoboletin.value = tipo;
		/*if (!esES()) {
			document.envio.nombre.value=escape(document.envio.nombre.value);
			document.envio.critica.value=escape(document.envio.critica.value);
		}*/
		document.envio.submit();
	}
}    


function validaOtros() {
	var message="";
	var valida=true;
	var urldest="";
	if  (!isNotEmpty(document.formAtc.fnombre)) {		
		valida=false;
		message=message+" El nombre es obligatorio.";
	}		
	if (!isNotEmpty(document.formAtc.fapellidos)){
		valida=false;
		message=message+" Los apellidos son obligatorios.";
	}
 	 if (!isNotEmpty(document.formAtc.fpregunta)){
		valida=false;
		message=message+" La pregunta es obligatoria.";
	}

	if ( !isEmail(document.formAtc.fmail.value) ) {		
		message=message+" E-mail incorrecto o vacío.";
		valida=false;
	}	
	urldest=document.formAtc.url.value;
	if (!valida) {			
		document.formAtc.error_msn.value=message; 	
		document.formAtc.action=urldest;
		document.formAtc.submit();
	} else {
		/*if (!esES()) {
			document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
			document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
			document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
		}*/		
		document.formAtc.submit();
	}
}

function validaCV() {
	var message="";
	var valida=true;
	var urldest="";
	if  (!isNotEmpty(document.formAtc.fnombre)) {		
		valida=false;
		message=message+" El nombre es obligatorio.";
	}		
	if (!isNotEmpty(document.formAtc.fapellidos)){
		valida=false;
		message=message+" Los apellidos son obligatorios.";
	}

	if ( !isEmail(document.formAtc.fmail.value) ) {		
		message=message+" E-mail incorrecto o vac�o.";	
		valida=false;
	}
	
	if (!isNotEmpty(document.formAtc.ftelefono)){
		valida=false;
		message=message+" El tel&eacute;fono es obligatorio.";
	}
	
	if (!isNotEmpty(document.formAtc.fpregunta)){
		valida=false;
		message=message+" El CV es obligatorio.";
	}
	
	urldest=document.formAtc.url.value;
	if (!valida) {			
		document.formAtc.error_msn.value=message; 	
		document.formAtc.action=urldest;
		document.formAtc.submit();
	} else{
		/*if (!esES()) {
			document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
			document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
			document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
			document.formAtc.freferencia.value=escape(document.formAtc.freferencia.value);
			document.formAtc.fdisponible.value=escape(document.formAtc.fdisponible.value);
		}*/
		document.formAtc.submit();
	}
	
}

function validaPedidos(){
	var valida=true;
	var message="";	
	if (!isEmail(document.formAtc.fmail.value)) {		
		message=message+" E-mail incorrecto.";	
		valida=false;
	}	
	if  (!isNotEmpty(document.formAtc.fnombre)){
		valida=false;
		message=message+" El nombre es obligatorio.";
	}	
	if (!isNotEmpty(document.formAtc.fapellidos)){
		valida=false;
		message=message+" Los apellidos son obligatorios.";
	} 	 
	
	var i;
	var check=false;
    	for (i=0;i<document.formAtc.subtipoIncid.length;i++){ 
            if (document.formAtc.subtipoIncid[i].checked) {        		 	
                if ((i==1) || (i==3)){
                    if (!isNotEmpty(document.formAtc.fpregunta)){
                        valida=false;
			message=message+" La pregunta es obligatoria.";
                    }
                }
                check=true;
	        break;
            }
    	} 
	if(!check){
            valida=false;
            message=message+" Debe seleccionar un tipo de consulta.";
	}
	if (!valida) {			
            document.formAtc.error_msn.value=message; 	
            document.formAtc.action="/atc/incidenciaPedido";
            document.formAtc.submit();
	}else{
            /*if (!esES()) {
                document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
		document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
		document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
            }*/
            document.formAtc.submit();
	}	
}
function validaModificacionPedido(numPed){
	var valida=true;
	var message="";	
        if  (!isNotEmpty(document.formAtc.fnumero)){
		valida=false;
		message=message+" El número de pedido es obligatorio.";
	}
	if (!isEmail(document.formAtc.fmail.value)) {		
		message=message+" E-mail incorrecto.";	
		valida=false;
	}	
	if  (!isNotEmpty(document.formAtc.fnombre)){
		valida=false;
		message=message+" El nombre es obligatorio.";
	}	
	if (!isNotEmpty(document.formAtc.fapellidos)){
		valida=false;
		message=message+" Los apellidos son obligatorios.";
	} 	 
	
	var i;
	var check=false;
    	for (i=0;i<document.formAtc.subtipoIncid.length;i++){ 
            if (document.formAtc.subtipoIncid[i].checked) {        		 	
                if ((i==1) || (i==2) || (i==0) ){
                    if (!isNotEmpty(document.formAtc.fpregunta)){
                        valida=false;
			message=message+" La pregunta es obligatoria.";
                    }
                }
                check=true;
	        break;
            }
    	} 
	if(!check){
            valida=false;
            message=message+" Debe seleccionar el tipo de modificación.";
	}
	if (!valida) {			
            document.formAtc.error_msn.value=message; 	
            document.formAtc.action="/atc/modificacionPedido?codPed="+numPed;
            document.formAtc.submit();
	}else{
            /*if (!esES()) {
                document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
		document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
		document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
            }*/
            document.formAtc.submit();
	}	
}


function validaRespuestas(){ //para las respuestas con radiobutton si/no
	var valida=true;
	message="";
	var urldest="";
	var check=false;
	var i;
	urldest=document.formAtc.url.value;
	for (i=0;i<document.formAtc.respuesta.length;i++){
		if (document.formAtc.respuesta[i].checked){
			check=true;
		}
	}
	if (!check){
		valida=false;
		message="Debe marcar una respuesta.";
	}	
	if (!valida) {			
		document.formAtc.error_msn.value=message; 	
		document.formAtc.action=urldest;
		document.formAtc.submit();
	}else{
		/*if (!esES()) {
			document.formAtc.fcomentarios.value=escape(document.formAtc.fcomentarios.value);
		}*/		
		document.formAtc.submit();
	}
}

function validaRespuestaSin(){  //para las respuestas sin radiobutton si/no
	var valida=true;
	var message="";
	var urldest="";
	urldest=document.formAtc.url.value;
	if (!isNotEmpty(document.formAtc.fcomentarios) ){
		valida=false;
		message=message+" El comentario es obligatorio.";
	}
	if (!valida) {			
		document.formAtc.error_msn.value=message; 	
		document.formAtc.action=urldest;
		document.formAtc.submit();
	}else{
		/*if (!esES()) {
			document.formAtc.fcomentarios.value=escape(document.formAtc.fcomentarios.value);
		}*/		
		document.formAtc.submit();
	}
}

function validaCambioEmail(){
	var valida=true;
	var message="";
	if (document.formAtc.fmailnew.value == document.formAtc.fmailnew2.value){
		valida=true;
	}else{
		message=message+" El e-mail nuevo y su confirmaci&oacute;n no coinciden.";
		valida=false;
	}
	if (!isEmail(document.formAtc.fmailold.value)) {		
		message="E-mail antiguo incorrecto.";	
		valida=false;
	}
	if (!isEmail(document.formAtc.fmailnew.value)) {		
		message=message+" E-mail nuevo incorrecto.";	
		valida=false;
	}
	if (!isEmail(document.formAtc.fmailnew2.value)) {		
		message=message+" Confirmaci&oacute;n E-mail nuevo incorrecto.";	
		valida=false;
	}
	if (!isNotEmpty(document.formAtc.fpassword)){
		valida=false;
		message=message+" La contrase&ntilde;a es obligatoria.";
	} 
	if (!valida) {			
		document.formAtc.error_msn.value=message; 	
		document.formAtc.action="/atc/incidenciaCambioEmail";
		document.formAtc.submit();
	}else{
		
		document.formAtc.submit();
	}
}
function validaConsBiblio(){        
	var valida=true;
	var message="";
	if (!isEmail(document.fConsultaBib.tEmail.value)) {		
		message=message+" E-mail incorrecto.";	
		valida=false;
	}
	
	if  (!isNotEmpty(document.fConsultaBib.tNombre)){
		valida=false;
		message=message+" El nombre es obligatorio.";
	}	
	if (!isNotEmpty(document.fConsultaBib.tApellidos)){
		valida=false;
		message=message+" Los apellidos son obligatorios.";
	} 	 
	if (!isNotEmpty(document.fConsultaBib.tTelefono)) {         
  		message = message + " El tel&eacute;fono es obligatorio.";
	}
	if (!isNotEmpty(document.fConsultaBib.taPreguntaLibro)) {
		valida=false;
  		message = message + " La pregunta es obligatoria.";
	}
	
	if (!valida) {			
		document.fConsultaBib.error_msn.value=message; 	
		document.fConsultaBib.action="/atc/incidenciaConsultaBiblio";
		document.fConsultaBib.submit();
	}else{
		/*if (!esES()) {
			document.fConsultaBib.tNombre.value=escape(document.fConsultaBib.tNombre.value);
			document.fConsultaBib.tApellidos.value=escape(document.fConsultaBib.tApellidos.value);
			document.fConsultaBib.taPreguntaLibro.value=escape(document.fConsultaBib.taPreguntaLibro.value);
		}*/
		document.fConsultaBib.submit();
	}	
}

function validaPedidosEmpresas(){
	var valida=true;
	var message="";
	var i;
	var check=false;
	
    	for (i=0;i<document.formInc.subtipoIncid.length;i++){ 
	      	 if (document.formInc.subtipoIncid[i].checked) {
         		if ((i==1) || (i==3) || (i==4) ){
         		 	if (!isNotEmpty(document.formInc.fpregunta)){
					valida=false;
					message=message+" La pregunta es obligatoria.";
				}
	         	}
	         	check=true;
	         	break;
	         }
    	} 
    	
	if(!check){
		valida=false;
		message=message+" Debe seleccionar un tipo de consulta.";
	}
	
	if (document.formInc.fnumero.value.length != 10){	
		valida=false;
		message=message+" C&oacute;digo de pedido incorrecto o vac&iacute;o.";
	}
	
	if (!isNotEmpty(document.formInc.fnombre)) {		
		message=message+" Debe poner su nombre.";	
		valida=false;
	}
	
	if (!isNotEmpty(document.formInc.fapellidos)) {		
		message=message+" Debe poner sus apellidos.";	
		valida=false;
	}
	
	if (!isEmail(document.formInc.fmail.value)) {		
		message=message+" E-mail incorrecto o vac&iacute;o.";	
		valida=false;
	}
	
	if (!valida) {	
		document.formInc.error_msn.value=message; 	
		document.formInc.action="/empresas/incidenciaempresas";
		document.formInc.submit();
	}else{
		/*if (!esES()) {
			document.formInc.fnombre.value=escape(document.formInc.fnombre.value);
			document.formInc.fapellidos.value=escape(document.formInc.fapellidos.value);
			document.formInc.fpregunta.value=escape(document.formInc.fpregunta.value);
		}*/		
		document.formInc.submit();
	}	
}
function validaPedidosEmpresasSugerencias(){
	var valida=true;
	var message="";
	
	if (!isNotEmpty(document.formInc.fnombre)) {		
		message=message+" Debe poner su nombre.";	
		valida=false;
	}
	
	if (!isNotEmpty(document.formInc.fapellidos)) {		
		message=message+" Debe poner sus apellidos.";	
		valida=false;
	}
	
	if (!isEmail(document.formInc.fmail.value)) {		
		message=message+" E-mail incorrecto o vac&iacute;o.";	
		valida=false;
	}
	if (!valida) {	
		document.formInc.error_msn.value=message;
		document.formInc.action="/empresas/incidenciasugerenciaempresas";
		document.formInc.submit();
	}else{
		/*if (!esES()) {
			document.formInc.fnombre.value=escape(document.formInc.fnombre.value);
			document.formInc.fapellidos.value=escape(document.formInc.fapellidos.value);
			document.formInc.fpregunta.value=escape(document.formInc.fpregunta.value);
		}*/	
		document.formInc.submit();
	}	
}

function validaPedidosEmpresasOtros(){
	var valida=true;
	var message="";
	
	if (!isNotEmpty(document.formInc.fnombre)) {		
		message=message+" Debe poner su nombre.";	
		valida=false;
	}
	
	if (!isNotEmpty(document.formInc.fapellidos)) {		
		message=message+" Debe poner sus apellidos.";	
		valida=false;
	}
	
	if (!isEmail(document.formInc.fmail.value)) {		
		message=message+" E-mail incorrecto o vac&iacute;o.";	
		valida=false;
	}
	if (!valida) {
		document.formInc.error_msn.value=message;
		document.formInc.action="/empresas/incidenciaotrosempresas";
		document.formInc.submit();
	}else{
		/*if (!esES()) {
			document.formInc.fnombre.value=escape(document.formInc.fnombre.value);
			document.formInc.fapellidos.value=escape(document.formInc.fapellidos.value);
			document.formInc.fpregunta.value=escape(document.formInc.fpregunta.value);
		}*/	
		document.formInc.submit();
	}	
}

/********* VALIDACION DE LOS CAMPOS DE LOS FORMULARIOS DE PEDIDO Y GESTOR COMERCIAL ********/
function validaPedidosEmpresasPresupuesto(){

	var valida=true;
	var message="";
    var textError = document.getElementById("textoError");
    

	if (!isNotEmpty(document.formInc.fnombre)) {
		message=message+" Debe poner su nombre.";
		valida=false;
	}

	if (!isNotEmpty(document.formInc.fapellidos)) {
		message=message+" Debe poner sus apellidos.";
		valida=false;
	}
    
	if (!isEmail(document.formInc.fmail.value)) {
		message=message+" E-mail incorrecto o vacio.";
		valida=false;
	}

    if(!isNotEmpty(document.formInc.ftelefono)){
        message=message+"Debe poner el telefono.";
        valida=false;
    }

    if(document.formInc.fpedido!=null && typeof(document.formInc.fpedido)!='undefined'){
    if(!isNotEmpty(document.formInc.fpedido)){
        message=message+"Debe poner el pedido."
        valida=false;
    }
    }

    if(document.formInc.fpregunta!=null && typeof(document.formInc.fpregunta)!='undefined'){
    if(!isNotEmpty(document.formInc.fpregunta)){
        message=message+"Debe poner la pregunta.";
        valida=false;
    }
    }

    if(document.formInc.flistado!=null && typeof(document.formInc.flistado)!='undefined'){
    if(!isNotEmpty(document.formInc.flistado)){
        message=message+"Debe poner el listado de libros.";
        valida=false;
    }
    }

var textoError;
	if (!valida) {
        //document.formInc.error_msn.value=message;
		//document.formInc.action="/empresas/incidenciaotrosempresas";
		//document.formInc.submit();
        if(textError != null){
           //textoError = document.createTextNode(message);
           //textError.value=textoError;
           textError.innerHTML="<img src='/i/error2.gif' alt='error datos' />"+message;
           
        }else{
        var parrafo = document.createElement("p");
        var imagen = document.createElement("IMG");
        imagen.setAttribute("id", "miImagen");
        imagen.setAttribute("src", "/i/error2.gif");
        textoError = document.createTextNode(message);
        parrafo.id="textoError";
        parrafo.style.fontFamily="Arial";
        parrafo.style.fontWeight="bold";
        parrafo.style.fontSize="13px"
        parrafo.style.color="#8A0808";
        parrafo.style.textDecoration="none";
        parrafo.style.textAlign="justify";
        parrafo.appendChild(imagen);
        parrafo.appendChild(textoError);
        
        document.getElementById("error").appendChild(parrafo);
        
    }
        //document.getElementById("error").style.visibility="visible";
	}else{
		/*if (!esES()) {
			document.formInc.fnombre.value=escape(document.formInc.fnombre.value);
			document.formInc.fapellidos.value=escape(document.formInc.fapellidos.value);
			document.formInc.fpregunta.value=escape(document.formInc.fpregunta.value);
		}*/
        document.getElementById("enviar").style.visibility="hidden";
		document.formInc.submit();
	}
}

function validaConsulta(){
	var valida=true;
	var message="";
	
	if (!isNotEmpty(document.formInc.fnombre)) {		
		message=message+" Debe poner su nombre.";	
		valida=false;
	}
	
	if (!isNotEmpty(document.formInc.fapellidos)) {		
		message=message+" Debe poner sus apellidos.";	
		valida=false;
	}
	
	if (!isEmail(document.formInc.fmail.value)) {		
		message=message+" E-mail incorrecto o vac&iacute;o.";	
		valida=false;
	}
	
	if (!isNotEmpty(document.formInc.ftelefono)) {		
		message=message+" Debe poner Un tel&eacute;fono de contacto.";	
		valida=false;
	}
	
	if (!valida) {	
		document.formInc.error_msn.value=message;	
		document.formInc.action="/empresas/consultabibliograficaempresa";
		document.formInc.submit();
	}else{
		/*if (!esES()) {
			document.formInc.fnombre.value=escape(document.formInc.fnombre.value);
			document.formInc.fapellidos.value=escape(document.formInc.fapellidos.value);
			document.formInc.fpregunta.value=escape(document.formInc.fpregunta.value);
		}*/	
		document.formInc.submit();
	}	
}

function clearDatosConsulta() {
	document.formInc.fnombre.value='';
	document.formInc.fapellidos.value='';
	document.formInc.fmail.value='';
	document.formInc.ftelefono.value='';
}

/*A�adidas para que funcione RESPUESTATARJETA*/

var DINNERSCLUB = 1;
var MASTERCARD = 2;
var VISA = 3;
var AMERICANEXPRESS = 4;
var CONTRAREEMBOLSO = 5;
var CUENTALIBRERIA = 6;
var UNDEFINED = 7;
var BPE = 8;
 
function isDigit (c) {   
	return ((c >= "0") && (c <= "9"));
}

function isInteger (s) {   
	if ((s == null) || (s.length == 0)) return false;
	var i;
	for (i = 0; i < s.length; i++){
		// Check that current character is number.
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	// All characters are numbers.
	return true;
}
 
function esTarjetaValidaRes() {
	var index= document.formAtc.ftipo.selectedIndex;
	if (eval(document.formAtc.ftipo[index].value)==VISA) {
		return isVisa(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==MASTERCARD) {
		return isMasterCard(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==AMERICANEXPRESS) {
		return isAmericanExpress(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==DINNERSCLUB) {
		return isDinersClub(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==CUENTALIBRERIA) {
		return isCuentaLibreria(document.formAtc.ftarjeta.value);
	} else return false;
}


function validaTarjetaRes(){ //para las respuestas con radiobutton si/no
	var valida=true;
	message="";
	var urldest="";
	var check=false;
	var i;
	urldest=document.formAtc.url.value;

	for (i=0;i<document.formAtc.respuesta.length;i++){
		if (document.formAtc.respuesta[i].checked){
			check=true;
		}
	}
	if (!check){
		valida=false;
		message="<li>Debe marcar una respuesta.</li>";
	}
	if (check && document.formAtc.respuesta[0].checked){
		if (!isNotEmpty(document.formAtc.ftitular) ) {
			message += '<li>Titular de la Tarjeta.</li>';
			valida=false;
		}
		if( eval(document.formAtc.ftipo[document.formAtc.ftipo.selectedIndex].value) == -1 ) {
			message += '<li>Tipo de Tarjeta.</li>';
			valida=false;
		} else {
			if( !esTarjetaValidaRes() ) {
				message += '<li>N&uacute;mero de la Tarjeta.</li>';
				valida=false;
			}
		}
		if( !esFechaValida() ) {
			message += '<li>Fecha de caducidad.</li>';
			valida=false;
		}
		if (!valida) {
			document.formAtc.error_msn.value='<ul>'+message+'</ul>';
			document.formAtc.action=urldest;
			document.formAtc.submit();
		}else{
			/*if (!esES()) {
				document.formAtc.ftitular.value=escape(document.formAtc.ftitular.value);
				document.formAtc.fcomentarios.value=escape(document.formAtc.fcomentarios.value);
			}*/		
			document.formAtc.submit();
		}
	}else {
		if (!check){
			document.formAtc.error_msn.value='<ul>'+message+'</ul>';
			document.formAtc.action=urldest;
			document.formAtc.submit();
		}else{
			if(document.formAtc.respuesta[1].checked) document.formAtc.submit();
		}
	}
}

function isVisa(cc){
	if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4)){
		return isCreditCard(cc);
	}else 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 esFechaValida() {
	var mesActual= document.formAtc.mesActual.value * 1;
	var anoActual= document.formAtc.anoActual.value *1;
	var mesTarjeta= document.formAtc.mes[document.formAtc.mes.selectedIndex].value * 1;
	var anoTarjeta= document.formAtc.ano[document.formAtc.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 clearDatosConsulta() {
	document.fConsultaBib.tNombre.value='';
	document.fConsultaBib.tApellidos.value='';
	document.fConsultaBib.tEmail.value='';
	document.fConsultaBib.tTelefono.value='';
}

function validateConsulta(form) {
	var message='<ul>';

	if (!isNotEmpty(form.tTelefono)) {         
		message = message + '<li>Telefono.';    
	}

	if (!isNotEmpty(form.tEmail)) {
		message = message + '<li>e-mail.';
	}

	if (!isNotEmpty(form.tApellidos)) {
		message = message + '<li>Apellidos.';
	}

	if (!isNotEmpty(form.tNombre)) {
		message = message + '<li>Nombre.';
	}
	if ((!isNotEmpty(form.taPreguntaMateria)) && (!isNotEmpty(form.taPreguntaLibro))) {
		message = message + '<li>Pregunta.';
	}
	if (message != '<ul>') {
		message = message + '</ul>';
		document.fConsultaBib.error_msn.value=message; 
		document.fConsultaBib.action="/servicios/consultaBibliograficain"; 
		document.fConsultaBib.submit();
	} else {
		if (!checkTextLength(form.taPreguntaMateria, 'Pregunta Materia', 100)) {
			return false;
		}
		if (!checkTextLength(form.taPreguntaLibro, 'Pregunta Libro', 600)) {
			return false;
		};
		var inputStr = Trim(form.tEmail.value);
		var atFound=false;
		var dotFound=false;
		for (var i = 0; i < inputStr.length; i++) {
			var oneChar = inputStr.substring(i, i + 1)
			if (oneChar == '.') {
				dotFound=true;
			}
			if (oneChar == '@') {
				atFound=true;
			} 
		}
		if ( (!atFound) || (!dotFound) ){
			var message='<ul><li>e-mail incorrecto.</ul>';
			document.fConsultaBib.error_msn.value=message; 
			document.fConsultaBib.action="/servicios/consultaBibliograficain"; 
			document.fConsultaBib.submit();
		}
		/*if (!esES()) {
			document.fConsultaBib.tNombre.value=escape(document.fConsultaBib.tNombre.value);
			document.fConsultaBib.tApellidos.value=escape(document.fConsultaBib.tApellidos.value);
			document.fConsultaBib.taPreguntaMateria.value=escape(document.fConsultaBib.taPreguntaMateria.value);
			document.fConsultaBib.taPreguntaLibro.value=escape(document.fConsultaBib.taPreguntaLibro.value);
		}*/
		return true;
	}
}

function confirmarPedido(){
	var message="";
	var valido= new Boolean(false);

	if(document.formConfirmaPedido.radioConfirmacion[0].checked){
		//Confirma pedido
		document.formConfirmaPedido.accion.value="Confirmar";
		valido=true;
	}else 
		if (document.formConfirmaPedido.radioConfirmacion[1].checked){
			//Anula lineas agotadas
			document.formConfirmaPedido.accion.value="AnularAgotadas";
			//si hay mas de un checkbox
			if(document.formConfirmaPedido.libroCheck.length>1){
				for(var i=0; i < document.formConfirmaPedido.libroCheck.length; i++){
					if(document.formConfirmaPedido.libroCheck[i].checked){
						valido = true;
					}
				}
			}else{
				//Solo hay un checkbox
				if(document.formConfirmaPedido.libroCheck.checked){
					valido = true;
				}
			}   
			if(valido==false){
				message=message+"Debe seleccionar las lineas que quiere borrar";	
			}
		}else 
			if (document.formConfirmaPedido.radioConfirmacion[2].checked){
				//Anula pedido
				valido=true;
				document.formConfirmaPedido.accion.value="AnularPedido";
			}
	if (valido==false) {			
		document.formConfirmaPedido.error_msn.value=message; 	
		document.formConfirmaPedido.action="/atc/confirmacionPedido";
	}
	document.formConfirmaPedido.submit();
}

function validaSolicitudAgotados(){
	var valida=true;
	var message="";
	if (!isEmail(document.formularioSolicitudAgotados.tEmail.value)) {		
		message=message+" E-mail incorrecto.";	
		valida=false;
	}
	
	if (!valida) {	
		document.formularioSolicitudAgotados.error_msn.value=message; 	
		document.formularioSolicitudAgotados.action="/otros/solicitudAlarmaAgotados";
		document.formularioSolicitudAgotados.submit();
	}else{		
                var tipo="";
		if (document.formularioSolicitudAgotados.tipogeneral.checked){
                    tipo = document.formularioSolicitudAgotados.tipogeneral.value + "|";
                }
		if (document.formularioSolicitudAgotados.tiponoticia.checked){
                    tipo = tipo + document.formularioSolicitudAgotados.tiponoticia.value;	
                }
		document.formularioSolicitudAgotados.tipoboletin.value = tipo;	
		document.formularioSolicitudAgotados.submit();
	}	
}

function clearDatosSolicitudAlarma() {
	document.formularioSolicitudAgotados.tEmail.value='';
}
