var statusText="";
var FSEP='¯',PSEP='®',LSEP="»";
var bMSIE=false,bShift=false, bHandleReturnKey=true;
var i;
var fields= new Array();
var pos=navigator.userAgent.indexOf("MSIE");
var currDlg=window;
var bUsingCodeFrame=false
var bAccessParentDenied; // parent object located on another website than this pages
var bLogErrors=false; // default is to log errors, turn off when debugging

if(bLogErrors)
	window.onerror = handleError;
function handleError(msg,url,line) // All javascript errors will be logged to file
{
	alert("Unfortunately an error occured on the page.\r\n\r\nThe error has been logged!");
	window.location.replace("logerror.asp?errType=javascript&errUrl=" + escape(url) + "&errMsg=" + escape(msg) + "&errLine=" + escape(line));
}

if(pos>=0)
{
	var ver=parseInt(navigator.userAgent.charAt(pos+5));
	bMSIE=true;
	if(ver>4)
		bHandleReturnKey=false;
}
if(!bMSIE)
{
	currDlg.document.captureEvents(Event.KEYPRESS);
	currDlg.document.captureEvents(Event.KEYDOWN);
	currDlg.document.onkeypress = EventKeyPressedNS;
	currDlg.document.onkeydown = EventKeyDownNS;
}
else
{
	currDlg.document.onkeypress = EventKeyPressedIE;
}

SavedObjNamesArray= new Array(0);
SavedObjArray= new Array(0);

// Saves drop down code to code frame array if drop down has values
// Fetches drop down from frame array if drop down is empty
// if fetch fails then function returns false (uset to refresh mainframe
function SetDropDownObject(dialog,form,fieldName)
{
	var text,field, bReturn=true;
	if(Exists(form,fieldName))
	{
		field=eval("form." + fieldName);
		if(field.type=="select-one")
		{
			if(field.length<=1)
			{
				text=GetFieldFromCodeFrame(dialog,fieldName);
				if (text!=false)
					field.outerHTML=text
				else
					bReturn=false;
			}
			else
				SaveFieldInCodeFrame(dialog,fieldName,field.outerHTML);
		}
	}			
	return bReturn;
}
function ReloadCodeFrame(name)
{

}
function SaveInput(theForm)
{
	var name,formName="",bRepeat=true;
	if(theForm.CurrentFormName.value.length>0)
		formName=theForm.CurrentFormName.value;
	while(bRepeat)
	{
		name=prompt(lngJsEnterNameTemplate + ":",formName);
		if(name!=null && name!="") // ok (IE 4-null, IE3-""???)
		{
			if(name.length==0)
				alert(lngJsEnterTemplNameOrCancel);
			else if(!IsAlphaNum(name,true))
				alert(lngJsOnlyAlfanum);
			else if(name.length>35)
			{
				alert(lngJsTemplNameMax35);
				formName=name.substr(0,35);
			}
			else
			{
				bRepeat=false;
				if(theForm.SavedFormNames.value.indexOf("¯" + name,0)!=-1)
				{
					if(confirm(lngJsTemplateExist))
					{			
						theForm.action=theForm.action + "SaveAs=" + escape(name) + "&Overwrite=Y";
						theForm.submit();
					}
				}
				else
				{
					theForm.action=theForm.action + "SaveAs=" + escape(name);
					theForm.submit();
				}
			}
		}
		else
			bRepeat=false;
	}
}

function MessageBox(text)
{
	alert(text);
}
function Remember(Dialog,String) // Saves SessionVariables from javascript
{
	if(FrameExists(parent, "setget"))
	{
		frame=GetFrame(parent,"setget");
		frame.location.href="setget.asp?Dialog=" + Dialog + String;
		frame.location.reload(true);
	}
}

function GetFieldFromCodeFrame(dialog,fieldName)
	{
	var i,check,form;
	frame=GetFrame(parent,"code");
	check=eval("frame." + dialog + "_Form." + fieldName + "_Empty");
	if(check.value!="Y") // Field has value(s)
		{
		field=eval("frame." + dialog + "_Form." + fieldName);
		return field.outerHTML;
	}
	return false;
}

function SaveFieldInCodeFrame(dialog,name,obj)
	{
	var i,frame,field;
		frame=GetFrame(parent,"code");
	field=eval("frame." + dialog + "_Form." + name);
	field.outerHTML=obj;
	field=eval("frame." + dialog + "_Form." + name + "_Empty"); // Eg frame.Order_Form.Customer
	field.value="N"; // Indicate that this field is "filled" with data
	return true;
}

function InitCode(frame)
{
	currDlg=frame;
}

function GetKey(e)
{
	var key;
	if(!bMSIE)
		key=e.which;
	else
		key=currDlg.event.keyCode;
	return key;
}

function CheckShiftKey(e)
{
	if(bMSIE)
		bShift=currDlg.event.shiftKey;
	else
	{
		if(!bMSIE && e.modifiers==4)
			bShift=true;
		else
			bShift=false;
	}
	return bShift;
}

function EventKeyUp(e)
{
	return true;
}

function EventKeyDownNS(e)
{
	var key;
	key=String.fromCharCode(e.which);
	if(key=="'")
		return false;
	return true;
}
function EventKeyPressedNS(e)
{
	var key,keyChar;
	key=GetKey(e);
	if(key==13)
	{
		if(currDlg.document.forms[0])
			SubmitForm(currDlg.document.forms[0]);
	}
	else
		return true;
	return false;
}
function EventKeyPressedIE(e)
{
	var key;
	key=GetKey(e);
	if(key==13 && bHandleReturnKey)
	{
		if(currDlg.document.forms[0])
			SubmitForm(currDlg.document.forms[0]);
	}
	else if(key==39)
		return false;
	else
		return true;
}

function IsExpanded(txt)
{
	var d,obj,c,o,bRc=true;
	d=currDlg.document.all;
	obj=d.item(txt);
	c=isNaN(obj.length)?c=1:c=obj.length;
	o= c==1?obj:obj(0);
	if(o.style.display=="none")
		bRc=false;
	return bRc;
}

function Expand(bShow,partTxt,imgTxt)
{
	var d,i,obj,view,x,o,c=0,y,imgC=0,z;
	d=currDlg.document.all;
	img=d.item(imgTxt);
	if(img!=null)
		imgC=isNaN(img.length)?imgC=1:imgC=img.length;
	obj=d.item(partTxt);
	if(obj!=null)
		c=isNaN(obj.length)?c=1:c=obj.length;
	for(i=0;i<c;i++)
	{
		o= c==1?obj:obj(i);
		view=o.style.display;
		if(!bShow && (view=="" || view=="inline"))
		{
			o.style.display ="none";
			for(y=0;y<imgC;y++)
			{
				z= imgC==1?img:img(y);
				z.src= "../images/open.gif";
			}
		}
		if(bShow && view=="none")
		{
			o.style.display = "inline";
			for(y=0;y<imgC;y++)
			{
				z= imgC==1?img:img(y);
				z.src= "../images/close.gif";
			}
		}
	}
	// change tab order
	obj=d.item(partTxt + "TabField");
	c=0;
	if(obj!=null)
		c=isNaN(obj.length)?c=1:c=obj.length;
	for(i=0;i<c;i++)
	{
		o= c==1?obj:obj(i);
		o.tabIndex==-1?o.tabIndex=0:o.tabIndex=-1;
	}
}

function CheckRadio(ourRadio,value) // checks radio button with same value as "value"
{
   var i;
   if(value.length)
		for (i=0;i<ourRadio.length;i++) 
			if (ourRadio[i].value==value && !ourRadio[i].checked) 
				ourRadio[i].checked=true;
}

function GetFieldOrderNo(theForm,szFieldName) // get eg field 10 for eg field "ShipName"
{
	var i;
	for(i=0;i<theForm.elements.length;i++)
		if(theForm.elements[i].name==szFieldName)
			return i;
	return 0;
}
 
function GetFieldValue(theForm,szFieldName)
{
   var i;
	for(i=0;i<theForm.elements.length;i++)
		if(theForm.elements[i].name==szFieldName)
			return theForm.elements[i].value;
	return "";
}

function UnDisableAllFields(theForm)
{
	var i;
	for(i=0;i<theForm.elements.length;i++)
		if(theForm.elements[i].disabled)
			theForm.elements[i].disabled=false;
}

function Disable(bDisable) // multi
{
//' In javascript you may call a function with more parameters then the function is defined
//' with. Eg above Disable(true,"Field1","Field2"). All parameters in a call to a function
//' is accessed in the var arguments.
//' In order to reduce the output to the client of some .asp files (eg Create_shipment)
//' javascript code might be stored in a separate code frame or in the .ASP file.
//' If one keeps the javascript in a code frame then all call to javascriptfunctions
//' goes to an "header" file (included in the .ASP file instead of the actual js file
//' that is tored in the code frame). When calling js functions via this header file who 
//' makes the actuall call to the real javascript function it is a problem to access
//' the arguments that is not defined in the function. In this case the function 
//' (defined in js_func_header) will be sent in an array (the first will be argument[1])
//' eg c.Disable(bDisable,arguments). And this will be taken care of by the function
//' The call to the function however will be as defined
	var i,args=arguments; 
	if(typeof(arguments[1])=="object")
		args=arguments[1];
	for(i=1;i<args.length;i++)
		args[i].disabled=bDisable;
}

function IsVisible(field) // check if field not displayed. Returns "" if visible else tagid
{
	var f=field;
	do {
		if(f.style.display=="none")
			return f.id;
		f= f.parentElement;
	} while(f.parentElement!=null)
	return "";
}

function Replace(ourString,strReplace,strWith) // Eg replace "," with "." in numeric string
{
	var newstr, regularexpression = new RegExp(strReplace,"gi");
	newstr=ourString.replace(regularexpression,strWith);
	return newstr;
}

function getCookie(Name) // Gets cookie string that contains all items (all items is in one cookie)
{
	var ourCookie="",offset,end;
	var search = Name
	if (currDlg.document.cookie.length > 0) 
	{ // if there are any cookies
		offset = currDlg.document.cookie.indexOf(search) 
		if (offset != -1) 
		{ // if cookie exists
			offset += search.length 
			// set index of beginning of value
			end = currDlg.document.cookie.indexOf(";", offset) 
			// set index of end of cookie value
			if (end == -1) 
				end = currDlg.document.cookie.length
			ourCookie= unescape(currDlg.document.cookie.substring(offset, end))
		}
	}
	return ourCookie;
}

function getCookieItem(ourCookie,item) // Gets cookie item from cookie string
{
	var strCookieItem="";
	var search= item + "=";
	index= ourCookie.indexOf(search,0);	
	if (index!= -1) // item found
	{
		// now collect value of item
		var pos= index + item.length + 1;
		while (pos < ourCookie.length)
		{
			if (ourCookie.charAt(pos)!="&")
				if (ourCookie.charAt(pos)!="+")
					strCookieItem += ourCookie.charAt(pos++);
				else
				{
					strCookieItem += " "; // replace "+" with " " (Unescape does not fix this!?)
					pos++;
				}
			else
				break;
		}
	}
	return unescape(strCookieItem);
}

function CheckAwbNo(AwbNo)
{
	var no;
	no=AwbNo.value;
	if(no.length==12 && no.charAt(3)=='-')
		no=no.substring(0,3) + no.substring(4,12);
	if(no.length!= 11)
		return false;
	return (parseInt(no.substring(3,10),10) % 7) == parseInt(no.substring(10,11),10);
}
// check that string does not contain any of the chars: "/\:*<>|
function Contains(s,badchars)
{
    for (i = 0; i < badchars.length; i++)
	{	
		var z;
		z=s.indexOf(badchars.charAt(i))
		if(z!=-1)
		{
			alert("badchar: " + badchars.charAt(i) + "found");
			return false;
		}
	}
	return true;
}
function GetDate(bFormatted) // curr local date
{
	var theDate= new Date(), y,m,d,tmp;
	y= theDate.getFullYear();
	tmp= "0" + (theDate.getMonth()+1);
	m = tmp.substr(tmp.length-2);
	tmp= "0" + theDate.getDate();
	d = tmp.substr(tmp.length-2);
	if(bFormatted)
		tmp= y + "-" + m + "-" + d;
	else
		tmp=  y + m + d;
	return tmp;
}

function GetTime(bFormatted) // curr local time
{
	var theDate= new Date(), h,m,tmp;
	tmp= "0" + theDate.getHours();
	h = tmp.substr(tmp.length-2);
	tmp= "0" + theDate.getMinutes();
	m = tmp.substr(tmp.length-2);
	if(bFormatted)
		tmp=h + ":" + m;
	else
		tmp= h + m;
	return tmp;
}

function CheckDate(theDate) 
{
	var x,i,f,iDay,iMonth,szDate;
	szDate=theDate.value;
	if(szDate.length!=8 && szDate.length!=10)
		return false;
	if(szDate.length==10 && (szDate.charAt(4)!='-' && szDate.charAt(7)!='-'))
		return false;
	for(i=0;i<szDate.length;i++)
	{
		f=szDate.charAt(i);
		if((f<'0' || f>'9') && ((f!='-') || (f=='-' && i!=4 && i!=7)))
			return false;
	}	
	x=szDate.length==8?0:1;
	if(szDate.charAt(4+x)>0 && szDate.charAt(5+x)>2)
		return false;
	if(szDate.charAt(4+x)>1 || (szDate.charAt(4+x)==1 && szDate.charAt(5+x)>2))
		return false;
	if((szDate.charAt(6+x*2)==3 && szDate.charAt(7+x*2)>1) || szDate.charAt(6+x*2)>3)
		return false;
	intYear=parseInt(szDate.substr(0,4)) // check year
	if(intYear<1900 || intYear>9999)
		return false;
	return true;
}

function CheckTime(theTime)
{
	if(theTime.value.length<4)
		return false;
	if(theTime.value.length>4 && theTime.value.charAt(2)!=':')
		return false;
	for(i=0;i<theTime.value.length;i++)
		if(isNaN(theTime.value.charAt(i)) && (theTime.value.charAt(i)==':' && i!=2))
			return false;
	x=theTime.value.length==4?0:1;
	if(theTime.value.charAt(0)>2 && theTime.value.charAt(1)>3)
		return false;
	if(theTime.value.charAt(2+x)>6)
		return false;
	return true;
}

function Show(bView) // multi
{
	var d,i,y,obj,c,l1,l2,oC;
	d=currDlg.document.all;

	// Comments reg arguments see function Disable
	var i,args=arguments; 
	if(typeof(arguments[1])=="object")
		args=arguments[1];

	for(i=1;i<args.length;i++)
	{
		obj=d.item(args[i]);
		c=isNaN(obj.length)?c=1:c=obj.length;
		for(y=0;y<c;y++)
		{
			o= c==1?obj:obj(y);
			o.style.display = bView?"inline":"none"; // "block"
			if(o.tagName=="INPUT" || o.tagName=="select-one")
				o.tabIndex=bView?'':-1;
			for(l1=0;l1<o.children.length;l1++)
			{
				oC=o.children[l1];
				if(oC.tagName=="INPUT" || oC.tagName=="select-one")
					oC.tabIndex=bView?'':-1;
				for(l2=0;l2<oC.children.length;l2++)
				{
					if(oC.children[l2].tagName=="INPUT" || oC.children[l2].tagName=="select-one")
						oC.children[l2].tabIndex=bView?'':-1;
				}
			}
		}
	}
}

function SetTab(bTabbed) // multi
{
	return; 
	var i;
	// Comments reg arguments see function Disable
	var i,args=arguments; 
	if(typeof(arguments[1])=="object")
		args=arguments[1];
	for(i=1;i<args.length;i++)
		args[i].tabIndex=bTabbed?'':-1;
}

function Set(bSet,value) // multi
{
	// Comments reg arguments see function Disable
	var i,args=arguments; 
	if(typeof(arguments[1])=="object")
		args=arguments[1];

	for(i=2;i<args.length;i++)
		if(bSet)
			args[i].value=value;
}

function ClassMandatory(value) // multi
{
	// Comments reg arguments see function Disable
	var i,args=arguments; 
	if(typeof(arguments[1])=="object")
		args=arguments[1];

	for(i=1;i<args.length;i++)
		args[i].className=value?"Mandatory":"Optional";
}

function IsMandatory(field)
{
	if(field.className=="Mandatory")
		return true;
	return false;
}

function Is(value) // multi
{
	// Comments reg arguments see function Disable
	var i,args=arguments; 
	if(typeof(arguments[1])=="object")
		args=arguments[1];

	for(i=1;i<args.length;i++)
		if(value==args[i])
			return true;
	return false;
}

function IsNumeric(val,bFloat) // Returns false if field is not numeric or float (bFloat=true)
{
	var f,i;
	bDec=false;
	for(i=0;i<val.length;i++)
	{
		f=val.charAt(i);
		if(((f<'0' || f>'9') && f!=".") || (bFloat && f=='.' && bDec) || (!bFloat && f=='.'))
			return false;
		else if(f=='.')
			bDec=true;
	}
	return true;
}

function SubmitForm(theForm) 
{
	if(Exists(theForm,"Submit"))
		theForm.Submit.disabled=true;
	if(ValidateInput(theForm))
		theForm.submit();
	else
	{
		if(Exists(theForm,"Submit"))
			theForm.Submit.disabled=false;
	}
	return false;
}

function GetDlgInputAsString(f,bIncludeHidden,bIncludeEmpty)
{
	var i,str='';
	for(i=0;i<f.elements.length;i++)
	{
		t=f.elements[i];
		if(t.name!="Template" && (t.type=="checkbox" && t.checked) || (t.type=="radio" && t.checked)|| t.type=="text" || t.type=="select-one" || (bIncludeHidden && t.type=="hidden"))
			if(bIncludeEmpty || (!bIncludeEmpty && t.value!='' && t.value!=' '))
		{
			str= str + FSEP + t.name + PSEP + t.value;
		}
	}
	return str;
}

function GetFieldsToArray(f)
{
	var i;
	for(i=0;i<f.elements.length;i++)
		fields[f.elements[i].name]=f.elements[i];
}

function GetTemplateFields()
{
	var i,f,tmp="",type,name;
	f=currDlg.document.Form;
	for(i=0;i<f.elements.length;i++)
	{
		type=f.elements[i].type;
		if(type=="text" || type=="select-one" || type=="textarea")
			tmp=tmp + f.elements[i].name + ",";
		else if(type=="hidden" && f.elements[i].className=="Template")
			tmp=tmp + f.elements[i].name + ",";
		else if(type=="checkbox")
			tmp=tmp + f.elements[i].name + ",";
	}
	f.TemplateFields.value=tmp;
}

function GetTemplateSingleValue(searchStr,templStr)
{
	var tmp="",pos1;
	searchStr= FSEP + searchStr + PSEP;
	pos=templStr.indexOf(searchStr);
	if(pos>=0)
	{
		pos = pos + searchStr.length;
		for(i=pos;i<templStr.length;i++)
			if(templStr.charAt(i)==FSEP)
				break;
		tmp= templStr.substring(pos,i);
	}
	return tmp;		
}

function GetTemplateValues(str)
{
	var f,i,tmp,s;
	f=currDlg.document.Form;
	arrTempl=str.split(FSEP);
	for(i=0;i<arrTempl.length;i++)
		if(arrTempl[i].length>0)
		{
			tmp=arrTempl[i].split(PSEP);
			field=eval("f." + tmp[0]);
			if(typeof(field)!="undefined")
			{
				type=field.type;
				if(type=="text")
					field.value=tmp[1];
				else if(type=="textarea")
					field.value=Replace(tmp[1],CRLFSEP,CRLF);
				else if(type=="select-one")
				{
					if(field.name=="Agent")
						SetOptionByPart(field,tmp[1]);
					else
						SetOption(field,tmp[1]);
				}
				else if(type=="checkbox" && tmp[1]=='Y')
					field.checked=true;
				if(type=="hidden" && field.className=="Template") // hidden that should be fetched
				{
					if(tmp[0]=="ItemsContent" && tmp[1].length>0) // Fix for when Pcs=0, etc. Dont display when all empty
					{
						
						// only add items content row if Desc exists, a workaround for empty rows saved in templ transfer from old Logiman
						arr=tmp[1].split(ISEP);
						s="";
						for(x=0;x<arr.length;x++) // for each item name and value pair
							if(arr[x].substr(0,3)=="Pcs") // found Pcs itemname
							{   
								if(x<(arr.length-1) && arr[x+1].substr(0,4)!="Desc")
								{ // No Desc item, delete this item row from array
									tst=arr[x].split(LSEP)
									szIdx= tst[0].substr(3) // "Pcs10" -> "10"
									for(y=0;y<arr.length;y++) // for each item in array, locate and delete all with this idx
									{
										tst=arr[y].split(LSEP)
										if(tst[0] == "Pcs" + szIdx) arr[y]="" // delete if same index
										if(tst[0] == "Wgt" + szIdx) arr[y]=""
										if(tst[0] == "Vol" + szIdx) arr[y]=""
										if(tst[0].substr(0,3) == "Ref") // Ref and refQlf if same idx
										{
											xtmp=tst[0].split("_") // split by first occurance of "_" Eg refqlf1_1 or Ref1_1
											if((xtmp[0] = "RefQlf" + szIdx) || (xtmp[0] = "Ref" + szIdx)) arr[y]="" // delete from array
										}
									}
								}
							}
						// Build ItemsContent String back, all unwanted item rows removed
						for(x=0;x<arr.length;x++)
							if(arr[x].length>0)
								s=s + ISEP + arr[x];
						field.value=s;
					}
					else
						field.value=tmp[1];
				}
			}
		}
}

function IsAlphaNum(Str)
{
	return true;
}

function ErrMsg(field,msg,bErase)
{
	var tag;
	alert(msg);
	if(field!=null && field.type!="hidden")
	{
		if(bMSIE)
		{
			tag=IsVisible(field);
			if(tag!="" && !field.disabled)
					Show(true,tag);
		}
		if(bErase)
			field.value="";
		field.focus();
	}
	return false;
}

function FrameExists(parent, framename)
{
	var i;
	if(parent.length>0)
	{
	for(i=0;i<parent.frames.length;i++)
		if(parent.frames[i].name==framename)
			return true;
	}
	return false;
}

// assumes that frame exists (check with FrameExists first)
function GetFrame(parent,framename)
{
	var i;
	for(i=0;i<parent.frames.length;i++)
		if(parent.frames[i].name==framename)
			return parent.frames[i];
	return false;
}
function Exists(form,fieldName) // Checks if field contain any value - accept to check fields that do not exist
{
	var z;
	z=eval("currDlg." + form.name + "." + fieldName)
	if(!z)
		return false;
	return true;
}

function HasLength(form,fieldName)
{
	var f;
	f=eval("currDlg." + form.name + "." + fieldName);
	if(!f)
		return false;
	if(f.type=="select-one")
		val=RTrim(f.options[f.selectedIndex].value);
	else
		val=RTrim(f.value);
	return val.length>0?true:false;
}

function SetOption(select,ourValue)
{
	var bFound=false,i;
	for(i=0;i<select.options.length;i++)
		if(select.options[i].value==ourValue)
		{
			select.options[i].selected=true;
			bFound=true;
		}
	return bFound;
}
// JR 2001-06-20 Set value in option list corresponding to ourValue 
// Looks for a part of each OPTION value separated by sep
// Eg. "AGENTACC»AGENTNAME" is fetched by SetOptionByPart(f.Agent,"AGENTACC»AGENTNAME","»")
// this would set option value based on AGENTACC match on both values.
// Special handling on agent field
// Agent drop down field contains of agentacc + agentname sep by LSEP, but when SetOption we search only
// on agentacc to make it possible for users to change agentname in admin and still get it to work
// with fetching an agent from templates
function SetOptionByPart(select,ourValue) 
{
	var tmp,iPos,tmpOption,sz;
	var bFound=false;

	if(ourValue.search(LSEP)>0) //Contains sep
	{
		sz=ourValue.split(LSEP);
		tmp=sz[0];
	}
	else
		tmp=ourValue;
	for(i=0;i<select.options.length;i++)
	{
		tmpOption=select.options[i].value;
		iPos=tmpOption.search(LSEP);
		if(iPos>0)
		{
			if(tmpOption.substr(0,iPos)==tmp)
			{
				select.options[i].selected=true;
				bFound=true;
			}
		}
	}

	return bFound;
}

function RTrim(str)
{
	var iPos=str.length-1;
	while(str.charAt(iPos)==' ' && iPos>=0)
		iPos--;
	str=str.substr(0,iPos+1);
	return str;
}

function LTrim(str)
{
	var iPos=0;
	while(str.charAt(iPos)==' ' && iPos<str.length)
		iPos++;
	str=str.substr(iPos);
	return str;
}

function GetOptionText(select,val)
{
	var i;
	for(i=0;i<select.options.length;i++)
		if(select.options[i].value==val)
			return select.options[i].text;
	return "";
}

function helpBox(Path,DocName,UserType,Item,Owner)
{
	var wndHelp;
	thefile=Path + "/hlp/help.asp?DocName=" + DocName + "&UserType=" + UserType +"&Item=" + Item + "&Owner=" + Owner;
	wndHelp=currDlg.open(thefile ,"Help","scrollbars=yes,toolbar=no,directories=no,menubar=no,width=500,height=500,resizable=yes");
	wndHelp.focus();
}
var currCalField; // Current calendar field
function CloseCalendar(val)
{
	if(val) alert(val);
	document.all.calendar.style.display="none";	
}
function ShowCalendar(field)
{
	var d=document.all;cal=document.all.calendar,frame="";
	var img=eval("d.img" + field.name);
	currCalField=field;
	cal.style.display="inline";	
	cal.style.left= img.offsetLeft;
	cal.style.top= img.offsetTop;
	frame=GetFrame(window,"calendar");
	frame.Init();
}

function CloseAddrBook()
{
	var ab=document.all.addrbook,bCloseOk=true;
	frame=GetFrame(window,"addrbook");
	if(frame.Form && frame.Form.Display && frame.Form.Display.value=="NoClose")
	{
		bCloseOk=false;
	}
	if(bCloseOk)
	{
		ab.style.display="none";
		ab.style.height=1;
		ab.style.width=1;
	}
}
function ShowAddrBook(szAddrDest)
{
	var d=document.all;ab=document.all.addrbook;
	var img=eval("d.img" + szAddrDest);
	ab.style.display="inline";	
	ab.style.left= img.offsetLeft;
	ab.style.top= img.offsetTop;
	var frame=GetFrame(window,"addrbook");
	frame.Init("ShowSearch",szAddrDest);
}

// Display propertys and its value of an object (for debug use)
function interrogate(obj) 
{
    var sz = '',i,bProp=false;
	if(obj.length)
	{
		for(i=0;i<obj.length;i++)
		{
			sz += "Object[" + i + "]---------------------------------------\r\n";
			for (var prop in obj[i])
			{
				bProp=true;
				sz += prop + "=" + obj[i][prop] + '\n';
			}
			if(!bProp)
				sz += obj;
		}			
	}
	else
		for (var prop in obj)
			sz += prop + "=" + obj[prop] + '\n';
    alert(sz);
}
function St(txt) // Status bar
{
	window.status=txt;
}
///////////////////
// Eg in String "?Owner=TDV&db=$TAT3&Dlg=TEST" set db=$TAT with SetProfileString("db","$TAT",OurUrl)
// sets value if db does not exists or change it if already exists
// Case Sensitive
function SetUrlQueryFieldValue(szTag,szValue,szUrl)
{
	var i,pos;
	pos=szUrl.indexOf(szTag + "=");
	if(pos>-1) // Found , change value
	{
		for(i=pos;i<szUrl.length;i++) // locate end of this query field and its current value
			if(szUrl.charAt(i)=='&') break;
		tmp=szUrl.substr(0,pos) + szTag + "=" + szValue + szUrl.substr(i,szUrl.length-1);
	}
	else // Not found add as new tag
		tmp=szUrl + (szUrl.indexOf("?")==-1?"?":"&") + szTag + "=" + szValue;
	return tmp;
}
