//::Navigation-Only Pop-Up Window
var win = null;
function NavWin(mypage,myname,w,h){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',left='+LeftPosition+',top='+(TopPosition-34)+',toolbar=1,scrollbars=1,location=0,status=0,menubar=0,resizable=0';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::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();}
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val) {
	if (val != '') {
		for (i=0; i<val.length; i++){
			if (isNaN(val.charAt(i)) &&
			   (val.charAt(i) != ',' &&
				val.charAt(i) != '.')){
				return false;
			}
		}
	}
	else {
		return false;
	}
	return true;
}

//::Valid E-Mail
function ValidEmail(str){
	ComPos = str.indexOf(',');
	PerPos = str.indexOf('..');
	SpcPos = str.indexOf(' ');
	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(	   (ComPos == -1)
		&& (PerPos == -1)
		&& (SpcPos == -1)
		&& (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 4)){
		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 Form
function ValidateForm() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.FIELD.value == "") {
	missinginfo += "\n     »  Name";
	}
	if (!ValidEmail(objForm.FIELD.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (!ValidPhone(objForm.FIELD.value,objForm.FIELD.value,objForm.FIELD.value)) {
	missinginfo += "\n     »  Phone";
	}

	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;
}
