﻿//------------ BEGIN Functions -------------

//Trim functions to remove spaces from the beginning and end of text strings
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
function Trim(s)
{
	return s.replace(/^\s+|\s+$/g,'');
}

//Check for null, undefined, and unknown values of an object
function IsNull(o)
{
   return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o)
}

//Get a dropdowns selected item
function getDDItem(ctl)
{
	try{
		c = ctl.options;
		for(x=0; x<c.length; x++) if(c(x).selected) return c(x);
	}catch(e){}
	return null;
}

//Get a dropdowns selected value
function getDDValue(ctl)
{
	try{
		c = ctl.options;
		for(x=0; x<c.length; x++) if(c(x).selected) return Trim(c(x).value);
	}catch(e){}
	return "";
}

//Get a dropdowns selected text
function getDDText(ctl)
{
	try
	{
		c = ctl.options;
		for(x=0; x<c.length; x++) 
		   if(c(x).selected) 
		      return Trim(c(x).innerText);
	}catch(e){}
	return "";
}

//Get the label text of a radio button
function getRBText(ctl)
{
   if(ctl.nextSibling.tagName=="LABEL")
      return ctl.nextSibling.innerText;
   else
      return ctl.id;
}

//Set the Radio Button Group item by text
function setRBGItem(oGroupDiv, rbText)
{
   l = oGroupDiv.getElementsByTagName("input");
   for(x=0;x<l.length;x++)
   {
      if(l[x].type=="radio" && getRBText(l[x])==rbText)
      {
         l[x].checked = true;
         break;
      }
   }
}

//Code to access the querystring
QS.keys = new Array();
QS.values = new Array();

//Use QS(key) to access the items in the QueryString
function QS(key)
{
	//only parse the query string if we need it
 	QS_Parse();
   var value = null;
   for (var i=0;i<QS.keys.length;i++)
   {
      if (QS.keys[i]==key)
      {
         value = QS.values[i];
         break;
      }
   }
   return value;
}

function QS_Parse()
{
    var query = window.location.search.substring(1);
    var pairs = query.split("&");
    
    for (var i=0;i<pairs.length;i++)
    {
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QS.keys[QS.keys.length] = argname;
			QS.values[QS.values.length] = value;          
		}
	}
}
//---------- END Functions ------------
//---------- BEGIN Events -------------
function document.onkeypress()
{
   var event = window.event;
   if (event.ctrlKey && event.keyCode == 80)
   {
      event.keyCode = 0;
      return false;
   }
}

document.onkeydown = document.onkeypress;

function window.onerror()
{
   return false;
}

//Disabled until code complete
function document.xoncontextmenu()
{
   var s = event.srcElement.tagName;
   event.returnValue =
      (
         !event.srcElement.disabled &&
         (document.selection.createRange().text.length > 0 ||
         s == "TEXTAREA" ||
         s == "INPUT" && event.srcElement.type == "text")
      );
}

function document.onselectstart()
{
   var s = event.srcElement.tagName;
   if (s != "INPUT" && s != "TEXTAREA") 
      event.returnValue = false;
}
//---------END Events --------------

