	function SearchKeyAction(runStr, e)
	{
		if ((e.keyCode == 70) && (e.ctrlKey)) {
			setTimeout(runStr, 1);
			HandledEvent  (e);
		}
	}
	function KeyToButtonAction (obj, enterObjName, searchObjName, e)
	{
		if (e.keyCode == 13) {
			FireButtonEvent(enterObjName, obj);
			HandledEvent  (e);
			return;
		}
		if ((e.keyCode == 70) && (e.ctrlKey)) {
			FireButtonEvent(searchObjName, obj);
			HandledEvent  (e);
			return;
		}		
	}
	function IsNumeric(sText)
	{
		var ValidChars = "0123456789.,-";
		var IsNumber=true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++) { 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) {
				IsNumber = false;
			}
		}
		return IsNumber;
	}
	function NumericCheck(obj)
	{	
		if (IsNumeric (obj.value))
			alert ('Invalid Number');
	}
	function EnterKeyAction(runStr, e)
	{
		if (e.keyCode == 13) {
			setTimeout(runStr, 1);
			HandledEvent  (e);
		}
	}
	function HandledEvent (e)
	{
		if (!IsFireFoxBrowser ())
			e.keyCode = 0;
		CancelBubble (e);
		PreventEvent (e);
	}
	function FireButtonEvent(filterName, btn)
	{
		var firstChild = btn.firstChild;
		if (firstChild && firstChild.disabled)
			return;
		var firstLoop = true;
		while (filterName.indexOf (":", 0) != -1) 
			filterName = filterName.replace (':', '_');
		
		var finalName = filterName.replace (':', '_') + '_m_button';
		var clientName = filterName.replace (':', '_') + '_m_client';
		if (document.getElementById (clientName) == null)
			return;
		if (document.getElementById (clientName).value != null && document.getElementById (clientName).value.length != 0) {
			var runMe = document.getElementById (clientName).value
			eval (runMe);
		}
		else {
			this.className = 'BorderStandard';
			FireOnClickEvent(document.getElementById (finalName));
		}
	}
	function SubmitForm (obj, objName, e)
	{
		if (e.keyCode == 13) 
			FireButtonEvent(objName, obj);
	}
	function OverButton(btn)
	{
		var firstChild = btn.firstChild;
		if (!firstChild)
			return;
		if (firstChild.disabled)
			return
		btn.className = 'ButtonMouseOver';
	}
	function OutOnBtn(btn)
	{
		var firstChild = btn.firstChild;
		if (!firstChild)
			return;
		if (firstChild.disabled)
			return
		btn.className = 'BorderStandard';
	}

// AWFormattedField Functions
	
	function EE_IsData($a,$b)
	{
		if($b>=0)
		{
			var x=$a.value.charCodeAt($b);
			if (x>=48&&x<=57)
				return true;
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	function EE_KeyPress($a, e)
	{
		var k=EE_GetKeyCode(e);
		var c=EE_GetKeyString(k);
		var x=EE_getSelectionStart($a);
		PreventEvent (e);
		if(k>=48&&k<=57)
			EE_KeyNumber($a,x,c);
	}

	function EE_KeyDown($a, e)
	{	
		var k=EE_GetKeyCode(e);
		var x=EE_getSelectionStart($a);
		if(k==8||k==37||k==39||k==46) {
			PreventEvent (e);
			if(k==8)
				EE_KeyBackspace($a,x);
			else if(k==37)
				EE_PushCaretPos($a,0);
			else if(k==39)
				EE_PushCaretPos($a,1);
				else if(k==46)
					EE_KeyDelete($a,x);
		}
	}

	function EE_KeyNumber($a,$b,c)
	{
		EE_CutMask($a,$b,1);
		EE_InsertChar($a,c,$b);
		EE_PutCaretPos($a,$b);
		EE_PushCaretPos($a,1);
	}

	function EE_KeyDelete($a,$b)
	{
		EE_CutMask($a,$b,1);
		EE_InsertChar($a,"_",$b);
		EE_PutCaretPos($a,$b);
	}

	function EE_KeyBackspace($a,$b)
	{
		var $z=false;
		var oP=$b;
		while($z==false&&$b>0) {
			var x=EE_CharAtCaretPos($a,$b-1);
			if(EE_IsData($a,$b-1)) {
				EE_CutMask($a,$b,0);
				EE_InsertChar($a,"_",$b-1);
				$z=true;
				EE_PutCaretPos($a,$b-1);
			}
			else if(x=="_") {
				$z=true;
				EE_PutCaretPos($a,$b-1);
			}
			$b--;
		}
		if(!$z)
			EE_PutCaretPos($a,oP);
	}

	function EE_PushCaretPos($a,$d)
	{
		var k=EE_getSelectionStart($a);
		var x=EE_CharAtCaretPos($a,k);
		do {
			if($d==0) {
				if(k>0)
					EE_PutCaretPos($a,--k);
			} 
			else 
			{
				if (k<$a.value.length-1) 
					EE_PutCaretPos($a,++k);
			}
			x=EE_CharAtCaretPos($a,k)
		}while (x!="_"&&k<$a.value.length-1&&k!=0&&!EE_IsData($a,k))EE_SetupCaretPos($a);
	}

	function EE_InsertChar($a,c,$b)
	{
		var x=$a.value;
		var $e=x.substring(0,$b);
		var $f=x.substring($b,x.length);
		$a.value=$e+c+$f;
	}

	function EE_CutMask($a,k,$d)
	{
		var x=$a.value;
		if($d==0) {
			var $e=x.substring(0,k-1);
			var $f=x.substring(k,x.length);
		}
		else
		{
			var $e=x.substring(0,k);
			var $f=x.substring(k+1,x.length);
		}
		$a.value=$e+$f;
	}

	function EE_OnClick($a)
	{
		var x=EE_getSelectionStart($a);
		EE_PutCaretPos($a,x);
		EE_SetupCaretPos($a);
	}

	function EE_GetKeyCode(e)
	{
		var $g=e.keyCode?e.keyCode:e.which;
		return $g;
	}

	function EE_GetKeyString($g)
	{
		var x=String.fromCharCode($g);
		return x;
	}
	function EE_CharAtCaretPos($a,$b)
	{
		var x=$a.value.split("");
		if($b>=0&&$b<x.length) 
			return x[$b];
		else {
			return "";
		}
	}

	function EE_SetupCaretPos($a)
	{
		var x=EE_getSelectionStart($a);
		var $i=false;
		var oP=x;
		while(x<$a.value.length-1&&$i==false)
		{
			var y=EE_CharAtCaretPos($a,x);
			if (EE_IsData($a,x) || y=="_") {
				EE_PutCaretPos($a,x);
				$i=true;
			}
			x++;
		}
		if (!$i) {
			while (x>=0&&$i==false) {
				var y=EE_CharAtCaretPos($a,x);
				if (EE_IsData($a,x)||y=="_") {
					EE_PutCaretPos($a,x);
					$i=true;
				}
				x--;
			}
		}
		if (!$i) {
			if ($a.type=="text") {
				$a.style.color="rgb(255,0,0)";
				$a.value="< invalid mask >";
			}
		}
	}
	function EE_PutCaretPos($a,$b)
	{
		if($b<=0)
			$b=0;
		if($b>=$a.value.length-1)
			$b=$a.value.length-1;
		if ($a.setSelectionRange) { // FireFox
			$a.focus ();
			$a.setSelectionRange ($b, $b+1);
		}
		else if ($a.createTextRange ()) { // IE
			var r=$a.createTextRange();
			r.moveStart('character',$b);
			r.moveEnd('character',$b+1-$a.value.length);
			r.select();
		}
	}
	function EE_getSelectionStart($a)
	{ 
		if (document.selection) { // IE
			if ($a.createTextRange()) {
				$k=document.selection.createRange().duplicate();
				$k.moveEnd("character",$a.value.length);
				$b=$a.value.lastIndexOf($k.text);
				if($k.text=="")
					$b=$a.value.length;
				return $b;
			}
		}
		return $a.selectionStart;
	}
	
	function EE_getSelectionEnd ($a) 
	{
		if (document.selection) { // IE
			if ($a.createTextRange) {
				$k=document.selection.createRange ().duplicate ();
				$k.moveStart ("character",-$a.value.length);
				$b=$k.text.length;
				return $b;
			}
			return $a.selectionEnd;
		}
	}
	
	function EE_GotFocus ($a)
	{
		EE_DisplayMask ($a);
		EE_PutCaretPos($a,0); 
		EE_SetupCaretPos($a);
	}

	function EE_DisplayMask ($a)
	{
		if ($a.value=="")
			$a.value=$a.getAttribute("mask");
	}
	function EE_LostFocus ($a)
	{
		if($a.value==$a.getAttribute("mask"))
			$a.value="";
	}

// AWUiAddress Functions
	function GetCity (cell, e)
	{
		var zip = cell.firstChild;
		if (e.keyCode == 13) {
			AutoWeb.AWUiAddress.AjaxSetEntity (zip.value, "ADD_ZIP");
			var cmdLine = "AutoWeb.AWUiAddress.AjaxGetEntity('ADD_ZIP')";
			var entityWrapper	= eval (cmdLine);
			var address			= entityWrapper.value;
			if (address == null) 
				return;
			SetComboValue (zip.CityComboID,		address.City);
			SetComboValue (zip.StateComboID,	address.State);
		}
	}
	
	function SetComboValue (id, obj)
	{
		// Get the combo objects using their ids.
		var comboObj = document.getElementById (id).object;
		var savedDataSource = comboObj.GetList	().GetDatasourceUrl ();
		var tempDataSource = savedDataSource + "&JavaScriptSearch=" + obj.Name;
		comboObj.GetList	().SetDatasourceUrl		(tempDataSource);
		comboObj.GetList	().GetPage				(obj.Code, 1);
		comboObj.GetList	().SetSelectedRowIndex	(-1);
		comboObj.GetTextBox	().SetValue				(obj.Name);
		comboObj.GetList	().SetDatasourceUrl		(savedDataSource);
	}
	
	function PreventEvent (e)
	{
		// Cancel the event
		e.preventDefault? e.preventDefault() : e.returnValue = false; 
	}
	
	function CancelBubble (e)
	{
		// the current event should not bubble up the hierarchy of event handlers.
		e.stopPropagation? e.stopPropagation () : e.cancelBubble = true;
	}
	
	
// AWTimePicker Functions

	var srcElement = null;
	var incrVal = 0;
	var timeChangeTimeOut = null;	
	function HighlightInputText (oInput)
	{
		oInput.focus();
		oInput.select();
		srcElement = oInput;
	}
	function ChangeTime_OnMouseDown (uniqueID,side, maxHoures)
	{
		timeChangeTimeOut = window.setTimeout ("ChangeTime_OnMouseDown('" + uniqueID + "','" + side + "'," + maxHoures + ")",200);			
		ChangeTime (uniqueID,side,maxHoures);
	}
	function ChangeTime_OnMouseUp ()
	{
		window.clearTimeout (timeChangeTimeOut);
	}	
	function ChangeTime_KeyDown (uniqueID, maxHoures)
	{			
		if (window.event.keyCode == 37) //left arrow key
			return;	
		else if (window.event.keyCode == 38) //up arrow key
			ChangeTime (uniqueID,'up',maxHoures);
		else if (window.event.keyCode == 39) //right arrow key
			return;				
		else if (window.event.keyCode == 40) //down arrow key
			ChangeTime (uniqueID,'down',maxHoures);										
	}	
	function ChangeTime_KeyPress (oInput, e, isAmPm, maxHoures)		
	{ 
		var key;
		var keychar;

		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
		
		keychar = String.fromCharCode(key);			
		// control keys
		if ((key==null) || (key==0) || (key==8) || 	(key==9) || (key==13) || (key==27)  ) {								
			return true;			
		}
		else if (isAmPm) {									
			if (window.event.srcElement.value.length == 2)
				window.event.srcElement.value = "";	
			var tval = window.event.srcElement.value.toUpperCase();									
			if (tval.length == 0 && (keychar.toUpperCase()=="A" || keychar.toUpperCase()=="P")) {					
				return true;
			}
			else if (tval.length == 1 && (keychar.toUpperCase()=="M"))
				return true;
			else
				return false;
		}
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1)) {								
			return true;
		}
		else
			return false;						
	}	
	function ChangeTime (uniqueId, side, maxHoures)
	{
		houreControlId = uniqueId + "_m_houre";			
		if (srcElement == null)
			srcElement = document.getElementById(houreControlId);
		
		if (side == "up")
			incrVal = 1;
		else
			incrVal = -1;
							
		if (srcElement.obj == "h")
			ChangeHoure (maxHoures);
		else if (srcElement.obj == "m")
			ChangeMinute ();
		else
			ChangePmAm ()
	}
	function ChangeHoure (maxHoures)
	{
		var hour = Number (srcElement.value) + incrVal;						
		if (hour > maxHoures) {
			srcElement.value = "00";				
		}			
		else if (hour < 0) {
			srcElement.value = maxHoures;				
		}
		else {
			srcElement.value = hour;				
			if (srcElement.value.length == 1)
				srcElement.value = "0" + srcElement.value;			
		}
		HighlightInputText (srcElement);				
	}
	function ChangeMinute ()
	{
		var min = Number (srcElement.value) + incrVal;						
		if (min > 59) {
			srcElement.value = "00";				
		}			
		else if (min < 0) {
			srcElement.value = "59";				
		}
		else {
			srcElement.value = min;				
			if (srcElement.value.length == 1)
				srcElement.value = "0" + srcElement.value;			
		}
		HighlightInputText (srcElement);			
	}	
	function ChangePmAm ()
	{
		if (srcElement.value == "AM")
			srcElement.value = "PM";
		else
			srcElement.value = "AM";
				
		HighlightInputText (srcElement)
	}
	function ChangeTime_OnBlur (maxHoures)
	{
		var eventSourceObj = window.event.srcElement;
		if (eventSourceObj.obj == "h")	{
			var val = eventSourceObj.value
			if (val == "" || Number (val) > maxHoures) {
				eventSourceObj.value = "00"
				HighlightInputText (eventSourceObj)
			}	
		}
		else if (eventSourceObj.obj == "m") {
			var val = eventSourceObj.value
			if (val == "" || Number (val) > 60) {
				eventSourceObj.value = "00"
				HighlightInputText (eventSourceObj)
			}				
		}				
		else {
			var val = eventSourceObj.value.toUpperCase ()
			if ( val != "AM" && val != "PM"){
				eventSourceObj.value = "AM"
				HighlightInputText (eventSourceObj)
			}					
		}
		
		if (eventSourceObj.value.length == 1)
			eventSourceObj.value = "0" + eventSourceObj.value
	}
	function SetDefaultTime (uniqueId)
	{
		var defaultTimeObj = document.getElementById (uniqueId + "_m_default");
		SetTime (uniqueId, defaultTimeObj.value);			
	} 
	function SetTime (uniqueId, strTime)
	{
		var houresObj = document.getElementById (uniqueId + "_m_houre");
		var minutesObj = document.getElementById (uniqueId + "_m_minute");		
		var pmAmObj = document.getElementById (uniqueId + "_m_pmAm");
		
		houresObj.value = ParseHoures (strTime);		
		minutesObj.value = ParseMinutes (strTime);			
		if (pmAmObj != null)
			pmAmObj.value = ParsePmAm (strTime);
		
	}	
	function ParseHoures (strTime)
	{
		var arr = strTime.split (":");
		return arr[0];
	}
	function ParseMinutes (strTime)
	{
		var arr = strTime.split (":");
		return arr[1];		
	}
	function ParsePmAm (strTime)
	{
		var arr = strTime.split (" ");
		return arr[1];		
	}
	function TimeEnabled (uniqueId, value)
	{
		var disValue = "disabled"
		if (value == true)
			disValue = "";
		var houresObj       = document.getElementById (uniqueId + "_m_houre");
		var minutesObj      = document.getElementById (uniqueId + "_m_minute");		
		var pmAmObj         = document.getElementById (uniqueId + "_m_pmAm");		
		var imgUp           = document.getElementById (uniqueId + "_m_imgUp");		
		var imgDown         = document.getElementById (uniqueId + "_m_imgDown");						
		houresObj.disabled  = disValue;
		minutesObj.disabled = disValue;
		if (pmAmObj != null)
			pmAmObj.disabled    = disValue;		
		imgUp.disabled      = disValue;
		imgDown.disabled    = disValue;		
	}
	function GetHoureObjId (objUniqueId)
	{
		return objUniqueId + "_m_houre";
	}	
	function GetMinuteObjId (objUniqueId)
	{
		return objUniqueId + "_m_minute";
	}		

	
// Date Time Ranger
function CalcDateDiff (rangerUniqeId, dateId1, dateId2)
{
	var date1 = document.getElementById (dateId1).value;
	var date2 = document.getElementById (dateId2).value;
	var ret = AutoWeb.AWDateTimeRanger.DateDiff (date1,date2);
	
	var rangerId      = rangerUniqeId.replace (":","_");
	var daysDiffId	  = rangerId + "_m_daysDiff";
	
	document.getElementById (daysDiffId).value = ret.value;	
}	
function CalcTimeDiff (rangerUniqeId, objUniqueId1, objUniqueId2)
{
	var fixedId1 = objUniqueId1.replace(":","_");		
	var houres1  = document.getElementById ( GetHoureObjId  (fixedId1) ).value;	
	var minutes1 = document.getElementById ( GetMinuteObjId (fixedId1) ).value;
	
	var fixedId2 = objUniqueId2.replace(":","_");
	var houres2  = document.getElementById ( GetHoureObjId  (fixedId2) ).value;
	var minutes2 = document.getElementById ( GetMinuteObjId (fixedId2) ).value;	
	
	var rangerId      = rangerUniqeId.replace (":","_");
	var houresDiffId  = rangerId + "_m_houresDiff";
	var minutesDiffId = rangerId + "_m_minutesDiff";	
	
	document.getElementById (houresDiffId).value  = Number(houres2)  - Number(houres1);
	document.getElementById (minutesDiffId).value = Number(minutes2) - Number(minutes1);
}