document.write("<script type='text/javascript' src='inc/js/jquery.min.js'></scr"+"ipt>");
function fnGenericValidate(f){
	var colEl = f.elements;
	var arErrors = [];
	for (var i=0; i<colEl.length; i++){
		o = colEl[i];
		switch (''+o.tagName+o.getAttribute('type')){
			case 'INPUTtext':
				if (o.type != 'text') continue;
				o.value = Trim(o.value);
				if ( (o.getAttribute('required') == 1) && IsEmpty(o.value) ){
					arErrors[arErrors.length] = o.title + ' is required';
				}
				if (IsEmpty(o.value)) break;
				switch (o.getAttribute('datatype')){
					case 'int':
						if (!IsNumeric(o.value)) arErrors[arErrors.length] = o.title + ' must be numeric';
						break;
					case 'email':
						if (!IsValidEmail(o.value)) arErrors[arErrors.length] = '"' + o.value + '" is not a valid email address';
						break;
				}
				break;
			case 'INPUThidden':
				//catch the hidden required fields used for double select boxes and richedit
				if ( (o.getAttribute('required') == 1) && IsEmpty(o.value) ){
					arErrors[arErrors.length] = o.title + ' is required';
				}
				break;
			case 'INPUTfile':
				//catch the hidden required fields used for double select boxes
				if ( (o.getAttribute('required') == 1) && IsEmpty(o.value) ){
					arErrors[arErrors.length] = o.title + ' is required';
				}
				if (IsEmpty(o.value)) break;
				strExt = o.getAttribute('extensions');
				if (strExt && !IsEmpty(strExt)){
					strExt = ',' + strExt.replace(/\./g,'').toLowerCase() + ',';
					testExt = Trim(o.value).toLowerCase();
					testExt = ',' + testExt.match(/[A-Za-z0-9]*$/)[0] + ',';
					if ( (testExt == ',,') || (strExt.indexOf(testExt) == -1) ){
						arErrors[arErrors.length] = 'The document you have selected for ' + o.title + ' is not a valid document type. Valid types are: '+ o.getAttribute('extensions');
					}
				}
				break;
			case 'SELECTselect-one':
				if ( (o.getAttribute('required') == 1) && (o.selectedIndex < 1) ){
					arErrors[arErrors.length] = 'Please select a ' + o.title + '';
				}
				break; 
		}
	}
	
	if ($("input[type='radio'][name='optin']").length > 0 && $("input[name='receive_info_bit']:checked").length == 0) {
		arErrors[arErrors.length] = "Receive Email is required";
	}
	if (arErrors.length == 0){
		return true
	} else {/*
		if (!document.all["divErrorReport"]){
			f.insertAdjacentHTML('beforebegin','<div id="divErrorReport"></div>');
		}
		document.all["divErrorReport"].innerHTML = 'Please correct the following before continuing:<ul><li>'+ arErrors.join('</li><li>') +'</li></ul>';
		*/
		document.getElementById("divErrorReport").innerHTML = "Please correct the following before continuing:<ul><li>" + arErrors.join('</li><li>') + "</li></ul>";
		document.body.scrollTop = 0;
		return false
	}
}

function LTrim(s) {
	var whitespace = ' \t\n\r';
	if (s.length == 0) return s;
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++;
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(s) {
	var whitespace = ' \t\n\r';
	if (s.length == 0) return s;
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(s) {
   return RTrim(LTrim(s));
}

function IsNumeric(val) {
	var ValidChars = "0123456789.";
	for (i=0; i<val.length; i++) {
		if (ValidChars.indexOf(val.charAt(i)) == -1) return false
	}
	return true
}

function IsEmpty(val) {
	for (i=0; i<val.length; i++) { 
		if (val.charAt(i) != ' ') return false
	}
	return true
}

function IsValidEmail(val) {
	var iLen = val.length;
	if 	((iLen < 6) || (val.indexOf('@') < 1) || ((val.charAt(iLen - 3) != '.') && (val.charAt(iLen - 4) != '.')) ) return false
	return true
}

function NumCBGroupChecked(f,strName){
	var colEl = f.elements;
	var iChecked = 0;
	for (var i=0; i<colEl.length; i++){
		el = colEl[i];
		if (el.name && (el.name == strName) && el.checked) iChecked++;
	}
	return iChecked;
}


/**************************************************************
	2008.2.26, Ye Wang
	functions for Payment Method
***************************************************************/
function toggle(obj) {
	var otherAddressObj = document.getElementById("otherAddress");
	var newAddressObj = document.getElementById("newAddress"); 
	switch (obj.value) {
		case "0":
			otherAddressObj.style.display = "none";
			newAddressObj.style.display = "";
			break;
		case "1":
			otherAddressObj.style.display = "";
			newAddressObj.style.display = "none";
			break;
		default: 
			otherAddressObj.style.display = "none";
			newAddressObj.style.display = "none";
			break; 
	}
}
/**************************************************************
	2008.9.9, Ye Wang
	Re-Skin features:
	- Print
	- Email
***************************************************************/
function Print() {
	var urls = window.location.href;
	var flagStr = "ispf=0";
	var printStr = "ispf=1";
	urls = urls.replace(/[&]*ispf=[^&]/gim, "");
	if (urls.indexOf("?") < 0) {
		urls = urls + "?" + printStr;
	} else {
		urls = urls + "&" + printStr;
	}
	WinPrint = window.open(urls, "", "width=600,height=500,toolbar=no,resizable=yes,scrollbars=yes,location=no");
}
function Load() {
	if (window.location.href.indexOf("ispf=1") != -1) {
		setTimeout("window.print()", 500);
	}
}
function Email() { 
	var contentTitle = document.title;  
	urls = "../pop_email.cfm?urls=" + window.location.href + "&contentTitle=" + contentTitle;
	WinEmail = window.open(urls, "", "width=440,height=400,toolbar=no,resizable=no,scrollbars=yes,location=no");

}