function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                         "Thursday", "Friday", "Saturday");
    return DayArray[intDay];
}

function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December"); 
    return MonthArray[intMonth]; 	  	 
}

function email_check(email){

		var patt="/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i";

		if (preg_match(patt,email))return -1;
		else return 0;
}

function getDateStrWithDOW(){
    var today = new Date();
    var year = today.getYear();
    if(year<1000) year+=1900;
    var todayStr = GetDay(today.getDay()) + ", ";
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate();
    todayStr += ", " + year;
    return todayStr;
}

function get_val(x){
//	reads value with commas and poss percent sign and converts to floating point
	var flag=0;
	var y=x.replace(/,/g,"");		//get rid of commas

	if (y.indexOf('%')>-1){			//set flag if there's a percent sign in there
		flag=-1;
		y=y.replace(/%/g,"");		//get rid of the percent sign
	}
	var res=0.0 + y*1.0;			//convert to a floating point number
	if (flag) res /=100;			//if flag set, divide by 100 to convert to percentage
		
	
	return res;


}

function ShowTodaysDate(){

    document.write(getDateStrWithDOW());
}



function QueryString_Parse()
{

	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	var output = new Array();
	var apair;

	
	for (var i=0;i<pairs.length;i++)
	{
		apair=pairs[i].split("=");
		output[apair[0]]=apair[1];

	}
	return output;
}

/////////////////////////////////////
//	cookie functions
/////////////////////////////////////

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

////////////////////////////////////////////////////
//
//		emailCheck
//
//////////////////////////////////////////////

function emailCheck(emailStr){

	var patt=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i;
	if (emailStr.match(patt)) return true;
	else return false;
}
///////////////////////////////////////
//
//		AJAX
//
///////////////////////////////

function AJAX()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        return false;
        }
      }
    }
   return xmlHttp;
  }



///////////////////////////////////
//
//		ROLLOVERS
//
////////////////////////////////////

var m_confirm=0;
var m_save;
var m_backcolour_save;
var m_tabstrip=0;
var m_tab=0;
var m_taboffstyle;
var m_tabonstyle;

function inittd(){
	var i,j,val,elt,rollover,list,tags,tag;

	tags=Array("TD","IMG","TR");

	for (i=0;i<tags.length;i++){
		tag=tags[i];
		list=document.getElementsByTagName(tag);
		for (j=0;j<list.length;j++){
			elt=list[j];
			if (elt.getAttribute("action") != undefined){
				elt.style.cursor="pointer";
				elt.onclick=click1;
			}
			if (elt.getAttribute("rollover") !=undefined){
				if (elt.getAttribute("tabstrip")==undefined){
					elt.onmouseover=mouseover1;
					elt.onmouseout=mouseout1;
				}
			}	
		}
	}

}

function init_tabstrip(){
	var i,j,list,elt;
	
	list=document.getElementsByTagName("TR");

	for (j=0;j<list.length;j++){
		elt=list[j];
		if (elt.getAttribute("tabstrip") != undefined){
			m_tabonstyle=elt.getAttribute("rollover");
			m_taboffstyle=elt.getAttribute("rollout");

			m_tabstrip=elt.childNodes;
			for (i=0;i<m_tabstrip.length;i++){
				m_tabstrip[i].setAttribute("tab",i);
				m_tabstrip[i].onmouseover=tabover;
				m_tabstrip[i].onmouseout=tabout;
				m_tabstrip[i].onclick=click1;

				if (!i) m_tabstrip[i].className=m_tabonstyle;
				else m_tabstrip[i].className=m_taboffstyle;
			}

			break;
		}
	}
	
}

function tabover(){
	this.className=m_tabonstyle;
}

function tabout(){
	var itab;
	itab=parseInt(this.getAttribute("tab"));
	if (itab !=m_tab) this.className=m_taboffstyle;
}

function mouseover1(){
	if (this.tagName=="IMG"){
		m_save=this.src;
		this.src=this.getAttribute("rollover");
	}
	else {
		m_save=this.className;
		this.className=this.getAttribute("rollover");
	}
}
function mouseout1(){
	if (this.tagName=="IMG") this.src=m_save;
	else this.className=m_save;
}

function mouseover2(){
	m_save=this.src;
	this.src=this.getAttribute("rollover");
}
function mouseout2(){
	this.src=m_save;
}

function click1(){
	var itab;
	if (this.getAttribute("tab") !=undefined){		//it's a tabstrip element
		itab=parseInt(this.getAttribute("tab"));
		if (itab !=m_tab){
			m_tabstrip[m_tab].className=m_taboffstyle;
			m_tab=itab;
		}
	}

	var a=this.getAttribute("action");
	var check=this.getAttribute("confirm");
	var link;
	var action;
	
	if (a == undefined) return;

	if (check !=undefined){
		var x=confirm("Are you sure you want to do this?");
		if (!x) return;

	}

	var i=a.indexOf(':');
	if (!i) return;

	action=a.substr(0,i);

	switch (action){

	case "close":
		window.close();
		break;
	case "back":
		window.history.back();
		break;
	case "link":
		link=a.substr(i+1,a.length-i);
		window.location=link;
		return;
	case "open":
		link=a.substr(i+1,a.length-i);
		window.open(link,'awin');
		return;
	case "js":
		evalstr=a.substr(i+1,a.length-i);
		eval(evalstr);
		return;

	}

}






