//GOOGLE MAP
function load(lati,longi) {
	if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));

		map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(lati,longi), 17);
						
		//marca puntual
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		//map.addOverlay(new GMarker(point));
       

		//Icono Logo RYC
		var point2 = new GLatLng(southWest.lat() + latSpan/2  , southWest.lng() + lngSpan/2 );
		
		var icono2=new GIcon();
		icono2.image="http://www.carril10.com/images/icono_google_map.png";
		icono2.iconSize=new GSize(29,28);
		icono2.shadowSize=new GSize(29,28);
		icono2.iconAnchor=new GPoint(10,45);
		var marker2 = new GMarker(point2, icono2);
		map.addOverlay(marker2);


    }
}

//AÑADIR A FAVORITOS
function bookmarksite(title, url){
  if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else
		alert("Presione Crtl+D para agregar este sitio en sus Bookmarks"); 
} 


//CESTA
function suma_cesta(articulo,precio,cuantos,accion,comple,sec)
{  
	if(comple!=1){
		comple=0;
	}
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_box_bolsa_roja";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/box_bolsa_roja.php" ;
	url=url+"?articulo="+articulo+"&precio="+precio+"&cuantos="+cuantos+"&accion="+accion+"&comple="+comple+"&sec="+sec;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}


function comprueba_quedan_articulos()
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			//alert(xmlHttp.responseText);
			if(xmlHttp.responseText.length>10){
				//document.getElementsByTagName('body').className="";
				var div_carga="content";
				document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
				window.location.reload();
			}
		}
	}
	var url="principales/ajax/comprueba_quedan_articulos.php" ;
	url=url+"?id=1";
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}

function busca_precio(cod_barras, cant, comple)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			//return xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
	var url="principales/ajax/busca_precio.php" ;
	url=url+"?id=" + cod_barras + "&cuantos=" + cant + "&comple=" + comple;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}

function anadir_datos_facturacion(valor)
{  

	if(valor==1){

		var xmlHttp=null;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}


		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var div_carga="anadir_direccion_factu";
				document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
			}
		}
		var url="principales/ajax/anadir_datos_facturacion.php" ;
		url=url+"?id=" + valor;
		url=url+"&sid="+Math.random();
		//alert(url);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);  
	}else{
		var div_carga="anadir_direccion_factu";
		document.getElementById(div_carga).innerHTML="";
	}
}


function muestra_form_compra(cod_barras,event){
	   
	   var NS = (navigator.appName=="Netscape")?true:false; 
       iWidth = (NS)?window.innerWidth:document.body.clientWidth; 
       iHeight = (NS)?window.innerHeight:document.body.clientHeight; 
	   
	   /*
	   iWidth =  screen.availWidth;
	   iHeight = screen.availHeight;
	   */
	   var postop=(iHeight/2)-90;
	   var posleft=(iWidth/2)-20;
	   x=event.clientX;
	   y=event.clientY;


		if(document.getElementById('cest_vista').value!=0){
			 var form_compra_="form_compra_" + document.getElementById('cest_vista').value;
		  	 document.getElementById(form_compra_).style.display="none";
		}


	   var form_compra_="form_compra_" + cod_barras;
  	   document.getElementById(form_compra_).style.display="block";
	   document.getElementById('cest_vista').value=cod_barras;

}


//NEWSLETTER
function anade_email(email)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="content_news";
			document.getElementById(div_carga).style.display='none';
			var div_carga="aviso_content_news";
			document.getElementById(div_carga).style.display='block';
			//document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/anade_email.php" ;
	url=url+"?email="+email;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}



//proceso_compra1 -> Login / Registro

function valida_login(){
	var email="email";
	if(document.getElementById(email).value.length<5){
		alert("Introduzca su email");
		document.getElementById(email).focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById(email).value);
		if(resu ==false){
			 document.getElementById(email).focus();
			 return resu;
		}
	
	}


	var contrasena="contrasena";
	if(document.getElementById(contrasena).value.length<5){
		alert("Introduzca su contraseña");
		document.getElementById(contrasena).focus();
		return false;
	}

}



function valida_modifi_pass(){
	var contrasena="contrasena_actu";
	if(document.getElementById(contrasena).value.length<5){
		alert("Introduzca su contraseña actual (6-15 caracteres)");
		document.getElementById(contrasena).focus();
		return false;
	}

	if(!(valida_registro_mail_pass('1'))){
		return false;
	}	
	return true;
}


function valida_registro_mail_pass(val_email){
	if(val_email!=1){
		var email="email_reg";
		if(document.getElementById(email).value.length<5){
			alert("Introduzca su email");
			document.getElementById(email).focus();
			return false;
		}else{
			var resu=emailCheck (document.getElementById(email).value);
			if(resu ==false){
				 document.getElementById(email).focus();
				 return resu;
			}
		
		}
	}

	var contrasena="contrasena_reg";
	if(document.getElementById(contrasena).value.length<6){
		alert("Introduzca su contraseña (6-15 caracteres)");
		document.getElementById(contrasena).focus();
		return false;
	}

	var contrasena2="contrasena2_reg";
	if(document.getElementById(contrasena2).value.length<6){
		alert("Repita su contraseña (6-15 caracteres)");
		document.getElementById(contrasena2).focus();
		return false;
	}
	
	if(document.getElementById(contrasena).value!=document.getElementById(contrasena2).value){
		alert("Las contraseñas introducidas no coinciden");
		document.getElementById(contrasena2).focus();
		return false;
	}
		return true;
}

function valida_registro_datos(nombre,apellido1,apellido2,telefono,direccion,cp,localidad,provincia,focus){
	if(focus!=1) focus=0;
	//var nombre="nombre";
	if(document.getElementById(nombre).value.length<3){
		alert("Introduzca su nombre");
		if(focus!=1) document.getElementById(nombre).focus();
		return false;
	}

	//var apellido1="apellido1";
	if(document.getElementById(apellido1).value.length<3){
		alert("Introduzca su apellido");
		if(focus!=1) document.getElementById(apellido1).focus();
		return false;
	}

	//var telefono="telefono";
	if(telefono!=""){
		if(document.getElementById(telefono).value.length<9){
			alert("Introduzca su teléfono");
			if(focus!=1) document.getElementById(telefono).focus();
			return false;
		}
	}	


	//var direccion="direccion";
	if(document.getElementById(direccion).value.length<3){
		alert("Introduzca su dirección");
		if(focus!=1) document.getElementById(direccion).focus();
		return false;
	}

	//var cp="cp";
	if(document.getElementById(cp).value.length<5){
		alert("Introduzca su código postal");
		if(focus!=1) document.getElementById(cp).focus();
		return false;
	}

	//var localidad="localidad";
	if(document.getElementById(localidad).value.length<3){
		alert("Introduzca su localidad");
		if(focus!=1) document.getElementById(localidad).focus();
		return false;
	}

	//var provincia="provincia";
	if(document.getElementById(provincia).value=='no'){
		alert("Seleccione su provincia");
		if(focus!=1) document.getElementById(provincia).focus();
		return false;
	}

	return true;
}


function valida_registro(){
	if(!valida_registro_mail_pass()){
		return false;
	}

	if(!valida_registro_datos('nombre','apellido1','apellido2','telefono','direccion','cp','localidad','provincia','0')){
		return false;
	}
	

	if(document.getElementById("pass").value.length<5){
		alert("Introduzca los números del Anti-Spam");
		document.getElementById("pass").focus();
		return false;
	}


	var acepto="acepto";
	if(document.getElementById(acepto).checked==false){
		alert("Para registrarse debe aceptar las condiciones legales");
		document.getElementById(acepto).focus();
		return false;
	}

	return true;
}


function valida_modifi_datos_usu(){

	if(!valida_registro_datos('nombre','apellido1','apellido2','telefono','direccion','cp','localidad','provincia','0')){
		return false;
	}
	
	var email="email";
	if(document.getElementById(email).value.length<5){
		alert("Introduzca su email");
		document.getElementById(email).focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById(email).value);
		if(resu ==false){
			 document.getElementById(email).focus();
			 return resu;
		}
	
	}

	return true;
}



//proceso_compra2 -> Direcciones de facturacion
function checkea_datos_factu(num){
	var list=document.getElementById('list_datos_factu').value;
	var ids=list.split(",");
	var i=0;
	while(i<ids.length){
		var chec="check_dire_factu_" + ids[i];
		//alert(ids[i] + "--" + num) ;
		if(ids[i]!=num){
			document.getElementById(chec).checked=false;
		}
		i++;
	}
}

//valida el envío del formulario de facturación en proceso_compra2
function comprueba_dire_factu(){
	//		alert(document.getElementById('id_dato_factu').value);

	//si se quiere seleccionar otra dirección de facturación
	if((document.getElementById('check_seleccionar_otra_dire_factu'))&&(document.getElementById('check_seleccionar_otra_dire_factu').checked==true)){
	//if(document.getElementById('check_seleccionar_otra_dire_factu').checked==true){
		//alert("otra dire");
		return true;//cambiar a true
	//si se quiere añadir una dirección de facturación
	}else if(document.getElementById('check_anadir_direccion_factu').checked==true){
		var dni_cif="nuevo_dni_cif";
		if(document.getElementById(dni_cif).value.length<9){
			alert("Introduzca su DNI/CIF");
			document.getElementById(dni_cif).focus();
			return false;
		}
		if(!valida_registro_datos('nuevo_nombre','nuevo_apellido1','nuevo_apellido2','nuevo_telefono','nuevo_direccion','nuevo_cp','nuevo_localidad','nuevo_provincia')){
			return false;
		}
		return true;//cambiar a true
	//comprobamos que los datos de facturación por defecto son correctos
	}else {
		var error=0;
		var dni_cif="dni_cif";
		if(document.getElementById(dni_cif).value.length<9){
			alert("Introduzca su DNI/CIF");
			var error=1;
		}
		if(!valida_registro_datos('nombre','apellido1','apellido2','telefono','direccion','cp','localidad','provincia','1')){
			var error=1;
		}
		if(error==1){
			document.getElementById('cambiar_direccion_factu').style.display='block';
			replaceSelects();
			if(document.getElementById('seleccionar_otra_dire_factu')) document.getElementById('seleccionar_otra_dire_factu').style.display='none';
			if(document.getElementById('check_seleccionar_otra_dire_factu')) document.getElementById('check_seleccionar_otra_dire_factu').checked=false;
			if(document.getElementById('anadir_direccion_factu')) document.getElementById('anadir_direccion_factu').style.display='none';
			if(document.getElementById('check_anadir_direccion_factu')) document.getElementById('check_anadir_direccion_factu').checked=false;
			return false;
		}else{
			return true;//cambiar a true
		}
		
	
	}

	return true;
}

//valida el envío del formulario de entregas/envío en proceso_compra3
function comprueba_dire_envio(id_envio){
	if( (document.getElementById('id_dato_envio_ini').value>=1) || (document.getElementById('check_anadir_direccion_envio').checked==true) ){
		//si se quiere seleccionar otra dirección de entrega
		if( (document.getElementById('check_seleccionar_otra_dire_envio')) && (document.getElementById('check_seleccionar_otra_dire_envio').checked==true) ){

			if(id_envio){
				var ext="_" + id_envio;
			}else{
				var ext="";
			}
			if(!valida_registro_datos('nombre'+ext,'apellido1'+ext,'apellido2'+ext,'','direccion'+ext,'cp'+ext,'localidad'+ext,'provincia'+ext,'1')){
				return false;
			}
			if(id_envio){
				document.getElementById('id_dato_envio').value=id_envio;
			}

			return true;//cambiar a true
		//si se quiere añadir una dirección de facturación
		}else if(document.getElementById('check_anadir_direccion_envio').checked==true){

			if(!valida_registro_datos('nuevo_nombre','nuevo_apellido1','nuevo_apellido2','','nuevo_direccion','nuevo_cp','nuevo_localidad','nuevo_provincia')){
				return false;
			}
			return true;//cambiar a true
		//comprobamos que los datos de envío por defecto son correctos
		}else {


			var error=0;
			if(!valida_registro_datos('nombre','apellido1','apellido2','','direccion','cp','localidad','provincia','1')){
				var error=1;
			}
			if(error==1){
				document.getElementById('cambiar_direccion_envio').style.display='block';
				replaceSelects();
				document.getElementById('seleccionar_otra_dire_envio').style.display='none';
				document.getElementById('check_seleccionar_otra_dire_envio').checked=false;
				document.getElementById('anadir_direccion_envio').style.display='none';
				document.getElementById('check_anadir_direccion_envio').checked=false;
				return false;
			}else{
				document.getElementById('id_modi').value=1;
				document.getElementById('check_seleccionar_otra_dire_envio').checked=false;//true
				document.getElementById('id_dato_envio').value=document.getElementById('id_dato_envio_ini').value;
				return true;//cambiar a true
				
			}
			
		
		}
	}else{
		alert("NO dire");
		return false;
	}
	return true;
}

//proceso_compra3 -> Direcciones de envío
function checkea_datos_envio(num){
	var list=document.getElementById('list_datos_envio').value;
	var ids=list.split(",");
	var i=0;
	while(i<ids.length){
		var chec="check_dire_envio_" + ids[i];
		//alert(ids[i] + "--" + num) ;
		if(ids[i]!=num){
			document.getElementById(chec).checked=false;
		}
		i++;
	}
}



function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email incorrecto")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		alert("Email incorrecto")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Email incorrecto")
			return false
			}
		}
		return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Email incorrecto")
		return false;
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>4) {
		 alert("Email incorrecto")
	   return false
	}

	if (len<2) {
	   var errStr="Email incorrecto"
	   alert(errStr)
	   return false
	}

	  return true;
}

function valida_recomendar_web(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Introduzca su nombre");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<5){
		alert("Introduzca su email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	if(document.getElementById("nombre_amigo").value.length<3){
		alert("Introduzca el nombre de su amigo");
		document.getElementById("nombre_amigo").focus();
		return false;
	}

	if(document.getElementById("email_amigo").value.length<5){
		alert("Introduzca el email de su amigo");
		document.getElementById("email_amigo").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email_amigo").value);
		if(resu ==false){
			 document.getElementById("email_amigo").focus();
			 return resu;
		}
	
	}

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduzca su mensaje")){
		alert("Introduzca el mensaje");
		document.getElementById("mensaje").focus();
		return false;
	}

	
	/*
	if(document.getElementById("pass").value.length<5){
		alert("Introduzca los números de la imagen");
		document.getElementById("pass").focus();
		return false;
	}
	*/
}

function validar_contacto(){
/*
	if(document.getElementById("nombre").value.length<3){
		alert("Introduzca su nombre y apellidos");
		document.getElementById("nombre").focus();
		return false;
	}
*/
	if(document.getElementById("email").value.length<1){
		alert("Introduzca su email");
		document.getElementById("email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email").value);
		if(resu ==false){
			 document.getElementById("email").focus();
			 return resu;
		}
	
	}
	/*
	if(document.getElementById("asunto").value.length<3){
		alert("Introduzca el asunto");
		document.getElementById("asunto").focus();
		return false;
	}
	*/

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduzca su mensaje")){
		alert("Introduzca su mensaje");
		document.getElementById("mensaje").focus();
		return false;
	}
	
	if(document.getElementById("pass").value.length<5){
		alert("Introduzca los números del Anti-Spam");
		document.getElementById("pass").focus();
		return false;
	}
	
	return true;
}


function unblur() {
	this.blur();
} 

function blurLinks() {
	if (!document.getElementById) return;
	theLinks = document.getElementsByTagName("A");
	theAreas = document.getElementsByTagName("AREA");
	for(i=0; i<theLinks.length; i++) {theLinks[i].onfocus = unblur;}
	for(i=0; i<theAreas.length; i++) {theAreas[i].onfocus = unblur;}
  }



function reposiciona_ventana(){ 
	var pos=window.name || 0; 
	window.scrollTo(0,pos); 
} 

//window.onunload=
function guarda_posicion_ventana(){ 
	window.name=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop); 
} 



function validar_xmas(){
	if(document.getElementById("nombre_remitente").value.length<3){
		alert("Introduzca su nombre");
		document.getElementById("nombre_remitente").focus();
		return false;
	}

	if(document.getElementById("email_remitente").value.length<5){
		alert("Introduzca su email");
		document.getElementById("email_remitente").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email_remitente").value);
		if(resu ==false){
			 document.getElementById("email_remitente").focus();
			 return resu;
		}
	
	}
	if(document.getElementById("nombre_destinatario").value.length<3){
		alert("Introduzca el nombre del destinatario");
		document.getElementById("nombre_destinatario").focus();
		return false;
	}

	if(document.getElementById("email_destinatario").value.length<5){
		alert("Introduzca el email del destinatario");
		document.getElementById("email_destinatario").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email_destinatario").value);
		if(resu ==false){
			 document.getElementById("email_destinatario").focus();
			 return resu;
		}
	
	}

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduzca su mensaje")){
		alert("Introduzca el mensaje");
		document.getElementById("mensaje").focus();
		return false;
	}

	
	if(document.getElementById("pass").value.length<5){
		alert("Introduzca los números de la imagen");
		document.getElementById("pass").focus();
		return false;
	}
}

/*******/
/* FUNCION CONTADOR DE CARACTERES*/

/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
	if (lengthleft<0){
		theform.value=theform.value.substring(0,maxlength)
		//placeholderobj.innerHTML=0
		copia('mensaje');
	}else{
		//placeholderobj.innerHTML=lengthleft
		copia('mensaje')
	}
}
}

function displaylimit(thename, theid, thelimit , ver){
	var theform=theid!=""? document.getElementById(theid) : thename
	//var limit_text='<div ><span id="'+theform.toString()+'">'+thelimit+'</span></div>'
	var limit_text='<div ><span id="'+theform.toString()+'"></span></div>'


	if (document.all||ns6)
	document.write(limit_text)
	if (document.all){
	eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
	eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}

	eval(theform).onblur=function(){ countlimit(thelimit,event,theform)}

	}
	else if (ns6){
	document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
	document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 

	document.body.addEventListener('blur', function(event) { countlimit(thelimit,event,theform) }, true); 

	}
}



/* FIN FUNCION CONTADOR DE CARACTERES*/
/*******/