
//Función para abrir ventanas alternas popups
// --- La liga que abra el popup se pondrá de la siguiente manera
// --- javascript:PopUps('pagina.ext', 'nombrePagina', 'width=300, height=500, scrollbar=yes')
function PopUps(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//Funciones para secciones que se colapsan
// --- En la propiedad onclic se pondrá de la siguiente manera
// --- onclick="doSection(document.getElementById('idElemento'))"
function doSection (secNum){
if (secNum.style.display=="none"){secNum.style.display=""}
else {secNum.style.display="none"}
}
function noSection (secNum){
if (secNum.style.display==""){secNum.style.display="none"}
}

//Nueva funciones para secciones que se colapsan (esta es la que se esta usando)

function displaySubs(id, numHijos){
	for(i=0; i<numHijos; i++){
		if(document.getElementById(id + '_' + i)!=null){
			if(document.getElementById(id + '_' + i).className == 'hide')
				document.getElementById(id + '_' + i).className = 'show';
			else
				document.getElementById(id + '_' + i).className = 'hide';
		}
	}
}

function imgRoll(id){
 	img = document.getElementById(id); //imagen a replazar dinamicamente
	if(img.alt=="Ver m&aacute;s"){
		img.src = "images/bullet_menos.jpg";
		img.alt = "Cerrar";
		img.title = "Cerrar";
	}else{
		img.src = "images/bullet_mas.jpg";
		img.alt = "Ver m&aacute;s";
		img.title = "Ver m&aacute;s";
	}
}



//Funciones necesarias para el rollover
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_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_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];}
}

function validNumeric(e, tipo) {
    tecla = (document.all)?e.keyCode:e.which;
    if(tecla == 0 || tecla == 8 || tecla == 9 || tecla == 32){return true};
    if (tipo==0){  //numerico
          patron = /[0-9]/;
    }
    if (tipo==1){ //decimal
        patron = /[0-9.]/;
     }
    if (tipo==2){ //telefono
         patron = /[0-9.,)(-]/;
     }
    te = String.fromCharCode(tecla);
    return patron.test(te); 
} 

function validChar(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if(tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 32){return true};
    patron = /[a-zA-Z0-9áéíóúÁÉÍÓÚñÑ´.,:$%*_/@!¡)(¿?]/;
    te = String.fromCharCode(tecla);
    return patron.test(te); 
} 

function validEmail(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if(tecla == 0 || tecla == 8 || tecla == 9 || tecla == 13 || tecla == 32 ){return true};
    patron = /[-",\w.@]/; 
    te = String.fromCharCode(tecla);
    return patron.test(te); 
} 
/****************************** Validar formulario ************/
function validaForma(idioma){
	var szMsg = "";
	var strNombre =  document.getElementById('nombre').value;
	var strEmail =  document.getElementById('email').value;
	var strTelefono =  document.getElementById('telefono').value;
	var strComentarios =  document.getElementById('comentarios').value;

	if(strNombre == "" || strNombre == "Nombre:" )
		{
			if(idioma == 'esp')
				szMsg  = szMsg + "\t- Nombre\n";
			else
				szMsg  = szMsg + "\t- Name\n";
		}
				
	if(strEmail == "" || strEmail == "E-mail:")
		{szMsg  = szMsg + "\t- E-mail\n";}
	else
	{	
		var s = strEmail
		var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
		if (filter.test(s)){
			posAt = strEmail.indexOf("@")+1;
			posFin = strEmail.length;
			strEmailNew = strEmail.substring(posAt,posFin);
			contP = 0;
			for (i = 0; i < strEmailNew.length; i++)
				{
					var c = strEmailNew.charAt(i);
					if(c == "."){contP = contP + 1;}
				}
			
			if(contP >= 3)
				{
					if(idioma == 'esp')
						szMsg  = szMsg + "\t- E-mail válido\n";
					else
						szMsg  = szMsg + "\t- valid E-mail\n";}
		}
		else{ 
			if(idioma == 'esp')
				szMsg  = szMsg + "\t- E-mail válido\n";
			else
				szMsg  = szMsg + "\t- valid E-mail\n";
			}
	}
	
	
	if(strTelefono != "" && strTelefono != "Teléfono:")
		{
			filtro = /^\({0,1}[0-9]{2,3}\){0,1}[0-9\-\s]+[0-9]$/;
			if(!filtro.test(strTelefono)){
				if(idioma == 'esp')
					szMsg  = szMsg + "\t- Teléfono no valido, introduce lada y telefono \n\t\tEjemplo: (33) 36363636\n";
				else
					szMsg  = szMsg + "\t- Phone number - Please enter only numbers\n";
			}
		}
	
	if(strComentarios == "" || strComentarios == "Mensaje:")
		{
			if(idioma == 'esp')
				szMsg  = szMsg + "\t- Comentarios\n";
			else
				szMsg  = szMsg + "\t- Comments\n";
		}

if(szMsg != "")
		{
			if(idioma == 'esp')
				szMsg  = "Para continuar debes proporcionar la siguiente \n información:   \n" + szMsg;
			else
				szMsg  = "To continue you must provide the folowing information:   \n" + szMsg;
			alert(szMsg);
			return false;
		}
		else
		{
			document.getElementById('formaContacto').submit();
			return true;
		}
	}

/**************************** implementar ajax **********************/
function objAjax()
{
    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;
}


function include(file_path){
	var j = document.createElement("script");
	j.type = "text/javascript";
	j.src = file_path;
	document.body.appendChild(j);
}

function contenidoDinamico(pagina,contenido)
{
    var content;
    content = document.getElementById(contenido);
    
    // creamos un nuevo objeto ajax
    ajax=objAjax();
    //cargar el archivo html por el método GET
    ajax.open("GET", pagina ,true);
   
    ajax.onreadystatechange=function()
    {
        if (ajax.readyState==4) // Readystate 4 significa que ya acabó de cargarlo
        {
            content.innerHTML = ajax.responseText
			include("js/floatbox/floatbox.js")
        }
		else 
	    {
			content.innerHTML = '<img src="images/loader.gif" alt="" />';
		}
		
    }
    ajax.send(null)
}

/************ Obtiene variable de URL *******************/

function obtener_valor(variable)
{
	var variable_may = variable.toUpperCase();
	var variable_pos = url.indexOf(variable_may);
	
	if (variable_pos != -1)
	{
		var pos_separador = url.indexOf("&", variable_pos);
	
		if (pos_separador != -1)
		{
			return url.substring(variable_pos + variable_may.length + 1, pos_separador);
		} 
		else
		{
			return url.substring(variable_pos + variable_may.length + 1, url.length);
		}
	} 
	else
	{
		return "NO_ENCONTRADO";
	}
}


