// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}


	// Check if a form object has a value in it,  supply a warning text if it has no value and return false
function checkFormObject(objName, inMessage, DisplayInDiv) {
	var obj = document.getElementById(objName);
	var ContainingDviClass = obj.parentNode.parentNode.parentNode.className;
	var ContainingContainingDviClass = obj.parentNode.parentNode.parentNode.parentNode.parentNode.className;
	
	
	//alert(objName);
	//alert(ContainingDviClass);
	
	//var ParentDivObj = document.getElementById(obj.container);
	if (ContainingContainingDviClass != "InvisibleWidget")
	{
	
	if (ContainingDviClass != "InvisibleWidget")
	{
	if (obj.type == "checkbox") 
	
		{if (obj.checked == false) 
		
		{var WarningObj = document.getElementById(DisplayInDiv);
									
										
			if (WarningObj.innerHTML =='')
			{
				WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
				}
			else{
				WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
				}
				
			return false;
			}
			return true;
		}
		
	
	if (obj.type == "text") 
	
		{if (obj.value == "") {
			
			
			var WarningObj = document.getElementById(DisplayInDiv);
			var ObjType = WarningObj.className;
			
			if (WarningObj.innerHTML ==''){
				WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
				}
			else{
				WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
				}
				
			return false;
			}
			return true;
		}
		
	
	if (obj.type == "password") 
	
		{if (obj.value == "") {
			obj.focus();
			
			var WarningObj = document.getElementById(DisplayInDiv);
			var ObjType = WarningObj.className;
			
			if (WarningObj.innerHTML ==''){
				WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
				}
			else{
				WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
				}
				
			return false;
			}
			return true;
		}
	
	
	if (obj.type == "select-one") 
	
		{if (obj.value == "") {
			obj.focus();
			
			var WarningObj = document.getElementById(DisplayInDiv);
			var ObjType = WarningObj.className;
			
			if (WarningObj.innerHTML ==''){
				WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
				}
			else{
				WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
				}
				
			return false;
			}
			return true;
		}
		
	
	if (obj.type == "radio") {
	
		var radioElements=document.getElementsByName(objName);
		var returnValue=false;
		var radio_choice = false;
		 for (var i=0 ; i < radioElements.length; i++)
		 {
		  if(radioElements[i].checked)
		   radio_choice = true;
		 }
		  if (!radio_choice){
		
		var WarningObj = document.getElementById(DisplayInDiv);
			var ObjType = WarningObj.className;
			
			if (WarningObj.innerHTML ==''){
				WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
				}
			else{
				WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
				}}
			
		 return radio_choice;
		 
		
    }
	}
	return true;
	
	}
	return true;
}


// Check if a form object has a value in it,  supply a warning text if it has no value and return false
function checkFormObjectIsNumeric(objName, inMessage, DisplayInDiv) {
	var obj = document.getElementById(objName);
	
	if (obj.type == "text") 
		if ((obj.value) != ""){
			{if (!(IsNumeric(obj.value))) {
				
				obj.focus();
				
				var WarningObj = document.getElementById(DisplayInDiv);
				WarningObj.innerHTML = '<strong>Please enter only numbers into this field</strong> <br/> <br/>';
					
				return false;
				}
				return true;
			}
			
		}
		return true;
}



// Check if a form object has a value in it,  supply a warning text if it has no value and return false
function checkFormObjectNoFocus(objName, inMessage, DisplayInDiv) {
	var obj = document.getElementById(objName);
	if (obj.value == "") {
	
	var WarningObj = document.getElementById(DisplayInDiv);
	if (WarningObj.innerHTML ==''){
		WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
		}
	else{
		WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
		}
		
	return false;
	}
	
	return true;
}
// Check if a form object has a value in it,  supply a warning text if it has no value and return false
function checkFormObjectNoFocus(objName, inMessage, DisplayInDiv) {
	var obj = document.getElementById(objName);
	if (obj.value == "") {
	
	var WarningObj = document.getElementById(DisplayInDiv);
	if (WarningObj.innerHTML ==''){
		WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
		}
	else{
		WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
		}
		
	return false;
	}
	
	return true;
}
// Check if a form object EXISTS,  if it does it must have a value in it,  supply a warning text if it has no value and return false
function checkFormObjectIfAvailable(objName, inMessage, DisplayInDiv) {
	if (document.getElementById(objName) != null){
		var obj = document.getElementById(objName);
		if (obj.value == "") {
		obj.focus();
		
		var WarningObj = document.getElementById(DisplayInDiv);
		if (WarningObj.innerHTML ==''){
			WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
			}
		else{
			WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
			}
			
		return false;
		}
		
		return true;
	} else{
return true;}

}


// Check if a form object has a value in it,  supply a warning text if it has no value and return false
function checkFormLocationOrLongLat(inMessage, DisplayInDiv) {

	var obj2 = document.getElementById('PCVerifyResult');
	if (obj2.innerHTML != 'OK') {	


		var WarningObj = document.getElementById(DisplayInDiv);
		if (WarningObj.innerHTML ==''){
			WarningObj.innerHTML = '<strong>Please enter</strong> <br/>' + inMessage
		}else{
			WarningObj.innerHTML = WarningObj.innerHTML + '<br/>' + inMessage
		}
		return false;
	}else{
		return true;
	}
	
}


function ResetValidationErrors()
//Hide this DIV if we have been there before, also remove its contents
{
	$('div.inntelWarningArea').hide();	
	var WarningObj = document.getElementById('ValidationErrors');
	WarningObj.innerHTML = ''
}

function ResetValidationErrorsCASE(inDivID)
//Hide this DIV if we have been there before, also remove its contents
// This is for Login.asp Registered Users
{
	$('div.inntelWarningArea').hide();	
	var WarningObj = document.getElementById(inDivID);
	WarningObj.innerHTML = ''
}


function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function CheckVal(inControlName){
	var TheControl = findObj(inControlName)
	if (TheControl.value.length == 0) 
      {
      alert("Please enter a value between 0 and 9.");
	  TheControl.value = 0;
      } 
   else if (IsNumeric(TheControl.value) == false) 
      {
      alert("Please check - you have entered a non numeric value!");
  	  TheControl.value = 0;
      }
}

function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

function isNumberKeyV2(evt)
//this check for numeric only and allows decimals and backspace
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         
		 if ((charCode == 46) || (charCode == 8) || (charCode > 47 && charCode < 58))
            return true;

         return false;
      }

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	document.randform.randomfield.value = randomstring;
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
} 


// Check if a form object has a value in it,  supply a warning text if it has no value and return false
function CheckCondition(objID, inTrueValues, inDivToShow) {

var obj = document.getElementById(objID);
var DivToShowObj = document.getElementById(inDivToShow);
var myString = inTrueValues;
var mySplitResult = myString.split("|");
var valuefound = false;

if (obj.type == "select-one") 
	{
		for(i = 0; i < mySplitResult.length; i++)
	{
		if (obj.value == mySplitResult[i])
		{
			valuefound = true;
		}  
	}
	
	if (valuefound == true)
	{
		DivToShowObj.className='VisibleWidget';
	}
	else
	{
		DivToShowObj.className='InvisibleWidget';
	}
}



if (obj.type == "checkbox") 
	{if (obj.checked == true) 
		{
		if (inTrueValues == 'Yes')
			{
				DivToShowObj.className='VisibleWidget';
			}
			else
			{
				DivToShowObj.className='InvisibleWidget';
			}
		}
		else
		{
		if (inTrueValues == 'No')
			{
				DivToShowObj.className='VisibleWidget';
			}
			else
			{
				DivToShowObj.className='InvisibleWidget';
			}
		}
	}
}



function OnCheckAvailability(inUsernameTextboxID, inDelegateAccountID)
{



var obj = document.getElementById(inUsernameTextboxID);	

	
if(window.XMLHttpRequest)
{
oRequest = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
oRequest = new ActiveXObject("Microsoft.XMLHTTP");
}

oRequest.open("POST", "AJAXCheckUsername.asp", true);
oRequest.onreadystatechange = UpdateCheckAvailability;

oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oRequest.send("strCmd=availability&strUsername=" + obj.value + "&DelegateAccountID=" + inDelegateAccountID);
}





function UpdateCheckAvailability()
{
	if(oRequest.readyState == 4)
	{ 
		if(oRequest.status == 200)
		{ 
			if (oRequest.responseText == 'OK') 
			{
				if (document.getElementById("USERNAME_TAKEN").style.display == 'block')
				{
				document.getElementById("USERNAME_TAKEN").innerHTML = "Sorry that Username is already taken, please choose another.";
				document.getElementById("USERNAME_TAKEN").style.display = 'none';
				
				document.getElementById("USERNAME_OK").innerHTML = "That Username is available.";
				document.getElementById("USERNAME_OK").style.display = 'block';
				}
			}
			else
			{
				
					document.getElementById("USERNAME_TAKEN").innerHTML = "Sorry that Username is already taken, please choose another.";
					document.getElementById("USERNAME_TAKEN").style.display = 'block';
					
					document.getElementById("USERNAME_OK").innerHTML = "That Username is available.";
					document.getElementById("USERNAME_OK").style.display = 'none';
				
			}
			}
	else
			{
			document.getElementById("USERNAME_TAKEN").innerHTML = "Asychronous Error";
	}
	}
}





//-->