/* ---------------------------------------------*
* Modulo Fuctions.js  							*
* Autor : Eliezer Benjamin Gonzales Basilio		*
* e-mail: benjamin@ispgraf.com					*
* I.S.P.GRAF.SAC - http://www.ispgraf.com 		*    	 
* Copyright (c) 2003 ISPGRAF.SAC				*  
* ----------------------------------------------*/

/*----------------------------------------- *
* Author: Eliezer Benjamín Gonzales Basilio	*
* Version 1.0 - 05/09/2003 					*
*-------------------------------------------*/
function checkNull(inComp, inMsg)
{
  var er_empty = /^$/ 
	while (er_empty.test(inComp.value))
	{
	   alert(inMsg); 
	   inComp.focus(); 
	   return false;
	    
	 }
	 return true
}

/*----------------------------------------- *
* Author: Eliezer Benjamín Gonzales Basilio	*
* Version 1.0 - 05/09/2003 					*
*-------------------------------------------*/

function checkEmail(inEmail)
{
 var er_email1 = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ ;//primer filtro
 var er_email2 = /^([0-9]|[a-z]|[A-Z]|\.|\@|\_|-)+$/ ;//segundo filtro
 var myTest1 =! er_email1.test(inEmail.value); 
 var myTest2 =! er_email2.test(inEmail.value);

    xvar = checkNull(inEmail, "Ingrese por favor su e-mail"); 
	if (!xvar)return false; 
	
	if (inEmail.value.indexOf('@') == -1)
	{
		alert ("Ingrese un e-mail valido"); 
		inEmail.focus(); 
		return false 
	}
	
	if (myTest1 || myTest2) 
	{
		alert('Su e-mail no es Válido\n'
		+'Verifique que este correctamente escrito\n'
		+'Posibles errores:\n'
		+'- Su e-mail contiene caracteres especiales [#$%&8¿?Çñ]\n'
		+'- Su e-mail contiene tildes [áéíóú]\n- Su e-mail contiene espacios en blanco');
		inEmail.focus(); 
		return false;
	}
	return true
}


function checkList(inComp, inMsg){
	if(inComp.options[inComp.selectedIndex].value == -1)
	{
		alert(inMsg);
		inComp.focus();
		return false;
	}
	return true;
}

function checkPassword(inComp1,inComp2)
{
	xvar=checkNull(inComp1, "Ingrese por favor una contraseña"); if (!xvar)return false; 
	
	if(inComp1.value.length < 5)
	{
		alert ("Ingrese una contraseña no menor de 5 caracteres")
		inComp1.value = ""
		inComp1.focus()
		return false;
	}
	
	if(inComp1.value != inComp2.value)
	{
	 	alert ("La contraseña ingresada no coinciden con la contraseña de confirmación")
	 	inComp1.value = ""
	 	inComp2.value = ""
		inComp1.focus()
		return false;
	} 
	return true;
}

/* Version 2.0 - 08/03/2005  */
function trim(str)
{
	if (typeof str != "string") return str;
	str = str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
}


//popups
function windows(url, name, myWidth, myHeight)
{
	myLeft = (window.screen.width / 2) - (myWidth / 2)
	myTop = (window.screen.height / 2) - (myHeight / 2)
	myWindow = window.open(url, name, "width =" + myWidth + ", height =" + myHeight + " , left =" + myLeft + ", top =" + myTop +", toolbar=0, resizable=1, scrollbars=1, status=no, menubar=no")
	myWindow.focus();
}


var nav4 = window.Event ? true : false;
function acceptNum(evt)
{	
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
	var key = nav4 ? evt.which : evt.keyCode;	
	return (key <= 13 || (key >= 48 && key <= 57));
}
//-->


function es_alfanumerico(str,Validos){
		strInputString=str.toString();
		strValidos=Validos.toString();
		fin_i = strInputString.length+10;
		fin_z = strValidos.length + 10;
		encontro=false;
		for(i=0;i<strInputString.length;i++){
			for(z=0;z<strValidos.length;z++){
				if(strInputString.substr(i,1) == strValidos.substr(z,1)){
					z=fin_z;
				}
			}
			if(z==fin_z+1)
				encontro = true;
			else{
				i=fin_i;
				encontro = false;
			}
		}
		return encontro;
	}

function esNumero(inComp1,inMens)
{
   cadena="0123456789";
   if(!es_alfanumerico(inComp1.value,cadena)){
		alert(inMens);
		inComp1.value = "";
		inComp1.focus();
		return false;
   }else{	   	
		return true;	   
   }
   
  
   
}

function esDouble(inComp1,inMens)
{
	cadena="0123456789.";
   if(!es_alfanumerico(inComp1.value,cadena)){
		alert(inMens);
		inComp1.value = "";
		inComp1.focus();
		return false;
   }else{	   	
		return true;	   
   }
   
}

/*function restaurar(){
	window.focus()
	setTimeout("restaurar()",300);
}*/


function msgBox(){  

	myWidth	 = 400;
	myHeight = 40;
	myLeft = (window.screen.width / 2) - (myWidth / 2)
	myTop = (window.screen.height / 2) - (myHeight / 2)
	
	if (window.showModalDialog) {
		modal = window.showModalDialog("msgbox.php","name","dialogWidth: "+ myWidth +"px; dialogHeight:124px; center:yes; help:no; scroll:no; status:no");
	}else{
		modal = window.open("msgbox.php","name","width =" + myWidth + ", height =" + myHeight + ", left =" + myLeft + ", top =" + myTop +", toolbar=no, directories=no, status=no, linemenubar=no, scrollbars=no, resizable=no, modal=yes");
	}

}



/*Nuevos Campos de Texto*/
var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput(inDIV) {
  arrInput.push(arrInput.length);
  arrInputValue.push("");
  display(inDIV);
}

function display(inDIV) {
	get(inDIV).innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    get(inDIV).innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}

function createInput(id,value) {
  intID = 2 + intI;
  return '<div class="xrow">'+
  	'<div id="f_label">'+
	'<strong>Tel&eacute;fono '+(intID)+'</strong> : </div><div id="f_ctrl">'+
	'<input name="txt_telf_'+intID+'" type="text" class="f" id="txt_telf_'+intID+'" '+
	'size="15" maxlength="15"'+
	'onChange=\'saveValue('+ id +',this.value)\' value="'+ value +'"/>'+
	' Oficina: <input name="txt_office_'+intID+'" type="text" class="f" id="txt_office_'+intID+'"'+ 
	'size="15" maxlength="15"'+
	//'onChange=\'saveValue2('+ id +',this.value)\' value="'+  +'"/>'+
	'</div></div>';
}

function deleteInput(inDIV) {
  /*if (arrInput.length > 0) { 
     arrInput.pop(); 
     arrInputValue.pop();
  }
  display(inDIV); */
  delItem()
  
}
function delItem() {
  this.parentNode.parentNode.removeChild(this.parentNode);
}
function getArrInput(){
	return intI;	
} 


/*######################################################3otro*/
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    return false;
  }
}


function get(obj) {
  return document.getElementById(obj);
}

function cloneObj(obj){
	return get(obj).cloneNode(true);
}

var frmInfo = new Array();
var frmTel  = new Array();
var frmMail = new Array();

function addInfo ()
{
	var i = frmInfo.length;
	frmInfo.push(i); //agrega un elemento 
	frmInfo[i]=cloneObj("info_clone");
	get("info_group").appendChild(frmInfo[i]);
	if(arguments.length==0){
		document.form1["txt_info1T[]"][i+3].value = "";
		document.form1["txt_info1B[]"][i+3].value = "";
	}else{
		document.form1["txt_info1T[]"][i].value =arguments[0];
		document.form1["txt_info1B[]"][i].value = arguments[1];
	}
}
function addTel(){
	var i = frmTel.length;
	frmTel.push(i); //agrega un elemento 

	frmTel[i]=cloneObj("tel_clone")//elemento a clonar ;
	get("tel_group").appendChild(frmTel[i])// lugar donde se va clonar;
	
	if(arguments.length == 0){
		document.form1["txt_telf[]"][i+1].value = "";
		document.form1["txt_location[]"][i+1].value="";
	}else{
		document.form1["ctrl_tt[]"][i].options[arguments[0]-1].selected=true;
		document.form1["txt_telf[]"][i].value = arguments[1] 
		document.form1["txt_location[]"][i].value= arguments[2]
	}
}

function addMail(){
	var i = frmMail.length;
	frmMail.push(i); //agrega un elemento 

	frmMail[i]=cloneObj("mail_clone")//elemento a clonar ;
	get("mail_group").appendChild(frmMail[i])// lugar donde se va clonar;
	
	if(arguments.length == 0){
		document.form1["txt_email[]"][i+1].value = "";
	}else{
		document.form1["ctrl_tm[]"][i].options[arguments[0]-1].selected=true;
		document.form1["txt_email[]"][i].value = arguments[1] 
	}
}


function removeItem()
{
	if(frmInfo.length>0)
	get("info_group").removeChild(frmInfo.pop());
}

function removeTel()
{
	if(frmTel.length > 0)
	get("tel_group").removeChild(frmTel.pop());
}

function removeMail()
{
	if(frmMail.length > 0)
	get("mail_group").removeChild(frmMail.pop());
}


function delItem()
{
  this.parentNode.parentNode.removeChild(this.parentNode);
}
/*###########################################################3333*/
/*AJAX*/

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function view(url, inDIV){
	sec=getHTTPObject();
	URL=url;
	//alert(inDIV);
	sec.open("GET",URL,true); 
     sec.onreadystatechange=function() {
         if (sec.readyState==4)
		  { 
         	if(sec.status==200)
         	{
			 //alert(inDIV)
             document.getElementById(inDIV).innerHTML=sec.responseText;
          }
       }
    }
   sec.send(null);
   
   	xh= url.split('/'); 
	//hashListener.setHash((xh[xh.length-1]));
	//hashListener.setHash("h" + Math.random());
   return
}
function confirmLink(f,g)
{
		e = confirm(g);
		return e
		
}

function ExpCon(ObjectID, LinkID)
{
var identity = document.getElementById(ObjectID);
var imglink = document.getElementById(LinkID);

	if(identity.style.height=="" || identity.style.height=="auto")
	{
		identity.style.height ='0px';
		imglink.src="img/hideMod.gif"
	}
	else
	{
		identity.style.height ='auto';
		imglink.src="img/showMod.gif"
	}
}