function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 )
	{
			var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    		var aQueryString = strQueryString.split("&");
			for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
	      		if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
			{
		        	var aParam = aQueryString[iParam].split("=");
			        strReturn = aParam[1];
		        	break;
  				}
			}
      }
      
	return unescape(strReturn);
}
	
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}
function StopEvent(pE)
{
   if (!pE)
	 if (window.event)
	   pE = window.event;
	 else
	   return;
  if (pE.cancelBubble != null)
	 pE.cancelBubble = true;
  if (pE.stopPropagation)
	 pE.stopPropagation();
  if (pE.preventDefault)
	 pE.preventDefault();
  if (window.event)
	 pE.returnValue = false;
  if (pE.cancel != null)
	 pE.cancel = true;
}

function BlockTextInsert(e) 
{  
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (!(code == 8 || code == 46 || code == 9))
		StopEvent(e);
}

function ValidateLimit(obj, maxChar)
{
    var remaningChar = maxChar - obj.value.length;
    if( remaningChar <= 0)
    {
       obj.value = obj.value.substring(maxChar, 0);
       alert('Only ' + maxChar + ' characters are allowed!');
       return false;
    }
    return true;
}
function setMaxLength(obj, intLen)
{
	if (obj.getAttribute && obj.value.length > intLen)
	{
		obj.value=obj.value.substring(0,intLen);
		alert("Maximum " + intLen + " characters are allowed!");
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return [curleft, curtop];
}
function DoTrim(strComp)
{
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}
function ValidateInteger(e)
{
	// Always use this function for onkeydown event
	var key;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	if (!((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key >= 33 && key <= 39) || key == 8 || key == 9 || key == 16 || key == 18 || key == 46 ||  key == 116))
	{
		StopEvent(e);
	}
}
function ValidateDouble(e, obj)
{
	// Always use this function for onkeydown event
	var key;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	if (!((key >= 48 && key <= 57) || (key >= 96 && key <= 105) || (key >= 33 && key <= 39) || key == 8 || key == 9 || key == 16 || key == 18 || key == 46 ||  key == 116))
	{
		if (key == 110 || key == 190)
		{
			if (obj.value.indexOf('.') > -1)
			{
				StopEvent(e);
			}
		}
		else
		{
			StopEvent(e);
		}
	}
}
function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}
function Right(str, n)
{
      if (n <= 0)
          return "";
      else if (n > String(str).length)
          return str;
      else
   {
          var iLen = String(str).length;
          return String(str).substring(iLen, iLen - n);
      }
}

function ValidateEmail(elementValue)
{
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue);
}

function ValidatePhoneNumber(elementValue){
    var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
    return phoneNumberPattern.test(elementValue);
}

function GetKeyCode(e)
{
    var key;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	return key;
}

function EnterKey(e, obj, lnkObject)
{
    if (GetKeyCode(e) == 13)
    {
        lnkObject.click();
    }
}

function ViewTooltip(tooltipContainerId, refObj, width, leftOffSetFromRefObj, topOffSetFromRefObj, text)
{
    if (document.getElementById(tooltipContainerId) != null)
    {
        document.getElementById(tooltipContainerId).innerHTML = '';
        document.getElementById(tooltipContainerId).innerHTML = text;
        var Pos = findPos(refObj);
        document.getElementById(tooltipContainerId).style.left = (Pos[0] + leftOffSetFromRefObj) + 'px';
        document.getElementById(tooltipContainerId).style.top = (Pos[1] + topOffSetFromRefObj) + 'px';
        if (width != '')
        {
            document.getElementById(tooltipContainerId).style.width = width;
        }
        document.getElementById(tooltipContainerId).style.display = '';
    }
    else
    {
        alert('tooltip container not found');
    }
}

function HideTooltip(tooltipContainerId)
{
    if (document.getElementById(tooltipContainerId) != null)
    {
        document.getElementById(tooltipContainerId).style.display = 'none';
    }
    else
    {
        alert('tooltip container not found');
    }
}