// JavaScript Document


function irUrl(url) 
{ 
	location.href = url;
}

function ajustarimagen(imgfuente, w, h, wmax,hmax){
			formImg = eval(imgfuente)
		  if (formImg.width > wmax) {
				formImg.width = wmax
				formImg.height = wmax*h/w
			}
			
		  if (formImg.height > hmax) {
				formImg.height =hmax
				formImg.width = hmax*w/h				
			}
}

function abrirbusqueda(pagina,alto,ancho){
	 op = window.open(pagina,'_new','menubar=no,scrollbars=yes,toolbar=no,status=no,height='+alto+',width='+ancho+'');
	 op.opener = self
}

// Funciones tipo MM
function confirmacion(msg,url) { //v1.0
  if (confirm(msg)==true) 
	{  
		location.href=url;  
	}
}


function Alternar(Seccion)
{ 
    if (Seccion.style.display=="none")
		{Seccion.style.display=""}
    else
		{Seccion.style.display="none"} 
}



function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function openpopup(){
window.open("pendientes.asp","","width=300,height=125")
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length

      // set index of beginning of value

      end = document.cookie.indexOf(";", offset);

      // set index of end of cookie value

      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadpopup(){
	if (get_cookie('popped')==''){
			openpopup()
			document.cookie="popped=yes"
		}
}

function fVentana(nom_pag,idemp,idcli) {
	 pag = nom_pag+'?idemp='+idemp+'&idcli='+idcli
	window.open(pag,'nuevo','menubar=no,scrollbars=yes,toolbar=no,statusbar=no,height=400,width=300');
}

function fWindow(nom_pag,idemp,idcli) {
	 pag = nom_pag+'?idemp='+idemp+'&idcli='+idcli
	window.open(pag,'nuevo','menubar=no,scrollbars=yes,toolbar=no,statusbar=no,height=400,width=300');
}

function fGroup(nom_pag,idemp,idcli) {
	 pag = nom_pag+'?idemp='+idemp+'&idcli='+idcli
	window.open(pag,'nuevo','menubar=no,scrollbars=yes,toolbar=no,statusbar=no,height=400,width=300');
}


function fPopUp(pagina,alto,ancho){
	 window.open(pagina,'_new','menubar=no,scrollbars=no,toolbar=no,statusbar=no,height='+alto+',width='+ancho+'');
}



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 YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}

/* Funcion showpedidosrev */

function GP_popupConfirmMsg(msg) { //v1.0
  document.MM_returnValue = confirm(msg);
}

function fRegistrar()
{
	/* Valida los campos */
	// ---------- NOMBRES ----------------------
	if(document.frmadd.Nombre.value == '')
	{
		alert('its name must write ');
		document.frmadd.Nombre.focus();
		return;
	}
	// ---------- LOGIN ----------------------
	if (document.frmadd.Login.value == '')	
	{
		alert('its login must write ');
		document.frmadd.Login.focus();
		return;
	}

	// ---------- PASSWORD ----------------------
	if (document.frmadd.Password.value == '')	
	{
		alert('its password must write ');
		document.frmadd.Password.focus();
		return;
	}

	// ---------- EMAIL ----------------------	
	if (document.frmadd.Email.value == '')	
	{
		alert('its Email must write ');
		document.frmadd.Email.focus();
		return;
	}
	else
	{

/*		var s = document.frmRegistro_Tmp.CUSR_EMAIL.value;
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		  if (!filter.test(s))
		 alert("Entre una direccion Email valida");
		 document.frmRegistro_Tmp.CUSR_EMAIL.focus();
		return;*/
		/* isEmailAddress(document.frmRegistro_Tmp.CUSR_EMAIL, 'document.frmRegistro_Tmp.CUSR_EMAIL' )
		 return;*/
		if ((document.frmadd.Email.value.indexOf ('@', 0) == -1)||(document.frmadd.Email.value.length < 5))
		{ 
			alert("A valid direction of email must write"); 
			document.frmadd.Email.focus();
			return; 
		  }
	}

	if (confirm('Do you want save this') == true)
	{
		document.frmadd.submit();
	}
}


function fCompara()
{
 valor1 = parseInt(document.frmadd.PriceFrom.options[document.frmadd.PriceFrom.selectedIndex].value)
 valor2 = parseInt(document.frmadd.PriceTo.options[document.frmadd.PriceTo.selectedIndex].value)
 if (valor1>valor2)
 {
 alert('Price To does not have to be smaller than Price From');
 }
 
}

/* Funciones de Reportes */

function idsender(num)
{
	document.report_menu.tipo.value = num;
	document.report_menu.submit();
}

function validarEntero()
{ 

	 if (document.frmfiltros.PriceFrom.value != '')
	 {
	 valor = document.frmfiltros.PriceFrom.value;
     valor = parseInt(valor) 
      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
            //entonces (no es numero) devuelvo el valor cadena vacia 
           alert('Field Price from not is number');
		   document.frmfiltros.PriceFrom.focus();
		    return;
	      }
	 }

      //intento convertir a entero. 
     //si era un entero no le afecta, si no lo era lo intenta convertir 
	 if (document.frmfiltros.PriceTo.value != '')
	 {
	 valor = document.frmfiltros.PriceTo.value;
     valor = parseInt(valor);
      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
            //entonces (no es numero) devuelvo el valor cadena vacia 
           alert('Field Price to not is number');
		   document.frmfiltros.PriceTo.focus();
		    return;
	      }
	 }
	 document.frmfiltros.submit();
} 

function CallDestroy()
{
	window.open("Cleanup.asp");
}


/* Funciones de Users/Agents */

function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}


/* Funcion de Seleccion de empresa en Entrerprise */

function redirecciona(id)
{
location.href = "sop_contagentfile3.asp?up=1&empid=" + id
}

function redirecc(id)
{
location.href = "ECom-sop_contagentfile3.asp?up=1&empid=" + id
}

