// AJAX function
function showResult(id, qstr)
{
if (id =="") return false;

xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }
url=qstr;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4)
  {
  document.getElementById(id).innerHTML=xmlhttp.responseText;
  //document.getElementById(id).style.border="1px solid #A5ACB2";
  }
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
function hideResults(id){
  document.getElementById(id).innerHTML="&nbsp;";
  //alert(id);
  return;
}
// End of Ajax functions here

// DateAdd function
Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}

// functions to handle dynamic font resize
function textSize(){
//call this function on each page load
var fSize = getCookie("fontSize")
if (fSize){
	var s = fSize
	}
	else{
	s = 12
	}
// s is the font size and h in the line height
var h = parseInt(s)+2
document.styleSheets[0].rules[1].style.fontSize= s+"px";
document.styleSheets[0].rules[1].style.lineHeight = h+'px';
// set images
var fNm = getCookie("fontNm")
	if (fNm == 'sml'){
		document.getElementById('fontSmall').src = "images/fontSmall_on.jpg"
		document.getElementById('fontMedium').src = "images/fontMedium.jpg"
		document.getElementById('fontLarge').src = "images/fontLarge.jpg"
	}
	else if (fNm == 'lrg'){
		document.getElementById('fontSmall').src = "images/fontSmall.jpg"
		document.getElementById('fontMedium').src = "images/fontMedium.jpg"
		document.getElementById('fontLarge').src = "images/fontLarge_on.jpg"
	}
	else { // must be medium
		document.getElementById('fontSmall').src = "images/fontSmall.jpg"
		document.getElementById('fontMedium').src = "images/fontMedium_on.jpg"
		document.getElementById('fontLarge').src = "images/fontLarge.jpg"
	}



}
function get( name ){ 
// Gets the var from a URL
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )    
		return "";  
	else    
		return results[1];
}
function startDemo(url,uname,pass){
	//alert("The demo section is temorarily disabled - Check back later."); return;
	url = url + "?f=demo";
	alert('The username is ' + uname + ' and the password is ' + pass);
	window.open(url, 'demo', 'width=1024, height=768, resizable, top=0, left=0, alwaysRaised');
	//demo.focus();
}
function Minimize() 
{
window.innerWidth = 100;
window.innerHeight = 100;
window.screenX = screen.width;
window.screenY = screen.height;
alwaysLowered = true;
}

function Maximize() 
{
window.innerWidth = screen.width;
window.innerHeight = screen.height;
window.screenX = 0;
window.screenY = 0;
alwaysLowered = false;
}

function checkfrm(){
	if(form.first_name.value == ''){
		alert("Please enter your first name");
		form.first_name.focus();
		return false;
	}
	if(form.email.value == ''){
		alert("Please enter your email address");
		form.email.focus();
		return false;
	}
	if(!emailCheck(form.email.value)){
		alert("The email address you entered seems to be invalid.\nPlease correct it and resubmit.");
		form.email.focus();
		return false;
	}
	form.email_from.value = form.email.value;
	return checkPhone(form.phone);
}
function getTicketStatus(){
	window.open('http://office.ecdsi.com:888/phpTickets/index.php','ticket','width=300, height=250, resizable');
}
function setTextSize(sizeNm) {
	// set text sizes here
	if (sizeNm == 'sml'){
		sizeID = 12;
	}
	if (sizeNm == 'med'){
		sizeID = 14;
	}
	if (sizeNm == 'lrg'){
		sizeID = 16;
	}
	
	// set the user's cookie
    setCookie("fontSize", sizeID, 10);
	setCookie("fontNm", sizeNm, 10);
	// make the size changes
    textSize();
}
function setCookie(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 getCookie(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;
}
// login functions
function forgotpass(){
window.alert("Disabled")
}
function register(){
window.alert("Disabled")
}
function user_login(){
//window.alert("Disabled")
if (login.userid.value == ''){
	alert("You must enter your user name.");
	login.userid.focus();
	return false;
	}
if (login.pass.value == ''){
	alert("You must enter your password.");
	login.pass.focus();
	return false;
	}
login.method = "post";
login.submit();
}

// functions for ActiveX content
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

// check string functions

// test the maximum size for a textarea box
function max_text(field, len){
if (field.value.length >= len){
	alert("The maximum length for this text area has been reached")
	field.focus()
	return false
	}
}
function checkDate (e) {
   var charCode= e.keyCode
   if (charCode > 31 ) { // have something other than control char
          
		 if ((charCode < 46) || (charCode > 57)) {
            alert("Only a number may be entered here.")
			return false;
         	}
      }
    return true;
}
function checkNumber (e) {
   var charCode= e.keyCode
   if (charCode > 31 ) { // have something other than control char
          
		 if ((charCode < 48) || (charCode > 57)) {
            alert("Only a number may be entered here.")
			return false;
         	}
      }
    return true;
}
function checkPhone(field){
num = field.value
if (num == "") return true
// Check that the length is 10
if (num.length != 10){
	alert("The phone number must be 10 digits")
	field.select()
	return false
	}
// Check that there are no invalid characters
strPhone = "0123456789"
strTest = true
for (p=0; p < num.length; p++){
	phInd = num.substr(p,1)
	if (strPhone.indexOf(phInd) < 0) strTest = false
	}
if (!strTest){
	alert("The phone number seems to be invalid.")
	field.select()
	return false
	}
// Check that the phone number does not start with 1
if (num.substr(0,1) == "1"){
	alert("The phone number must NOT begin with 1")
	field.select()
	return false
	}
// The phone number is good
return true
}

function checkTime (e) {
   var charCode= e.keyCode
   if (charCode > 31 ) { // have something other than control char
          
		 if ((charCode < 48) || (charCode > 58)) {
		 	if (charCode != 80 && charCode != 65 && charCode != 112 && charCode != 97){// P and A are ok for time
            	alert("That is an invalid character for the time.\n Enter time in format HH:MMP or HH:MMA")
				return false;
				}
         	}
      }
    return true;
}
// check the time
function checkTheTime(field){
if (field.value == "") return true
if (parseInt(field.value.substr(0,2), 10) > 12 || parseInt(field.value.substr(0,2), 10) < 1 || field.value.indexOf(":") != 2 || parseInt(field.value.substr(3,2), 10) > 59 || (field.value.indexOf("P") != 5 && field.value.indexOf("A") != 5 && field.value.indexOf("p") != 5 && field.value.indexOf("a") != 5)){
	alert("Invalid time.\nYou must use HH:MMP or HH:MMA")
	return false
	}
return true
}
// check the date
function checkTheDate (field){
date = field.value
if (date == "" || date == "00-00-00" || date == "<<>>" || date == "*") return true;
if (date.indexOf("-") < 1 || date.lastIndexOf("-") < 3){
alert ("Invalid date format\nYou need to have hyphens seperating MM-DD-YY");
field.select();
return false;
}
sysDate = new Date();
month = (date.substring(0,date.indexOf("-")));
day = (date.substring(date.indexOf("-")+1,date.lastIndexOf("-")));
year = (date.substring(date.lastIndexOf("-")+1));
if (year.length == 2) year = '20' + year;

var daysInMonth = new Array(13)
daysInMonth[1] = 31;
daysInMonth[2] = 29;   
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
var intYear = parseInt(year,10);
var intMonth = parseInt(month,10);
var intDay = parseInt(day,10);
//alert("year=" + intYear + " month=" + intMonth + " day=" + intDay);

minyear = 1910
maxyear = 2020
if (date.length < 8 || intMonth < 1 || intMonth > 12 || intDay < 1 || intDay > 31 || intYear < parseInt(minyear,10) || intYear > parseInt(maxyear,10)){
  return err(field);
}
    // catch invalid days, except for February
    else if (intDay > daysInMonth[intMonth]) {return err(field);}
    // catch invalid days, for February
    else if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) {return err(field);}
 	
}
	//checks no. of days in February if leap year
function daysInFebruary (year){
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}



function err(field){
window.alert ( "Invalid date. Please enter the date in the proper format MM-DD-YY" );
field.select();
return false;
}
// end of date check

// check email addresses
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=0;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(ca|com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
return false;
}

// If we've gotten this far, the email is valid!
return true;
}
