//::pop-up window (complete settings)
//ex -> onClick="CiPopWin('./pageurl.asp','WindowName','500','300','no','no','no','no','no','no');return false"
var win = null;
function CiPopWin(mypage,myname,w,h,scroll,resize,toolbar,loc,status,menubar){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',toolbar='+toolbar+',location='+loc+',status='+status+',menubar='+menubar;
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Build E-Mail Link
//ex. document.write(BuildEmail('Click Here','email','isp.com','Subject',''))
function BuildEmail(lnkName,lnkEmail,lnkHost,lnkSubject,lnkStyle){
	if(lnkName == ""){
		lnkName = lnkEmail + "&#64;" + lnkHost;
	}
	if(lnkSubject != ""){
		lnkSubject = "?subject=" + lnkSubject;
	}
	return "<a href='" + "mail" + "to:" + lnkEmail + "@" + lnkHost + lnkSubject + "' " + lnkStyle + ">" + lnkName + "</a>";
}

//::Alphanumeric Only Function
function AlphanumericOnly(e,t){
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	//filter
	switch (t) {
		case 0:		//Numeric Only
			filter = "0123456789.";
			break;
		case 1:		//Alpha Only
			filter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
			break;
		default:	//Aplphanumeric Only
			filter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789., ";
			break;
	}

	//control keys
	if ((key==null) || (key==0) || (key==8) ||
		(key==9) || (key==13) || (key==27) )
	   return true;
	else if (((filter).indexOf(keychar) > -1))
	   return true;
	else
	   return false;
}
//Example: onKeyPress="return AlphanumericOnly(event,2);"

//::Numeric Only Function
function NumericOnly(e){
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	// control keys
	if ((key==null) || (key==0) || (key==8) ||
		(key==9) || (key==13) || (key==27) )
	   return true;

	// alphas and numbers
	else if ((("0123456789.").indexOf(keychar) > -1))
	   return true;
	else
	   return false;
}
//Example: onKeyPress="return NumericOnly(event);"



//::check if radio or checkbox items are selected
function CheckSelected(arr){
	if(arr.length > 0){
		for(var index = 0; index < arr.length; index++){
			if(arr[index].checked){
				return true;
				break;
			}
		}
	}
	else{
		if(arr.checked){
			return true;
		}
		else{
			return false;
		}
	}
	return false;
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf){
	if ((Trim(PhoneArea) == "") ||
		(Trim(PhonePre) == "") ||
		(Trim(PhoneSuf) == "") ||
		(PhoneArea.length != 3) ||
		(PhonePre.length != 3) ||
		(PhoneSuf.length != 4)){
		return false;
	}else{
		if (IsNumeric(PhoneArea) &&
			IsNumeric(PhonePre) &&
			IsNumeric(PhoneSuf) &&
			(PhoneArea.length == 3) &&
			(PhonePre.length == 3) &&
			(PhoneSuf.length == 4)){
			return true;
		}
	}
}

//::Valid Telephone
function ValidTelephone(str){
	str = Trim(str);
	str = str.replace("(","");
	str = str.replace(")","");
	str = str.replace(".","");
	str = str.replace(".","");
	str = str.replace("-","");
	str = str.replace("-","");
	str = str.replace(" ","");
	strLen = str.length;
	if((strLen == 10 || strLen == 7) && IsNumeric(str)){
		return true;
	}
	else{
		return false;
	}
}

//::Validate Contact
function ValidateContact() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	/*
	if (!ValidTelephone(objForm.phone.value)) {
	missinginfo += "\n     »  Phone";
	}
	*/
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Comments / Questions";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Questions & Answers
function ValidateQA() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (objForm.category.value == "") {
	missinginfo += "\n     »  Category";
	}
	if (objForm.question.value == "") {
	missinginfo += "\n     »  Question";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Feedback
function ValidateFeedback() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Newsletter
function ValidateNewsletter() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}