function addDays(myDate,days) 
{
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

function setCookie(name)
{
	var the_date = addDays(new Date(),2);
	var the_cookie_date = the_date.toGMTString();
	var the_cookie = name + " = true";
	the_cookie = the_cookie + ";expires=" + the_cookie_date;
	document.cookie = the_cookie;
}


// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}



// THIS SCRIPT DOES THE DOUBLE SWAP (CLOSES THE POP-UP, CHANGES THE PARENT)
// USAGE: <a href="#" ONCLICK="DoubleSwap('http://www.domain.com')">text link</a>
function DoubleSwap(URL)
{
	window.opener.location = URL;
	window.close();
}

// THIS SCRIPT RUNS THE POPUP WINDOWS
// USAGE: <a href="javascript:NewWindow('page.html', 'nameOfWindow', 500, 300, 1, 1)">Text Link</a>
function NewWindow(url, myname, w, h, scroll, resize, blur) 
{
	winprops = 'height='+h+',width='+w+',top=10,left=10,scrollbars='+scroll+',resizable='+resize+',toolbar=0'
	win = window.open(url, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	
	if(blur==1)
	{
		// make the window "pop under".
		win.blur();	
		window.focus();
		setTimeout("window.location.reload()",2000);
	}
}



//	THIS SCRIPT IS USED TO PREVENT DOUBLE SUBMISSIONS ON FORMS
//
//	USE: add this inside your form tag: <FORM onSubmit="return checkFields()">

var submitcount=0;
function checkFields()
{
	if (submitcount == 0)
	{
		submitcount++;
		return true;
	}
	else
	{
		alert("Please Wait. This form has already been submitted and is still processing. Thanks!");
		return false;
	}
}


// THIS SCRIPT RUNS THE DROPDOWN MENUS
// USAGE: <DIV CLASS="navBlock" onMouseOver="this.className='navBlockHover'; change('subs1', 'subNavHover'); change('flash', 'flashHide'); change('flash2', 'flashHide')" onMouseOut="this.className='navBlock'; change('subs1', 'subNavHide'); change('flash', 'flashShow'); change('flash2', 'flashShow')" onClick="this.className='navBlock'; change('subs1', 'subNavHide'); change('flash', 'flashShow'); change('flash2', 'flashShow')" STYLE="margin-left: 10px; width: 130px;">
function change(id, newClass)
{
	if(document.getElementById(id) == null)
	{
		//do nothing
	}
	else
	{
		var identity = document.getElementById(id);
		identity.className = newClass;
	}
}


// THIS SCRIPT CHECKS TO SEE IS THE PASSED VALUE IS MADE UP ENTIRELY OF NUMBERICAL CHARACTERS (0-9)
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}



//THIS SCRIPT IS FOR formtools.php textbox function:
function nextFocusWithMaxLength(el)
{
	if (el.value.length < el.getAttribute('maxlength')) return;
	
	var f = el.form;
	var els = f.elements;
	var x, nextEl;
	for (var i=0, len=els.length; i<len; i++){
		x = els[i];
		if (el == x && (nextEl = els[i+1])){
			if (nextEl.focus) nextEl.focus();
		}
	}
}
