// JavaScript Document
function no_nulos(forma)	//ESTA FUNCION SE EJECUTA EN EL EVENTO onsubmit() 
{						 	//NO PERMITE CAMPOS EN BLANCO

  cont=0; arroba=-1; punto=-1;
  x = forma.length	//ESTA LINEA OBTIEN EL NUMERO DE OBJETOS DE LA FORMA
  //mensajesw de alerta para los campos obligatorios
  msg_alert_nombre = "Escribe tu nombre"
  msg_alert_direccion = "Escribe tu direccion"
  msg_alert_ciudad = "Escribe tu ciudad"
  msg_alert_pais = "Escribe tu pais"
   msg_alert_telefono = "Escribe tu numero de telefono"
  msg_alert_seccion = "Escribe tu seccion"
  msg_alert_mail = "Escribe tu direccion de correo electronico"
  msg_alert_opc = "Por favor, selecciona ona de las opciones de la seccion \"Como se entero de nosotros\" "
  
 
  
  //checa que el campo del nombre no este vacio antes de enviar el formulario 
    if( forma.nombre.value == ""){ 
    alert (msg_alert_nombre)
	forma.nombre.style.backgroundColor="#ADCDFE"
	forma.nombre.focus()
	return false;
	}
 
  //checa que el campo del Email no este vacio antes de enviar el formulario 
	if( forma.email.value == ""){ 
    alert (msg_alert_mail)
	forma.email.style.backgroundColor="#ADCDFE"
	forma.email.focus()
	return false;
	}
	
  //checa que la direccion de email sea valida segun la estructura o forma correcta 
	 arroba = forma.email.value.indexOf('@')
	 punto = forma.email.value.indexOf('.')
  if(forma.email.value.indexOf(' ')==-1 &&
	 (forma.email.value.indexOf('@') > 0 &&
      forma.email.value.indexOf('@') < forma.email.value.length-3) &&
	 (forma.email.value.indexOf('.') > 0 &&
	  forma.email.value.indexOf('.') < forma.email.value.length-1) &&
	 (forma.email.value.lastIndexOf('.') > forma.email.value.lastIndexOf('@')) )
	  forma.email.style.backgroundColor=""
  else
  {
    alert("La direccion del e-mail es incorrecta.\nEjemplo:\ntu_login@tu_proveedor.ext.ext")
    forma.email.style.backgroundColor="#ADCDFE"
    forma.email.focus()
    return false
  }

// checa que la confirmacion del correo electronico sea igual 
if( forma.confirma_email.value != forma.email.value){ 
    alert ("La confirmacion del e-mail es incorrecta")
	forma.confirma_email.style.backgroundColor="#ADCDFE"
	forma.confirma_email.focus()
	return false;
	}


    //checa que el campo del pais no este vacio antes de enviar el formulario 
	if( forma.pais.value == ""){ 
    alert (msg_alert_pais)
	forma.pais.style.backgroundColor="#ADCDFE"
	forma.pais.focus()
	return false;
	}
  
  //checa que el campo de la ciudad no este vacio antes de enviar el formulario 
	if( forma.ciudad.value == ""){ 
    alert (msg_alert_ciudad)
	forma.ciudad.style.backgroundColor="#ADCDFE"
	forma.ciudad.focus()
	return false;
	}  
	
  
  //PARA VALIDAR EL NUMERO DE TELEFONO NO IMPORTA QUE TENGA GUION 
  //Y DEBEN DE SER AL MENOS 8 DIGITOS
  
  var cad = forma.telefono.value
  if(cad.indexOf('-') != -1)
  {
    
    var temp = new Array();
    temp = cad.split('-');
    cad = ''
    for(var i = 0; i < temp.length; i++)
      cad = cad + temp[i];
  }

  if(cad.length < 7)
  {
    alert("El telefono debe contener al menos 7 digitos.")
    forma.telefono.style.backgroundColor="#ADCDFE"
    forma.telefono.focus()
    return false;
  }
  
 
return true;

}	//FIN FUNCION NO_NULOS									



function menu_actual(id_menu, id_menu_lateral, id_footer, id_sub_footer){

 if(document.getElementById){ 
  document.getElementById(id_menu).style.color="#BBB4AE"
  document.getElementById(id_menu).style.textDecoration = "underline"
 document.getElementById(id_footer).style.color="#BBB4AE" 
 document.getElementById(id_footer).style.textDecoration = "underline"  
 if(id_sub_footer){
	document.getElementById(id_sub_footer).style.color="#BBB4AE" 
    document.getElementById(id_sub_footer).style.textDecoration = "underline" 	 
 				}
if(id_menu_lateral){
	document.getElementById(id_menu_lateral).style.color="#BBB4AE" 
    document.getElementById(id_menu_lateral).style.textDecoration = "underline" 	 
 				}

	                         }
					}

function Lhover(div_id){
 document.getElementById(div_id).style.color="#DAC5A7"
  document.getElementById(div_id).style.textDecoration = "underline"
}

function Lout(div_id, div_id2){
if(document.getElementById("my_menu").offsetHeight<100 || document.getElementById(div_id2).style.textDecoration=="underline"){
 document.getElementById(div_id).style.color="#FFFFFF"
  document.getElementById(div_id).style.textDecoration = "none"
}
}



function openWin(stURL, ancho, alto){
var windowsProps= "width="+ancho+",height="+alto+",toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no";
subWin = window.open(stURL, "accwin", windowsProps);
subWin.moveTo(0,0);
	}

//////////////////////////////////////////////////////////////////////////////////////////////
//// Funciones para la precarga de las imagenes y el cambio o intercambio de estas de los logos del pie de pagina ///////////////////////////
function salto_img(img_name){
if(document.getElementById){
document.getElementById(img_name).src= "images/productos/"+img_name+"_gr.jpg"
}
}

function salto_img_normal(img_name){
if(document.getElementById){
document.getElementById(img_name).src= "images/productos/"+img_name+".jpg"
}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////
////  Prepara el objeto de Ajax y checa que no existan errores /////////////////////////
function objetoAjax(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
  		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}


// JavaScript Document
var ban;



function email(edit, e){		//ESTA FUNCION SE EJECUTA EN EL EVENTO onkeypress()
 texto=edit.value			//PERMITE SOLO UNA "@"
 var c = (document.all) ? e.keyCode : e.which; 	  
 if(c==64) 
  if(texto.indexOf("@")==-1)
   return true
  else
   return false
}

// esta funcion soo permite numeros 
function permite_numeros(e){
var c = (document.all) ? e.keyCode : e.which; 
    if ((c>=48 && c<=57) || c==45 || c==46 || c==32 || c==8 || c==0)
      return true
	else
	  return false
}


function new_captcha()
{
	
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Error al generar el texto de seguridad");
	}
}


/* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& FUNCIONES DEL EFECTO CORTINA (sdmenu) &&&&&&&&&&&&&&&&&&&&&&&&&&&& */

function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = true;
	this.speed = 3;
	this.markCurrent = true;
	this.oneSmOnly = true;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleMenu(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
};

SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};


SDMenu.prototype.expandMenu = function(submenu) {
	this.collapseOthers(submenu);

  if(document.getElementById("menunav02")){
	 document.getElementById("menunav02").id="menunav";;  
	  menu_init(0,12,1,0,5);
	   										}


	var menu=submenu.getElementsByTagName("span")[0];
	menu.style.color="#DAC5A7";
	menu.style.textDecoration = "underline";
	var fullHeight = menu.offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	
	if(fullHeight>=900){
		fullHeight=350;
	}
	else
	if(fullHeight>=419){
  		fullHeight=140;
	                   }



	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "";
			mainInstance.memorize();
			
      if(fullHeight==140){
	  document.getElementById("menunav").id="menunav02";
	  menu_init(0,12,1,0,5);
	                   }
	
		}
	}, 30);

	
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var menu=submenu.getElementsByTagName("span")[0];
	menu.style.color="#FFFFFF";
	menu.style.textDecoration = "none";
	var minHeight = menu.offsetHeight;
	var moveBy = Math.round(this.speed * (submenu.getElementsByTagName("a").length));
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
				}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};
