//::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();}
}

//::Auto-centering Enlarged Pop-Up Window
var win = null;
function Enlarge(mypage){
w = 300;
h = 200;
myname = 'EnlargeWindow';
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=no,resizable=no';
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Resize Window Dynamically
function resizeWin(maxX,maxY,speed,delay,win){
	this.obj = "resizeWin" + (resizeWin.count++);
	eval(this.obj + "=this");
	if (!win)     this.win = self;    else this.win = eval(win);
	if (!maxX)    this.maxX = 400;    else this.maxX = maxX;
	if (!maxY)    this.maxY = 300;    else this.maxY = maxY;
	if (!speed)   this.speed = 1/7;   else this.speed = 1/speed;
	if (!delay)   this.delay = 30;    else this.delay = delay;
	this.doResize = (document.all || document.getElementById);
	this.stayCentered = false;
	this.initWin = 	function(){
		if (this.doResize){
			this.resizeMe();
			}
		else {
			this.win.resizeTo(this.maxX + 10, this.maxY - 20);
			}
		}
	this.resizeMe = function(){
		this.win.focus();
		this.updateMe();
		}
	this.resizeTo = function(x,y){
		this.maxX = x;
		this.maxY = y;
		this.resizeMe();
		}
	this.stayCentered = function(){
		this.stayCentered = true;
		}
	this.updateMe = function(){
		this.resizing = true;
		var x = Math.ceil((this.maxX - this.getX()) * this.speed);
		var y = Math.ceil((this.maxY - this.getY()) * this.speed);
		if (x == 0 && this.getX() != this.maxX) {
			if (this.getX() > this.maxX) x = -1;
			else  x = 1;
			}
		if (y == 0 && this.getY() != this.maxY){
			if (this.getY() > this.maxY) y = -1;
			else y = 1;
			}
		if (x == 0 && y == 0) {
			this.resizing = false;
    		}
		else {
			this.win.top.resizeBy(parseInt(x),parseInt(y));
			if (this.stayCentered == true) this.win.moveTo((screen.width - this.getX()) / 2,(screen.height - this.getY()) / 2);
			setTimeout(this.obj + '.updateMe()',this.delay)
			}
		}
	this.write =  function(text){
		if (document.all && this.win.document.all["coords"]) this.win.document.all["coords"].innerHTML = text;
		else if (document.getElementById && this.win.document.getElementById("coords")) this.win.document.getElementById("coords").innerHTML = text;
		}
	this.getX =  function(){
		if (document.all) return (this.win.top.document.body.clientWidth + 10)
		else if (document.getElementById)
			return this.win.top.outerWidth;
		else return this.win.top.outerWidth - 12;
	}
	this.getY = function(){
		if (document.all) return (this.win.top.document.body.clientHeight + 29)
		else if (document.getElementById)
			return this.win.top.outerHeight;
		else return this.win.top.outerHeight - 31;
	}
	this.onResize =  function(){
		if (this.doResize){
			if (!this.resizing) this.resizeMe();
			}
		}
	return this;
}
resizeWin.count = 0;

//::Attach onLoad Event (Crossbrowser)
//ex.	 onLoadEvent("alert('sample')");
function onLoadEvent(strFunc) {
	if (window.addEventListener)
		window.addEventListener("load", function(){eval(strFunc)}, false);
	else if (window.attachEvent)
		window.attachEvent("onload", function(){eval(strFunc)});
	else if (ie4||dom||document.layers)
		window.onload = function(){eval(strFunc)};
}

//::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 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 Form
function ValidateContactForm() {
	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 Subscribe Form
function ValidateSubscribeForm() {
	missinginfo = "";
	var objForm = document.frmSubscribe;

	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;
}

//::Validate Unsubscribe Form
function ValidateUnsubscribeForm() {
	missinginfo = "";
	var objForm = document.frmUnsubscribe;

	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;
}

//::Check All Function
//ex.	onClick="CheckAll(document.forms[0].chkFields);"
var checkflag = "false";
function CheckAll(field){
	if(field.length == null){
		if (checkflag == "false") {
			field.checked = true;
			checkflag = "true";
		}
		else{
			field.checked = false;
			checkflag = "false";
		}
	}
	else{
		if (checkflag == "false") {
			for (i = 0; i < field.length; i++){
			field[i].checked = true;}
			checkflag = "true";
		}
		else{
			for (i = 0; i < field.length; i++){
			field[i].checked = false; }
			checkflag = "false";
		}
	}
}

//::Confirm Delete
function del(url,msg){
	if (confirm(msg)) {
		document.location.href = url;
	}else{}
}

//::JS Calendar
function showCalendar(str_target, str_datetime) {
	var arr_months = ["January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];
	var week_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
	var n_weekstart = 0; //day week starts from (normally 0 or 1)
	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt4(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	window.onerror=ignore
	function ignore(){return true}
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	if (dt_datetime.getMonth()%12 != (dt_prev_month.getMonth()+1)%12) {
		dt_prev_month.setMonth(dt_datetime.getMonth());
		dt_prev_month.setDate(0);
	}
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	if ((dt_datetime.getMonth() + 1)%12 != dt_next_month.getMonth()%12)
		dt_next_month.setDate(0);
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	var str_buffer = new String (
		"<HTML>"+
		"<HEAD>"+
		"	<TITLE>[calendar]</TITLE>"+
		"<style>"+
		"a.{color:#AOAOA4;text-decoration:none}"+
		"a:link{color:#AOAOA4;}"+
		"a:active{color:#A0A0A4;}"+
		"a:visited{color:#A0A0A4;}"+
		"a:hover{color:#FFFFFF; text-decoration:none}"+
		"</style>"+
		"<SCR"+
		"IPT>"+
		"var isIE4 = false;"+
		"function CheckBrowser(){ "+
		"	if (navigator.appName == \"Microsoft Internet Explorer\" && navigator.appVersion.charAt(0) >= 4) { isIE4 = true; }"+
		"}"+
		"function mOvr(src,clrOver){"+
		"	if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver;}"+
		"}"+
		"function mOut(src,clrIn){"+
		"	if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn;}"+
		"}"+
		"</SCR"+
		"IPT>"+
		"</HEAD>"+
		"<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" TOPMARGIN=3 LEFTMARGIN=3 MARGINWIDTH=3 MARGINHEIGHT=3 STYLE='border:0;'>"+
			"<TABLE BORDER=0 BGCOLOR=\"#000000\" CELLSPACING=1 CELLPADDING=0 WIDTH=\"100%\" >"+
				"<TR>"+
					"<TD WIDTH=29 BGCOLOR=\"#4D8F87\" HEIGHT=15 style=\"cursor:hand\" onClick=\"javascript:window.opener.showCalendar('"+
				str_target+"', '"+ dt2dtstr4(dt_prev_month)+"');\">"+
						"<P ALIGN=CENTER><a href=\"javascript:window.opener.showCalendar('"+
				str_target+"', '"+ dt2dtstr4(dt_prev_month)+"');\"><FONT COLOR=\"#FFFFFF\" SIZE=\"-2\" FACE=\"Verdana\">«</FONT></P></a>"+
					"</TD>"+
					"<TD COLSPAN=5 BGCOLOR=\"#4D8F87\" style=\"cursor:default\">"+
						"<P ALIGN=CENTER><B><FONT COLOR=\"#FFFFFF\" SIZE=\"-2\" FACE=\"Verdana\">"+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</FONT></B></P>"+
					"</TD>"+
					"<TD WIDTH=28 BGCOLOR=\"#4D8F87\" style=\"cursor:hand\" onClick=\"javascript:window.opener.showCalendar('"
				+str_target+"', '"+dt2dtstr4(dt_next_month)+"');\">"+
						"<P ALIGN=CENTER><a href=\"javascript:window.opener.showCalendar('"
				+str_target+"', '"+dt2dtstr4(dt_next_month)+"');\"><FONT COLOR=\"#FFFFFF\" SIZE=\"-2\" FACE=\"Verdana\">»</FONT></P></a>"+
					"</TD>"+
				"</TR>"+
				"<TR>"
	);
	var dt_current_day = new Date(dt_firstday);
	//weekdays titles
	for (var n=0; n<7; n++)
		str_buffer += "<TD WIDTH=29 BGCOLOR=\"#D2D2D2\" HEIGHT=15 style=\"cursor:default\"><P ALIGN=CENTER><B><FONT SIZE=\"-2\" FACE=\"Verdana\">"+
		week_days[(n_weekstart+n)%7]+"</FONT></B></P></TD>";
	//calendar table
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		//row header
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if ((dt_current_day.getMonth() == dt_datetime.getMonth()) && (dt_current_day.getDate() == dt_datetime.getDate()))
					// print current date
					str_buffer += "	<td bgcolor=\"#0099FF\" align=\"right\" HEIGHT=15 onmouseover=\"mOvr(this,'#A6CAF0');\" onmouseout=\"mOut(this,'#0099FF');\" onClick=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#EBF1F1\" align=\"right\" HEIGHT=15 onmouseover=\"mOvr(this,'#A6CAF0');\" onmouseout=\"mOut(this,'#F0F0F0');\" onClick=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\" HEIGHT=15 onmouseover=\"mOvr(this,'#A6CAF0');\" onmouseout=\"mOut(this,'white');\" onClick=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"verdana\" size=\"-2\">";
				else
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr4(dt_current_day)+"'; window.close();\">"+
					"<font color=\"#A0A0A4\" face=\"verdana\" size=\"-2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		//row footer
		str_buffer += "</tr>\n";
	}
	//calendar footer
	str_buffer +=
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";
	var w = 200;
	var h = 131;
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var vWinCal = window.open("", "Calendar",
		"width="+w+",height="+h+",status=no,resizable=no,top="+TopPosition+",left="+LeftPosition);
	vWinCal.opener = self;
	vWinCal.focus();
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
//::Valid Date Function
function str2dt4(dt) {
	var dt1 = /(\d+)\/(\d+)\/(\d+)$/;
	var dt2 = /(\d+)\-(\d+)\-(\d+)$/;
	var dt3 = /(\d+)\.(\d+)\.(\d+)$/;
	if (dt1.exec(dt) ||
		dt2.exec(dt) ||
		dt3.exec(dt)) {
		return (new Date (RegExp.$3, RegExp.$1-1, RegExp.$2));
	}
	else{
		return alert("Invalid Date format: "+ dt);
	}
}
function dt2dtstr4 (dt_datetime) {
	return (new String (
			(dt_datetime.getMonth()+1)+"/"+dt_datetime.getDate()+"/"+dt_datetime.getFullYear()));
}
//::Examble of HTML usage
//<a href="javascript:showCalendar('document.frmDate.date', document.frmDate.date.value);">
//<script language="JavaScript" src="calendar.js"></script>
