function AbrirCentro(url,nompopup,popW,popH,resizable,scroll){
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2; topPos = (h-popH)/2;
	leftPos = leftPos - 20;
	topPos = topPos - 20;
	window.open(url,nompopup,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',resizable=' + resizable + ',scrollbars=' + scroll );
}

function EsEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}

function Password() {
	var errorMsg = "";
	var errorMsgLong = "";
		
	if (document.gatwebsite.username.value == "") {
		errorMsg += "\n\tUserName \t- UserName can not be blank.";
	}
	
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "____________________________________________________________\n\n";
		msg += "The form was not submitted due to errors.\n";
		msg += "Please correct the error(s) and re submit.\n";
		msg += "____________________________________________________________\n\n";
		msg += "The following fields need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return;
	}	
	checkPassword(document.gatwebsite.username.value)
}

function Register(type) {
	document.gatwebsite.action = "/create_account.asp"
	document.gatwebsite.AccountType.value = type
	document.gatwebsite.submit()
}

function Login() {
	var errorMsg = "";
	var errorMsgLong = "";
		
	if (document.gatwebsite.username.value == "") {
		errorMsg += "\n\tUserName \t- UserName can not be blank.";
	}
	if (document.gatwebsite.password.value == "") {
		errorMsg += "\n\tPassword \t- Password can not be blank.";
	}
	
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "____________________________________________________________\n\n";
		msg += "The form was not submitted due to errors.\n";
		msg += "Please correct the error(s) and re submit.\n";
		msg += "____________________________________________________________\n\n";
		msg += "The following fields need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return;
	}	
	document.gatwebsite.action = "/check_account.asp"
	document.gatwebsite.process.value = "login"
	document.gatwebsite.submit()
}

function LoginAdmin() {
	var errorMsg = "";
	var errorMsgLong = "";
		
	if (document.gatwebsite.username.value == "") {
		errorMsg += "\n\tUserName \t- UserName can not be blank.";
	}
	if (document.gatwebsite.password.value == "") {
		errorMsg += "\n\tPassword \t- Password can not be blank.";
	}
	
	if ((errorMsg != "") || (errorMsgLong != "")){
		msg = "____________________________________________________________\n\n";
		msg += "The form was not submitted due to errors.\n";
		msg += "Please correct the error(s) and re submit.\n";
		msg += "____________________________________________________________\n\n";
		msg += "The following fields need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		return;
	}	
	document.gatwebsite.action = "/check_admin.asp"
	document.gatwebsite.process.value = "login"
	document.gatwebsite.submit()
}

function Logout() {
	if (confirm('Are you sure logout?')){
		document.gatwebsite.action = "/check_account.asp"
		document.gatwebsite.process.value = "logout"
		document.gatwebsite.submit()
	}
}

function LogoutAdmin() {
	if (confirm('Are you sure logout?')){
		document.gatwebsite.action = "/check_admin.asp"
		document.gatwebsite.process.value = "logout"
		document.gatwebsite.submit()
	}
}

function Messages(errorMsg) {	
	do {
		errorMsg = errorMsg.replace("_"," ");
	} while(errorMsg.indexOf("_") >= 0);
	msg = "____________________________________________________________\n\n";
	msg += "The form was not submitted due to errors.\n";
	msg += "Please correct the error(s) and re submit.\n";
	msg += "____________________________________________________________\n\n";
	msg += "The following errors to be corrected: -\n";
		
	errorMsg += alert(msg + errorMsg);
	return;
}

Array.prototype.sort = function() {
	for(i=0;i<this .length;i++) {
		for(j=i+1;j<this.length;j++) {
			if(Number(this[i]) >Number(this[j])) {
				temp = this[j];
				this[j] = this[i];
				this[i] = temp;
			}
		}
	}
}

Array.prototype.removeDuplicate = function() {
	// Here we remove duplicate values from first array
	var array4 = new Array;
	for(var i=0; i<this.length; i++) {
		var xx = true;
		for(var j=i+1; j<this.length; j++) {
			if(this[i] == this[j])
				xx = false;		
		}	
		if(xx == true)
			array4.push(this[i]);
	}
	return array4;
}

function ClearID(string) {
	var array1 = string.split(',');
	array1 = array1.removeDuplicate();
	return array1;
}

function FilterID(string) {
    var valid = ",0123456789";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}

function PhoneNumber(string) {
    var valid = "0123456789()*- ";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}

function Amount(string) {
    var valid = ".0123456789";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}

function Integer(string) {
    var valid = "0123456789";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}

function UpperCase(string) {
	rpta = string.toUpperCase();
	return rpta;	
}

function RefreshCaptcha(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function CheckAll(chkbox) {
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		var elemento = document.gatwebsite.elements[i];
		if ((elemento.type == "checkbox") && (elemento.name.substring(0,3) == "chk")) {
			elemento.checked = chkbox.checked
		}
	}
}

function Favorites(process) {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	if (process == "add") { document.gatwebsite.add.value = true }
	if (process == "remove") { document.gatwebsite.remove.value = true }
	document.gatwebsite.submit()
}

function Shipped() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.shipped.value = true
	document.gatwebsite.submit()
}

function Expired() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.expired.value = true
	document.gatwebsite.submit()
}

function Cancel() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.cancel.value = true
	document.gatwebsite.submit()
}

function Active() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.active.value = true
	document.gatwebsite.submit()
}

function Procedure(code,process) {
	if (process == "edit") {
		if (confirm('Are you sure edit?')) {
			document.gatwebsite.action = "edit_loads.asp"
			document.gatwebsite.Loads_Id.value = code
			document.gatwebsite.submit()
		}
	}
	if (process == "review") {
		document.gatwebsite.action = "review_loads.asp"
		document.gatwebsite.Loads_Id.value = code
		document.gatwebsite.submit()
	}	
	if (process == "active") {
		if (confirm('Are you sure active this Load?')) {
			document.gatwebsite.action = "check_loads.asp"
			document.gatwebsite.process.value = "shipped"
			document.gatwebsite.Loads_Id.value = code
			document.gatwebsite.submit()
		}
	}	
	if (process == "favorite") {
		if (confirm('Are you sure favorite this Load?')) {
			document.gatwebsite.action = "check_loads.asp"
			document.gatwebsite.process.value = "favorite"
			document.gatwebsite.Loads_Id.value = code
			document.gatwebsite.submit()
		}
	}	
	if (process == "shipped") {
		if (confirm('Are you sure shipped this Load?')) {
			document.gatwebsite.action = "check_loads.asp"
			document.gatwebsite.process.value = "shipped"
			document.gatwebsite.Loads_Id.value = code
			document.gatwebsite.submit()
		}
	}
	if (process == "expired") {
		if (confirm('Are you sure expired this Load?')) {
			document.gatwebsite.action = "check_loads.asp"
			document.gatwebsite.process.value = "expired"
			document.gatwebsite.Loads_Id.value = code
			document.gatwebsite.submit()
		}
	}	
	if (process == "cancel") {
		if (confirm('Are you sure cancel this Load?')) {
			document.gatwebsite.action = "check_loads.asp"
			document.gatwebsite.process.value = "cancel"
			document.gatwebsite.Loads_Id.value = code
			document.gatwebsite.submit()
		}
	}
	if (process == "details") {
		document.gatwebsite.action = "view_profile.asp"
		document.gatwebsite.process.value = "view"
		document.gatwebsite.Profile_Id.value = code
		document.gatwebsite.submit()
	}
	if (process == "login") {
		document.gatwebsite.action = "check_account.asp"
		document.gatwebsite.target = "_blank"
		document.gatwebsite.process.value = "autologin"
		document.gatwebsite.Profile_Id.value = code
		document.gatwebsite.submit()
	}
	if (process == "enable") {
		document.gatwebsite.action = "check_account.asp"
		document.gatwebsite.process.value = "enable"
		document.gatwebsite.Profile_Id.value = code
		document.gatwebsite.submit()
	}	
	if (process == "incomplete") {
		document.gatwebsite.action = "check_account.asp"
		document.gatwebsite.process.value = "incomplete"
		document.gatwebsite.Profile_Id.value = code
		document.gatwebsite.submit()
	}	
	if (process == "verify") {
		document.gatwebsite.action = "check_account.asp"
		document.gatwebsite.process.value = "verify"
		document.gatwebsite.Profile_Id.value = code
		document.gatwebsite.submit()
	}	
	if (process == "disable") {
		document.gatwebsite.action = "check_account.asp"
		document.gatwebsite.process.value = "disable"
		document.gatwebsite.Profile_Id.value = code
		document.gatwebsite.submit()
	}		
}

function Enable() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.enable.value = true
	document.gatwebsite.submit()
}

function Incomplete() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.incomplete.value = true
	document.gatwebsite.submit()
}

function Verify() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.verify.value = true
	document.gatwebsite.submit()
}

function Disable() {
	estado = 0
	for (var i=0;i < document.gatwebsite.elements.length;i++) {		
		if (document.gatwebsite.elements[i].name.substring(0,3) == "chk") {
			if (document.gatwebsite.elements[i].checked == true) {
				estado = 1
			}
		}
	}
	if (estado == 0) {
		alert("You need to choose at least one Load.")
		return
	}
	document.gatwebsite.disable.value = true
	document.gatwebsite.submit()
}