var CurrentNewsOpenedID = "";
	var numPcs =0;
	var tolVal =0;
	
function checkPrintWaybills(){
	if (document.getElementById("txtWBList").value != ''){
		var sRotate;
		if (document.getElementById("chkRotate").checked){
			sRotate = '&Rotate=Y';
		}
		else
		{
			sRotate = '';
		}
		sRotate = '';
		if (document.getElementById("txtUseThermoPrinter").value == "Y")
		{
			printEachThermoLabel(document.getElementById("txtWBList").value,document.getElementById("txtLoginID").value,document.getElementById("txtLoginSenderID").value);
		}
		else
		{
			window.open("wfPrintLabels.aspx?ShipmentId=" + document.getElementById("txtWBList").value + sRotate ,"_blank");
		}
		document.getElementById("txtWBList").value = '';
	}
}

function checkOther(obj){
	if (obj.options[obj.selectedIndex].value == "Other"){
		obj.form.other.style.display = "";
		obj.form.other.focus();
	}else{
		obj.form.other.style.display = "none";		
	}
}

function checkShipTo(obj){
	if (obj.options[obj.selectedIndex].value == "Collect"){
		obj.form.shipTo.style.display = "";
		obj.form.shipTo.focus();
	}else{
		obj.form.shipTo.style.display = "none";		
	}
}

function layout(){
	leftMN = document.getElementById("left_menu");
	mainAR = document.getElementById("main_content");
	FT = document.getElementById("footer");
	lineV = document.getElementById("line_ver");
	
	var MA_height = mainAR.offsetHeight;
	var Lheight = leftMN.offsetHeight;

	if (MA_height >= Lheight){
		Mheight = MA_height;
	}else{
		Mheight = Lheight;
	}
	leftMN.style.height = Mheight - 10 + "px";
	mainAR.style.height = Mheight - 10+ "px";
	FT.style.top = Mheight + mainAR.offsetTop + "px";
	FT.style.display="block";
	lineV.style.height = Mheight + mainAR.offsetTop + FT.offsetHeight  + "px";
}
function showLogin_backup(){
	AR = document.getElementById("login_area");
	AR.style.display = "block";
}
function hideLogin(){
	AR = document.getElementById("login_area");
	AR.style.display = "none";
}
function showHelp(obj){
	obj.className='help help_area_open';
	document.execCommand("BackgroundImageCache",false,true);
}
function hideHelp(obj){
	obj.className='help_close help_area_open';
	//document.execCommand("BackgroundImageCache",false,false);
}
function NewNameShow(obj){
	if (obj.options[obj.selectedIndex].value == "NN"){
		obj.form.NewName.style.display = "inline"
	}else{
		obj.form.NewName.style.display = "none";
	}
}
function openDiv(aObj, objID){
	var  obj = document.getElementById(objID);
	var LT = document.getElementById(objID + "_link");
	H2tag = aObj.parentNode.parentNode.tagName.toLowerCase();
	
	if (obj.className == "fields_group_closed"){
		obj.className = "fields_group";
		LT.innerHTML = "Close"
		window.location.href="#"+ objID + "_link"
	}else{
		obj.className = "fields_group_closed";
		LT.innerHTML = "Open"		
	}
}
spOld = "sp1";
function SwitchShipment(shipperID){
	
		var switchTab = document.getElementById(shipperID + "switch");
		var closeTab = document.getElementById(shipperID + "close");
		var SP = document.getElementById(shipperID);
	if (switchTab.className == "off"){
		switchTab.className = "on";
		closeTab.className = "tab_on";
		SP.className = "sp_open";
		
		var switchTabOld = document.getElementById(spOld + "switch");
		var closeTabOld = document.getElementById(spOld + "close");
		var SPhide = document.getElementById(spOld);
		switchTabOld.className = "off";
		closeTabOld.className = "tab_off";
		SPhide.className = "sp_closed";

		spOld = shipperID;
	}else{
		return ;
	}
}
function DeleteShipment(shipperID){
	var switchTab = document.getElementById(shipperID + "switch");
	var closeTab = document.getElementById(shipperID + "close");
	var TABS = document.getElementById("TabGroups");
	var allSP = TABS.getAttribute("shipments");
	allSParr = allSP.split(", ");
	if (allSParr.length != 1){
		for (i = 0; i < allSParr.length; i++){
			if (allSParr[i] == shipperID){
				allSParr.splice(i,1);
				break;
			}
		}
		if (switchTab.className == "on"){
			SwitchShipment(allSParr[0]);
		}
		var newAttr = allSParr.join(", ");
		TABS.setAttribute("shipments", newAttr);

		switchTab.parentNode.removeChild(switchTab);
		closeTab.parentNode.removeChild(closeTab);
	}
}

sectOld = "serv1"
linkOld = "_04000lnkLoginInfoEdit"

contOldId ="cont1"

function hideDefault(){
		linkDefault = document.getElementById(linkOld);
		linkDefault.innerHTML = "";
	}

function openServiceEDIT(sectID, link, contID){
	DIVold = document.getElementById(sectOld);
	DIV = document.getElementById(sectID);
	
	contentID = document.getElementById(contID);
	contOld = document.getElementById(contOldId);
	
	Oldlink = document.getElementById(linkOld);
	link_link = document.getElementById(link);
	
	if (DIV.className != "fields_group"){
		contentID.className = "txtCustomMessage_open"
		contOld.className = "txtMessage_close"
		DIV.className = "fields_group";
		DIVold.className = "fields_group_closed";
	
		if(link_link.innerHTML == "Edit"){
				link_link.innerHTML = "";
				Oldlink.innerHTML="Edit";
				}
		else if(link_link.innerHTML == "Modifier")
		{
				link_link.innerHTML = "";
				Oldlink.innerHTML="Modifier";
				}
				
			
		linkOld = link;
		sectOld = sectID;
		contOldId = contID;
	}

}
function openService(sectID)
{
	DIVold = document.getElementById(sectOld);
	DIV = document.getElementById(sectID);
	
	Oldlink = document.getElementById(linkOld);
	
	if (DIV.className != "fields_group")
	{
		
		DIV.className = "fields_group";
		DIVold.className = "fields_group_closed";
		sectOld = sectID;
	}
}
function customOpenService(sectID, contID)
{
	DIVold = document.getElementById(sectOld);
	DIV = document.getElementById(sectID);
	
	contentID = document.getElementById(contID);
	contOld = document.getElementById(contOldId);
	
	Oldlink = document.getElementById(linkOld);
	
	if (DIV.className != "fields_group")
	{
		contentID.className = "txtCustomMessage_open"
		try
		{
			contOld.className = "txtMessage_close"
		}
		catch (e)
		{}
		DIV.className = "fields_group";
		contentID.className = "txtCustomMessage_open"
		DIVold.className = "fields_group_closed";
		sectOld = sectID;
		contOldId = contID;
	}
}

function closeEditAddress(c, o){
	toClose = document.getElementById(c);
	toOpen = document.getElementById(o);
	toClose.style.display = "none";
	toOpen.style.display = "block";
}
function fitUsers(n){
	UH = DIVold = document.getElementById("users_horizontal");
	UH.style.width = n * 125 + "px";
}

function show_MS(obj){
	var topDiv = obj.parentNode.parentNode.parentNode;
	var holder = topDiv.parentNode;
	if (topDiv.className.indexOf("ms_closed")>0){
		obj.innerHTML = "Close";
		topDiv.className = "multi-select ms_open";
		var IFtag = document.createElement("iframe");

		holder.appendChild(IFtag);
		IFtag.style.position = "absolute";
		IFtag.style.top = topDiv.offsetTop;
		IFtag.style.left = topDiv.offsetLeft;
		IFtag.style.width = topDiv.offsetWidth;
		IFtag.style.height = topDiv.offsetHeight;
		IFtag.style.zIndex = -1;
		IFtag.setAttribute("frameborder", 0);
		holder.style.zIndex = 100;
		
	}else{
		topDiv.className = "multi-select ms_closed";
		var IFTag = holder.getElementsByTagName("iframe")[0];
		IFTag.parentNode.removeChild(IFTag);
		obj.innerHTML = "Open";
		holder.style.zIndex = 1;
	}
}
function closeBrowser(){
	var br = document.getElementById("browser");
	br.style.display = "none";
}

/*webship prompt functionality*/

function showPrompt(k, obj){
	holder = obj.parentNode;
	pr = document.getElementById("promptDiv");
	var cnt =  document.getElementById("promptCont");
	var mText = document.getElementById(k);
	pr_cr = document.getElementById("pr_screen");
	
	holder.appendChild(pr);
	cnt.innerHTML = mText.innerHTML;
	pr.style.display = "block";
	
		var browserName = navigator.appName;
		
		
	if (browserName == "Microsoft Internet Explorer"){
		holder.appendChild(pr_cr);
	
		//pr_cr.style.top = pr.offsetTop;
		//pr_cr.style.left = pr.offsetLeft;
		pr_cr.style.width = pr.offsetWidth;
		pr_cr.style.height = pr.offsetHeight;
		pr_cr.style.display = "block"; 
	}
	else{}
	
}
function closePrompt(obj){
	pr = document.getElementById("promptDiv");
	pr.style.display = "none";
	pr_cr.style.display = "none"; 
}
function showErrorCityPrompt(k, objid){
    var holderObject = document.getElementById(objid);
	showPrompt(k, holderObject);
}
/*function closePrompt(obj){
	var pr = document.getElementById("promptDiv");
	pr.style.display = "none";
}*/
/* scripts Extension */
function showLogin()
{
	var aLoginText = document.getElementById("_00000hylLogin");
	if (aLoginText.innerHTML != "Logoff" && aLoginText.innerHTML != "Quitter")
	{
		AR = document.getElementById("login_area");
		AR.style.display = "block";
	}
	else
	{
		window.open("wfBackendProcessPage.aspx","_self");
		aLoginText.innerHTML = "Login";
	}
}
function showManageProfile()
{
	AR = document.getElementById("greeting_area");
	AR.style.display = "block";
	AR = document.getElementById("loginUserName_area");
	AR.style.display = "block";
	AR = document.getElementById("manageProfile_area");
	AR.style.display = "block";
}
function hideManageProfile()
{
	var mGreeting = document.getElementById("greeting_area");
	mGreeting.style.display = "none";
	var mLoginUserName = document.getElementById("loginUserName_area");
	mLoginUserName.style.display = "none";
	var mManageProfile = document.getElementById("manageProfile_area");
	mManageProfile.style.display = "none";
}
function hideErrorObject(obj)
{
	obj.className = 'fields_group_closed';
}
function showErrorObject(obj)
{
	obj.className = 'fields_group';
}
function openDiv_backup(anObj, objID)
{
	var  obj = document.getElementById(objID);
	var LT = document.getElementById(objID + "_link");
	if (obj.className == "fields_group_closed")
	{
		obj.className = "fields_group";
		LT.innerText = "Close";
		window.location.href="#"+ objID + "_link";
	}
	else
	{
		obj.className = "fields_group_closed";
		LT.innerText = "Edit";		
	}
}
function showHelp_backup(obj){
	obj.className='help help_area';
	document.execCommand("BackgroundImageCache",false,true);

	var ifr = document.createElement("iframe");
	ifr.style.width = obj.offsetWidth;
	ifr.style.height = obj.offsetHeight;
	obj.appendChild(ifr);

}
function openHylDiv(anObj, objID)
{
	var obj = document.getElementById(objID);
	var LT = document.getElementById(objID + "_link");
	if (obj.className == "fields_group_closed")
	{
		obj.className = "fields_group";
		window.location.href="#"+ objID + "_link";
	}
	else
	{
		obj.className = "fields_group_closed";
	}
}
function openSelectedNews(contID){
   var oRows = document.getElementById('dgDHLNews').getElementsByTagName('tr');
	var iRowCount = oRows.length;
	if (CurrentNewsOpenedID != ""){
		var prevNewsID = document.getElementById(CurrentNewsOpenedID);
		prevNewsID.className = 	"txtMessage_close"; 
	}
	var CurrentNewsID =document.getElementById(contID);
	CurrentNewsOpenedID = contID;
	CurrentNewsID.className = "txtCustomMessage_open";
}
function ComInv_CellChangeHandler(gridName, cellId){
	var aCellObj = igtbl_getCellById(cellId);
	var aColObj = aCellObj.Column;
	var curRow = igtbl_getRowById(cellId);
	if (aColObj.Index == 3 || aColObj.Index == 4){
		curRow.getCell(5).setValue(curRow.getCell(3).getValue() * curRow.getCell(4).getValue());
		UpdateTotalNum();
	}
	
	//UpdateTotalVal();
}
function UpdateTotalNum(){

	var iCount = 0;
	var aGridObj = igtbl_getGridById("_05100grdPackageDetails");
	var aGridLength = aGridObj.Rows.length;
	var aRow = aGridObj.Rows;
	var totalNum = 0;
	var totalVal = 0;
	var tempValue = 0;
	var tmpNum = 0;
	for (iCount = 0;iCount < aGridLength ;iCount++)
	{
			if (aRow.rows[iCount].cells[3]==null){
				tempNum=0;
			}else{
				if (aRow.rows[iCount].cells[3].getValue()==null){
					tempNum=0;
				}else{
					tempNum=aRow.rows[iCount].cells[3].getValue();
				}
			}
			if (aRow.rows[iCount].cells[4]==null){
				tempValue=0;
			}else{
				if (aRow.rows[iCount].cells[4].getValue()==null){
					tempValue=0;
				}else{
					tempValue=aRow.rows[iCount].cells[4].getValue();
				}
			}
			totalNum+=tempNum;
			totalVal+=tempNum * tempValue;
	}	
	document.getElementById('_05100txtNumberPieces').innerText = totalNum;
	document.getElementById('_05100txtTotalValue').innerText = '$ ' + totalVal.toFixed(2);
}

function UpdateTotalVal(){
	var iCount = 0;
	var aGridObj = igtbl_getGridById("_05100grdPackageDetails");
	var aGridLength = aGridObj.Rows.length;
	var aRow = aGridObj.Rows;
	var totalVal = 0;
	for (iCount = 0;iCount < aGridLength ;iCount++)
	{
		totalVal+=aRow.rows[iCount].cells[3].getValue()/1 *aRow.rows[iCount].cells[4].getValue()/1;
	}	
	document.getElementById('_05100txtTotalValue').innerText = '$ ' + totalVal.toFixed(2);
}
/*function ComInv_CellChangeHandler(gridName, cellId){
	var aCellObj = igtbl_getCellById(cellId);
	var aColObj = aCellObj.Column;
	var curRow = igtbl_getRowById(cellId);
	if (aColObj.Index == 3 || aColObj.Index == 4){
		curRow.getCell(5).setValue(curRow.getCell(3).getValue() * curRow.getCell(4).getValue());
		UpdateTotalNum();
		UpdateTotalVal();
	}
}
function UpdateTotalNum(){

	var iCount = 0;
	var aGridObj = igtbl_getGridById("_05100grdPackageDetails");
	var aGridLength = aGridObj.Rows.length;
	var aRow = aGridObj.Rows;
	var totalNum = 0;
	for (iCount = 0;iCount < aGridLength ;iCount++)
	{
			totalNum+=aRow.rows[iCount].cells[3].getValue("0.0")/1;
	}	
	document.getElementById('_05100txtNumberPieces').innerText = totalNum;
}

function UpdateTotalVal(){
	var iCount = 0;
	var aGridObj = igtbl_getGridById("_05100grdPackageDetails");
	var aGridLength = aGridObj.Rows.length;
	var aRow = aGridObj.Rows;
	var totalVal = 0;
	for (iCount = 0;iCount < aGridLength ;iCount++)
	{
		totalVal+=aRow.rows[iCount].cells[3].getValue()/1 *aRow.rows[iCount].cells[4].getValue()/1;
	}	
	document.getElementById('_05100txtTotalValue').innerText = '$ ' + totalVal.toFixed(2);
}*/
//----------------- processing image -----------------------
function showLayer(lan){

	var browserName = navigator.appName;
	var browserVer = parseInt(navigator.appVersion);
	if (browserName != "Microsoft Internet Explorer"){
		BR = false;
	}else{
		BR = true;
	}

	if (BR){
		myDiv = document.createElement("<iframe frameborder='0' border='0'>");
		//myDiv.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
		//myDiv = document.createElement("div");

	}else{
		myDiv = document.createElement("div");
	}

	myDiv.className = "cover";
	document.body.appendChild(myDiv);

	loader = document.createElement("div");
	loader.className = "loader";
	if (lan == "en"){
		loader.innerHTML = "Processing...";
	}else{
		loader.innerHTML = "En traitement...";
	}
	document.body.appendChild(loader);
//window.status = 
	//SQ2_H = window.innerHeight;
	//for(var i=0;i<50000;i++){
	//}
	myInt = setInterval(reposition, 50);
}

function reposition(){

	delta = 0; //what is delta for?
	
	ST = document.body.scrollTop;
	
	SL = document.body.scrollLeft;
	
	SQ2_H = document.body.clientHeight - delta;
	SQ2_W = document.body.clientWidth - delta;
	
	//SQ2_H = document.body.clientHeight;
	
	if (navigator.appName == "Opera"){
		SQ2_H = window.innerHeight - delta;
		SQ2_W = window.innerWidth - delta;
	}
	
	SQ_H = document.body.offsetHeight + document.body.offsetTop;
	SQ_W = document.body.offsetWidth + document.body.offsetLeft;
	
	
	if (SQ2_H >= SQ_H){
		SQ_H = SQ2_H;
	}
	
	if (SQ2_W >= SQ_W){
		SQ_W = SQ2_W;
	}


	loader.style.top = ST + SQ2_H/2 - 25 + "px"; 
	loader.style.left = SL + SQ2_W/2 - 25 + "px";
	

	myDiv.style.width = SL + SQ2_W + "px"
	myDiv.style.height = ST + SQ2_H + "px"
	
}
function clearCover(){
	clearInterval(myInt);
	loader.parentNode.removeChild(loader);
	myDiv.parentNode.removeChild(myDiv);
}

function enlargeImage()
{
	if (document.getElementById("txtImageURL").value != '')
	{	
		var sHTML = "<HTML><HEAD></HEAD><BODY onLoad='window.focus();' onblur='self.close();'><IMG name=imgobj src='" + document.getElementById("txtImageURL").value + "'>"
		sHTML = sHTML + "<SCRIPT>window.resizeTo(imgobj.width+50,imgobj.height+70);</SCRIPT></BODY></HTML>";
		var ImagePopup;
		ImagePopup = window.open('','EnlargeImage','status=no,toolbar=no,location=no,menubar=no');
		ImagePopup.document.writeln(sHTML);
		ImagePopup.document.close();
		
		
	}
}
function beforeunload()
{
	try
	{
		var Lan = document.getElementById('btnLanguage').innerHTML;
		if (Lan == 'English')
		{
			showLayer('fr');
		}
		else
		{
			showLayer('en');
		}
	}
	catch (e) {}
}
function showSimple(idName){
	block = document.getElementById(idName);
	block.style.display = "block";
}
function hideSimple(idName){
	block = document.getElementById(idName);
	block.style.display = "none";
}
// Cancel default behavior
function doBeforePaste(control,maxLength){
    //maxLength = control.attributes["maxLength"].value;
     if(maxLength)
     {
          event.returnValue = false;
     }
}
// Cancel default behavior and create a new paste routine
function doPaste(control,maxLength){
    //maxLength = control.attributes["maxLength"].value;
    value = control.value;
     if(maxLength){
          event.returnValue = false;
          maxLength = parseInt(maxLength);
          var oTR = control.document.selection.createRange();
          var iInsertLength = maxLength - value.length + oTR.text.length;
          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
          oTR.text = sData;
     }
}
function isMaxLength(txtBox,LENGTH_TEXT) {
    	if(txtBox) { 
    		return ( txtBox.value.length <LENGTH_TEXT );
	}
}
