var temp1,temp2;
var jumped = false;
var w_global = null;


/***************************************************************************
Added for MedTox
***************************************************************************/
function callback(res)
{   
    processAjaxResponse(res.value);
}

function EmailSignupSubmit()
{
    var errstr;
    errstr = "";
    var em = "EmailSignup_Email";
    
    if (CheckRequiredTextField(em) == false)
        errstr = "*** Please Enter Your Email Address\n\r";
    else if(ValidateEmail(em) == false)
        errstr = "*** Please Enter a Valid Email Address\n\r";
    
    if(errstr != "")
    {
        errstr = "Errors were found.  Correct the errors and click Submit.\n\r" + errstr;
        ShowErrorPopup(errstr);
        return false;
    }

    var x = GetFormData(0);
    AJAX.API.AjaxEvent(isBluebox(), '', 'EmailSignupEvent', x, "", callback);//, callback);    
    return false;
}

function CheckRequiredTextField(id)
{
    var o = MM_findObj(id)
    if (o)
    {
        if (o.value==null || o.value == "")
            return false;
    } 
    return true;    
}

function ValidateEmail(id)
{
    var o = MM_findObj("EmailSignup_Email");
    var str = o.value
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1){
       return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        return false;
    }

     if (str.indexOf(at,(lat+1))!=-1){
        return false;
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false;
     }

     if (str.indexOf(dot,(lat+2))==-1){
        return false;
     }

     if (str.indexOf(" ")!=-1){
        return false;
     }

     return true;
}

function setObjectClass(ob, cl)
{
    var o=MM_findObj(ob);
    if(o) o.className=cl;
}

//used for the test catalog screen
function ShowDivTab(tabDiv)
{
    HideAllTabDivs();
    setVis(tabDiv, true);
    
    //set the value of the hidden field
    var o = document.getElementById('selectedTab')
    if (o)
        o.value = tabDiv;
}

function HideAllTabDivs()
{
    setVis('divTestName', false);
    setVis('divKeyword', false);
    setVis('divCategory', false);
}

function setVis(id, vis, displayNone) {
    if (id != '') {
        if (displayNone == undefined || (displayNone != true && displayNone != false)) {
            displayNone = true;
        }
	    obj = MM_findObj(id);
	    if (obj == undefined) {
	        return;
	    }
	    if(document.getElementById || document.all){//all the modern browsers
		    obj.style.visibility = vis ? "visible" : "hidden";
		    if (displayNone) {
		        obj.style.display = vis ? "block" : "none";
		    }
	    }
	    else if(document.layers){//this is NS4
		    obj.visibility = vis ? "show" : "hide";
		    if (displayNone) {
    		    obj.display = vis ? "block" : "hide";
            }
	    }  
	}
}

function SetCurrent(i)
{
    if(i == 'aTabTestName')
    {
        if (document.getElementById('aTabTestName'))
            document.getElementById('aTabTestName').className = "tab_on";
        if (document.getElementById('aTabKeyword'))
            document.getElementById('aTabKeyword').className = 'tab_off';
        if (document.getElementById('aTabCategory'))
            document.getElementById('aTabCategory').className = 'tab_off';
    }
    else if (i == 'aTabKeyword')
    {
        if (document.getElementById('aTabTestName'))
            document.getElementById('aTabTestName').className = 'tab_off';
        if (document.getElementById('aTabKeyword'))
            document.getElementById('aTabKeyword').className = 'tab_on';
        if (document.getElementById('aTabCategory'))
            document.getElementById('aTabCategory').className = 'tab_off';
    }
    else if (i == 'aTabCategory')
    {
        if (document.getElementById('aTabTestName'))
            document.getElementById('aTabTestName').className = 'tab_off';
        if (document.getElementById('aTabKeyword'))
            document.getElementById('aTabKeyword').className = 'tab_off';
        if (document.getElementById('aTabCategory'))
            document.getElementById('aTabCategory').className = 'tab_on';
    }
}


function TestNameSearch(obj, ord)
{
    if (ord == null)
        ord = '';
    
    AJAX.API.TestCatalogAlphaSearch(obj.id, ord, TestCatalogSearch_Callback);
}
function TestCatalogSearch_Callback(response)
{
    if (response.error)
    {
        alert(response.error.Message);
    }
    else
    {
        var divSR = Ext.get("divSearchResults");
        var a = Ext.DomQuery.selectNode('data', response.value);
        divSR.update(a.firstChild.nodeValue);
    }  
}

function ResetAnchorClass()
{
    
    var o = document.getElementById('Letters');
    if(o)
    {
        var c = o.childNodes;

        for(var i = 0; i < c.length; i++)
        {
            if (c[i].id != null)
            {
                var x = document.getElementById(c[i].id)
                if (x)
                    x.className = "";
            }
        }
    }     
}

function SetClass(obj, c)
{
    obj.className = c;
}

function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}

function searchTestKeyUp(evt){
    // If it’s Mozilla/FF use evt; else use window.event
    evt = evt ? evt : event;

    var keyCode = evt.keyCode;

    // figure out which key code goes with which key
    // alert(evt.keyCode);

    if(keyCode == 13){
        // do this if it IS the enter key
        KeywordTestCodeSearch();
    }
}

function KeywordTestCodeSearch(ord, queryStringVal){
    var isTCSearch;
    isTCSearch = false;
    
    var o = document.getElementById('rdoTestCode');
    if (o){
        if (o.checked){
            isTCSearch = true;
            var t = document.getElementById('txtKeyword');
            if(!IsNumeric(t.value)){
                alert("TestCode must be a number.");
                return false;
            } 
        }
    }
    
    var k = document.getElementById('txtKeyword').value;
        
    if (isTCSearch == true)
    {
        if (queryStringVal != null && queryStringVal != "")
            AJAX.API.TestCatalogTestCodeSearch(k, ord, true, TestCatalogSearch_Callback);
        else
            AJAX.API.TestCatalogTestCodeSearch(k, ord, false, TestCatalogSearch_Callback);
    }
    else
    {
        AJAX.API.TestCatalogKeywordSearch(k, ord, TestCatalogSearch_Callback);
    }
}

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 CategoryChange(obj, ord)
{
    if (obj.value == -1)
        return;
 
    AJAX.API.TestCatalogCategorySearch(obj.value, ord, TestCatalogSearch_Callback);
}

function SelectAll(ob)
{
ob.focus();
ob.select();
}

function SortData(ord)
{
    var o = document.getElementById('selectedTab');
    if (o)
    {
        if (o.value == "divTestName")
        {
            var l = document.getElementById('selectedAlphaSearch');
            if (l)
            {
                var a = document.getElementById(l.value);
                TestNameSearch(a, ord);
            }
            
        }
        else if (o.value == "divKeyword")
        {
            KeywordTestCodeSearch(ord);
        }
        else if (o.value == "divCategory")
        {
            var c = document.getElementById('categoryDDLID');
            if (c)
            {
                var d = document.getElementById(c.value);
                if (d)
                {
                    CategoryChange(d, ord);
                }
            }
        }
     }
}

function SetHiddenField(a)
{

    var o = document.getElementById('selectedAlphaSearch');
    if (o)
        o.value = a.id
}
/***************************************************************************
END - Added for MedTox
***************************************************************************/


/* Given a comma-separated list of checkbox names, sets each of these
   to be "checked" if it exists.

--pok 01/10/04
*/
function MM_checkMultiple(checkboxes) {
  var arr_check = checkboxes.split(',');
  for(var i = 0; i < arr_check.length; i++) {
    var check = MM_findObj(arr_check[i]);
    if(check) {
      check.checked = true;
    }
  }
}

/* Creates a Unique number per call on one client browser.
	DOES NOT CREATE A SERVER-SCOPED UNIQUE KEY! */
function createUUID() {
	var l_dDate = new Date();
	var l_nUUID = l_dDate.getTime().toString();
	return l_nUUID;
}

/* (reloads) the current page in window (win) without the query string (adds a UUID to make browser refresh) */
function cleanReload(win) {
	var myurl = getUrl(win, 1) + "?null=" + createUUID();
	win.document.location.replace(myurl);
}
/* (reloads) the current page in window (win) with the query string (adds a UUID to make browser refresh) */
function urlReload(win) {
	var myurl = win.document.location.href;
	myurl = (myurl.indexOf("?") >= 0) ? myurl + "&" : myurl + "?";
	myurl = myurl + "null=" + createUUID();
	win.document.location.replace(myurl);
}



/* gets the document url (minus query string if (clean)) */
function getUrl(win, clean) {
  var myurl = win.document.location.href;
  if (clean) {
    var loc = myurl.indexOf("?");
    if (loc > 0) {
      myurl = myurl.substring(0,loc);
    }
  }
  return myurl;
}

/* (load new url)  */
function urlLoad(new_href) {
	var myurl = new_href;
	myurl = (myurl.indexOf("?") >= 0) ? myurl + "&" : myurl + "?";
	myurl = myurl + "null=" + createUUID();
	window.document.location.replace(myurl);
}

/* adds junk */

/* RTRIM() -removes ending spaces */
function rtrim(str) {
	if (str.length) {
		var cutLoc, i, stop;
		i = str.length;
		stop = 0;
		do {
			if (str.charAt(i-1) == " ") {
				i--;
			} else {
				stop = 1;
			}
		} while (stop == 0 && i > 0)
		if (i < (str.length)) {
			str = str.substring(0,i);
		}
	}
	return str;
}

/* LTRIM() -removes leading spaces */
function ltrim(str) {
	if (str.length) {
		var cutLoc, i, stop;
		i = 0;
		stop = 0;
		do {
			if (str.charAt(i) == " ") {
				i++;
			} else {
				stop = 1;
			}
		} while (stop == 0 && i < str.length)
		if (i > 0) {
			str = str.substring(i,str.length);
		}
	}
	return str;
}

/* TRIM() leading and ending spaces */
function trim(str) {
	if (str.length) {
		str = rtrim(str);
	}
	if (str.length) {
		str = ltrim(str);
	}
	return str;
}

/* Function to swap a font tag's font class */
function NC_swapClass(textID,myClass) {
	obj=MM_findObj(textID);
	if (obj) obj.className=myClass;
}

/* Function to find a document object */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/* Functions that swap layers - used only in product nav menu */
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Function that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v3.0
  var ok=false; document.MM_returnValue = false;
  with (navigator) if (appName.indexOf('Microsoft')==-1) ok=(plugins && plugins[plgIn]);
  else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
    if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
    else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
    else ok=autoGo; }
  if (!ok) theURL=altURL; if (theURL) window.location=theURL;
}

function popNew(loc,name,width,height) {
	pop = window.open(loc,name,'scrollbars,status,resizable,width=' + width + ',height=' + height);
	pop.focus();
}

function popMenu(loc,name,width,height) {
	pop = window.open(loc,name,'scrollbars,menubar,status,resizable,width=' + width + ',height=' + height);
	pop.focus();
}

function popNewResize(loc,name,width,height) {
	pop = window.open(loc,name,'scrollbars,status,resizable,width=' + width + ',height=' + height);
	pop.focus();
}

function popRestricted(loc,name,width,height) {
	pop = window.open(loc,name,'scrollbars,status,width=' + width + ',height=' + height);
	pop.focus();
}

function popNewNoChrome(loc,name,width,height) {
	pop = window.open(loc,name,'width=' + width + ',height=' + height);
	pop.focus();
}

function popReal(loc,name,width,height) {
	pop = window.open(loc,name,'scrollbars,status,toolbar,menubar,directories,location,resizable,width=' + width + ',height=' + height);
	pop.focus();
}
function openWindow (f_name, s_title, s_attrib) {
	w_global = window.open(f_name, s_title, s_attrib);
}

/* checks if text in a form field is a possible email address */
/*   x@x.xx  minimum  */
/*   usage: if (isemail('txt_username','Email not valid!')) submitForm('frm_login');  */
/* djh 2/7/01 added ',atloc' to the 4th line to fix bug with '.' before @ */
function isemail(field,message) {
	var obj=MM_findObj(field);
	var val=obj.value;
	var atloc=val.indexOf('@');
	var dotloc=val.indexOf('.',atloc);
	if ((atloc > 1) && (dotloc > atloc+1) && (val.length > dotloc+2)) {
		var bob=true;
	} else {
		alert(message);
		var bob=false;
	}
	return bob;
}

/* used to submit forms easily within divs, or from within other forms */
//v3.0
function submitForm(frm) { 
	var obj = MM_findObj(frm);
	obj.submit();
}


function submitFormCheck(form) {
	var obj = MM_findObj(form);
	var frmname = "_CF_check" + form + "(obj)";
	var success = eval(frmname);
	if (success) {
		obj.submit();
	}
	//return success;
}

/* used to ensure a combo's value is not "" */
function verifyCombo(form,cbo,message) {
	obj=MM_findObj(form);
	obj=eval('obj.'+cbo);
	var index=obj.selectedIndex;
	var val=obj.options[index].value;
	if (val == "") {
		if (message != "")
			alert(message);
		return false;
	} else {
		return true;
	}
}
/* used to jump to url specified in combo's selected VALUE */
function jumpToCombo(form,cbo,addnull) {
	if (addnull == null) addnull = 1;
	obj=MM_findObj(form);
	obj=eval('obj.'+cbo);
	var index=obj.selectedIndex;
	var val = obj.options[index].value;
	if (addnull)
		val +=  ((val.indexOf("?") >= 0) ? "&null="+createUUID() : "?null="+createUUID());
	if (val != "") {
		document.location.href=val;
	}
}

/* used to verify a user's request before connecting a link */
function verifyLink(message,myurl) {
	if (confirm(message)) {
		myurl += (myurl.indexOf('?') >= 0) ? "&null="+createUUID() : "?null="+createUUID();
		document.location.href=myurl;
	}
}

// djh 11/21/00
// This popup window will upload images to the server
// the set the parent text boxes to the correct value
//
function popUpload(p_ccaption, p_ctextname, p_noid, p_cpath) {
	popNew("uploadpop.cfm?caption=" + p_ccaption + "&textname=" + p_ctextname + "&oid=" + p_noid + "&path=" + p_cpath,"uploadwindow","270","190");
}

//  Function to open a new window and place focus there.
// If the window is already opened focus will be placed.
var newWindow
function openWebTopWindow(URL, winName, chrome) {
	if (!newWindow || newWindow.closed) {
		newWindow = window.open(URL,winName,chrome)
		if (!newWindow.opener) {
			newWindow.opener = window
		}
	} else {
		// window's already open; bring to front
		newWindow.location = URL;
		newWindow.focus();
	}
}

//populate combo from object
function populateSelectFromObject(cbo,obj,selData,defSelection) {
	// clears a select form object, and populates it using the passed data
	cbo.length = 0;
	if(defSelection && defSelection.length > 0) {
		var tmpOpt = new Option;
		tmpOpt.value = "";
		tmpOpt.text = defSelection;
		if ("" == selData) tmpOpt.selected = true;
		cbo.length++;
		cbo.options[cbo.length-1] = tmpOpt;
	}
	for (a in obj) {
		var tmpOpt = new Option;
		tmpOpt.value = a;
		tmpOpt.text = obj[a];
		if (a == selData) tmpOpt.selected = true;
		cbo.length++;
		cbo.options[cbo.length-1] = tmpOpt;
	}
}

var newWindow
function openCMAPWindow(URL, winName, chrome) {
	if (!newWindow || newWindow.closed) {
		newWindow = window.open(URL,winName,chrome)
		if (!newWindow.opener) {
			newWindow.opener = window
		}
	} else {
		// window's already open; bring to front
		newWindow.location = URL;
		newWindow.focus();
	}
}
//function used for Store Locator's dropdown navigation
function goPage(form){
	//alert(form);
	window.location.href = form;
}

 


function checkEnter(event, myform)
{ 	
	var frm = MM_findObj(myform);
	if(frm != null) {
		var NS4 = (document.layers) ? true : false;
		var code = 0;
		
		if (NS4)
			code = event.which;
		else
			code = event.keyCode;
		if (code==13) {
			frm.submit();
		}
	}
}



/*
 * Set the radio option with value 'val' of group 'group' to be checked.
 * --pok 01/02/04
 */

function MM_selectRadio(radiofield, val) {
	var field = MM_findObj(radiofield);
	if(field != null) {
		for(var i=0; i<field.length; i++) {
			if(field[i].value == val) {
				field[i].checked = true;
			}
		}
	}
}

 /*
 * Clear the named field to an empty string, if it exists.
 * --pok 01/02/04
 */
function MM_clearField(fieldName) {
  var field = MM_findObj(fieldName);
  if(field != null) {
    field.value = '';
  }
}
 /*
 * Clear the named field to an empty string, if it exists and if the checked FIELD is turned off.
 * --eo 01/06/04
 */
function MM_clearFieldOnCheckOff(clearField, checkField, val) {
  var clearfield = MM_findObj(clearField);
  var checkfield = MM_findObj(checkField);
  
  if(clearfield != null) {
  	for(var i=0; i<checkfield.length; i++) {
		if(checkfield[i].value == val && checkfield[i].checked) {
		//alert(checkfield[i].value);
		//	checkfield[i].checked = true;
		}
	}
  
    clearfield.value = '';
  }
}
 

/*
 * Focus the named field, if it exists.
 * --pok 01/02/04
 */
function MM_focusField(fieldName) {
  var field = MM_findObj(fieldName);
  if(field != null) {
    field.focus();
  }
}

///
/// Replace the string specified in the from variable with the variable in the 
/// to parameter.
///
function strReplace(src, from, to) 
{
	if (from == "")
		return src;

	return _strReplace(src, from, to);
}

// helper function - don't call directly
function _strReplace(src, from, to)
{
	var i = src.indexOf(from);
	if (i == -1) return src;

	var r = "";
	r += src.substring(0,i) + to;
	if(i + from.length < src.length)
		r += _strReplace(src.substring(i + from.length, src.length), from, to);
	return r;
}


function ShowMessage(msg)
{
	msg = strReplace(msg, "<br>", "\n");
	alert(msg)
}

function ShowErrorPopup(msg)
{
	ShowMessage(msg);
}


function CloseForm()
{
	window.close();
    return false;
}

function GetElementById(id)
{
	if(typeof(id) == "object")
		return id;
		
	return MM_findObj(id);
}


function GetElementName(el)
{
	var sReturn = '';
	
	if(typeof(el.id)=='string')
		sReturn = el.id;

	if (el.type == "radio"  || (sReturn.length==0 && typeof(el.name)=='string'))
		sReturn = el.name;

	return sReturn;
}

/// <summary>
/// </summary>
function GetElementData(el)
{

	if(typeof(el) == "string")
		el = GetElementById(el);

	if(!el)
		return null;
		
	var sReturn = null;
	switch(el.type)
	{
		case 'radio':
			sReturn = '0';
			if(el.checked)
				sReturn = el.value;
			break;

		case 'checkbox':
			sReturn = '0';
			if (el.checked)
			{
				sReturn = '1';
				
				// FIX: Check to see if a value exists for each checkbox.
				// If not 0 or blank, then return the value instead of "1"
				// for items checked.
				if(el.value && el.value != "0" && el.value != "")
					sReturn = el.value;
			}
			break;
			
		case 'text':
		case 'textarea':
		case 'password':
		case 'hidden':
		case 'select-one':
			sReturn = el.value;
			break;
		case 'select-multiple':
			var aReturn = new Array();
			var elLen = el.length;
			var opt = el.options;
			for (i=0;i<elLen;i++)
			{
				if (opt[i].selected)
				{
					aReturn.push(opt[i].value + ',');
				}
			}
			
			sReturn = aReturn.join('');
			if (sReturn!=null && sReturn.charAt(sReturn.length-1)==',')
				sReturn = sReturn.substr(0, sReturn.length-1);
			break;
	}
	
	if (typeof(sReturn)=='undefined')
		return null;

	return escape(sReturn).replace(/\+/g,'%2B');
}


/**********************************************************************************************************
 <summary>
	GetFormData function returns data so that it can be posted via AJAX. Data posted via AJAX can
	be accessed from the Request.Form object on the server just like you normally would.
 </summary>

 <returns>string formatted call to AJAX API (name=value&name=value)</returns>
*********************************************************************************************************/
function GetFormData(formnum)
{
	var sReturn='';
	var objName='';
	var objValue='';
	var el;
	var i;
	var s;
	
	if(!formnum || typeof(formnum)=="undefined")
		formnum = 0;
		
	var elBase=document.forms[formnum].elements;
	var elLen =elBase.length;	
	var aReturn =new Array();
	 
	try
	{
	aReturn.push('<root>');
		for(i=0;i<elLen;i++)
		{
			el = elBase[i];		
			
			objName = GetElementName(el);	
			objValue = '';
			

			//exclude all .NET native controls, buttons and images
			if (objName.length>0 
					&& objName!='__VIEWSTATE' && objName!='__EVENTTARGET' && objName!='__EVENTARGUMENT' && objName!='\r\n__VIEWSTATE'
					&& el.type!='submit' && el.type!='reset' && el.type!='image' && el.type!='button')
			{
				if(el.type == 'radio' && el.checked == false)
					continue;

				// Exclude disabled controls, to be consistent with standard HTML form posts and to
				// eliminate data for controls that aren't likely needed.
				if (el.isDisabled)  // Note: isDisabled will be true if the control or a parent element is disabled
					continue;

				objValue = GetElementData(el);

                // <v id="idval">asdfasdfasdf</v>
				aReturn.push('<v id="' + objName + '">' + objValue + '</v>'); 
			}
		}
			aReturn.push('</root>');

	}catch(e){alert('Error Getting Form Data:' + e.message);} 

	sReturn = aReturn.join('');

	if (sReturn.charAt(sReturn.length-1)=='&')
		sReturn = sReturn.substr(0, sReturn.length-1);
	
	return sReturn;
}



function ajaxCallback(res)
{   
    processAjaxResponse(res.value);
}


/*
<APAjax>
<Obj name='jscall'>setVisible('fldid')</Obj>
<Obj name='jsfile'>filename.js</Obj>
<Obj name="rightNavID" type="value">new value</Obj>
<Obj name="rightNavID" type="obj"><!CData[<table><tr><td>hello</td></tr></table>]</Obj>
</APAjax>


_name = _nodes[i].getAttribute('name');
_type = _nodes[i].getAttribute('type');
_value = _nodes[i].text;
*/

function processAjaxResponse(xml)	// xml should be a XML Dom object
{
    var _node;
	var _nodes;
	var _rootnodename = 'APAjax/Obj';
	var _name = '';
	var _type = '';
	var _value = '';
	var _obj;
	var _errmsg = '';
	var _infomsg = '';

	_nodes = Ext.DomQuery.select('APAjax/Obj', xml)

	for(var i = 0; i < _nodes.length; i++)
	{
	    _node = _nodes[i];
	    
		_name = _node.getAttribute('id');
		_value = ''
		
		var l = _node.childNodes.length;
		for(var x=0; x < l; )
		{
		    _value += _node.childNodes[x].nodeValue;
		    ++x;
		}
		    
		switch(_name)
		{
			case "jscall":
				try
				{
					eval(_value);
				}
				catch(e)
				{
					if(_errmsg != "")
						_errmsg += "<br/>";
					_errmsg += 'Error executing script: ' + _value + '\n' + e.message;
				}
				break;


			case "jsfile":
				try
				{
					_obj = document.createElement('script');
					_obj.type = 'text/javascript';
					_obj.src = _value;
					document.body.appendChild(_obj);
				}
				catch(e)
				{
					if(_errmsg != "")
						_errmsg += "<br/>";
					_errmsg += 'Error registering javascript file: ' + _value + '\n' + e.message;
				}
				break;


			case "showerror":
				if(_errmsg != "")
					_errmsg += "<br/>";
				_errmsg += _value;
				break;

			case "showmsg":
				if(_infomsg != "")
					_infomsg += "<br/>";
				_infomsg += _value;
				break;

			case "close":
				try
				{
					if (_infomsg != "")
					{
						ShowMessage(_infomsg);
						_infomsg = "";
					}
					CloseForm();
				}
				catch(e){}

				break;

			default:
				try
				{
					_type = _nodes[i].getAttribute('type');

					_obj = MM_findObj(_name);
					
					if (_obj && _type=='val')
					{
						_obj.value = _value;
					}
					else if (_obj && _type=='obj')
					{
						if (!_value)  _value = '';
						    
					    if(setOuterHTML(_obj, _value) == false)
					    {
							setInnerHTML(_obj, _value);
						}
					}
				}
				catch(e)
				{
					if(_errmsg != "")
						_errmsg += "<br>";
					_errmsg += 'Error setting/replacing: ' + _name + '\nwith: ' + _value + '\n' + e.message;
				}
				break;
		}
	}

	if(_errmsg != "")  ShowErrorPopup(_errmsg);

	if (_infomsg != "")  ShowMessage(_infomsg);
}


function parseBool(str)
{
	if(!str)
		return null;
		
	switch(str)
	{
		case "0":
		case "false":
			return false;
		default:
			return true;
	}
	return true;
}

function SetElementValue(id, val)
{
	var obj, retValue;
	if(typeof(id) == "object")
		obj = id;
	else
		obj = MM_findObj(id);

	if(!obj)
		return false;
		
	if (obj.tagName == 'SPAN' || obj.tagName == 'LABEL')
		obj.value = val;
	else if(obj.type == 'radio' || obj.type=="checkbox" )
		obj.checked = parseBool(val);
    else if (obj.length > 0 && obj[0].type == "radio")
    {
        for (var n=0; n< obj.length; n++)
        {
            if (obj[n].value == val)
            {
                obj[n].checked = true;
                break;
            }
        }
    }
	else if (obj.tagName != "SELECT")
		obj.value = val;
	else 
	{
		val = ('' + val).toLowerCase();  // handle numeric values in null along with strings.
		obj.selectedIndex = -1;

		var optLen = obj.options.length; 
		for (var n=0; n < optLen; n++) 
		{ 
			var opt = obj.options[n];
			if (opt.value.toLowerCase()==val || opt.text.toLowerCase()==val)
			{ 
				obj.selectedIndex = n; 
				break;
			}

		}
	}
	return true;
}


function isBluebox()
 {
    var str = 0;
    
    try {
    var query = window.location.search.substring(1);
    
    if(query != null && query.toLowerCase().indexOf("gentype=bluebox") >= 0)
        str = 1;    
    } catch(e) { 
        //alert("Error: " + e.message);
    }
    
    return str;
}

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}


function setOuterHTML(obj, str) 
{

    try
    {
        if(obj.outerHTML != undefined)
        {
            obj.outerHTML = str;
        }
        else
        {
            var r = obj.ownerDocument.createRange();
            r.setStartBefore(obj);
            var df = r.createContextualFragment(str);
            obj.parentNode.replaceChild(df, obj);
	    }
    } catch(ex) {return false;}
    	
	return true;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


