//// Copyright © 2005 Avilar Technologies, Inc. All rights reserved.


//--------------------------------
// Do nothing (void function placeholder)
//--------------------------------
function doNothing() {
}

//--------------------------------
// Display status bar message.
//--------------------------------
function showStatus(msg) {
	window.status = msg
	return true
}

//--------------------------------
// Set global date variables for copyright notice.
//--------------------------------

var today = new Date()
var year = today.getYear()
if(year < 1000){
	year += 1900
}

var monthArray = new Array("January", "February", "March", 
                   "April", "May", "June", "July", "August",
                   "September", "October", "November", "December")

//--------------------------------
// Popup window creator.
// syntax: launchPopup(file)
//
//     where path = <path or URL to load into the window>
//--------------------------------

var newPopupWindow

function launchPopup(path) {

var popupURL = path;
var windowFeatures = "scrollbars,toolbar=no,directories=no,menubar,resizable,width=800,height=645"
    
if (!newPopupWindow || newPopupWindow.closed) {

    newPopupWindow = window.open(popupURL,"Popup",windowFeatures) 

    // Create .opener property if necessary for old browsers.
    if (!newPopupWindow.opener) {
    	newPopupWindow.opener = window
    }
} else {
    // window's already open; bring to front
    newPopupWindow.focus()
    }
}

//--------------------------------
// Sendform launcher (to email form data)
// syntax: invoke_sendform(filename)
//--------------------------------

function invoke_sendform(filename){
    var working_url = window.location.href
    window.location = "/cgi-bin/sendform.cgi?init="+filename+"&working_url="+escape(working_url);
}

//--------------------------------
// Maintenance Alert
// syntax: display_alert()
//--------------------------------

function display_alert(){
    var message = "NOTICE: The web server that operates this site will undergo scheduled maintenance\non Tuesday, March 19, 2002 from 6:00-7:00 am EST. You may experience some brief\ninterruptions in service during this period. We apologize for any inconvenience that\nthis may cause."
    alert (message)
}

//----------------------------
// Email address masking
//----------------------------

// Set global variables. 
 
var special= "#$%^&*()-+=!@|.:";
var atsign = special.charAt(12);
var dot = special.charAt(14);
var colon = special.charAt(15);
var zzz = "c" + "o" + "m";
var emailProtocol = "mai" + "lto" + colon;
var Domain = atsign + "avilar" + dot + zzz;

function eMail (masked,visible) {
    this.masked = masked
    this.visible = visible
}

// Associate each masked email address with its visible link text.
// Edit only the items in quotes. 

var emailAddrs = new Array ()
    emailAddrs[0] = new eMail(emailProtocol + "webmaster" + Domain,"Webmaster")
    emailAddrs[1] = new eMail(emailProtocol + "webmentor" + Domain,"Webmentor")
    emailAddrs[2] = new eMail(emailProtocol + "sales" + Domain,"Sales")
    emailAddrs[3] = new eMail(emailProtocol + "support" + Domain,"Tech Support")
    emailAddrs[4] = new eMail(emailProtocol + "hr" + Domain,"Human Resources")
    emailAddrs[5] = new eMail(emailProtocol + "security" + Domain,"Security")
	emailAddrs[6] = new eMail(emailProtocol + "webmaster" + Domain,"Webmaster")
    emailAddrs[7] = new eMail(emailProtocol + "webmentor" + Domain,"Webmentor")
    emailAddrs[8] = new eMail(emailProtocol + "sales" + Domain,"Ventas")
    emailAddrs[9] = new eMail(emailProtocol + "support" + Domain,"Soporte Técnico")
    emailAddrs[10] = new eMail(emailProtocol + "hr" + Domain,"Recursos Humanos")
    emailAddrs[11] = new eMail(emailProtocol + "security" + Domain,"Seguridad")
//    emailAddrs[0] = new eMail(emailProtocol + "w3bm4st3r" + Domain,"Webmaster")
//    emailAddrs[1] = new eMail(emailProtocol + "w3bm3nt0r" + Domain,"Webmentor")
//    emailAddrs[2] = new eMail(emailProtocol + "s4l3s" + Domain,"Sales")
//    emailAddrs[3] = new eMail(emailProtocol + "s2pp0rt" + Domain,"Tech Support")
//    emailAddrs[4] = new eMail(emailProtocol + "8chare" + Domain,"Human Resources")
//    emailAddrs[5] = new eMail(emailProtocol + "s3c2r1ty" + Domain,"Security")

function writeMaskedAddr (addrID,subject,style) {
// Write an email link onto the page. 
// Arguments: addrID  = array index of one of the address in the emailAddrs array defined above. 
//                     This identifies which address you want to send the email to.
//                     Example: writeMaskedAddr(0) sends email to the "webmaster" address.
//            subject = Optional quoted string variable for email Subject line. If omitted, no Subject
//                     is supplied for the email message. Users, of course, may add a subject manually.
//                     Example: writeMaskedAddr(2,'Sales inquiry from the web site')
//            style   = Optional CSS style for the link

	document.write("<a href=\"javascript:doNothing()\;\"");
	if (style != '') {
		document.write(" class='" + style + "' ");
	}
	document.write(" onMouseOver=\"return showStatus('Send email.')\" onMouseOut=\"return showStatus('')\"");
	document.write(" onClick=\"parent.location='");
	document.write(emailAddrs[addrID].masked);
	if (subject == '') {
		document.write("'\">");
	} else {
		document.write("?subject=" + subject + "'\">");
	}
	document.write(emailAddrs[addrID].visible);
	document.write("</a>");
}

function fillTo(f,addrID){
// Supply the TO field to sendform.cgi. 
// Arguments: f       = name of the FORM object invoking sendform.cgi. Typically 'document.name'. 
//            addrID  = array index of one of the address in the emailAddrs array defined above. 
//                     This identifies which address you want to send the email to.
//                     Example: fillTo(xyz,1) sends email to the 'Sales Inquiries' address.
//
// Note: We're stripping off the first 7 chars to remove 'mailto:' from the front of the string.
    f.TO.value = emailAddrs[addrID].masked.substring(7);
    return true;
}

function isEmpty(inputStr) {
    if (inputStr == null || inputStr == "") {
        alert ("Please enter a value in this field.");
		return true;
    }
    return false;
}

function isPosInteger(inputVal) {
	inputStr = inputVal.toString();
	for (var i=0; i<inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar > "9") {
			alert ("Please enter only digits in this field.");
			return false;
		}
	}
	return true;
}

function inRange(inputStr,startRange,endRange){
// Validate that the user-supplied value meets the input criteria.
// Arguments: inputStr     = form field data being validated.
//            startRange   = first valid integer
//            endRange     = last valid integer

	num = parseInt(inputStr)
	if (num < startRange || num > endRange) {
		alert ("Please enter a number between " + startRange + " and " + endRange + ".");
		return false
	}
	return true
}

function isValidNumber(form,fieldName,inputStr,startRange,endRange) {
	valid = true;
    if (isEmpty(inputStr)) {
		valid = false;
    } else {
		if (!isPosInteger(inputStr)) {
			valid = false;
		} else {
			if (!inRange(inputStr,startRange,endRange)) {
				valid = false;
			}
		}
    }
    if (!valid) {
		form[fieldName].value = "";
//		Use setTimeout to introduce a slight delay before resetting form focus to work around a Firefox bug.
		setTimeout(function(){form[fieldName].focus()},10);
		form[fieldName].select();
	} else {
		showStatus ("")
	}
    return valid;
}

function isValidString(form,fieldName,inputStr) {
	valid = true;
    if (isEmpty(inputStr)) {
		valid = false;
    }
    if (!valid) {
		form[fieldName].value = "";
//		Use setTimeout to introduce a slight delay before resetting form focus to work around a Firefox bug.
		setTimeout(function(){form[fieldName].focus()},10);
		form[fieldName].select();
	} else {
		showStatus ("")
	}
    return valid;
}

function toggleOther(form,fieldName,otherTarget) {
// enable or clear an "Other" input field based on status of a checkbox
    if (form[fieldName].checked) {
   		form[otherTarget].disabled = false;
//		Use setTimeout to introduce a slight delay before resetting form focus to work around a Firefox bug.
		setTimeout(function(){form[otherTarget].focus()},10);
		form[otherTarget].select();  		
    } else {
        // clear otherTarget
   		form[otherTarget].disabled = true;
   		form[otherTarget].value = " ";
    }
}

function clearOther(form,otherTarget) {
// disable and clear an "Other" input field when the user clicks a radio button
	form[otherTarget].disabled = true;
	form[otherTarget].value = " ";
}

function enableOther(form,otherTarget) {
// enable an "Other" input field when the user clicks a radio button
	form[otherTarget].disabled = false;
//	Use setTimeout to introduce a slight delay before resetting form focus to work around a Firefox bug.
	setTimeout(function(){form[otherTarget].focus()},10);
	form[otherTarget].select();  		
}

function noNulls(form) {
// identify form elements with null values.
	found = false;
	for (i=0; i<form.elements.length; i++) {
		if (form.elements[i].value == "") {
			alert("Please fill out all the fields.");
			setTimeout(function(){form.elements[i].focus()},10);
//			form.elements[i].focus();
			found = true;
			break;
		}
	}
	if (found) {return false} else {return true}
}
