function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
/*function dameCookie(str){
	var retorno;
	var c_start=document.cookie.indexOf(str + '=');
	if (c_start!=-1){
		c_start=c_start + (str + '=').length;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1){
			c_end=document.cookie.length;
		}
		retorno = unescape(document.cookie.substring(c_start,c_end));
	}else{
		retorno = null;
	}
	return retorno;
}*/
function leerMas(value){
	document.getElementById(value).submit();
}
function cambiaIdioma(value){
	//document.cookie='idioma=' + value;
	createCookie('idioma',value,1);
	//document.cookie='anuncio=';
	//document.cookie='video=';
	var newLoc = location.href.split('?');
	if(newLoc.length>0){
		location.replace(newLoc[0]);
	}else{
		location.reload();
	}
}
function cambiaBanner(value){
	createCookie('banner',value,1);
	//document.cookie='banner=' + value;
}
function callVideo(name,value){
	var video = readCookie('video');
	var anuncio = readCookie('anuncio');
	if(video!=null && anuncio!=null){
		document.getElementById(video).className = 'boton_anuncio';
		var url = '<a href="javascript:callVideo(\''+video+'\',\''+anuncio+'\');">'+video+'</a>';
		document.getElementById(video).innerHTML = url;
	}
	document.getElementById(name).className = 'anuncio_select';
	document.getElementById(name).innerHTML = name;
	createCookie('anuncio',value,1);
	createCookie('video',name,1);
	//document.cookie='anuncio=' + value;
	//document.cookie='video=' + name;
	
	//ply.callAnuncio(value);
	callAnuncio(value);
}
function callAnuncio(url){
	var source = 'player/reproductor.swf';
	if(url.indexOf('http://')>-1){
		source = url+'&hl=es_ES&fs=1&rel=0&color1=0x82be32&color2=0x358996';
	}
	  var so = new SWFObject(source,'ply','265','235','9','#ffffff');
	  so.addParam('allowfullscreen','true');
	  so.addParam('allowScriptAccess','always');
	  so.addParam('wmode','opaque');
	  var img = 'images/video.png';
	  so.addVariable('file',url);
	  so.addVariable('image',img);
	  so.addVariable('fullscreen','true');
	  so.addVariable('stretching','fill');
	  so.write('video_player');
}
function callLogo(value){
	createCookie('stoped',value,1);
	//document.cookie='stoped=' + value;
}
function changeCHContacto(val){
	document.contacto.ch_distribuir.checked = false;
	document.contacto.ch_productos.checked = false;
	document.contacto.ch_venta.checked = false;
	document.contacto.ch_otros.checked = false;
	val.checked = true;
}

function controlInput(value,event){
	var tecla = '';
	if(document.all){
		tecla = event.keyCode;
	}else{
		tecla = event.which;
	}
	switch(value.name){
		case 'telefono':
			if (tecla < 48 || tecla > 57)
				return false;
			break;
		default:
			if (tecla == 39 || tecla == 60 || tecla == 62)
				return false;
			else
				return true;
			break;
	}
}

function emailCorrecto(value){
	var parte1 = value.indexOf('@');
	var parte2 = value.lastIndexOf('.');
	if(parte1>1 && parte2>(parte1+2) && parte2<(value.length-2)){
		return true;
	}else{
		return false;
	}
}
function enviarContacto(cita){
	var status = '';
	if(document.contacto.email.value.length<=0){
		status += document.contacto.msg1.value+'\r';
	}else if(document.contacto.confemail.value.length<=0){
		status += document.contacto.msg2.value+'\r';
	}else if(emailCorrecto(document.contacto.email.value)){
		if(document.contacto.confemail.value != document.contacto.email.value){
			status += document.contacto.msg4.value+'\r';
		}else{
			if(document.contacto.nombre.value.length>0 && document.contacto.telefono.value.length>0){
				var msg = "<table>";
				if(cita){
					var dia = document.contacto.dia.options[document.contacto.dia.selectedIndex].value;
					var mes = document.contacto.mes.options[document.contacto.mes.selectedIndex].value;
					var hora = document.contacto.hora.options[document.contacto.hora.selectedIndex].value;
					msg += '<tr><td colspan="2">El paciente ' + document.contacto.nombre.value;
					msg += ' con teléfono ' + document.contacto.telefono.value;
					msg += ', ha solicitado cita el dia ' + dia;
					msg += ' de ' + mes + ' a las ' + hora + '.</td></tr>';
				}else{
					msg += '<tr><td>Nombre:</td><td>' + document.contacto.nombre.value + '</td></tr>';	
					msg += '<tr><td>Teléfono:</td><td>' + document.contacto.telefono.value + '</td></tr>';	
				}
				if(document.contacto.mensaje.value.length>0){
					msg += "<tr><td>Comentario:</td><td>" + document.contacto.mensaje.value + "</td></tr>";
				}
				msg += "</table>";
				document.contacto.msg.value = msg;
				document.contacto.envia.value = true;
				document.contacto.submit();
			}else{
				status += document.contacto.msg7.value+'\r';
			}
		}
	} else {
		status += document.contacto.msg3.value+'\r';
	}
	if(status.length>0){
		alert(status);	
	}
}
function clearContacto(val){
	document.contacto.msg.value = '';
	document.contacto.subject.value = '';
	document.contacto.envia.value = false;
	document.contacto.nombre.value = '';
	document.contacto.email.value = '';
	document.contacto.confemail.value = '';
	document.contacto.telefono.value = '';
	document.contacto.mensaje.value = '';
	document.contacto.nombre.focus();
}
function nuevoContacto(){
	document.contacto.submit();
}
function accesoClub(){
	var status = '';
	if(document.form_acceso.user.value.length<=0){
		status += document.form_acceso.msg_acceso1.value+'\r';
	}else if(document.form_acceso.pass.value.length<=0){
		status += document.form_acceso.msg_acceso2.value+'\r';
	}else{
		status += document.form_acceso.msg_acceso3.value+'\r';
		document.form_acceso.submit();
	}
	if(status.length>0){
		alert(status);	
	}
}
function suscribirNews(){
	var status = '';
	if(document.form_newsletter.email.value.length<=0){
		status += document.form_newsletter.msg_news1.value+'\r';
	}else{
		if(emailCorrecto(document.form_newsletter.email.value)){
			status += document.form_newsletter.msg_news3.value+'\r';
			document.form_newsletter.submit();
		}else{
			status += document.form_newsletter.msg_news2.value+'\r';
		}
	}
	if(status.length>0){
		alert(status);	
	}
}
