//=========================== 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;
}

//===================================== Bookmark this page ====================================
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

//-----------------------------------------------
// 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 field ("+char_left+" characters left)"); }


if (varfield.value.length > length_max)
{ alert("You've reached your max input length for this field ("+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";
		}
	}
}


//============================================ color chooser code
var SetBG = top.SetBG ;
var Tog = top.Tog ;

var colordelim = "000|003|006|009|00C|00F|030|033|036|039|03C|03F|060|063|066|069|06C|06F|090|093|096|099|09C|09F|0C0|0C3|0C6|0C9|0CC|0CF|0F0|0F3|0F6|0F9|0FC|0FF|300|303|306|309|30C|30F|330|333|336|339|33C|33F|360|363|366|369|36C|36F|390|393|396|399|39C|39F|3C0|3C3|3C6|3C9|3CC|3CF|3F0|3F3|3F6|3F9|3FC|3FF|600|603|606|609|60C|60F|630|633|636|639|63C|63F|660|663|666|669|66C|66F|690|693|696|699|69C|69F|6C0|6C3|6C6|6C9|6CC|6CF|6F0|6F3|6F6|6F9|6FC|6FF|900|903|906|909|90C|90F|930|933|936|939|93C|93F|960|963|966|969|96C|96F|990|993|996|999|99C|99F|9C0|9C3|9C6|9C9|9CC|9CF|9F0|9F3|9F6|9F9|9FC|9FF|C00|C03|C06|C09|C0C|C0F|C30|C33|C36|C39|C3C|C3F|C60|C63|C66|C69|C6C|C6F|C90|C93|C96|C99|C9C|C9F|CC0|CC3|CC6|CC9|CCC|CCF|CF0|CF3|CF6|CF9|CFC|CFF|F00|F03|F06|F09|F0C|F0F|F30|F33|F36|F39|F3C|F3F|F60|F63|F66|F69|F6C|F6F|F90|F93|F96|F99|F9C|F9F|FC0|FC3|FC6|FC9|FCC|FCF|FF0|FF3|FF6|FF9|FFC|FFF" ;

var colors = colordelim.split( "|" ) ;

function WriteColorTable( document, ncols ) {
    document.writeln( "<TABLE cellpadding=0 cellspacing=0 border=1>" ) ;

    for( var i = 0 ; i < colors.length ; i++ ) {
	if( (i % ncols) == 0 ) {
	    document.write( "\n<TR>" ) ;
	}
	var rgb = colors[i].split( "" ) ;
	var bgcol = "#"+rgb[0]+rgb[0]+rgb[1]+rgb[1]+rgb[2]+rgb[2] ;
	document.write( "<TD bgcolor=\"" + bgcol + "\">" +
		"<A href=\'javascript:Tog();\' " +
		"onMouseOver=\'SetBG(\"" + bgcol + "\");\' " +
		"onClick=\'updateColor(\""+ bgcol +"\");\'>" +
		"&nbsp;&nbsp;&nbsp;</A></TD>" ) ;
    }
    document.writeln( "</TABLE>" ) ;
}

// int.toString(radix) is not reliable:
// var x = 160 ; x.toString(16) ; produces ":0"??
var hexvals = new Array( "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F" ) ;

function WriteGrayTable( document, ncols ) {
    document.writeln( "<TABLE cellpadding=0 cellspacing=0 border=1><TR>" ) ;

    // Include 0 and 255 in the range.
    var grayincr = 255.0 / (ncols-1) ;
    var grayval = 0.0 ;
    for( var i = 0 ; i < ncols ; i++ ) {
	var igray = Math.round( grayval ) ;
	var graystr = (igray < 16) ? "0"+hexvals[igray] :
		hexvals[Math.floor(igray/16)]+hexvals[igray%16] ;
	var bgcol = "#"+graystr+graystr+graystr ;
	document.write( "<TD bgcolor=\"" + bgcol + "\">" +
		"<A href=\'javascript:Tog();\' " +
		"onMouseOver=\'SetBG(\"" + bgcol + "\");\' " +
		"onClick=\'updateColor(\""+ bgcol +"\");\'>" +
		"&nbsp;&nbsp;&nbsp;</A></TD>" ) ;
	grayval += grayincr ;
    }
    document.writeln( "</TABLE>" ) ;
}


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


//-------------------------------------------------------------------------------------------
//  This form validates a given form and then, if it passes, it submits the form.

function validate_form(form_name){

switch(form_name){
  case 'user_account': {
    if(document.mod.newusername.value == ''){ 
       alert("Must type a username for this account."); document.mod.newusername.focus(); return; }  
    if(document.mod.newpass1.value == ''){ 
       alert("Must type a password for this account."); document.mod.newpass1.focus(); return; }  
    if(document.mod.newpass2.value == ''){ 
       alert("Must retype the password for this account."); document.mod.newpass2.focus(); return; }  
    if(document.mod.email.value == ''){ 
       alert("Must type an email for this account."); document.mod.email.focus(); return; }  
   document.mod.submit();
   return;
  break;
  }

}

return;
}

//-------------------------------------------------------------------------------------------
// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


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

function disable_var(varfield, status){

 switch(status){
  case 'T': { varfield.disabled = true; break; }
  case 'F': { varfield.disabled = false; break; }
 }
 
 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;
}  


