/* ---------------------------------------------*
* Modulo Fuctions.js  							*
* Autor : samuel chuquista alcarraz		*
* e-mail: sachual@gmail.com				*

* ----------------------------------------------*/

/*----------------------------------------- *
* 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, "E-mail is required."); 
	if (!xvar)return false; 
	
	if (inEmail.value.indexOf('@') == -1)
	{
		alert ("Please enter a valid email address. For example fred@domain.com."); 
		inEmail.focus(); 
		return false 
	}
	
	if (myTest1 || myTest2) 
	{
		alert('Please enter a valid email address. For example fred@domain.com.');
		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;
}


/* 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=0, status=no, menubar=no")
	myWindow.focus();
}

function windowsall(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();
}


function windowsImage(page,img,name){	
 img1 = new Image()
 img1.src = img
 //alert(img1.width+'-'+img1.height);
 url = page+"?img="+img
 //alert(url);
 width = img1.width+100
 height = img1.height+50
 
 //alert(width+"*"+height);
 if(width < 400){
	 width = 400;
 }
 
 
 if(height < 400){
	 height = 400;
 }
 //alert(width+"*"+height);
 myWindow = window.open(url,name,"width =" + (width) + ", height =" + (height) + " ,left =50, top =50, toolbar=0, resizable=1, scrollbars=0, 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 viewajaxnoview(url) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() 
	{
	}	   
	sec.send(null);
}

//Carga una pagina y la muestra
function viewajax(url, inDIV) {
	var sec = getHTTPObject();
	sec.open("GET", url, true); 
	//alert(url);
	sec.onreadystatechange = function() 
	{
		//alert(sec.readyState);
		if(sec.readyState == 1) {
			document.getElementById(inDIV).innerHTML = " <font style='font-family:Arial, Helvetica, sans-serif; font-size:10px'><img border='0' src='/public/images/loading.gif'  /> Loading...</font>";
			//document.getElementById(inDIV).innerHTML = "Loading...";
		}
		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.send(null);
}