//para modificar links ambiguos
function checkFirstLink(){
    uriSection=document.location.pathname.substr(1);
    hasta=uriSection.indexOf('/');
    if (hasta>-1) uriSection=uriSection.substring(0,hasta);
    myLinkLayer=document.getElementById('firstLink');
    if (myLinkLayer!=null){
        if (myLinkLayer.innerHTML.indexOf(uriSection)==-1){
            uriSection=uriSection.replace(/.aspx/g,"");
            myLinkLayer.innerHTML="<a href='/" + uriSection + ".aspx' rel='nofollow' title='" + uriSection.replace(/_/g," ") + "'>" + uriSection.replace(/_/g," ") + "</a>";
        }
    }
}
//para registro hijos edades
var matrixAges=new Array(); var matrixAgesBoxes=new Array();
function loadValues(strMatrix){
    document.getElementById('hijomas').style.display='';
    arrayMatrix=strMatrix.split(",");
    elHtml = "<table><tbody>";
    for (j=0;j<arrayMatrix.length;j++){
        cnth=j+1;
        elHtml += "<tr id=\"hijo"+cnth+"\"><td nowrap='nowrap'><label style='width:150px;'>a&ntilde;o de nacimiento:</label>";
        elHtml += "<select style='width:55px;margin-left:9px; border:1px solid #dbdbdb;margin-right:10px;padding-left:2px;font-family:tahoma;font-size:10px;color:#929292;' id='agechildbox"+cnth+"' name='agechild'>";
        var d = new Date();
        var curr_year = d.getFullYear();
        for(i=1990;i<=curr_year;i++){
            elHtml += "<option value='"+i+"'>"+i+"</option>";
        }
        elHtml += "</select>&nbsp;<a href='#' onclick='removehijo("+cnth+"); return false;'>";
        elHtml += "<img src='/img/delhijo.gif' border='0' style='cursor: pointer;cursor: hand;' align='absmiddle'></a></td></tr>";
    }
    elHtml += "</tbody></table>";
    document.getElementById('divhijos').innerHTML=elHtml;
    for (j=0;j<arrayMatrix.length;j++){
        cnth=j+1;       
        combohijos=eval("document.getElementById('agechildbox" + cnth + "')");
        for(i=0;i<combohijos.options.length;i++){
            if (combohijos.options[i].text==arrayMatrix[j]) combohijos.selectedIndex=i;
        }
    }
}
function preserveValues(){
    matrixAges.splice(0, matrixAges.length);
    matrixAgesBoxes.splice(0, matrixAgesBoxes.length);
    cajas=document.getElementsByTagName("select");
    for (i=0;i<cajas.length;i++){
        if (cajas[i].name=="agechild"){
            matrixAgesBoxes.push(cajas[i].id);
            matrixAges.push(cajas[i].options[cajas[i].selectedIndex].value);
        }
    }
}
function restoreValues(){
    for (i=0;i<matrixAgesBoxes.length;i++){
        cb=document.getElementById(matrixAgesBoxes[i]);
        if (cb!=null){
            for(j=0;j<cb.options.length;j++){
                if (cb.options[j].value==matrixAges[i]) cb.selectedIndex=j;
            }
        }
    }
}
function addHijo(){
    document.getElementById('hijomas').style.display='';
    if (document.getElementById('divhijos').innerHTML==""){
        elHtml = "<table><tbody><tr id=\"hijo1\"><td nowrap='nowrap'><label style='width:150px;'>a&ntilde;o de nacimiento:</label>";
        elHtml += "<select style='width:55px;margin-left:9px; border:1px solid #dbdbdb;margin-right:10px;padding-left:2px;font-family:tahoma;font-size:10px;color:#929292;' id='agechildbox1' name='agechild'>";
        var d = new Date();
        var curr_year = d.getFullYear();
        for(i=1990;i<=curr_year;i++){
            elHtml += "<option value='"+i+"'>"+i+"</option>";
        }
        elHtml += "</select>&nbsp;<a href='#' onclick='removehijo(1); return false;'>";
        elHtml += "<img src='/img/delhijo.gif' border='0' style='cursor: pointer;cursor: hand;' align='absmiddle'></a></td></tr>";
        elHtml += "</tbody></table>";
        document.getElementById('divhijos').innerHTML=elHtml;
    }else{
        preserveValues();
        elHtml=document.getElementById('divhijos').innerHTML;
        elHtml=elHtml.substr(0,elHtml.length-16);
        //alert(elHtml);
        aux=elHtml.toLowerCase();
        cnt='1';
        while(aux.length>0){
            if (aux.indexOf('<tr id=')>-1){
                cad="<tr id=\"hijo";
                posi=elHtml.indexOf(cad);
                if (posi==-1){
                    cad="<tr id=hijo";
                }
                aux = aux.substr(aux.indexOf(cad)+cad.length);
                cnt = aux.substr(0,1);
                //alert(cnt);
            }else
            aux = "";
        }
        xcnt=""+(parseInt(cnt)+1);
        elHtml += "<tr id=\"hijo"+xcnt+"\"><td nowrap='nowrap'><label style='width:150px;'>a&ntilde;o de nacimiento:</label>";
        elHtml += "<select style='width:55px;margin-left:9px; border:1px solid #dbdbdb;margin-right:10px;padding-left:2px;font-family:tahoma;font-size:10px;color:#929292;' id='agechildbox"+xcnt+"' name='agechild'>";
        var d = new Date();
        var curr_year = d.getFullYear();
        for(i=1990;i<=curr_year;i++){
            elHtml += "<option value='"+i+"'>"+i+"</option>";
        }
        elHtml += "</select>&nbsp;<a href='#' onclick='removehijo("+xcnt+"); return false;'>";
        elHtml += "<img src='/img/delhijo.gif' border='0' style='cursor: pointer;cursor: hand;' align='absmiddle'></a></td></tr>";
        elHtml += "</tbody></table>";
        document.getElementById('divhijos').innerHTML=elHtml;   
        restoreValues();
    }
    //alert(elHtml);
     
}
function removehijo(v){
    if (v==0){
        document.getElementById('divhijos').innerHTML="";
        document.getElementById('hijomas').style.display='none';
    }else{
        preserveValues();
        elHtml=document.getElementById('divhijos').innerHTML.toLowerCase();
        cad="<tr id=\"hijo"+v;
        posi=elHtml.indexOf(cad);
        ini=elHtml.substr(0,posi);
        if(ini==""){
            cad="<tr id=hijo"+v;
            posi=elHtml.indexOf(cad);
            //alert(posi);
            ini=elHtml.substr(0,posi);
            //alert('INI '+ini);
        }        
        fin=elHtml.substr(posi);
        fin=fin.substr(fin.indexOf("</tr>")+5);
        //alert('FIN '+fin);        
        document.getElementById('divhijos').innerHTML=ini+fin; 
        if (document.getElementById('divhijos').innerHTML.toLowerCase().indexOf('<tr id=')==-1){
            document.getElementById('hijono').checked=true;
            document.getElementById('hijomas').style.display='none';
            document.getElementById('divhijos').innerHTML="";
        }else restoreValues();
    }
}	        

function clearForm(x){
    //para empresas
    obj=obtainObject('txtbuscar','input');
    if (obj!=null){
        if (x.id==obj.id){
            //reset combos
            categoriasChange(0);
            obj=obtainObject('ddlciudad','select');
            obj.selectedIndex=0;
            obj=obtainObject('ddlzone','select');
            obj.selectedIndex=0;
            obj=obtainObject('ddlseccion','select');
            obj.selectedIndex=0;
        }
    }
    x.value="";
}
function addLoadEvent (func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
} 
function esEnter(e){
	var keynum;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	return (keynum==13);
}
function doSubmit(e,btn){
    if (esEnter(e)){
        obj=obtainObject(btn,'input');
        if (obj!=null){
            obj.click(); 
            theForm.onsubmit=function(){return false;};
        }
    }
}
function obtainObject(cadena, tipo){ 
    var obj=null;
    combos=document.getElementsByTagName(tipo);
    for(i=0;i<combos.length;i++){
        if (combos[i].name.indexOf(cadena)>0) obj=combos[i];
    }
    return obj;
}
function clearList(lista){
    	last=lista.length-1;
	for (i=last;i>0;i--){
		if (document.all){
			lista.options.remove(i);
		}else{
			lista.options[i]=null;
		}
	}
}
function add2List(elemento, indice, lista){
	j=lista.options.length;
	if (document.all){
		//PROCEDURE ESPECIFICO PARA IE
		newElem=document.createElement("OPTION");
		newElem.text=elemento;
		newElem.value=indice;
		lista.options.add(newElem, j);
	}else{
		lista.options[j]= new Option(elemento, indice)
	}
}
function cambiaImg(obj, color) { 
	obj.style.backgroundColor=color
}
function cambiaBg(obj, img) { 
	if(img!="none"){
		img="/imagenes/template/"+img
		//obj.style.backgroundImage="url("+img+")"
		obj.src = img
	}
	else{
	    obj.src = img
		//obj.style.backgroundImage=img
	}
//alert(img)
	
}

function votar(url) {
    location.href = url
}

function Abrir_ventana (pagina) { 
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=730, height=550, top=85, left=140"; 
window.open(pagina,"",opciones); 
} 

document.write("<!--[if lt IE 7]><link rel='stylesheet' type='text/css' href='/css/template_ie.css' /><script type='text/javascript' src='/script/supersleight-min.js'></script><![endif]-->");

function SetHeightMenu(value)
{
   if(value=="100%")
   { 
        thisMovie("menu_flashObj").height = 500; 
        var ver = getInternetExplorerVersion();
        if(ver==6)
        {
            comboCiudad = obtainObject("ddlciudad", "select");
            if(comboCiudad!=null) comboCiudad.style.visibility = "hidden";
            comboZona = obtainObject("ddlzone", "select");
            if(comboZona!=null) comboZona.style.visibility = "hidden";
            comboSeccion = obtainObject("ddlseccion", "select");
            if(comboSeccion!=null) comboSeccion.style.visibility = "hidden";
            comboSubSeccion = obtainObject("ddlsubseccion", "select");
            if(comboSubSeccion!=null) comboSubSeccion.style.visibility = "hidden";
        }
   }
   else
   {
        thisMovie("menu_flashObj").height = 35; 
        
        var ver = getInternetExplorerVersion();
        if(ver==6)
        {
            comboCiudad = obtainObject("ddlciudad", "select");
            if(comboCiudad!=null)comboCiudad.style.visibility = "visible";
            comboZona = obtainObject("ddlzone", "select");
            if(comboZona!=null) comboZona.style.visibility = "visible";
            comboSeccion = obtainObject("ddlseccion", "select");
            if(comboSeccion!=null)comboSeccion.style.visibility = "visible";
            comboSubSeccion = obtainObject("ddlsubseccion", "select");
            if(comboSubSeccion!=null)comboSubSeccion.style.visibility = "visible";
        }
   }
   
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function CerrarFlash()
{
     thisMovie("menu_flashObj").CheckCerrar(); 
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        //return window[movieName];
         return document.getElementById(movieName);
    }
    else
    {
        return document[movieName];
    }

}
