function getXHR() {
if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
    if (! isObject(req)) {
    	alert("This site uses AJAX and requires ActiveX control are enabled in Internet Explorer.");
    }
return req
}   
  
function getHTTPObject() {
  var xmlhttp;
  
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); 

function lTrim(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}

function rTrim(sString)
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}


function allTrim(sString)
{
	return rTrim(lTrim(sString))
}

function UpdateField(toObject)
{
	var FieldName=toObject.name;
	var PK=toObject.id;
	var NewValue=toObject.value;
	var url = "updatefield.afp?cField=" + FieldName + "&vPK=" + PK + "&vNewValue=" + NewValue;

//	window.location=url;
	http.open("GET", url, true);
	http.onreadystatechange = handleUpdateResponse;
	http.send(null);  	
}

function handleUpdateResponse() 
{
  if (http.readyState == 4) 
  {
	var errorMessage = http.responseText;
	if (! errorMessage == "") 
	{
	   	alert(errorMessage); 
	}
  }
}

//function DeleteLink(cLink_Id) 
//{
// if (confirm('Are you sure you want to delete this link?'))
//  {
//	 http.open("GET", url + escape(cLink_Id), true);
//	 http.onreadystatechange = handleHttpResponse;
//	 http.send(null);  
//  } 
//}

// Credit card functions taken from http://www.evolt.org/article/rating/17/24700/
function isValidCardNumber (strNum)
{
   var nCheck = 0;
   var nDigit = 0;
   var bEven = false;
   
   for (n = strNum.length - 1; n >= 0; n--)
   {
      var cDigit = strNum.charAt (n);
      if (isDigit (cDigit))
      {
         var nDigit = parseInt(cDigit, 10);
         if (bEven)
         {
            if ((nDigit *= 2) > 9)
               nDigit -= 9;
         }
         nCheck += nDigit;
         bEven = ! bEven;
      }
      else if (cDigit != ' ' && cDigit != '.' && cDigit != '-')
      {
         return false;
      }
   }
   return (nCheck % 10) == 0;
}

function isDigit (c)
{
   var strAllowed = "1234567890";
   return (strAllowed.indexOf (c) != -1);
}

function isCardTypeCorrect (strNum, type)
{
   var nLen = 0;
   for (n = 0; n < strNum.length; n++)
   {
      if (isDigit (strNum.substring (n,n+1)))
         ++nLen;
   }
   
   if (type == 'Visa')
      return ((strNum.substring(0,1) == '4') && (nLen == 13 || nLen == 16));
   else if (type == 'Amex')
      return ((strNum.substring(0,2) == '34' || strNum.substring(0,2) == '37') && (nLen == 15));
   else if (type == 'Master Card')
      return ((strNum.substring(0,2) == '51' || strNum.substring(0,2) == '52'
              || strNum.substring(0,2) == '53' || strNum.substring(0,2) == '54'
              || strNum.substring(0,2) == '55') && (nLen == 16));
   else
      return false;
   
}

function pause(milliseconds)
{
var start = new Date();
var end = null;

do { var end = new Date(); }
while(start+milliseconds < end);
} 

function getRadioButtonValue(opgButtons)
{
var lcRetVal = "empty"
for(var i=0;i<opgButtons.length;i++) 
    if(opgButtons[i].checked) 
    {
       lcRetVal = opgButtons[i].value;
    }
    return lcRetVal;
}

function isObject(vObject) {
    return (vObject && typeof vObject == 'object') || isFunction(vObject);
}

function isFunction(vFunc) {
    return typeof vFunc == 'function';
}