/*

this will create two random integers between
randmin and randmax, and ensure that the two
are never the same.

returns an array.

usage:
	var foo = get2rand(randmin,randmax);
	alert(foo[0] + ',' + foo[1]);

*/

function get2rand(randmin,randmax) {

	if (randmin == randmax) {
		alert('min and max cant be the same');
		return false;
	}

	if (randmin > randmax) { // swap them if they are out of order
		var foo = randmin;
		randmin = randmax;
		randmax = foo;
	}

	var rand1 = Math.floor(Math.random()*(randmax-randmin+1))+randmin;
	var rand2 = Math.floor(Math.random()*(randmax-randmin+1))+randmin;

	while (rand1 == rand2) {
		rand2 = Math.floor(Math.random()*(randmax-randmin+1))+randmin;
	}

	return new Array(rand1,rand2);

}


/*
This function is used for forms that have fields that require numeric characters only.
*/
function noalpha(obj) {

	var alpha_regexp = /[^0-9]/;

	if (alpha_regexp.test(obj.value)) {
		alert('Sorry, numbers only in this field.');
	}

	while (alpha_regexp.test(obj.value)) {
		obj.value = obj.value.substr(0,obj.value.length-1);
	}

}

/*
This function is used for forms that have money fields that require numeric and period characters only.
*/
function noalpha_dotOK(obj) {

	var alpha_regexp = /[^0-9.]/;

	if (alpha_regexp.test(obj.value)) {
		alert('Sorry, numbers and decimal points only in this field.');
	}

	while (alpha_regexp.test(obj.value)) {
		obj.value = obj.value.substr(0,obj.value.length-1);
	}

}



/*JS pulled from Layout and put in here*/
function mOutMbutton(btn,drop) {
//	btn.className='topmenubtn';
	var dropspan = document.getElementById('drop_' + drop);
	dropspan.style.display='none';
}

function mOverMbutton(item,drop) {
	var dropspan = document.getElementById('drop_' + drop);

	dropspan.style.top = DL_GetElementTop(item) + 19;
	dropspan.style.left = DL_GetElementLeft(item);
	dropspan.style.display='block';
}

function DL_GetElementLeft(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }

      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}

function DL_GetElementTop(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nTopPos = eElement.offsetTop;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }

      nTopPos += eParElement.offsetTop;    // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                          // return the number calculated
}

function btnover(btn) {

	btn.className='topmenubtnover';

}

function btnout(btn) {

	btn.className='topmenubtn';

}

function menuclick(url) {
	window.location.href=url;
}


//Double Click Stopper Script Starts Here//
var cstimer;
var clickstop = 0;

function stopclick() {
	if (!clickstop) {
		clickstop = 1;
		cstimer = setTimeout(clear_clickstop,10000);
		$.blockUI('<h2 style="padding: .7em;">Please&nbsp;Wait...</h2>');
		return true;
	} else {
		return false;
	}
}

function set_clickstop() {
	stopclick();
}

function clear_clickstop() {
	clickstop = 0;
    clearTimeout(cstimer);
    $.unblockUI();
}
//Double Click Stopper Script Ends Here//

function is_valid_email(addr) {

	var pattern = /^(([a-z0-9!#$%&*+-=?^_`{|}~][a-z0-9!#$%&*+-=?^_`{|}~.]*[a-z0-9!#$%&*+-=?^_`{|}~])|[a-z0-9!#$%&*+-?^_`{|}~]|("[^"]+"))[@]([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/i;

	if (pattern.test(addr)) {
		return 1;
	} else {
		return 0;
	}

}