// Scripts_VP.js		Ventasalpublico.com   Ultima Actualzacion: Enero 17 de 2003
function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0 art
  var a,i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
    test=args[i+2]; 
  	mensaje=args[i+1];
	val=MM_findObj(args[i]);
	a=0;
    if(test=='RS') {	// art revisa Select valor Numerio <> 0
      if (val.value==0 || val.value=='0' || val.selectedIndex == 0) { errors += '- '+mensaje+' es requerido.\n';}
      a=1;
	 } // if test RS
	 
	if (val && a==0) {
	  nm=val.name; 
	  if ((val=val.value)!="") {  
        if (test.indexOf('isEmail')!=-1) { 
		  p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) { errors+='- '+mensaje+' debe ser una dirección de e-mail.\n'; }
        } else 
		  if (test!='R') {
            if (isNaN(val)) { errors+='- '+mensaje+' debe ser un Número.\n'; }
            if (test.indexOf('inRange') != -1) { 
			  p=test.indexOf(':');
              min=parseFloat(test.substring(8,p)); max= parseFloat(test.substring(p+1));
              if (val < min || val > max) { errors+='- '+mensaje+' ('+val+') debe ser un Número entre '+min+' y '+max+'.\n'; }
    		} 
	  	  } // test
	  } else 
	    if (test.charAt(0) == 'R') { errors += '- '+mensaje+' es requerido.\n';}
	} // if val
  } // for
  if (errors) { alert('Ocurrieron los siguientes errores:\n'+errors); }
  document.MM_returnValue = (errors == '');
}

function confirmaPass(p,c) {
  if (p.value == ''  || c.value == '') {
     alert("Campo requerido: Password");
    p.select();
    p.focus();
    return(false);
  } else { 
    if (p.value == c.value) return(true); 
     else { 
       alert("El password y la confirmación son diferentes. Reescribalos por favor.");
       p.select();
       p.focus();
       return(false);  }
    }
 }

var counter  = 0;
var cookData = "";

function getCookieData(name) {
  var label = name + "=";
  var labelLen = label.length;
  var cLen = document.cookie.length;
  var i = 0;
  while (i < cLen) {
   var j = i + labelLen;
   if (document.cookie.substring(i,j) == label) {
	var cEnd = document.cookie.indexOf(";",j);
	if (cEnd == -1) {
		cEnd = document.cookie.length;		}
	return unescape(document.cookie.substring(j,cEnd));
   }
   i++;
  } 
return "";
}

function setCookieData(name,value,expires,cue) {
  if(navigator.cookieEnabled) {
   document.cookie = name + "=" + cue + "@" + value + "; expires=" + expires;
  } else {
  alert("Para Realizar compras su navegador debe tener habilitados los cookies");
//  javascript:WinOpen('navegacookie.php','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=500, left=40');
  } 
}

function killCookie(name) {
 if (getCookieData(name)) {
  document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT";
  counter = 0;
  cookData = "";
 }
}

function showMe(name) {
 display = getCookieData(name);
 alert(display);
}

function fix(num) {
 string = "" + num;
 if (string.indexOf('.') == -1)
  return string;
 seperation = string.length - string.indexOf('.');
 if (seperation > 3)
  return string.substring(0,string.length-seperation+3);
 else if (seperation == 2)
  return string + '0';
 return string;
}

function WinOpen(strUrl,vent) { 
 newWindow = window.open( strUrl, 'Mensaje', vent);
 newWindow.focus();
}

function Mensaje(M,N){
 WinOpen('alerta.php?MensAlarma='+M +'&MensTit='+N,'toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=300, left=40');
}

function NoUser(){
 WinOpen('nouser.php','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=300, left=40');
}

function PassNoOk(){
 WinOpen('passnook.php',"toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=300, left=40");
}

function moduser(j) {
 MM_validateForm('email23','Email','RisEmail','pass23','Password','R');
if (document.MM_returnValue) { document.location.href = 'index.php?Com=Ru&email23='+document.user.email23.value +'&pass23='+document.user.pass23.value +'&Re=true'; }
}

function enviapass(f){
 MM_validateForm('email','Email','RisEmail');
 if (document.MM_returnValue) { WinOpen('sendpass.php?email23='+document.Compra.email.value,"toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=300, left=40"); }
}

function Ya(num){
 setTimeout("window.close()",num*1000);
}

function addUser(mailU,nomU,apeU,emprU,fpU) {
 killCookie(galletaU);
// showMe(galletaU);
 addU = '' + mailU + '`' + nomU  + '~' + apeU + '^'  + emprU + 'õ';
 UData = eval("addU");
 setCookieData(galletaU, UData, expdate.toGMTString(),fpU);
}

function moduser2(j) {
MM_validateForm('email23','Email','RisEmail','pass23','Password','R');
if (document.MM_returnValue) {
 document.location.href = 'index.php?Com=Ru&RegCorto=1&email23='+document.user.email23.value +'&pass23='+document.user.pass23.value +'&Re=true';
 }
}

function AUmoduser(j) {
MM_validateForm('emailAU','Email','RisEmail','passAU','Password','R');
if (document.MM_returnValue) { document.location.href = 'index.php?Com=Ru&email23='+document.AUuser.emailAU.value +'&pass23='+document.AUuser.passAU.value +'&Re=true&email2='+document.AUuser.emailAU.value +'&pass2='+document.AUuser.passAU.value +'&NewUser=1'; }
}

function AUenviapass(f){
MM_validateForm('emailAU','Email','RisEmail');
if (document.MM_returnValue) { WinOpen('sendpass.php?email23='+document.AUuser.emailAU.value,"toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=300, left=40"); }
}

function enviapass2(f){
MM_validateForm('email2','Email','RisEmail');
if (document.MM_returnValue) { WinOpen('sendpass.php?email23='+document.User.email2.value,"toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,copyhistory=no,width=310,height=300, left=40"); }
}

function Recarga(){
  window.location.reload();
}