var DHTML = (document.getElementById || document.all || document.layers);

var DH = 0;
var an = 0;
var al = 0;
var ai = 0;

if (document.getElementById) {ai = 1; DH = 1;}else {if (document.all) {al = 1; DH = 1;} else { browserVersion = parseInt(navigator.appVersion); if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {an = 1; DH = 1;}}} function fd(oi,ws) {if (ws == 1) {if (ai) {return (document.getElementById(oi).style);}
else {if (al) {return (document.all[oi].style);} else {if (an) {return (document.layers[oi]);}};}} else {if (ai) {return (document.getElementById(oi));} else {if (al) {return (document.all[oi]);} else {if (an) {return (document.layers[oi]);}};}}} function pw() {if (window.innerWidth != null) return window.innerWidth; if (document.body.clientWidth != null)
return document.body.clientWidth; return (null);} 
function popUp(evt,oi) {if (DH) {var wp = pw(); ds = fd(oi,1); dm = fd(oi,0); st = ds.visibility; if (dm.offsetWidth) ew = dm.offsetWidth; else if (dm.clip.width) ew = dm.clip.width; if (st == "visible" || st == "show") { ds.visibility = "hidden"; } else  { if (evt.y || evt.pageY) {if (evt.pageY) {tv = evt.pageY + 20;
lv = evt.pageX - (ew/4);} else {tv = evt.y + 20 + document.body.scrollTop; lv = evt.x  - (ew/4) + document.body.scrollLeft;} if (lv < 2) lv = 2; else if (lv + ew > wp) lv -= ew/2;if (!an) {lv += 'px';tv += 'px'};ds.left = lv; ds.top = tv;} ds.visibility = "visible";}}}

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
	} else if (document.all)  {
		this.obj = document.all[name];
	} else if (document.layers)  {
		this.obj = document.layers[name];
	}
	return this.obj;
}

function objExist(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
	} else if (document.all)  {
		this.obj = document.all[name];
	} else if (document.layers)  {
		this.obj = document.layers[name];
	}
	if(this.obj) 
		return true;
	else 
		return false;
}

function divDsp(hideThis,dspThis)
{
	if (!DHTML) return;
	var x = new getObj(hideThis);
	//x.style.display = dspThis;
	x.style.display = (dspThis)? dspThis : (x.style.display=='inline'||x.style.display=='') ? 'none' : 'inline';
	//alert(dspThis);
}


function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

function mmLoadMenus(site_url) {

  if (window.mm_menu_0) return;

  window.mm_menu_0 = new Menu("root",174,22,"Arial, Helvetica, sans-serif",12,"#ffffff","#708778","#708778","#F6F7E9","left","middle",3,0,500,-5,7,true,true,true,0,true,true);
  
  mm_menu_0.addMenuItem("Our Communities","location='"+site_url+"index.php?t=communities.php'");
  mm_menu_0.addMenuItem("Our Home Styles","location='"+site_url+"index.php?t=homes.php'");
  mm_menu_0.addMenuItem("Future Communities","location='"+site_url+"index.php?t=coming_soon.php'");
  mm_menu_0.addMenuItem("Early Delivery","location='"+site_url+"index.php?t=move-in.php'");
  mm_menu_0.fontWeight="bold";
   mm_menu_0.hideOnMouseOut=true;
   mm_menu_0.menuBorder=1;
   mm_menu_0.menuLiteBgColor='#b9ccb9';
   mm_menu_0.menuBorderBgColor='#555555';
   mm_menu_0.bgColor='#b9ccb9';

   window.mm_menu_1 = new Menu("root",174,22,"Arial, Helvetica, sans-serif",12,"#ffffff","#708778","#708778","#F6F7E9","left","middle",3,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_1.addMenuItem
  mm_menu_1.addMenuItem("Overview of Our Programs","location='"+site_url+"index.php?t=overview.php'");
  mm_menu_1.addMenuItem("Your Home. Your Way.","location='"+site_url+"index.php?t=yhyw.php'");
  mm_menu_1.addMenuItem("Options Calculator","location='http://web01.cpsusa.com/ACR'");
   mm_menu_1.fontWeight="bold";
   mm_menu_1.hideOnMouseOut=true;
   mm_menu_1.menuBorder=1;
   mm_menu_1.menuLiteBgColor='#b9ccb9';
   mm_menu_1.menuBorderBgColor='#555555';
   mm_menu_1.bgColor='#b9ccb9';
   
   window.mm_menu_2 = new Menu("root",174,22,"Arial, Helvetica, sans-serif",12,"#ffffff","#708778","#708778","#F6F7E9","left","middle",3,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_2.addMenuItem("Homebuilding Process","location='"+site_url+"index.php?t=home_process.php'");
  mm_menu_2.addMenuItem("Financing Your Home","location='"+site_url+"index.php?t=financing.php'");
   mm_menu_2.fontWeight="bold";
   mm_menu_2.hideOnMouseOut=true;
   mm_menu_2.menuBorder=1;
   mm_menu_2.menuLiteBgColor='#b9ccb9';
   mm_menu_2.menuBorderBgColor='#555555';
   mm_menu_2.bgColor='#b9ccb9';
      
   window.mm_menu_3 = new Menu("root",140,22,"Arial, Helvetica, sans-serif",12,"#ffffff","#708778","#8dae99","#F3F4E6","left","middle",3,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_3.addMenuItem("Our&nbsp;Commitment","location='"+site_url+"index.php?t=owners.php'");
  mm_menu_3.addMenuItem("Customer&nbsp;Care","location='"+site_url+"index.php?t=warranty.php'");
  mm_menu_3.addMenuItem("Homeowner's&nbsp;Manual","location='"+site_url+"index.php?t=manual.php'");
   mm_menu_3.fontWeight="bold";
   mm_menu_3.hideOnMouseOut=true;
   mm_menu_3.menuBorder=1;
   mm_menu_3.menuLiteBgColor='#ffffff';
   mm_menu_3.menuBorderBgColor='#555555';
   mm_menu_3.bgColor='#ffffff';

   window.mm_menu_4 = new Menu("root",115,22,"Arial, Helvetica, sans-serif",12,"#ffffff","#708778","#8dae99","#F3F4E6","left","middle",3,0,500,-5,7,true,true,true,0,true,true);
  mm_menu_4.addMenuItem("Realtor Rewards","location='"+site_url+"index.php?t=realtors.php'");

   mm_menu_4.fontWeight="bold";
   mm_menu_4.hideOnMouseOut=true;
   mm_menu_4.menuBorder=1;
   mm_menu_4.menuLiteBgColor='#ffffff';
   mm_menu_4.menuBorderBgColor='#555555';
   mm_menu_4.bgColor='#ffffff';

  mm_menu_4.writeMenus();
} // mmLoadMenus()


var popup;
var height=550;
var width=525;
var left=0;
var top=0;
function linkpop(filename){
popup = window.open(filename, "","height="+height+",width="+width+",top="+top+",left="+left+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,directories=no");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function Rollover(imgName,imgSrc) { document.images[''+imgName+''].src = imgSrc; }

function button_roll(button,wax)
{
 button.style.backgroundColor=(wax=="on")?"#FFFFFF":"#e4ded8";
 button.style.color=(wax=="on")?"#000000":"000000";
}

// this might need translating, if so, move it to the page and use definitions in place of error texts...
function CheckContent()
{
	var errs = '';
	if (document.content_form.title.value == '') 		errs = errs+'\nPlease enter a Title'
	if (document.content_form.category.value == '') 	errs = errs+'\nPlease choose a Category'
	if (document.content_form.status.value == '') 	errs = errs+'\nPlease choose a Status'
	if (document.content_form.summary.value == '') 	errs = errs+'\nPlease enter a Summary'
	if (document.content_form.article_type[2].checked && document.content_form.url.value=='') 	errs = errs+'\nPlease enter a valid Internet URL for the article type chosen'
	if (errs == '') document.content_form.submit();
	else alert(errs);
}

function CheckPhoneLen(num)
{
	// alert(num);
	if (num.length != 12 && num.length != "0") alert('Please enter only a ten digit phone number, formatted ###-###-####');
	
}


function printDate()
{
  today = new Date();
  mnt=today.getMonth()+1;
  day=today.getDate();
  if (mnt=="1"){month="January"}
  if (mnt=="2"){month="February"}
  if (mnt=="3"){month="March"}
  if (mnt=="4"){month="April"}
  if (mnt=="5"){month="May"}
  if (mnt=="6"){month="June"}
  if (mnt=="7"){month="July"}
  if (mnt=="8"){month="August"}
  if (mnt=="9"){month="September"}
  if (mnt=="10"){month="October"}
  if (mnt=="11"){month="November"}
  if (mnt=="12"){month="December"}
  if (day=="1"){end="st"}
  if (day=="2"){end="nd"}
  if (day=="3"){end="rd"}

  document.write(""+month+" "+day+", "+today.getYear());
}

function popwindow(address,width,height)
{
    var window_url = address;
    var window_name = "window_name";
    var window_features = "height="+height+",width="+width+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,top=100,left=100";
    window.open(window_url,window_name,window_features);
}

function popmenuwindow(address,width,height)
{
    var window_url = address;
    var window_name = "window_name";
    var window_features = "height="+height+",width="+width+",toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,copyhistory=0,top=100,left=100";
	window.open(window_url,window_name,window_features);
}

function changeto(highlightcolor)
{
	source=event.srcElement
	if (source.tagName=="TR"||source.tagName=="TABLE")
	return
	while(source.tagName!="TD")
	source=source.parentElement
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
	source.style.backgroundColor=highlightcolor
}

function changeback(originalcolor)
{
	if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
	return
	if (event.toElement!=source)
	source.style.backgroundColor=originalcolor
}



 function CountDown()
 {
/*	2009.03.04 DSL removed
	warnTime = 60000 * 59;
	warnMe = setTimeout('RunDown()', warnTime);
*/
 }

 function RunDown()
 {
	popwindow("../includes/expire_warning.php",260,120);
 }

 function Continue()
 {
 	self.close();
	opener.location.reload();
 }

 function LastMinute()
 {
 	closeMe = setTimeout('EndNow()', 60000);
 }

 function EndNow()
 {
 	self.close();
	opener.location = "../admin/index.php?action=do_logout&auto=1"; // take out the cms part if you wanted to go to the public site
 }
 
 // below here is the date picker code... hate putting all that html in it, but what the heck it was free right?

 
// Title: Timestamp picker
// Description: See the demo at url
// URL: http://us.geocities.com/tspicker/
// Script featured on: http://javascriptkit.com/script/script2/timestamp.shtml
// Version: 1.0
// Date: 12-05-2001 (mm-dd-yyyy)
// Author: Denis Gritcyuk <denis@softcomplex.com>; <tspicker@yahoo.com>
// Notes: Permission given to use this script in any kind of applications if
//    header lines are left unchanged. Feel free to contact the author
//    for feature requests and/or donations

function show_calendar(str_target, str_datetime) 
{
	if (str_datetime=="mm-dd-yyyy") str_datetime = "";
	var arr_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
	var n_weekstart = 1; // day week starts from (normally 0 or 1)

	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));
	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	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);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	
	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n"+
		"</head>\n"+
		"<body bgcolor=\"White\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#4682B4\">\n"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"#4682B4\"><a href=\"javascript:window.opener.show_calendar('"+
		str_target+"', '"+ dt2dtstr(dt_prev_month)+"');\">"+
		"<img src=\""+site_url+"/images/prev.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"previous month\"></a></td>\n"+
		"	<td bgcolor=\"#4682B4\" colspan=\"5\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"
		+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
		"	<td bgcolor=\"#4682B4\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('"
		+str_target+"', '"+dt2dtstr(dt_next_month)+"');\">"+
		"<img src=\""+site_url+"/images/next.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"next month\"></a></td>\n</tr>\n"
	);

	var dt_current_day = new Date(dt_firstday);
	// print weekdays titles
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#87CEFA\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		week_days[(n_weekstart+n)%7]+"</font></td>\n";
	// print calendar table
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getDate() == dt_datetime.getDate() &&
					dt_current_day.getMonth() == dt_datetime.getMonth())
					// print current date
					str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#DBEAF5\" align=\"right\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}
	// print calendar footer
	str_buffer +=
		"<form name=\"cal\">\n<tr><td colspan=\"7\" bgcolor=\"#87CEFA\">"+
		"<font color=\"White\" face=\"tahoma, verdana\" size=\"2\">"+
		//"Time: <input type=\"text\" name=\"time\" value=\""+dt2tmstr(dt_datetime)+
		//"\" size=\"8\" maxlength=\"8\">
		"</font></td></tr>\n</form>\n" +
		"</table>\n" +
		"</tr>\n</td>\n</table>\n" +
		"</body>\n" +
		"</html>\n";

	var vWinCal = window.open("", "Calendar", 
		"width=200,height=200,status=no,resizable=yes,top=200,left=200");
	vWinCal.opener = self;
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (str_datetime) {
	
	var re_date = /^(\d+)\-(\d+)\-(\d+)$/;	
	//var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	
	if (!re_date.exec(str_datetime))
		return alert("Invalid Datetime format: "+ str_datetime);
	return (new Date (RegExp.$3, RegExp.$1-1, RegExp.$2, RegExp.$4, RegExp.$5, RegExp.$6));
}
function dt2dtstr (dt_datetime) {
	return (new String (
			// dt_datetime.getFullYear()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getDate()+" "));
			(dt_datetime.getMonth()+1)+"-"+dt_datetime.getDate()+"-"+dt_datetime.getFullYear()));
}
function dt2tmstr (dt_datetime) {
	return (new String (
			dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));
}

function holler(method,url,parameters,callback) {
	method = method.toUpperCase();
	xmlhttp = null;
	 try{
	    if (window.XMLHttpRequest) {
	        xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        //xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'?'+parameters, true);
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	//alert(callback);
    xmlhttp.onreadystatechange = function () {
	
	  		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {
				if (xmlhttp.status == 200) {						
					eval(callback)
				} else{
					alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
					return;
				}
		    }
		};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}

function hollerBack(method,url,parameters,thisObj,LoadingTxt) {
	 //alert(parameters);
	 method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	        xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        //xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
    xmlhttp.onreadystatechange = function () {
			
		if (objExist(thisObj)) { 
			var x = new getObj(thisObj);
		}

		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {
		
			try {
				x.innerHTML = xmlhttp.responseText;
			} catch (e) {
				alert('An error occurred while trying to return your request. \nError '+e.description);
			}
			
			if (xmlhttp.status != 200) {
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
	    } else{
			
			if(LoadingTxt){
				x.innerHTML = '<div>'+LoadingTxt+'</div>';
			} else {
				x.innerHTML = '<div><img src="facility_patient_import/icon.indicator.gif" alt="" width="16" height="16" border="0"></div>';
			}
			return;
		}
	};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}
