<!--
// JavaScript Document

//------------------------------------------------------------------------------------
function callAjax(strUrl)  {
	xmlHttp=getAjaxVar();
	xmlHttp.open("GET",strUrl, false);
	xmlHttp.send(null);
//	alert(xmlHttp.responseText);
}

//------------------------------------------------------------------------------------
function getAjaxVar() {
	var xmlHttp;
	try {xmlHttp=new XMLHttpRequest();} 
	catch (e) {
		try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");} 
		catch (e) {
			try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return (xmlHttp);
}

//---Respond to Enter Key code-----------------------------------------------
var submitId
function installEnterKeyEvent(id) {
	submitId=id;
//-------------------- this adds ".click" as a function for firefox.
	if (!document.all) {
		HTMLElement.prototype.click = function() {
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
		} 
	}
	
//-------------------- Attach event handler to all input elements except ones of type "hidden"
	objInput=document.getElementsByTagName("input");
	for (i=0; i<objInput.length; i++) {
		if(objInput[i].type!="hidden") {
			objInput[i].onkeypress = handleEnterKey;
		}
	}
}
//-------------------- The event handler
function handleEnterKey(e) {
	if (!e) var e = window.event; //cross browser event object compatibility (ie uses "event", ff uses "e")
	if (e.keyCode == 13) {
		document.getElementById(submitId).click();
		return false;
	} else return true;
}

//---End of Enter Key code-----------------------------------------------

//------------------------------------------------------------------------------------
//real time filters
function filterNumberPlus(id) {
	document.getElementById(id).value=document.getElementById(id).value.replace(/[^\d-]/g,'');
}
function filterNumber(id) {
	document.getElementById(id).value=document.getElementById(id).value.replace(/[^\d/]/g,'');
}

//------------------------------------------------------------------------------------
function hasVal(id){
	if (document.getElementById(id).value==""){
		document.getElementById(id).focus();
		return false
	}
	return true;
}

//------------------------------------------------------------------------------------
var emailPattern = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i ;

//function validateForm(arg) {
//billing info required check
/*
	if (!emailPattern.test(document.getElementById("eMail").value)) {
		alert("Please enter a valid email address.");
		document.getElementById("eMail").focus();
		return false;
	}

	var datePatt = /^\d\d\/\d\d$/; //check for proper date format of mm/yy
	if (!datePatt.test(document.getElementById("billExpDate").value)) {
		alert("Date must be in the format of mm/yy (i.e. 05/16)");
		document.getElementById("billExpDate").focus();
		return false;
	}
	
	//now check for proper month ranges of 1 to 12
	aryDate=document.getElementById("billExpDate").value.split("/");
	if (Number(aryDate[0]) < 1 || Number(aryDate[0]) > 12){
		alert("Months must be in the range 01-12");
		document.getElementById("billExpDate").focus();
		return false;
	}
*/

//Check for presence of required field
//reqId="sampleField";
//strErr="Sample Error Message!";
//	if (document.getElementById(reqId).value == "") {
//		alert(strErr);
//		document.getElementById(reqId).focus();
//		return false;
//	}
	

//Check for length of required field
//reqId="sampleField";
//strErr="Sample Error Message!";
//fldLength=3;
//	if (document.getElementById(reqId).value.length != fldLength) {
//		alert(strErr);
//		document.getElementById(reqId).focus();
//		return false;
//	}
	

//Check required checkbox
//	if (document.getElementById("chkUseBill").checked==false) {
//	}

//	document.ccForm.submit();
//}

//-----------------------------------------------------------------------------
function dispSect(ctrlId, dispId) {
	if (document.getElementById(ctrlId).checked==false) {
		document.getElementById(dispId).style.display="";
		} else {
		document.getElementById(dispId).style.display="none";
	}
}

//=================================================	
function urlencode (str) {
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '', unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
//                ret += '+'; // %20 in rawurlencode
                ret += '%20'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}

//======================================================================
//format 0=phone, 1=zip, 2=length check  
function validateNumbers(id, format, length) {
	var phonePatt = /^\d{3}-?\d{3}-?\d{4}$/; //phone number = aaa-ppp-ssss
	var zipPattShort = /^\d{5}$/; //zip code = xxxxx
	var zipPattLong = /^\d{5}-\d{4}$/; ///zip code = xxxxx-xxxx
	
	switch(format){
		case 0: 
			pattern=phonePatt;
			if (!pattern.test(document.getElementById(id).value)) {
				document.getElementById(id).focus();
				alert("Please enter a valid phone number.");
				return false;
			}
			return true;
			break;
			
		case 1: 
			pattern=zipPattShort;
			if (document.getElementById(id).value.length>5) pattern=zipPattLong;
			if (!pattern.test(document.getElementById(id).value)) {
				document.getElementById(id).focus();
				alert("Please enter a valid zip code.");
				return false;
			}
			return true;
			break;
		
		case 2:
			if (document.getElementById(id).value.length!=length) {
				document.getElementById(id).focus();
				alert("Please check your credit card and/or ccv number.");
				return false;
			}
			return true;
			break;
	}
}

//-----------------------------------------------------------------------------
-->
