// JavaScript Document
/*
var rutaAbsoluta = self.location.href;        // http://asdas.asd/uno/dos/index.html
var posicionUltimaBarra = rutaAbsoluta.lastIndexOf("/");
var rutaRelativa = rutaAbsoluta.substring( posicionUltimaBarra + "/".length , rutaAbsoluta.length );       // index.html
alert(rutaRelativa);  
*/

function validar(f)
{
	if(f.empresa.value=="")
	{
		alert('Proporcione el nombre de su empresa')
		f.empresa.focus()
		return false
	}
	if(f.contacto.value=="")
	{
		alert('Proporcione el nombre del contacto')
		f.contacto.focus()
		return false
	}
	if(f.email.value=="")
	{
		alert('Proporcione la dirección de su correo electrónico')
		f.email.focus()
		return false
	}
	if(f.telefono.value=="")
	{
		alert('Proporcione un número de teléfono para contactarnos con usted')
		f.telefono.focus()
		return false
	}
	return true
}
///////////////////////////////////
function recto()
{
	document.forms.ficha.altura.value=""
	document.forms.ficha.largoA.value=""
	document.forms.ficha.bajada.value=""
	document.forms.ficha.largoB.value=""
	document.forms.ficha.altura.disabled=true
	document.forms.ficha.largoA.disabled=true
	document.forms.ficha.bajada.disabled=true
	document.forms.ficha.largoB.disabled=true
	
}
function inclinado()
{
	document.forms.ficha.altura.disabled=false
	document.forms.ficha.largoA.disabled=false
	document.forms.ficha.bajada.disabled=true
	document.forms.ficha.largoB.disabled=true
	
	document.forms.ficha.altura.value=""
	document.forms.ficha.largoA.value=""
	document.forms.ficha.bajada.value=""
	document.forms.ficha.largoB.value=""
}
function declinado()
{
document.forms.ficha.altura.disabled=true
	document.forms.ficha.largoA.disabled=true
	document.forms.ficha.bajada.disabled=false
	document.forms.ficha.largoB.disabled=false
	
	document.forms.ficha.altura.value=""
	document.forms.ficha.largoA.value=""
	document.forms.ficha.bajada.value=""
	document.forms.ficha.largoB.value=""
}
////////////////////////////////////


function menu_open_partes(wH){ 

 var bandera=0,i,x,tA,op,pp,wH,tA,aU,r1,k=-1,kk=-1,mt=new Array(1,'','');
 if(document.menuop){
	 mt=document.menuop;
	 				}
	 op=mt[0];
	 if(op<1){
		 return;
		     }
 tA=document.getElementById('menunav').getElementsByTagName("A");
//wH=window.location.href;

 r1=/index\.[\S]*/i;
 for(i=0;i<tA.length;i++){
     if(tA[i].href){
	    aU=tA[i].href.substring((tA[i].href.lastIndexOf("/"))+1)
	 if(op>0){
		 if(tA[i].href==wH||aU==wH){
			 k=i;
			 kk=-1;
			 break;
			 }
			             }
			 if(op==2){
				 if(tA[i].firstChild){
 					if(tA[i].firstChild.nodeValue==mt[1]){
					 kk=i;
					 }}}
			 if(op==3 && tA[i].href.indexOf(mt[1])>-1){
				 kk=i;
	 				}
			 if(op==4){
				 for(x=1;x<mt.length;x+=2){
					if(wH.indexOf(mt[x])>-1){
	 					if(tA[i].firstChild&&tA[i].firstChild.data){
		 					if(tA[i].firstChild.data==mt[x+1]){
			 					kk=i;
			 		break;
			 	}}}}}}}
			 k=(kk>k)?kk:k;
			

 if(k>-1){
	 tA[k].style.color="#DAC5A7";
	 //tA[k].style.textDecoration = "underline";
	 pp=tA[k].parentNode;
	 while(pp.nodeName!="BODY"){
		 if(pp.nodeName=="LI"){
			 pp.firstChild.className="menumark"+" "+pp.firstChild.className;
			                 }
     pp=pp.parentNode;
	
	 if(pp.parentNode.className=="menutrg"){
		 pp.parentNode.getElementsByTagName("a")[0].style.color="#DAC5A7";
		  pp.parentNode.getElementsByTagName("a")[0].style.background= "#363636 url('../libreria/linkarrow_active.png') right center no-repeat";
		  //pp.parentNode.getElementsByTagName("a")[0].style.textDecoration = "underline";
	                                       }
          }
		  }

 if(kk>-1){
	 document.menuad=1;
	 }
	 /*menu_adma();menu_admb();*/

	 
}


function menu_actual(id_menu, id_menu_lateral, id_footer, id_sub_footer){
 if(document.getElementById){ 
  document.getElementById(id_menu).style.color="#E77812"
  document.getElementById(id_menu).style.textDecoration = "underline"
 document.getElementById(id_footer).style.color="#E77812" 
 document.getElementById(id_footer).style.textDecoration = "underline"  
 if(id_sub_footer){
	document.getElementById(id_sub_footer).style.color="#E77812" 
    document.getElementById(id_sub_footer).style.textDecoration = "underline" 	 
 				}
if(id_menu_lateral){
	document.getElementById(id_menu_lateral).style.color="#E77812" 
    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];}
}

/////////////////////////////////////////////////////////////////////////////////////////////

///// cambia la imagen de la arroba por la que esta de color rojo/////////////////////////
function arroba_red(){
if (document.getElementById)
	document.getElementById("arroba").src="images/arroba_red.gif"
}

///// cambia la imagen de la arroba por la que esta de color verde /////////////////////////
function arroba_verde(){
if (document.getElementById)
	document.getElementById("arroba").src="images/arroba_green.gif"
}

////////////////////////////////////////////////////////////////////////////////////////
////  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;
}

/////////////////////////////////////////////////////////////////////////////
///////  carga la animacion en el id que se indica con ajax /////////////////

function carga_animacion(animacion, contenedor){
		//alert("animacion = "+animacion +" contenedor = "+ contenedor);
		
	ubicar = document.getElementById(contenedor);
	
	ajax=objetoAjax();
	ajax.open("GET", animacion,true);
	ajax.onreadystatechange=function() {
	if (ajax.readyState==4) {
		ubicar.innerHTML = ajax.responseText;
		}
	else{
		ubicar.innerHTML = '<p align="center"><img src="images/loading.gif" width="80" height="80" align="middle"/></p>';
		}
	}
	ajax.send(null);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// JavaScript Document
var ban;


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_colonia = "Escribe tu colonia"
  msg_alert_ciudad = "Escribe tu ciudad"
  msg_alert_estado = "Escribe tu estado"
  msg_alert_pais = "Escribe tu pais"
  msg_alert_cp = "Escribe tu codigo postal"
  msg_alert_tel = "Escribe tu telefono"
  msg_alert_captcha= "Escribe el texto de seguridad"
  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 de la calle no este vacio antes de enviar el formulario 
/*	 if( forma.Calle_numero.value == ""){ 
    alert (msg_alert_direccion)
	forma.Calle_numero.style.backgroundColor="#ADCDFE"
	forma.Calle_numero.focus()
	return false;
	}

  //checa que el campo de la colonia no este vacio antes de enviar el formulario 
	if( forma.Colonia.value == ""){ 
    alert (msg_alert_colonia)
	forma.Colonia.style.backgroundColor="#ADCDFE"
	forma.Colonia.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;
	}
	
  //checa que el campo del estado no este vacio antes de enviar el formulario 
	if( forma.Estado.value == ""){ 
    alert (msg_alert_estado)
	forma.Estado.style.backgroundColor="#ADCDFE"
	forma.Estado.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 del codigo postal no este vacio antes de enviar el formulario 
	if( forma.Codigo_Postal.value == ""){ 
    alert (msg_alert_cp)
	forma.Codigo_Postal.style.backgroundColor="#ADCDFE"
	forma.Codigo_Postal.focus()
	return false;
	}
*/	
  //checa que el campo del telefono no este vacio antes de enviar el formulario 
	if( forma.Telefono.value == ""){ 
    alert (msg_alert_tel)
	forma.Telefono.style.backgroundColor="#ADCDFE"
	forma.Telefono.focus()
	return false;
	}
	
  //checa que el campo del Email no este vacio antes de enviar el formulario 
	if( forma.e_mail.value == ""){ 
    alert (msg_alert_mail)
	forma.e_mail.style.backgroundColor="#ADCDFE"
	forma.e_mail.focus()
	return false;
	}
	
  //checa que la direccion de email sea valida segun la estructura o forma correcta 
	 arroba = forma.e_mail.value.indexOf('@')
	 punto = forma.e_mail.value.indexOf('.')
  if(forma.e_mail.value.indexOf(' ')==-1 &&
	 (forma.e_mail.value.indexOf('@') > 0 &&
      forma.e_mail.value.indexOf('@') < forma.e_mail.value.length-3) &&
	 (forma.e_mail.value.indexOf('.') > 0 &&
	  forma.e_mail.value.indexOf('.') < forma.e_mail.value.length-1) &&
	 (forma.e_mail.value.lastIndexOf('.') > forma.e_mail.value.lastIndexOf('@')) )
	    forma.e_mail.style.backgroundColor=""
  else
  {
    alert("La direccion del e-mail es incorrecta.\nEjemplo:\ntu_login@tu_proveedor.ext.ext")
    forma.e_mail.style.backgroundColor="#ADCDFE"
    forma.e_mail.focus()
    return false
  }

// checa que la confirmacion del correo electronico sea igual 
if( forma.e_mail_confirma.value != forma.e_mail.value){ 
    alert ("La confirmacion del e-mail es incorrecta")
	forma.e_mail_confirma.style.backgroundColor="#ADCDFE"
	forma.e_mail_confirma.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;
  }
 
  
  if( forma.tmptxt.value == ""){ 
    alert (msg_alert_captcha)
	forma.tmptxt.style.backgroundColor="#ADCDFE"
	forma.tmptxt.focus()
	return false;
	}

return true;

}	//FIN FUNCION NO_NULOS									


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 = false;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	this.expandMenu(this.submenus[0]);
	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) {
	var fullHeight = submenu.getElementsByTagName("span")[0].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;
	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();
		}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].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=/";
	}
};
