function calcKey(ctext)
{
	len=0;
	ctextlen=ctext.length;
	for(i=0; i<ctextlen; i++) len+=ctext.charCodeAt(i);

	while(len > 1000) {
		len = len % 1000;
	}
	if(len > 721) {
		len = len - 328;
	}
	return len;
}

function decrypt(text, key)
{
	var j=3;
	var temp1;
	var res="";
	len=calcKey(key.toString());
	if(len>0)
	{
		var dtxtlen=text.length;
		if(dtxtlen>0)
		{
			for(i=0; i<dtxtlen; i+=3)
			{
				var temp=text.substring(i,j);
				temp1=(parseInt(temp, 10)-len);
				var t=unescape('%'+temp1.toString(16));

				if(t=='%d' || t=='%a') res=res+' ';
				else res=res+t;
				j+=3;
			}
		}
	}
	return res;
}

function setAndLaunchAppendQuery(keyValue, keyType)
{

	var doc = document;
	var tbxKeyValue = getField2( "tbxKeyValue", doc );
	var ddlKeyType = getField2( "ddlQueryKey", doc );
	var txtStartDate = getField2( "TextboxStartDate", doc );
	var txtEndDate = getField2( "TextboxEndDate", doc );
	var txtProductCode = getField2( "TextboxProductCode", doc );
	if( tbxKeyValue != null && keyValue != null && ddlKeyType != null && keyType != null )
	{		
		selectListBoxObjectByValue( ddlKeyType, keyType );
		tbxKeyValue.value = keyValue;
		if (txtStartDate != null)
		    txtStartDate.value = "";
		if (txtEndDate != null)
		    txtEndDate.value = "";
		if (txtProductCode != null)
		    txtProductCode.value = "";
		doQuery(false);
    }
    scroll(0, 0);
}

function setAndLaunchAppendQuery2(keyType, key)
{
    var doc = document;
	var tbxKeyValue = getField2( "tbxKeyValue", doc );
	var ddlKeyType = getField2( "ddlQueryKey", doc );
	var txtStartDate = getField2( "TextboxStartDate", doc );
	var txtEndDate = getField2( "TextboxEndDate", doc );
	var txtProductCode = getField2( "TextboxProductCode", doc );
	if (ddlKeyType != null && keyType != null && tbxKeyValue != null && key != null)
	{		
		selectListBoxObjectByValue( ddlKeyType, keyType );
		tbxKeyValue.value = key;
		if (txtStartDate != null)
		    txtStartDate.value = "";
		if (txtEndDate != null)
		    txtEndDate.value = "";
	    txtProductCode.value = "";
		doQuery(false);
	}
}

function setAndLaunchAppendQueryAndClrTabs(keyValue, keyType) {

    var doc = document;
    var tbxKeyValue = getField2("tbxKeyValue", doc);
    var ddlKeyType = getField2("ddlQueryKey", doc);
    var txtStartDate = getField2("TextboxStartDate", doc);
    var txtEndDate = getField2("TextboxEndDate", doc);
    var txtProductCode = getField2("TextboxProductCode", doc);
    if (tbxKeyValue != null && keyValue != null && ddlKeyType != null && keyType != null) {
        selectListBoxObjectByValue(ddlKeyType, keyType);
        tbxKeyValue.value = keyValue;
        if (txtStartDate != null)
            txtStartDate.value = "";
        if (txtEndDate != null)
            txtEndDate.value = "";
        if (txtProductCode != null)
            txtProductCode.value = "";
        doQuery(true);
    }
    scroll(0, 0);
}

function launchDamageHeldWindow( webServiceName, wareHouseId, customerId, code, statusId)
{
	args = "webserviceName="+webServiceName + "&wareHouseId="+wareHouseId + "&customerId="+customerId + "&code="+code+
			"&statusId="+statusId;
	//alert(args);
	GoStockOnHandHeldDetails( args );	
}

function openNotifyWindow(WebServiceID, Version, KeyType, KeyValue, WebServiceCustomerID) {
	var data = "WSID=" + WebServiceID + "&V=" + Version + "&KT=" + KeyType + "&KV=" + KeyValue + "&WSCID=" + WebServiceCustomerID;
	sub = window.open("NotificationNew.aspx?" + data, "notify_" + WebServiceID, "height=264,width=374,resizable=no;channelmode=no,location=no,status=no,menubar=no,toolbar=no", true);
	window.setTimeout(waitone, 1000);
}

function openNotifyWindowLogistics(WebServiceID, Version, KeyType, KeyValue, WebServiceCustomerID, WarehouseID) {
	var data = "WSID=" + WebServiceID + "&V=" + Version + "&KT=" + KeyType + "&KV=" + KeyValue + "&WSCID=" + WebServiceCustomerID + "&WHID=" + WarehouseID;
	sub = window.open("NotificationNew.aspx?" + data, "notify_" + WebServiceID, "height=264,width=374,resizable=no;channelmode=no,location=no,status=no,menubar=no,toolbar=no", true);
	window.setTimeout(waitone, 1000);
}

function waitone() 
{
	if(sub == null) 
	{
		return;
	}
	if(sub.closed) 
	{
		sub = null;
		// need to find if the tab is open
		var intIndex = m_tabStrip.getTabIndexFromLabel("My Notifications");
		if (intIndex != -1)
		{
			var w = document.getElementById("framenotifications").contentWindow;
			w.navigate(w.location);	
		}
		return;
	}
	window.setTimeout(waitone, 1000);
}

function resizeParentFrame()
{
//	try {
//		if(!parent) {
//			return;
//		}
//		var i, f;
//		f = parent.document;
//		if(!f) {
//			return;
//		}
//		f = f.frames;
//		if(!f) {
//			return;
//		}
//		var loc = document.location;
//		var b = document.body;
//		for(i = 0;i < f.length;i++) {
//			if(f[i].location == loc) {
//				var h = b.scrollHeight;
//				if( h < 10) {
//					h = b.clientHeight;
//				}
//				if( h < 10) {
//					h = b.style.height;
//				}
//				if( h > 50) {
//					f[i].frameElement.height = (h + 25);
//				} else {
//					if(f[i].frameElement.height < 50) {
//						f[i].frameElement.height = 50;
//					}
//				}
//				return;
//			}
//		}
//	} catch(ex) {
//	}
}
function DBG( msg )
{
//	alert( msg );
//	window.status = msg;
}

function DBGX( msg )
{
//	alert( msg );
//	window.status = msg;
}

function validISOContainer(id )
{
	var obj = getField( id );
	if (obj)
	{
		var c, cc, s, i, t, total;
		var codeA = 'A'.charCodeAt(0);
		var codeZ = 'Z'.charCodeAt(0);
		var code0 = '0'.charCodeAt(0);
		var code9 = '9'.charCodeAt(0);

		s = new String(obj.value);
		total = 0;

		if (s.length < 9 || s.length > 11)
		{
			alert("warning, ISO standard container numbers are 4 letters and 7 numerals");
			return false;
		}	 

		for (i = 0; i < s.length; i++)
		{
			// capital alpha and number only
			c = s.charAt(i);
			cc = s.charCodeAt(i);
			if (!(cc >= code0 &&  cc <= code9) && !(cc >= codeA &&  cc <= codeZ))
			{
				alert("invalid character in container number");
				return false;
			}
			
			if (i < s.length - 1)
			{
				if (i < 4)
				{
					if (cc < codeA ||  cc > codeZ)
					{
						alert("warning, ISO standard container numbers are 4 letters and 7 numerals");
						return false;
					}

					t = cc - 55;
					
					if (t >= 33)
					{
						t += 3;
					}
					else if(t >= 22)
					{
						t += 2;
					}
					else if(t >= 11)
					{
						t += 1;
					}

					total += (t * (Math.pow(2, i)));
				}
				else
				{
					if (cc < code0 ||  cc > code9)
					{
						alert("warning, ISO standard container numbers are 4 letters and 7 numerals");
						return false;
					}
					total += (c * (Math.pow(2, i)));
				}
			}  
		}

		if (c != ((total % 11) % 10))
		{
			alert("warning, this container number has a invalid check digit");
			return false;
		}

	}

	return true;
}

function CapitaliseText( txt )
{
	var tmp = new String( txt.toLowerCase() );
	var ret = new String();
		
	var makeUpper = false;
	var i = 0;
	var len = tmp.length;
	var ch;
	var chPrev;
	
	for (i=0; i<len; i++)
	{
		ch = tmp.charAt(i);
		
		if ( i == 0 )
		{
			ch = ch.toUpperCase();
		}
		else
		{
			chPrev = tmp.charAt(i-1);
			
			if ( chPrev.match( " " ) )
				ch = ch.toUpperCase();
		}

		ret += ch;
	}
	
	return ret;
}

function showError( msg, title )
{
	if (title)
		window.alert( title + "\n" + msg );
	else
		window.alert( "common.js:showError: " + msg );

	window.status = msg;
}

function resetFrameset( framesetURL )
{
	// make sure we load the frameset at the Top
	DBG( 'resetFrameset( "' + framesetURL + '")' );

	var currentURL = document.location.href;
	var theTop = window.top;

	if ( theTop )
	{
		if ( theTop.location.href != currentURL )
		{
			if ( framesetURL )
			{
				DBG( "Load the frameset url ('" + framesetURL + "') into the top window" );
				theTop.document.location.href = framesetURL;
			}
			else
			{
				DBG( "Load default.aspx into the top window" );
				theTop.document.location.href = "default.aspx";
			}
		}
	}

	return true;
} // resetFrameset

function gotoURL( url, target )
{
	DBG( "gotoURL( '" + url + "', '" + target + "' )" );
	if(!url)
	{
		showError( "Cannot load a blank url\ntarget = '" + target + "'", "gotoURL" );
		return false;
	}
	
    var m_is_ie = ( (navigator.userAgent.toLowerCase().indexOf("msie") != -1) &&
		   (navigator.userAgent.toLowerCase().indexOf("opera") == -1) );
	
	if(target)
	{
//		var myParent = window.parent;
		var myTop = window.top;
		switch (target)
		{
			case "_top":
				if (myTop)
				{
				    if ( m_is_ie)
				    {myTop.document.URL = url;}
					else
					{myTop.document.location.href  = url; }
				}
				else
				{
					ShowError( "Could not find the Top Window\ntarget = '" + target + "'", "gotoURL" );
				}
				break;
			case "_blank":
				window.open( url );
				
				
				break;
			case "_self":
			    if ( m_is_ie){
				window.document.URL = url;}
				else 
				{window.document.location.href  = url; }
				break;
			default:
				window.open( url, target );
		} // switch
	}
	else
	{
		// go to the url in the current window
		if ( m_is_ie){
		window.document.URL = url;}
		else 
		{window.document.location.href  = url; }
		
	} // if
	
	return true;
} // gotoURL

function getField( id )
{
		return getField2(id, document);
}

function getField2( id, objParent )
{
	try {
	      
	    id=GetClientId(id, objParent);    
	    	    
		var obj = null;
		var p = null;
		if ( objParent )
		{
			p = objParent;
						
		}
		else
		{
			p = document;
		}
						
		if ( p.getElementById )
		{
			DBGX( "Using getElementById( '" + id + "' )" );
			obj = p.getElementById(id);
		}
		else if ( p.all )
		{
			DBGX( "Using objParent.all[ '" + id + "' ]" );
			obj = p.all[id];
		}
		else
		{
			DBGX( "[getElementById] and [all] are not available" );
			obj = null;
		}		
		if (obj)
			return obj;
		else
		{
			DBGX( "Element does not exist, id = \"" + id + "\"" );
			return null;
		}
	} catch(ex) {
		DBG( "Element does not exist, id = \"" + id + "\"" );
		return null;
	}
}

function getFieldValue( id )
{
	var obj = getField2( id, document );
	if (obj)
		return obj.value;
	else {
		return "";
	}
}

function setFieldValue( id, value )
{
	var obj = getField2( id, document );
	if (obj)
	{
		obj.value = value;
		return true;
	}
	else {
		return false;
	}
}

function getFrame( frameName, useSelf )
{
	if (frameName)
	{
		var framesetWindow = null;
		if (useSelf)
			framesetWindow = window;
		else
			framesetWindow = window.parent;
		
		if (framesetWindow)
		{

			// Get the frameset and the frame that is named in the frameName parameter
			var targetFrame = null; // framesetWindow.frames(frameName);
			var IFrameObj = null;

			if (framesetWindow.frames) 
			{
				// this is for IE5 Mac, because it will only allow access to the document object
				// of the IFrame if we access it through the document.frames array
				IFrameObj = framesetWindow.frames[ frameName ];
			}
			else
			{
				showError( "Failed to find the Target Frame to load the url into\n frameName = '" + frameName + ", useSelf = '" + useSelf + "'\ndocument.frames is not available.", "getFrame" );
				return false;
			}

			if (IFrameObj.contentDocument)
			{
				// For NS6
				targetFrame = IFrameObj.contentDocument;
			}
			else if (IFrameObj.contentWindow)
			{
				// For IE5.5 and IE6
				targetFrame = IFrameObj.contentWindow.document;
			}
			else if (IFrameObj.document)
			{
				// For IE5
				targetFrame = IFrameObj.document;
			}
			else 
			{
				//
				showError( "Failed to find the Target Frame to load the url into\nframeName = '" + frameName + ", useSelf = '" + useSelf + "'\n", "getFrame" );
				return true;
			}

			// load the url into the frame
			if (targetFrame)
			{
				// found the target frame, now load the url into it
				DBG("found the target frame (" + targetFrame.location + ")");
				return targetFrame;
			}
			else
			{
				showError( "Failed to find the Target Frame to load the url into\nframeName = '" + frameName + ", useSelf = '" + useSelf + "'", "getFrame" );
				return false;
			}
		}
		else
		{
			showError( "Failed to find the Frameset Window\nframeName = '" + frameName + "', useSelf = '" + useSelf + "'", "getFrame" );
			return false;
		}
	}
	else
	{
		// frame name is null
		showError( "Cannot find a blank frame\nframeName = '" + frameName + ", useSelf = '" + useSelf + "'", "getFrame" );
		return false;
	}
}

/*-------------------------------------------------------------
reloadFrame
	frameName	name of the frame to reload
	useSelf		true if the frame is located in the current window
				false (default) if the frame is in the parent window	

Finds the frame by name, in the parent window, ie. window.parent.frames(...)
If it finds it, it reloads it
Otherwise it returns false.

Example
reloadFrame( "contents" );
-------------------------------------------------------------*/
function reloadFrame( frameName, useSelf )
{
	DBG( "reloadFrame( '" + frameName + "', '" + useSelf + "' )" );
	var targetFrame = getFrame( frameName, useSelf );

	// reload the frame
	if (targetFrame)
	{
		// found the target frame, now reload it
		DBG( "found the target frame, now reload it (" + targetFrame.location + ")" );
		targetFrame.location.reload();
		
	}
	else
	{
		showError( "Failed to find the Target Frame to reload, frameName = '" + frameName + ", useSelf = '" + useSelf + "'", "reloadFrame" );
		return false;
	}

	return true;	
}

/*-------------------------------------------------------------
loadFrame
	url			url to load into the appropriate frame
	frameName	name of the frame to load the url into
	useSelf		true if the frame is located in the current window
				false (default) if the frame is in the parent window	
	
Finds the frame by name, in the parent window, ie. window.parent.frames(...)
If it finds it, it loads the url into it.
Otherwise it returns false.

Example (this will load the DocumentViewer.aspx page into the parents contents frame):
loadFrame( "DocumentViewer.aspx?id=1234", "contents" );
-------------------------------------------------------------*/
function loadFrame( url, frameName, useSelf )
{
	DBG( "loadFrame( '" + url + "', '" + frameName + "', '" + useSelf + "' )" );
	if (url)
	{
		var targetFrame = getFrame( frameName, useSelf );

		// load the url into the frame
		if (targetFrame)
		{
			// found the target frame, now load the url into it
			DBG("found the target frame, now load the url into it (" + targetFrame.location + ")");
			targetFrame.location.href = url;
			
		}
		else
		{
			showError( "Failed to find the Target Frame to load the url into\nurl = '" + url + "', frameName = '" + frameName + ", useSelf = '" + useSelf + "'", "loadFrame" );
			return false;
		}
	}
	else
	{
		showError( "Cannot load a blank url\nframeName = '" + frameName + ", useSelf = '" + useSelf + "'", "loadFrame" );
		return false;
	}

	return true;
} // loadFrame

/*-------------------------------------------------------------
postFrame
	frameName	name of the frame to post
	useSelf		true if the frame is located in the current window
				false (default) if the frame is in the parent window	
	
Finds the frame by name, in the parent window, ie. window.parent.frames(...)
If it finds it, it posts the first form on the page
Otherwise it returns false.

Example (this will post the page in the parents contents frame):
postFrame( "contents" );
-------------------------------------------------------------*/
function postFrame( frameName, useSelf )
{
	DBG( "postFrame( '" + frameName + "', '" + useSelf + "' )" );

	var targetFrame = getFrame( frameName, useSelf );

	// post the frame
	if (targetFrame)
	{
		// found the target frame, now post it
		DBG("found the target frame, now post it (" + targetFrame.location + ")");
		if (targetFrame.forms[0])
			targetFrame.forms[0].submit;
		else
			showError( "Failed to find the a form on the target frame\nframeName = '" + frameName + ", useSelf = '" + useSelf + "'", "postFrame" );
	}
	else
	{
		showError( "Failed to find the Target Frame to post\nframeName = '" + frameName + ", useSelf = '" + useSelf + "'", "postFrame" );
		return false;
	}

	return true;
} // postFrame

function GoHelpdesk( args )
{
	gotoURL( 'http://helpdesk.mainfreight.co.nz/LGHelp/ObjectCode/Logon.asp?' + args, '_blank' );
}

function GoStockOnHandHeldDetails( args )
{
	//gotoURL( 'http://dev.mainchain.net/StockOnHandHeldDetail.aspx?' + args, '_blank' );
	gotoURL( 'StockOnHandHeldDetail.aspx?' + args, '_blank' );
}

function GoOnIssue( args )
{
	//TODO: RWW - Update URL
	//gotoURL( 'http://onissueexpresststweb.mainfreight.co.nz/default.aspx?' + args, '_blank' );
	gotoURL( args,'_blank' );
}

function GoPrograms()
{
	gotoURL( 'Programs.aspx', '_blank' );
}

function GoReports()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Report Selection");
	if (intIndex == -1)
	{
		tab.deleteTabs();
		tab.addAndSelectTab("Report Selection", "", "<iframe id='frameReportSelection' class='orderFrame' width='1070px' height='800px' src='ReportsSelect.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function GoBookings()
{
	gotoURL('Bookings/Bookings.htm', '_blank');
}

function GoFileService()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Order Service");
	if (intIndex == -1)
	{
	    tab.addAndSelectTab("Order Service", "", "<iframe id='frameFileService' class='orderFrame' width='1070px' height='800px' src='admin/FileServiceStats.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}

}
function GoFileServiceDetails()
{
	
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Order Details");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Order Details", "", "<iframe id='frameFileServiceDetails' class='orderFrame' width='1070px' height='800px' src='admin/OrderEntryDetails.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}

}

function GoCHEPByPass() 
{
    var tab = m_tabStrip;
    var intIndex = tab.getTabIndexFromLabel("CHEP ByPass");
    if (intIndex == -1) {
        tab.addAndSelectTab("CHEP ByPass", "", "<iframe id='frameCHEPByPass' class='orderFrame' width='1070px' height='800px' src='admin/CHEPByPass.aspx' frameBorder='no'></iframe>");
    }
    else {
        tab.selectTab(intIndex);
    }
}

function GoFremanConsignmentUpload()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Freman Upload Status");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Freman Upload Status", "", "<iframe id='frameFremanUploads' class='orderFrame' width='1070px' height='1000px' src='admin/FremanConsignmentUploadStats.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function GoFremanConsignmentDetails()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Freman Connote Details");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Freman Connote Details", "", "<iframe id='frameFremanUploads' class='orderFrame' width='1070px' height='1000px' src='admin/FremanConnoteDetails.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}
function GoFremanCHEPUpload()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Freman CHEP File");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Freman CHEP File", "", "<iframe id='frameFremanFiles' class='orderFrame' width='1070px' height='1000px' src='admin/FremanCHEPUploads.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}
function GoDirectCHEPReport()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Direct CHEP Report");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Direct CHEP Report", "", "<iframe id='frameDirectCHEPReport' class='orderFrame' width='1070px' height='1000px' src='admin/DirectCHEPReport.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function showCHEPOverdueNotes()
{		
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Freman CHEP Details");
	if (intIndex < 0)
	{

		tab.addAndSelectTab("Freman CHEP Details", "", "<iframe id='frameCHEPNotes' width='1070px'  height='1000px' src='admin/CHEPNotes.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
	
}

function GoFremanQuoting()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Rate Calculator");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Rate Calculator", "", "<iframe id='frameFremanQuoteAU' class='orderFrame' width='1020px' height='1000px' src='FremanQuoting/QuoteAU.aspx' frameBorder='0'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}




function GoActivityReports()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Activity Reporting");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Activity Reporting", "", "<iframe id='frameActivityReporting' class='orderFrame' width='1070px' height='550px' src='ActivityReporting.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function GoSuperUser()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Super User");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Super User", "", "<iframe id='frameSuper' class='orderFrame' width='1070px' height='700px' src='SuperUserSelectAccount.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function GoMultiUser()
{
// disable multi users DG 28 AUG
//	var tab = m_tabStrip;
//	var intIndex = tab.getTabIndexFromLabel("Suppliers");
//	if (intIndex == -1)
//	{
//		tab.addAndSelectTab("Suppliers", "", "<iframe id='frameMutli' class='orderFrame' width='1070px' height='520' src='MultiUserSelectAccount.aspx' frameBorder='no'></iframe>");
//	}
//	else
//	{
//		tab.selectTab(intIndex);
//	}
}

function GoWebStatusGeneral()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Service Status");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Service Status", "", "<iframe id='frameStatus' class='orderFrame' width='1070px' height='1024px' src='admin/WebServiceStatus.aspx?scope=General' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function GoWebStatusSuper()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Service Status");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Service Status", "", "<iframe id='frameStatus' class='orderFrame' width='1070px' height='1024px' src='admin/WebServiceStatus.aspx?scope=Super' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}
function GoLogonMessageSuper()
{
	var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("Logon Message");
	if (intIndex == -1)
	{
		tab.addAndSelectTab("Logon Message", "", "<iframe id='frameStatus' class='orderFrame' width='1070px' height='700px' src='admin/LogonMessage/LogonMessageList.aspx' frameBorder='no'></iframe>");
	}
	else
	{
		tab.selectTab(intIndex);
	}
}

function GoAdminReports() 
{
    var tab = m_tabStrip;
    var intIndex = tab.getTabIndexFromLabel("Admin Reports");
    if (intIndex == -1) {
        tab.addAndSelectTab("Admin Reports", "", "<iframe id='frameStatus' class='orderFrame' width='1070px' height='950px' src='Reports/AdminReports.aspx' frameBorder='no'></iframe>");
    }
    else {
        tab.selectTab(intIndex);
    }
}

function GoEdiUrl()
{
	/*var tab = m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel("ediEnterprise");
	
	if (intIndex == -1)
	{
		tab.addAndSelectTab("ediEnterprise", "", "<iframe id='frameEDI' class='orderFrame' width='1070px' height='550' src='Edienterprise/edidetails.aspx?value=" + value+ "&customerid=" +customerid +"&url="+url+"' frameBorder='no'></iframe>");
	}
	else
	{
		tab.deleteTab(intIndex);
		tab.addAndSelectTab("ediEnterprise", "", "<iframe id='frameEDI' class='orderFrame' width='1070px' height='550' src='Edienterprise/edidetails.aspx?value=" + value+ "&customerid=" +customerid +"&url="+url+"' frameBorder='no'></iframe>");

	}*/
	
	gotoURL( 'Edienterprise/edidetails.aspx', '_blank' );

}

function GoMimsLabelUrl(tabname, url) 
{
	var tab = parent.m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel(tabname);
	if (intIndex == -1)
	{
		tab.addAndSelectTab(tabname, "", "<iframe id='frame" + tabname + "' class='orderFrame' width='1070px' height='520px' src='"+ url + "' frameBorder='no'></iframe>");
	}
	else
	{
		tab.deleteTab(intIndex);
		tab.addAndSelectTab(tabname, "", "<iframe id='frame" + tabname + "' class='orderFrame' width='1070px' height='520px' src='"+ url + "' frameBorder='no'></iframe>");

	}
}

function GoTabWithUrl(tabname, url, height)
{
	var tab = parent.m_tabStrip;
	var intIndex = tab.getTabIndexFromLabel(tabname);
	if (intIndex == -1)
	{
		tab.addAndSelectTab(tabname, "", "<iframe id='frame" + tabname + "' class='orderFrame' width='1070px' height='"+ height + "px' src='"+ url + "' frameBorder='no'></iframe>");
	}
	else
	{
		tab.deleteTab(intIndex);
		tab.addAndSelectTab(tabname, "", "<iframe id='frame" + tabname + "' class='orderFrame' width='1070px' height='"+ height + "px' src='"+ url + "' frameBorder='no'></iframe>");

	}
}
function GoTabWithUrl2(tabname, url, height, width) 
{
    var tab = parent.m_tabStrip;
    var intIndex = tab.getTabIndexFromLabel(tabname);
    if (intIndex == -1) {
        tab.addAndSelectTab(tabname, "", "<iframe id='frame" + tabname + "' scrolling='auto' class='orderFrame' width='" + width + "' height='" + height + "px' src='" + url + "' frameBorder='no'></iframe>");
    }
    else {
        tab.deleteTab(intIndex);
        tab.addAndSelectTab(tabname, "", "<iframe id='frame" + tabname + "' scrolling='auto' class='orderFrame' width='" + width + "' height='" + height + "px' src='" + url + "' frameBorder='no'></iframe>");

    }
}



function selectListBoxObjectByValue( objSelect, optionValue )
{
	// Walk through the select list looking for a match
	if (!objSelect)
		return false;

	var i;
	for (i=0; i < objSelect.options.length; i++)
	{
	    // Does this item match?
	    if ( objSelect.options[i].value == optionValue )
	    {
	        // OK, we can stop at this option. Set focus here
	        objSelect.selectedIndex = i;
	        return true;
	    }
	}  // for
	
	return false;
} // selectListBoxObjectByValue

function selectListBoxByValue( selectId, optionValue )
{
	// Walk through the select list looking for a match
    var objSelect  = getField( selectId );
	if (!objSelect)
		return false;

	var i;

	for (i=0; i < objSelect.options.length; i++)
	{
	    // Does this item match?
	    if ( objSelect.options[i].value == optionValue )
	    {
	        // OK, we can stop at this option. Set focus here
	        objSelect.selectedIndex = i;
	        return true;
	    }
	}  // for
	
	return false;
} // selectListBoxByValue

function CreateXMLDoc(loadXml)
{
     var xmlDoc;
     if (window.ActiveXObject) {
        xmlDoc =  new ActiveXObject("Microsoft.XMLDOM"); 
        xmlDoc.async = false;
		xmlDoc.resolveExternals = false; 
		xmlDoc.loadXML(loadXml);
      }
      else {
       
         var parser = new DOMParser();
				try {
					 xmlDoc = parser.parseFromString(loadXml, "text/xml");
				}
				catch(e){alert("XML file is not valid!");}
				
       }
      
	
    return xmlDoc;
}

function CreateXMLHTTP()
{
    var oXmlHttp;
    
    if (typeof XMLHttpRequest != "undefined") {
        oXmlHttp =  new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"
      ];

      for (var i = 0; i < aVersions.length; i++) {
        try {
            oXmlHttp = new ActiveXObject(aVersions[i]);
            oXmlHttp = oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
      }
    }
    return oXmlHttp;

}

function NodeText( node)
{
    if (window.ActiveXObject) 
    {
        return node.text;
    }
    else 
    {
        return node.textContent;
    }

}


function GetClientId(strid, mydoc)
{      
    //When chosing an option from the Enquiry & Tracking drop down list
    //mydoc is sometimes 'undefined'...whenever this occurs it is set to 'document' instead
    if(!mydoc)
    {
        mydoc = document;
    }
    
    var count=mydoc.forms[0].elements.length;
         
    var i=0;
    var eleName = ""; 
    for (i=0; i < count; i++ )
    {
        eleName=mydoc.forms[0].elements[i].id; 
        pos=eleName.indexOf(strid);
        if(pos>=0)  
        {
            // check exactmatch
            var splitstring = eleName
            break;               
        }
        else
        {
            eleName = "";
        }
    }
    if (eleName == "")
    {
               
          var eleName1 = "";
       
          //using this code instead of document.all which FF doesn't like
          var c = mydoc.getElementsByTagName("body")[0].getElementsByTagName("*");
          
          for (var x=0;x<c.length;x++) 
          {
                
                var pos1=c[x].id.indexOf(strid);
                if(pos1>=0)  
                {
                    // check exactmatch
                    eleName1 = c[x].id;
                    break;               
                }
                else{
                    eleName1 = "";
                }
            
           }   
    
    
//        // didn't fond it go try wild ass search
//        var count1=mydoc.all.length;
//        var j=0;
//        var eleName1 = ""; 
//       
//       
//        for (j=0; j < count1; j++ )
//        {
//            //eleName1=mydoc.all[j].id; 
//            pos1=eleName1.indexOf(strid);
//            if(pos1>=0)  
//            {
//                // check exactmatch
//                var splitstring1 = eleName1
//                break;               
//            }
//            else
//            {
//                eleName1 = "";
//            }
//        }
        eleName = eleName1;
    }
    return eleName;
}

function UserInfo() {
    DetectScreenRes();
    DetectFlash();
    DetectSilverlight();
}

function DetectScreenRes() {
    var res = screen.width + "x" + screen.height;
    document.getElementById("hdnScreenRes").value = res;
}

