// JavaScript Document
function main(){}
/*Cambio Css*/
main.over=function(id,Obj){
id=document.getElementById(id);
id.className=Obj;
}
/*Cambio Css*/


/*Envio la fecha*/
main.generaDate=function(objType,objCaracter){
if(objType==0){
    miFecha = new Date(); var oDay=miFecha.getDate();var oMes=miFecha.getMonth(); var oAno=miFecha.getFullYear();
    oMes= new String(oMes);
    if(parseInt(oMes.length)<2){oMes="0"+(parseInt(oMes)+1);}
    response=oAno+objCaracter+oMes+objCaracter+oDay;
	//response=oAno+oMes+oDay;
}
if(objType==1){
    miHora = new Date(); oHora=miHora.getHours(); oMinute=miHora.getMinutes(); oSegundos=miHora.getSeconds();
    oMinute= new String(oMinute);
    if(oMinute.length<2){oMinute="0"+(parseInt(oMinute)+1);}
    response=oHora+objCaracter+oMinute+objCaracter+oSegundos;
}
return response;
//alert(response);
}
/*Envio la fecha*/

/* Muestrop o oculto campos*/
main.displayObj=function(objDiv,Class,objImg){
	obj=document.getElementById(objDiv);
	if(obj.style.display=='none'){
		main.ES(objDiv,4);
		if(objImg!=''){objI=document.getElementById(objImg); objI.src='../img/minus.png';}
		}
	if(obj.style.display==''){
		main.ES(objDiv,5);
		if(objImg!=''){objI=document.getElementById(objImg); objI.src='../img/mas.png';}
		}
	}
/*Display Div*/
main.DisplayDiv=function(objId,type){
	objId=document.getElementById(objId);
	if(type==0){objstyle="";}
	if(type==1){objstyle="";}
	objId.style.display=objstyle;
	}
/*Display Div*/
main.CheckMenu=function(){
	arrayMenu=new Array('divCatalogos');
	for(i=0;i<arrayMenu.length;i++){obj=document.getElementById(arrayMenu[i]); obj.style.display='none';}
	}
main.ClickMenu=function(objDiv,objPage,objDivActual){
	main.CheckMenu();
	if(objPage!=''){main.openPage(objPage,'_SELF',0);}
	if(objPage==''){main.ES(objDiv,3);}
	}

/*Cambio BG*/
main.mClick=function(objId,objColor,objDiv){
	if(objColor==0){objColor='#FFFFFF'; objtype=0;}
	if(objColor==1){objColor='#939393'; objtype=1;}
	if(objDiv!=""){main.DisplayDiv(objDiv,objtype);}
	id=document.getElementById(objId);
	id.style.backgroundColor=objColor;
	}
/*Cambio BG*/
main.openPageValida=function(objPage,objType,objWindow,objWidth,objHeight,permiso){
	if(permiso==1){
		main.openPage(objPage,objType,objWindow,objWidth,objHeight);
		}else{
		alert('No tienes permiso suficientes.');
		}
	}
/* Main Valida Permissions*/
main.validaPermiso=function(obj){
objPermiso=document.getElementById(obj);
objPermiso=objPermiso.value;
return objPermiso;
}
/* Main Valida Permissions*/

/*Quito espacios en blanko*/
main.trim = function(string){
	  if(string==""){
      	 return string;
	  }else{
		  if(string!=undefined){
		 return string.replace(/^\s\s*/, '').replace(/\s\s*$/, '');		 
		  }else{
			  string="";
			  return string;
		  }
	  }
}
/*Quito espacios en blanko*/
/*Tratamiento de cadenas*/

/*Tratamiento de cadenas*/

/*Abro paginas*/
main.openPage=function(objPage,objType,objWindow,objWidth,objHeight){
var window_width = objWidth;
var window_height = objHeight;
var window_top = (screen.height-window_height)/2;
var window_left = (screen.width-window_width)/2;

switch(objWindow){
	case 0:
	//window.open(objPage,objType);
	window.location.href=objPage;
	break;
	case 1:
	window.open(objPage,(objType.toLowerCase()),"top="+window_top+", left="+window_left+",height="+objHeight+",width="+objWidth+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
	break;
	case 2:
	window.open(objPage,(objType.toLowerCase()),"top="+window_top+", left="+window_left+",height="+screen.height+",width="+screen.width+",resizable=yes,status=no,toolbar=no,menubar=no,location=yes,scrollbars=yes");
	//window.open(objPage,(objType.toLowerCase()),"resizable=1,status=1,toolbar=0,menubar=0,location=1,scrollbars=1");
	break;
	default:
	break;
	}
}
/*Abro paginas*/

//--- Creo los objetos de las busquedas 
main.addFiltro=function(cbxObj,txtObj,divObj){
cbx=cbxObj;
txtObj=document.getElementById(txtObj);
cbxObj=document.getElementById(cbxObj);
cbxIndex=cbxObj.selectedIndex;
cbxValue=cbxObj.value;
cbxCount=(cbxObj.length-1);
cbxText=cbxObj.options[cbxIndex].text;
divObj=document.getElementById(divObj);
//--Removiendo
cbxObj.remove(cbxIndex);
//--Creando Objetos
newDivContainer=document.createElement('div');
newDiv=document.createElement('div');
newDivBusca=document.createElement('div');
//newDivPrincipal=document.createElement('div');
// Properties
//newDivPrincipal.id='divPrincipal_'+cbxCount;
//newDivPrincipal.style.paddingLeft='5px';
//newDivPrincipal.style.paddingRight='5px';

newDivContainer.id='divContainer_'+cbxCount;
newDivContainer.title=cbxValue;
newDivContainer.style.paddingLeft='5px';
newDivContainer.style.paddingRight='5px';
//newDivContainer.style.backgroundColor='#000000';
//newDivContainer.style.width='100%';
//newDivContainer.style.height='100%';
newDivContainer.style.cssFloat='left';
newDivContainer.style.styleFloat='left';
newDivContainer.style.textAlign='left';
newDivContainer.style.cursor='pointer';
newDivBusca.id='divBusca_'+cbxCount;
newDivBusca.title=txtObj.value;
newDivBusca.innerHTML=txtObj.value;
newDivBusca.style.paddingLeft='5px';
newDivBusca.style.paddingRight='5px';
newDivBusca.style.backgroundColor='#FFFFFF';
newDivBusca.className="span_text_black_small";
newDivBusca.style.border='solid 1px #CCCCCC';
newDiv.id='divText_'+cbxIndex;
objImg="<img src='../img/imgClose.png' border=0>";
newDiv.innerHTML=objImg+"&nbsp;&nbsp;"+cbxText;
newDiv.style.paddingLeft='5px';
newDiv.style.paddingTop='5px';
newDiv.style.paddingRight='5px';
newDiv.style.paddingBottom='5px';
newDiv.style.backgroundColor='#FFE4DD';
//newDiv.style.cssFloat='left';
newDiv.className='span_text_black_small';
newDiv.style.border='solid 1px #CCCCCC';
//newDivContainer.style.border='solid 1px #CCCCCC';
//newDiv.onclick="javascript:alert('12');";
newDiv.onclick=function(){miproducto.addSelect('divContainer_'+cbxCount,cbx,cbxValue,cbxText,cbxCount);};
newDiv.setAttribute("onClick","main.addSelect(divContainer_"+cbxCount+",'"+cbx+"','"+cbxValue+"','"+cbxText+"',"+cbxCount+");");
newDivContainer.appendChild(newDiv);
newDivContainer.appendChild(newDivBusca);
divObj.appendChild(newDivContainer); 
//divObj.appendChild(newDivPrincipal);
//-- increment
objDiv=document.getElementById('divContainer_'+cbxCount);
objText=''+objDiv.innerHTML+'';
objDiv.innerHTML=objText;
proAncho0=objDiv.firstChild.offsetWidth;
proAncho1=objDiv.offsetWidth;
// Valido
// Borro valor del objeto con la frase Busca
txtObj.value='';
}

main.addSelect=function(obj,cbxObj,value,name,posicion){
  cbxObj=document.getElementById(cbxObj);
  var y=document.createElement('option');
  y.text=name;
  y.value=value;
  //posicion=cbxObj.options[cbxObj.selectedIndex];
  divFiltro=document.getElementById('divObjFiltro');
  divFiltro.removeChild(obj); 	
  try{  cbxObj.add(y, null);} // Otros  
  catch(ex){cbxObj.add(y);}// IE 
}

main.windowChild=function(cbxObj,objType, objResponse){
	cbxObj=document.getElementById(cbxObj);
	cbxIndex=cbxObj.selectedIndex;
	cbxText=cbxObj.options[cbxIndex].text;
	if(cbxText=='Ejecutivo' || cbxText=='Pais' || cbxText=='Estado' || cbxText=='Ciudad'){
	switch(cbxText){
		case 'Ejecutivo': // ejecutivo selector
		main.openPage('class.ejecutivos.php?objResponse='+objResponse+'','_blank',1,500,200);
		break;
		case 'Pais': // Pais Selector
		main.openPage('class.pais.php?objResponse='+objResponse+'','_blank',1,400,500);
		break;
		case 'Estado': // Estado Selector
		main.openPage('class.estado.php?objResponse='+objResponse+'','_blank',1,400,500);
		break;
		case 'Ciudad': // Pais Selector
		main.openPage('class.ciudad.php?objResponse='+objResponse+'','_blank',1,400,500);
		break;
		default:		
		break;
		}
	}
}

main.responseWindow=function(objName,objResponse){
	objRes=window.opener.document.getElementById(objResponse);
	objRes.value=objName;
	window.close();
	}

//- Analizo y Genero Query
main.generaQuery=function(objFiltro,objQuery){
	objFiltro=document.getElementById(objFiltro);
	len=objFiltro.childNodes.length;
	//--
	arrayidContainer=new Array();
	arrayField=new Array();
	arrayValue=new Array();
	//saco primero los id de los container
	for(i=0;i<len;i++){
		arrayidContainer[i]=objFiltro.childNodes[i].id;
		arrayField[i]=objFiltro.childNodes[i].title;
		}
	for(j=0;j<len;j++){
		objTemp=document.getElementById(arrayidContainer[j]);
		arrayValue[j]=objTemp.childNodes[1].title;
		}
	txtCode=document.getElementById(objQuery);
	var tempCode='';
	for(k=0;k<len;k++){
		tempCode=tempCode+"S3PARADOR"+arrayField[k]+"="+arrayValue[k];
		}
	txtCode.value=tempCode;
	}



main.code=function(objCode,objMostrar,Text){
  objCode=document.getElementById(objCode);
  len=objCode.childNodes.length;
  
  
  /*for(i=0;i<=len;i++){
	  //alert(objCode.childNodes[i].title);
	  objCodeChild=document.getElementById(objCode.childNodes[i].id)
	  len2=objCodeChild.childNodes.length;
	  for(j=0;j<=len2;j++){
		  //alert( typeof objCodeChild.childNodes[j]);
		   //alert(objCodeChild.childNodes[1].title);
		  }
	 
	  
	  }*/

  objArea=document.getElementById(objMostrar);
  objArea.innerHTML=objCode.innerHTML;
  objArea.innerHTML=Text;
}

main.demo=function(cbx){
cbx=document.getElementById(cbx);
alert(cbx.value);
}

/*Desplegar o  coultar  objeto */
main.ES=function(Obj,accion)
{
//-0 oculta  1- visual
if(accion==1){Effect.BlindDown(Obj);}
if(accion==0){Effect.BlindUp(Obj);}
if(accion==2){document.getElementById(Obj).style.display='none';}
if(accion==3){document.getElementById(Obj).style.display='';}
if(accion==4){Effect.Appear(Obj, { duration: 1.0, from:0, to:1});}
if(accion==5){Effect.Fade(Obj, { duration: 1.0, from:1, to:0});}
}
/*FinDesplegar o  coultar  objeto */
main.mesLetra=function(objMes){switch(objMes){ case '01': result='Enero'; break;case '02':result= 'Febrero'; break;case '03': result='Marzo'; break;case '04': result='Abril'; break;case '05': result='Mayo'; break;case '06': result='Junio'; break;case '07': result='Julio'; break;case '08': result='Agosto'; break;case '09': result='Septiembre'; break;case '10': result='Octubre'; break;case '11': result='Noviembre'; break;case '12': result='Diciembre'; break;} return result;}
main.fechaLetras=function(fecha,objCaracter,orden){
	objFecha=fecha.split(objCaracter);
	uno=objFecha[0];
	dos=objFecha[1];
	tres=objFecha[2];
	switch(orden){
		case 0: // anio -mes -dia
		result=tres +" de "+main.mesLetra(dos)+" del "+uno;
		break;
		case 1:
		result=uno +" de "+main.mesLetra(dos)+" del "+tres;
		break;
		}
	return result;
	}
/* Bloqueo y activo toda la pagina*/
main.desactivaPage=function(objDiv){main.centrar(objDiv); document.getElementById(objDiv).style.display='block'; document.body.style.overflow='hidden';}
main.activaPage=function(objDiv){main.centrar(objDiv); document.getElementById(objDiv).style.display='none'; document.body.style.overflow='';}
/* Bloqueo y activo toda la pagina*/

/* Funcion valida email*/
main.formatMail=function(texto){

    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    
    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    
    var punto = texto.lastIndexOf(".");
                
     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;
                
    return mailres;
}

/* Centrar objeto en la pantalla visual*/
main.centrar=function(elementoid) {
elementoid=document.getElementById(elementoid);
xpos = (screen.availWidth)
ypos = (screen.availHeight)

elementoid.style.top = (document.documentElement.scrollTop) + 'px';
elementoid.style.left = (document.documentElement.scrollLeft) + 'px';
//elementoid.style.display='block';
}

main.habilitaObj=function(obj){
	objC=document.getElementById(obj);
	if(objC.style.display=='none'){main.ES(obj,4);}else{main.ES(obj,5);}	
	}


function waitLoad(){
	
	}
	
function Exception(){
	
	}