function checkNull(inComp, inMsg)
{
  var er_empty = /^$/ 
	while (er_empty.test(inComp.value))
	{
	   alert(inMsg); 
	   inComp.focus(); 
	   return false;
	    
	 }
	 return true
}



function checkEmailb(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 confirmLink(f,g)
{
		e = confirm(g);
		return e
		
}

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");
	}

}

/* Version 2.0 - 08/03/2005  */
function trim(str)
{
	if (typeof str != "string") return str;
	str = str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
}

//popups emergentes
function emergentes(archivo, params, name, myWidth, myHeight)
{
	myLeft = (window.screen.width / 2) - (myWidth / 2)
	myTop = (window.screen.height / 2) - (myHeight / 2)
	
	
	if(archivo == "terminos")
	{
			scrollbars = 1;
	}else
	{
			scrollbars = 0;
	}
	
	myWindow = window.open(SERVER_NAME+"emergente.php?PG="+archivo+"&"+params, name, "width =" + myWidth + ", height =" + myHeight + " , left =" + myLeft + ", top =" + myTop +", toolbar=0, resizable=0, scrollbars="+scrollbars+", status=no, menubar=no")
	myWindow.focus();
}

//popups
function windowsopen(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=yes, status=no, menubar=no")
	myWindow.focus();
}

function windowsImage(page,img,name){	
 img1 = new Image()
 img1.src = img
 //alert(img1.width+'-'+img1.height);
 url = page+"?img="+img
 //alert(url);
 myWindow = window.open(url,name,"width =" + (img1.width+20) + ", height =" + (img1.height+50) + " ,left =50, top =50, toolbar=no, resizable=no, scrollbars=yes, status=no, menubar=no")
// alert(10);
 myWindow.focus();
}


/*function view(url){
	windows(url, "catalogo", 330, 460);
}*/

function pd(url){
	windows(url, "pd", 300, 235);	
}

//Constructor del objeto XMLHttpRequest
function getHTTPObject() {
	try {
		objetus = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try { 
			objetus= new ActiveXObject ("Microsoft.XMLHTTP");
		} catch (E) {
			objetus= false; 
		} 
	}
	
	if (!objetus && typeof XMLHttpRequest!= 'undefined') {
		objetus = new XMLHttpRequest();
	} 
	
	return objetus
}

//Carga una pagina y la muestra
function view(url, inDIV) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() {
		if(sec.readyState == 1)
		{
				document.getElementById(inDIV).innerHTML = "Cargando...";
		}
		if(sec.readyState == 4) 
		{
			if(sec.status == 200) { 
				document.getElementById(inDIV).innerHTML = sec.responseText;
			} else {
				switch(sec.status) {
					case 404:
						alert("404: " + sec.statusText);
						alert("No se encontró URL");
						break;						
					case 414:
						alert("414: " + sec.statusText);					
						alert("Los valores pasados por GET superan los 512");
						break;						
				}
			}
		}
	}
	 sec.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	sec.send(null);
}

//Carga una pagina y la muestra
function ajaxPost(url, valores, inDIV, acumula,textoloadin) {
	var sec = getHTTPObject();
	sec.open("POST", url, true); 
	//alert(url);
	sec.onreadystatechange = function() {
		if(sec.readyState == 1)
		{
				if(!textoloadin)
				{
					textoloadin = "Cargando...";
				}
				
				document.getElementById(inDIV).innerHTML = '<br><table border="0" align="center"><tr><td><img src="public/images/ajax-loader.gif" border="0" /></td><td style="color:#527fbf">'+textoloadin+'</td></tr></table>'
				
		}
		if(sec.readyState == 4) 
		{
			if(sec.status == 200) { 
				if(acumula)
				{
					document.getElementById(inDIV).innerHTML = document.getElementById(inDIV).innerHTML+sec.responseText;
				}else
				{
					document.getElementById(inDIV).innerHTML = sec.responseText;
				}
				
			} else {
				switch(sec.status) {
					case 404:
						alert("404: " + sec.statusText);
						alert("No se encontró URL");
						//document.getElementById(inDIV).innerHTML = "No se encontró URL";
						break;						
					case 414:
						alert("414: " + sec.statusText);					
						alert("Los valores pasados por GET superan los 512");
						//document.getElementById(inDIV).innerHTML = "Los valores pasados por GET superan los 512";
						break;						
				}
			}
		}
	}
	sec.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	sec.send(valores);
}

function sendMailAjax(url, inDIV,isreolad) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() {
		if(sec.readyState == 1)
		{			
			//document.getElementById(inDIV).innerHTML = "Enviando Correos...";
		}
		if(sec.readyState == 4) 
		{
			if(sec.status == 200) { 
				alert(sec.responseText);
				if(isreolad)
				{
					document.location.reload()
				}
			} else {
				switch(sec.status) {
					case 404:
						alert("404: " + sec.statusText);
						alert("No se encontró URL");
						break;						
					case 414:
						alert("414: " + sec.statusText);					
						alert("Los valores pasados por GET superan los 512");
						break;						
				}
			}
		}
	}
	   
	sec.send(null);
}

function viewValidEmail(url,inDIVt,inbtnnameideDIVt) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() {
		if(sec.readyState == 1)
		{
				document.getElementById(inDIVt).innerHTML = "Validando correo electrónico...";
		}
		if(sec.readyState == 4) 
		{
			if(sec.status == 200) {
				respot = sec.responseText;
				if(respot == "1")
				{
					document.getElementById(inDIVt).innerHTML = "<font color=#006600>El correo electrónico no está registrado. puede continuar.</font>";
					document.getElementById(inbtnnameideDIVt).disabled = false;
					
				}else
				{
					document.getElementById(inDIVt).innerHTML = "<font color=#990000>"+respot+"</font>";				
					document.getElementById(inbtnnameideDIVt).disabled = true;
				}
			} else {
				switch(sec.status) {
					case 404:
						alert("404: " + sec.statusText);
						alert("No se encontró URL "+url);
						break;						
					case 414:
						alert("414: " + sec.statusText);					
						alert("Los valores pasados por GET superan los 512");
						break;						
				}
			}
		}
	}
	   
	sec.send(null);
}


function viewValidLogin(url,inDIVt,inbtnnameideDIVt) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() {
		if(sec.readyState == 1)
		{
				document.getElementById(inDIVt).innerHTML = "Validando nombre de usuario...";
		}
		if(sec.readyState == 4) 
		{
			if(sec.status == 200) {
				respot = sec.responseText;
				if(respot == "1")
				{
					document.getElementById(inDIVt).innerHTML = "<font color=#006600>El nombre de usuario no está registrado. puede continuar.</font>";
					document.getElementById(inbtnnameideDIVt).disabled = false;
					
				}else
				{
					document.getElementById(inDIVt).innerHTML = "<font color=#990000>"+respot+"</font>";				
					document.getElementById(inbtnnameideDIVt).disabled = true;
				}
			} else {
				switch(sec.status) {
					case 404:
						alert("404: " + sec.statusText);
						alert("No se encontró URL "+url);
						break;						
					case 414:
						alert("414: " + sec.statusText);					
						alert("Los valores pasados por GET superan los 512");
						break;						
				}
			}
		}
	}
	   
	sec.send(null);
}


function viewValidCodePartToChange(url,inDIVt,inbtnnameideDIVt) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() {
		if(sec.readyState == 1)
		{
				document.getElementById(inDIVt).innerHTML = "Validando...";
		}
		if(sec.readyState == 4) 
		{
			if(sec.status == 200) {
				respot = sec.responseText;
				if(respot != "1")
				{
					document.getElementById(inDIVt).innerHTML = "<font color=#990000>"+respot+"</font>";					
					document.getElementById(inbtnnameideDIVt).disabled = true;
					
				}else
				{
					document.getElementById(inDIVt).innerHTML = "<font color=#006600>Ok</font>";
					document.getElementById(inbtnnameideDIVt).disabled = false;
					
				}
			} else {
				switch(sec.status) {
					case 404:
						alert("404: " + sec.statusText);
						alert("No se encontró URL "+url);
						break;						
					case 414:
						alert("414: " + sec.statusText);					
						alert("Los valores pasados por GET superan los 512");
						break;						
				}
			}
		}
	}
	   
	sec.send(null);
}


/*requeridos*/

function cloneObj(obj){
	return get(obj).cloneNode(true);
}
function get(obj) {
  return document.getElementById(obj);
}

/**
 * Opens calendar window.
 *
 * @param   string      calendar.php parameters
 * @param   string      form name
 * @param   string      field name
 * @param   string      edit type - date/timestamp
 */
function openCalendar(params, form, field, type) {
    window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
    dateField = eval("document." + form + "." + field);
    dateType = type;
}

//Mas en: http://javascript.espaciolatino.com/
//Objeto oNumero
function oNumero(numero)
{
	//Propiedades
	this.valor = numero || 0
	this.dec = -1;
	//Métodos
	this.formato = numFormat;
	this.ponValor = ponValor;
	//Definición de los métodos
	
	function ponValor(cad)
	{
		if (cad =='-' || cad=='+') return
		if (cad.length ==0) return
		if (cad.indexOf('.') >=0)
			this.valor = parseFloat(cad);
		else
			this.valor = parseInt(cad);
	}

function numFormat(dec, miles)
{
	var num = this.valor, signo=3, expr;
	var cad = ""+this.valor;
	var ceros = "", pos, pdec, i;
	for (i=0; i < dec; i++)
		ceros += '0';
		pos = cad.indexOf('.')
		if (pos < 0)
	    	cad = cad+"."+ceros;
		else
    	{
		    pdec = cad.length - pos -1;
		    if (pdec <= dec)
        	{
		        for (i=0; i< (dec-pdec); i++)
        		    cad += '0';
		    }
		    else
        	{
				num = num*Math.pow(10, dec);
				num = Math.round(num);
				num = num/Math.pow(10, dec);
				cad = new String(num);
	        }
    	}
		pos = cad.indexOf('.')
		if (pos < 0) pos = cad.lentgh
		if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+')
	       signo = 4;
		if (miles && pos > signo)
		    do{
        	expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
	        cad.match(expr)
    	    cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
        	}
			while (cad.indexOf(',') > signo)
		    if (dec<0) cad = cad.replace(/\./,'')
        		return cad;
			}
	}//Fin del objeto oNumero:

function formateranumero(textfield)
{
	var numero = new oNumero(textfield.value);
	textfield.value = numero.formato(2, true);
}


function disabledAllElements(frm)
{
		if (frm.elements.length) 
		for (var i = 0; i < frm.elements.length; i++){

			var obj = frm.elements[i];			
			switch (obj.type){
				
				case 'text':									
				case 'file':										
				case 'password':									
				case 'textarea':				
				case 'radio':				
				case 'checkbox':
				case 'select-one':
					obj.disabled = true;
			}
		}

}


function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function printswftransparent(ruta, ancho, alto)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ancho+'" height="'+alto+'">');
	document.write('  <param name="movie" value="'+ruta+'" />');
	document.write('  <param name="quality" value="high" />');
	document.write('  <PARAM NAME=wmode VALUE=transparent />');
	document.write('  <PARAM NAME=bgcolor VALUE=#FFFFFF>');
	document.write('  <embed src="'+ruta+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode=transparent bgcolor=#FFFFF type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" width="'+ancho+'" height="'+alto+'"></embed>');
	document.write('</object>');
}

function printswf(ruta, ancho, alto)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ancho+'" height="'+alto+'">');
	document.write('  <param name="movie" value="'+ruta+'" />');
	document.write('  <param name="quality" value="high" />');
	document.write('  <embed src="'+ruta+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ancho+'" height="'+alto+'"></embed>');
	document.write('</object>');
}


