//=========================== Get Todays Date =================================
function getdates()
{
var today_date= new Date()
var month=today_date.getMonth()
var dates=today_date.getDate()
var year=today_date.getYear()
var day= today_date.getDay()
var today;

if (year < 2000){ year += 1900;}

var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var today = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

var datestr = today[day]+" "+months[month]+" "+dates+", "+year;

return(datestr);
}

//===================================== Popup Window ====================================

function newwindow(locat){	
popup= window.open(locat,'newwindow_id','toolbar=yes,location=yes,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=200');
ndoc= popup.document;
}
//===================================== Popup Window ====================================


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];}
}

//===================================== Popup Window ====================================

function newwindow(locat){	
popup= window.open(locat,'newwindow_id','toolbar=yes,location=yes,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=790,height=500');
ndoc= popup.document;
}

//===================================== Fading Colors ====================================

<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// convert decimal value (0 - 255) to hexadecimal
// (use .toString(16) method supported by IE)
function toHex(dec) {
  var hexCharacters = "0123456789ABCDEF"  // create list of hex characters

// if number is out of range return limit
  if (dec < 0) return "00"
  if (dec > 255) return "FF"

  var i = Math.floor(dec / 16)  // decimal equivalent of first hex character in converted number
  var j = dec % 16   // decimal equivalent of second hex character in converted number

return hexCharacters.charAt(i) + hexCharacters.charAt(j)          // return hexadecimal equivalent
}

function getcolor(red,green,blue)
{

  return "#" + toHex(red) + toHex(green) + toHex(blue);
}
  
// set font color to specified descriptors
function setfontColor(red, green, blue) { text.style.color = "#" + toHex(red) + toHex(green) + toHex(blue);}


// fade from start to end descriptors (increase step to increase transition speed)
function fade(sred, sgreen, sblue, ered, egreen, eblue, step) {
        // loop to create fade effect
var nsred, nsgreen, nsblue;		
		if (sred <= ered)     { nsred = ered;} else {nsred = sred - step;}
		if (sgreen <= egreen) { nsgreen = egreen;} else {nsgreen = sgreen - step;}
		if (sblue <= eblue)   { nsblue = eblue;} else {nsblue = sblue - step;}				
		if ((sred <= ered)&&(sgreen <= egreen)&&(sblue <= eblue)) return;
		
          var red   = Math.floor(sred);       // set current red descriptor
          var green = Math.floor(sgreen);     // set current green descriptor
          var blue  = Math.floor(sblue);      // set current blue descriptor
          setfontColor(red, green, blue);     // set font color according to descriptors
		  setTimeout("fade("+nsred+","+nsgreen+","+nsblue+","+ered+","+egreen+","+eblue+",4)",100);
}
//-->

//-----------------------------------------------
// Find screen width function
function getwidth(margin){
 w = screen.width;
 h = screen.height;
 width=w-margin;
 
return width;
}

//===================================== Popup Window ====================================
function submitlogin(){
popup= window.open('','popwindow','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=750,height=400');
sstr  = "<html><body>";
sstr += "<form name='login' method='post' action='account.php'>";
sstr += "<input type=hidden name=username value='"+document.loginform.username.value+"'>";
sstr += "<input type=hidden name=password value='"+document.loginform.password.value+"'>";
sstr += "</form>";
sstr += "<script language='javascript'> document.login.submit(); </";
sstr += "script></body></html>";
ndoc= popup.document;
ndoc.write(sstr);
 return;
}


//=========================== Textbox Length Code =================================

function check_textbox(varfield, length_warn, length_max)
{
//varfield     == Question field pointer -- this
//length_warn  == Question warning -- approaching max length for question
//length_max   == Question max length

//Calculate how many characters left
var char_left = length_max - length_warn;

if (varfield.value.length == length_warn)
{ alert("You're approaching your max input length for this question ("+char_left+" characters left)"); }


if (varfield.value.length > length_max)
{ alert("You've reached your max input length for this question ("+length_max+" characters)"); }

if (varfield.value.length > length_max){ return false;}
else { return true; }
}

//=========================== Navigation Menu Code =================================
/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n');
document.write('.submenu{display: none;}\n');
document.write('</style>\n');
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

//=========================== Greyout Button Code =================================

function disable_var(varfield, status){

 switch(status){
  case 'T': { varfield.disabled = true; break; }
  case 'F': { varfield.disabled = false; break; }
 }
 
 return; 
}


//-------------------------------------------------------------------------------------------
// This function creates a new window and displays the colorchooser code and returns the value selected to 
//  the form that called it.

function color_window(field){		
 colorpopup= open('html/colorchooser.php?field='+field,'color_window','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,width=530,height=220');
 if (colorpopup.opener == null) colorpopup.opener = self;
 return;
}


//=========================== Confirm Delete Code =================================

function confirm_delete(action){

  if(confirm("Are you sure you want to delete this record?")){
   eval(action); return;
  }
return;
}  

//=========================== Confirm Continue Code =================================

function confirm_continue(action){

  if(confirm("Are you sure you want to do this?")){
   eval(action); return;
  }
return;
}  
