//BROWSERS
var recentBrowser = false; 
var isIE=false;
if ((parseInt(navigator.appVersion) >= 4 && navigator.appVersion.indexOf("MSIE") != -1) || ((parseInt(navigator.appVersion) >= 6 && navigator.appName.indexOf("Netscape") != -1))){
	recentBrowser = true; //Opera 7 also true for these parameters
	isIE=true;
}
if ((parseInt(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape") != -1) || ((parseInt(navigator.appVersion) >= 6 && navigator.appName.indexOf("Netscape") != -1))){
	recentBrowser=true;
}
//FAVICON
document.write("<link rel='icon' href='images/favicon.ico' type='image/x-icon'><link rel='shortcut icon' href='images/favicon.ico' type='image/x-icon'>");

//STYLES BROWSER ADJUSTMENT
if(!isIE){document.write("<style>body,td,th,p,li{font-size:small;}</style>")}

//BREAK OUT OF FRAMES
if (window.location != top.location){top.location.href=window.location};

//DATE & TIME
var days = new Array(7);
days[1]="Sunday";days[2]="Monday";days[3]="Tuesday";days[4]="Wednesday";days[5]="Thursday";days[6]="Friday";days[7]="Saturday";
var months = new Array(12);
months[1]="Jan";months[2]="Feb";months[3]="Mar";months[4]="Apr";months[5]="May";months[6]="Jun";months[7]="Jul";months[8]="Aug";months[9]="Sep";months[10]="Oct";months[11]="Nov";months[12]="Dec";
var today = new Date();
var day = days[today.getDay() + 1]
var month = months[today.getMonth() + 1]
var date = today.getDate();
var year=today.getYear(); 
if(year<2000){year = year + 1900;}

//MENU HIGHLIGHTING
var page;
querystring = location.search;

if(querystring.indexOf("page=")!=-1){
	var pairs = querystring.split("&");
	var first = pairs[0].split("=");
	var fileplusext = first[1].split(".");
	var page = fileplusext[0];
}	
function highlightMenu(){
		if(recentBrowser){
			if(document.getElementById(page)){
				isMenuPage=true;
				document.getElementById(page).className="menubtnactive";
				document.getElementById(page).childNodes[0].className="menutextactive";
			}
		}
}
function mouseoverMenu(menuid){
	if(recentBrowser){
		if (menuid==page){
			document.getElementById(menuid).style.className="menubtnactive";
		}else{
			if (isIE){document.getElementById(menuid).style.cursor="hand";}
			document.getElementById(menuid).className="menubtnover";
			document.getElementById(menuid).childNodes[0].className="menutextover";
		}
	}	
}
function mouseoutMenu(menuid){
	if(recentBrowser){
		if (menuid==page){
			document.getElementById(menuid).className="menubtnactive";
			document.getElementById(menuid).childNodes[0].className="menutextactive";
		}else{
			document.getElementById(menuid).className="menubtn";
			document.getElementById(menuid).childNodes[0].className="menutext";
		}
	}
}
function fnmenulink(menulink){
	
	if(recentBrowser){
		location.href = menulink;
	}
}

//COOKIE HANDLING
function deletecookies(){//deletes ALL cookies
	var cstring=unescape(document.cookie);
	var carray=cstring.split(";");
	for(i=0;i<carray.length;i++){
		var cpair = carray[i].split("=");
		var cname = cpair[0];alert(escape(cname))
		if(i!=0){cname=cname.substring(1,cname.length);}
		setcookie(cname,"",-1);//set expiry to -1 days
	}
	history.go(0);
}
function getexpirydate(nodays){
   var UTCstring;
   Today = new Date();
   nomilli=Date.parse(Today);
   Today.setTime(nomilli+nodays*24*60*60*1000);
   UTCstring = Today.toUTCString();
   return UTCstring;
}
function getcookie(cookiename) {
   var cookiestring=""+document.cookie;
   var index1=cookiestring.indexOf(cookiename);
   if (index1==-1 || cookiename=="") return ""; 
   var index2=cookiestring.indexOf(';',index1);//stringName.indexOf(searchValue, [fromIndex])
   if (index2==-1) index2=cookiestring.length; 
   return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setcookie(cname,value,duration){//TO DELETE A SINGLE COOKIE SEND duration VALUE -1 
  cookiestring=escape(cname)+"="+escape(value)+"; expires="+getexpirydate(duration);
  document.cookie=cookiestring;
  if(!getcookie(cname)){
  return false;
  }
  else{
   return true;
  }
}

//CURRENCY FORMATTING
function twodp(n) {
   n+=.005;
   ns = " "+n;
   ns = ns.substring(1,ns.length);
   var dp = ns.indexOf(".");
   if (dp < 0) ns = ns+".00";
   else if (dp == ns.length-2) ns = ns+"0";
   else if (dp < ns.length-1) ns = ns.substring(0,dp+3);
   return ns;
}

//LAST MODIFIED - CALLED BY document.write(lastMod())
function lastMod() {
	var x = new Date (document.lastModified);
	var original = new Date (document.lastModified);
	original = original.toLocaleDateString();
	
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730) 	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60) {
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14) {
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'Last modified: ';
	if (daysago == 0) towrite += 'Today';
	else if (daysago == 1) towrite += 'Yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite+' ('+original+')';
}
function takeYear(theDate) {
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

//EMAIL BUILDER
function buildemail(emailname,emaildom){
	window.open("mailto:"+emailname+"@"+emaildom);
}

//CHECK EMAIL
function checkemail(emailstr){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(emailstr)){
		testresults=true;
	}else{
		testresults=false;
	}
	return (testresults);
}

//DYNAMIC STYLES
function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}