//alert(document.compatMode);
var NamedWindow;
var AscDescColor;
var strNumbers = '0123456789';
var strLetters = 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var CorrectClose = false;

function setCorrectClose()
{
CorrectClose = true; 
}
function setRadioValue(strRadioName, lngValue)
{
	var radioObj = document.getElementById(strRadioName);
	
	// if no radio element 	with that name exists, just quit
	// if (!radioObj) alert(strRadioName + ' does not exist');
	if (!radioObj) return;
	
	var lngRadioLength = radioObj.length;

	if (lngRadioLength == undefined)
	{
		radioObj.checked = (radioObj.value == lngValue.toString());
		return;
	};	

	for (var i = 0; i < radioLength; i++)
	{
		radioObj[i].checked = false;
		if (radioObj[i].value == newValue.toString()) radioObj[i].checked = true;
	}
}

function OpenHelp(strURL)
{  
	var varwidth = 700;
	var varheight = 600;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	HelpWin = window.open(strURL, 'Remote', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
}
function ShowPersonFile (lngClientID, lngPersonID)
{
	//alert(parent.window.opener.document.BodyFrame.location);
	var strURL = '../PersonList/PersonDetail.asp?PersonID=' + lngPersonID + '&CID=' + lngClientID;
	if (parent.window.opener) {
		
		//parent.window.opener.document.BodyFrame.location = strURL;
		parent.window.opener.location = strURL;
	}
	else
	{
	var varwidth = 700;
	var varheight = 600;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	PersonDetail = window.open(strURL, 'Remote', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
	}
}
function OpenNewWindowWS(strURL,varwidth,varheight)
{  

	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	HelpWin = window.open(strURL, 'Remote', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollbars=yes,alwaysRaised=True,resizable=yes');
	HelpWin.focus();
}
function OpenNamedWindowWS(strName,strURL,varwidth,varheight,blnReturnHandle)
{  

	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	NamedWindow = window.open(strURL, strName, 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollbars,alwaysRaised=True,resizable=yes,titlebar=no');
	NamedWindow.focus();
	if (typeof blnReturnHandle == 'undefined') blnReturnHandle = false;
	if (blnReturnHandle) return NamedWindow;
}
function OpenFullscreen(strName,strURL)
{  

	NamedWindow = window.open(strURL, strName, 'fullscreen=yes, scrollbars=auto,titlebar=no,location=no,menubar=no,directories=no,maximized=yes');
	NamedWindow.focus();
}
function SubmitIfEnter(e){
	if (event.keyCode == 13) {
		ActivateProgress();
		document.forms(0).submit();
 		}
}
function SetOrderBy (strField, strSequence, blnOnLoad)
{
	var elemOrderField;
	var elemOrderBy;
	
	if (!AscDescColor) AscDescColor ='';
	
	if (document.images) if (document.images.length)
		for (i=0,n=document.images.length;i<n;i++)
		{
			if (document.images[i].name.substr(0,12)=='OrderBy_ASC_')
			{
				document.images[i].src = '/Code/_Images/ASC' + AscDescColor + '.gif';
			}
			else if (document.images[i].name.substr(0,12)=='OrderBy_DESC')
			{
				document.images[i].src = '/Code/_Images/DESC' + AscDescColor + '.gif';
			}
		}
	elemOrderField = document.getElementById('OrderField');
	elemOrderBy = document.getElementById('OrderBy');
	if (elemOrderField && elemOrderBy)
	if (elemOrderField.value == strField && elemOrderBy.value == strSequence)
	{
		elemOrderBy.value = '';
		elemOrderField.value = '';
	}
	else
	{
		if (document.images['OrderBy_' + strSequence + '_' + strField]) document.images['OrderBy_' + strSequence + '_' + strField].src = '/Code/_Images/'+ strSequence + '_RO.gif';
		elemOrderBy.value = strSequence;
		elemOrderField.value = strField;
	}
	if (blnOnLoad!=true) document.forms[0].submit();
}
function resizeToContent(strIframeName, lngMinWidth, lngMinHeight){
	//alert('resize');
	//alert(document.body.clientHeight);
	//alert(this.document.body.scrollHeight +';' +document.body.clientHeight);
	//alert(parent.document.body.clientWidth + ';' + parent.document.body.clientHeight);
	if (typeof(lngMinWidth) == 'undefined') lngMinWidth = 0;
	if (typeof(lngMinHeight) == 'undefined') lngMinHeight = 0;

	if (parent.frames.length != 0 && parent.document.getElementById(strIframeName) && parent.document.location.toString().indexOf('bodyframeset2') == -1) {
		if (lngMinWidth == 0 && parent.document.getElementById(strIframeName).width) lngMinWidth =parent.document.getElementById(strIframeName).width;
		if (lngMinHeight == 0 && parent.document.getElementById(strIframeName).height) lngMinHeight =parent.document.getElementById(strIframeName).height;
		
		if (parent.document.getElementById(strIframeName).style.height > parent.document.body.clientHeight-100) parent.document.getElementById(strIframeName).style.height=parent.document.body.clientHeight-100;
		if (parent.document.getElementById(strIframeName).style.width > parent.document.body.clientWidth-24) parent.document.getElementById(strIframeName).style.width=parent.document.body.clientWidth-24;;

		var x =0;
		var y =this.document.body.scrollHeight;
			x = y;
			if (parent.document.getElementById(strIframeName)) {
				if(document.body.clientHeight<x) {
					parent.document.getElementById(strIframeName).style.height=Math.max(x,lngMinHeight);
				}
				else {
					parent.document.getElementById(strIframeName).style.height=Math.max(document.body.clientHeight,lngMinHeight);
				}
			}
		x =0;
		y =this.document.body.scrollWidth;		
			x = y;			
			if (parent.document.getElementById(strIframeName)) {
				if(document.body.clientWidth<x) {
					parent.document.getElementById(strIframeName).style.width=Math.max(x,lngMinWidth);
				}
				else {
					parent.document.getElementById(strIframeName).style.width=Math.max(document.body.clientWidth,lngMinWidth);
				}
			}
		//alert(strIframeName + " style.height : " + parent.document.getElementById(strIframeName).style.height + " style.width : " + parent.document.getElementById(strIframeName).style.width);
	}
	if (parent.document.location.toString().indexOf('bodyframeset2') != -1) parent.resizeFrame(true);
}
function IEUpdate () {
	theObjects = document.getElementsByTagName("object"); 
	for (var i = 0; i < theObjects.length; i++) { 
	theObjects[i].outerHTML = theObjects[i].outerHTML; 
	}
}

function OpenNewWindow(strURL)
{  
	var varwidth = 800;
	var varheight = 550;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	HelpWin = window.open(strURL, 'Remote', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
	HelpWin.focus();
}
function OpenNewWindowWM(strURL)
{  
	var varwidth = screen.availWidth;
	var varheight = screen.availHeight;
	var vartop = 0;
	var varleft = 0;
	MaxWin = window.open(strURL, 'RemoteMax', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
	MaxWin.focus();
}
function OpenSecondNewWindowWS(strURL,varwidth,varheight, strName)
{  

	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	HelpWin2 = window.open(strURL, 'Remote2', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
	HelpWin2.focus();
}
function OpenPersonIDSelector(strFormName, strControlName, strControlNameFullName, ForPersonID, CID, bitShortName)
{  
	var varwidth = 250;
	var varheight = 400;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	PersonIDSelector = window.open('/code/pop_select_person.asp?FormName=' + strFormName + '&ControlName=' + strControlName + '&ControlNameFullName=' + strControlNameFullName + '&ForPersonID=' + ForPersonID + '&CID=' + CID + '&ShortName=' + bitShortName + '#' + ForPersonID , 'PersonIDSelector', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
}
function OpenPersonIDSelector2(strFormName, strControlName, strControlNameFullName, ForPersonID, ForPersonName, CID, SCID, bitShortName, strOnSelectFunctions, strModuleID, strMainModuleID, bitUsePLandML, bitSearchInCompany, MCID, MSCID, strExtraParameters)
{  
	var varwidth = 600;
	var varheight = 700;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	var varURL = '/code/pop_select_person.asp?FormName=' + strFormName + '&ControlName=' + strControlName + '&ControlNameFullName=' + strControlNameFullName + '&ForPersonID=' + ForPersonID + '&ForPersonName=' + escape(ForPersonName) + '&CID=' + CID + '&SCID=' + SCID + '&ShortName=' + bitShortName + '&OnSelectFunctions=' + strOnSelectFunctions + '&ModuleID=' + strModuleID + '&MainModuleID=' + strMainModuleID + '&UsePLandML=' + bitUsePLandML + '&SearchInCompany=' + bitSearchInCompany 
	if(MCID!=undefined) varURL += '&MCID=' + MCID
	if(MSCID!=undefined) varURL += '&MSCID=' + MSCID
	if(strExtraParameters!=undefined) varURL += strExtraParameters
	varURL += '#' + ForPersonID
	PersonIDSelector = window.open(varURL , 'PersonIDSelector', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
	//document.writeln('/code/pop_select_person.asp?FormName=' + strFormName + '&ControlName=' + strControlName + '&ControlNameFullName=' + strControlNameFullName + '&ForPersonID=' + ForPersonID + '&ForPersonName=' + escape(ForPersonName) + '&CID=' + CID + '&SCID=' + SCID + '&ShortName=' + bitShortName + '&OnSelectFunctions=' + strOnSelectFunctions + '&ModuleID=' + strModuleID + '&MainModuleID=' + strMainModuleID + '&UsePLandML=' + bitUsePLandML + '&SearchInCompany=' + bitSearchInCompany +'#' + ForPersonID);
}
function OpenCompanyIDSelector(strFormName, strControlName, lngCompanyID, strCompany, CID, SCID, strOnSelectFunctions)
{  
	var varURL = '/code/pop_select_company.asp?FormName=' + strFormName + '&ControlName=' + strControlName + '&CompanyID=' + lngCompanyID + '&Company=' + escape(strCompany) + '&CID=' + CID + '&SCID=' + SCID + '&OnSelectFunctions=' + strOnSelectFunctions
	varURL += '#' + lngCompanyID
	OpenNamedWindowWS('CompanyIDSelector',varURL,600,700);

}

function OpenFolderIDSelector(lngMainFolderID, lngCurrentFolderID, bitStopAtCurrentFID, strFunctionToExcute, CID, AID)
{  
	var varwidth = 400;
	var varheight = 600;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	var strURL = '/Code/ToDo/ToDoFolderBrowser.asp?CID=' + CID + '&AID=' + AID + '&MFID=' + lngMainFolderID + '&CurrentFID=' + lngCurrentFolderID  + '&StopAtCurrentFID=' + bitStopAtCurrentFID + '&FunctionToExcute=' + strFunctionToExcute;
	FolderIDSelector = window.open(strURL, 'FolderIDSelector', 'width='+varwidth+',height='+varheight+',top='+vartop+',left='+varleft+',scrollBars=yes,alwaysRaised=True,resizable=yes');
}
var winInputbox = null;
function Inputbox(strPrompt, strTitle, varDefault, intWidth, intHeight, CID, strFunctionToExcute, strLanguage, strButtons)
{
	switch (strLanguage) {
		case 'NL':
			var strYES = ' Ja ';
			var strNO = 'Nee';
			var strCANCEL = 'Annuleren';
			var strOK = 'OK';
			break;
		default:
			var strYES = 'Yes';
			var strNO = 'No';
			var strCANCEL = 'Cancel';
			var strOK = 'OK';
			break;
			}
  var windowWidth = intWidth;
  var windowHeight = intHeight;
  var locX = ( screen.width - windowWidth ) / 2;
  var locY = ( screen.height - windowHeight ) / 2;
  var windowFeatures = "width=" + windowWidth
                     + ",height=" + windowHeight
                     + ",screenX=" + locX
                     + ",screenY=" + locY
                     + ",left=" + locX
                     + ",top=" + locY
					 + ",toolbars=no,menubar=no,location=no";

  /* Close window first to make sure that our window has */
  /* the desired features */

  if ( ( winInputbox != null )
    && !winInputbox.closed )
  {
    winInputbox.close();
  }
	if (!strButtons) strButtons = 'INPUT,OK,CANCEL'
  /* Open the new confirm */
  winInputbox = open( "", "winInputbox", windowFeatures );

  /* Write to the confirm box */
  var theHTML = '<HEAD><TITLE>' + strTitle + '</TITLE></HEAD>'
  			  + '<link rel="stylesheet" href="/Data/Clients/' + CID + '/BodyIE.css" type="text/css">'
			  + '<link rel="stylesheet" href="/Data/Clients/BodyIE.css" type="text/css">'
              + '<BODY class="INPUTBOX" onLoad="alert(123);document.frmInputBox.InputBoxValue.focus();document.frmInputBox.InputBoxValue.select();">'
              + '<BR><CENTER>'
              + strPrompt
              + '<FORM NAME="frmInputBox" onSubmit="opener.'+ strFunctionToExcute + '(document.frmInputBox.InputBoxValue.value, \'OK\');self.close();">'
  if (strButtons.indexOf('INPUT')>=0) {
			  theHTML += '<INPUT TYPE="text" VALUE="' + varDefault +'" NAME="InputBoxValue"><br><br>'
			  }
			  else {
			  theHTML += '<INPUT TYPE="hidden" VALUE="' + varDefault +'" NAME="InputBoxValue"><br>'
			  }
  if (strButtons.indexOf('OK')>0) { theHTML +='<INPUT TYPE="button" VALUE="' + strOK + '" ONCLICK="opener.'+ strFunctionToExcute + '(document.frmInputBox.InputBoxValue.value, \'OK\');self.close();"> &nbsp;'};
  if (strButtons.indexOf('YES')>0) { theHTML +='<INPUT TYPE="button" VALUE="' + strYES + '" ONCLICK="opener.'+ strFunctionToExcute + '(document.frmInputBox.InputBoxValue.value, \'YES\');self.close();"> &nbsp;'};
  if (strButtons.indexOf('NO')>0) { theHTML +='<INPUT TYPE="button" VALUE="' + strNO + '" ONCLICK="opener.'+ strFunctionToExcute + '(document.frmInputBox.InputBoxValue.value, \'NO\');self.close();"> &nbsp;'};
  if (strButtons.indexOf('CANCEL')>0) {theHTML += '<INPUT TYPE="button" VALUE="' + strCANCEL + '" ONCLICK="opener.'+ strFunctionToExcute + '(null,\'CANCEL\');self.close();">&nbsp;'};
              + '</FORM>'
			  + '</BODY>';

  	winInputbox.document.writeln( theHTML );
	winInputbox.document.frmInputBox.InputBoxValue.select();
	winInputbox.document.frmInputBox.InputBoxValue.focus();
}
var intCounter = 0;
var intMaxCount = 30;
function UpdateProgress(){
	
	var elem = document.getElementById('Progress');
	if (elem) {
		if (intCounter == intMaxCount)
		{	
			if (elem.innerText != undefined) elem.innerText = '.';
			if (elem.innerHTML != undefined) elem.innerHTML = '.';
			intCounter=0;
		}	
		else
		{
			if (elem.innerText != undefined) elem.innerText = elem.innerText + '.';
			if (elem.innerHTML != undefined) elem.innerHTML = elem.innerHTML + '.';
			intCounter++;
		}
	}
}
function ActivateProgress (){
	
	document.body.style.cursor = 'wait';
	setCorrectClose(); 
	var IID = setInterval('UpdateProgress();',100);
	var elem;
	elem = document.getElementById('SubmitLine');
	if (elem) elem.style.display = 'none';
	elem = document.getElementById('ProgressLine');
	if (elem) elem.style.display = '';
}
function resizeToContent_TM(strIframeName){
	
	//alert(document.body.clientHeight);
	//alert(this.document.body.scrollHeight +';' +document.body.clientHeight);
	//alert(parent.document.body.clientWidth + ';' + parent.document.body.clientHeight);
	if (parent.frames.length != 0 && parent.document.getElementById(strIframeName)) {
		//alert(this.document.body.scrollHeight +';' +document.body.clientHeight);
		
		if (parent.document.getElementById(strIframeName).style.height>parent.document.body.clientHeight-100) parent.document.getElementById(strIframeName).style.height=parent.document.body.clientHeight-100;
		if (parent.document.getElementById(strIframeName).style.width > parent.document.body.clientWidth-24) parent.document.getElementById(strIframeName).style.width=parent.document.body.clientWidth-24;;

		var x =0;
		var y =this.document.body.scrollHeight;
		x = y;
			//while (x < y){
			//	x+=1;
			//}
			if (parent.document.getElementById(strIframeName)) {
				if(document.body.clientHeight<x) {
					parent.document.getElementById(strIframeName).style.height=x;
				}
				else {
					parent.document.getElementById(strIframeName).style.height=document.body.clientHeight;
				}
			}
		x =0;
		y =this.document.body.scrollWidth;
		x = y;
		
			//while (x < y){
			//	x+=1;
			//}
			if (parent.document.getElementById(strIframeName)) {
				if(document.body.clientWidth<x) {
					parent.document.getElementById(strIframeName).style.width=x;
				}
				else {
					parent.document.getElementById(strIframeName).style.width=document.body.clientWidth;
				}
			}
	}
}
function resizeWindowToContent(){
	//var x = document.body.clientWidth;
	//var y = document.body.clientHeight;
	//alert (window.innerWidth + ';' + y);
	//if (x < document.body.scrollWidth) x = document.body.scrollWidth;
	//if (y < document.body.scrollHeight) y = document.body.scrollHeight;
	
	//window.resizeTo(y,x)
}
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 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_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;
}

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_setTextOfTextfield() { //v3.0
	var i,args=MM_setTextOfTextfield.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
  	
	var obj = MM_findObj(args[i]); 
  	if (obj) obj.value = args[i+2];
	
  }
}
function htmlEncode(s) {
        var str = new String(s);
        str = str.replace(/&/g, "&amp;");
        str = str.replace(/</g, "&lt;");
        str = str.replace(/>/g, "&gt;");
        str = str.replace(/"/g, "&quot;");
        return str;
} 
function GoToPage(intPageNO){
	document.forms[0].PageNO.value = intPageNO;
	document.forms[0].submit();
}
function mousePos(e){
	
	if (document.all) {
        x = (document.layers) ? event.pageX : event.clientX;
        y = (document.layers) ? event.pageY : event.clientY;
		y = y + document.body.scrollTop;
	}
	else {
		x = (document.layers) ? e.pageX : e.clientX;
       	y = (document.layers) ? e.pageY : e.clientY;
	}
	
	var elem = document.getElementById('ScrollTopValue');
	if (elem) {
		elem.value = document.body.scrollTop;
	}
}
function GetXmlHttpObject()
{ 
	var objXMLHttp = null;
	if (window.XMLHttpRequest)
		objXMLHttp = new XMLHttpRequest();
	else if (window.ActiveXObject)
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	return objXMLHttp;
}

function CallAJAXURL(strURL,FunctionOnreadystatechange)
{	
	//alert (strURL);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		//alert ("Browser does not support HTTP Request");
		return;
	} 
	strURL=strURL+"&randomid="+Math.random();
	xmlHttp.open("GET",strURL,true);
	if (typeof(FunctionOnreadystatechange) != "undefined") xmlHttp.onreadystatechange = FunctionOnreadystatechange;
	xmlHttp.send(null);	
	return xmlHttp;
} 
function CallAJAXURLNoReturn(strURL)
{	
	//alert (strURL);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	//alert ("Browser does not support HTTP Request");
	return
	} 
	strURL=strURL+"&sid="+Math.random();
	xmlHttp.open("GET",strURL,true);
	//if (typeof(FunctionOnreadystatechange) != "undefined") xmlHttp.onreadystatechange = FunctionOnreadystatechange;
	xmlHttp.send(null);	
	//return xmlHttp;
}
function GetSJAXSingleValue(strURL)
{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	//alert ("Browser does not support HTTP Request");
		return null;
	} 
	strURL=strURL+"&sid="+Math.random();
	xmlHttp.open("GET",strURL,false);
	xmlHttp.send(null);	
	var sjaxResponse = xmlHttp;
	var records =  sjaxResponse.responseText.split("<br>");			
	var results = records[0].split("___"); 	
	return results[0];
} 
function DoNothing () {
	
}
function GetWindowWidth() // Call GetWindowWidth() after body.onload -> Not earlier!
{
	varWindowWidth = 0;
	if (typeof(window.innerWidth) == 'number')
	{
		//Non-IE
		varWindowWidth = window.innerWidth;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
	    varWindowWidth = document.documentElement.clientWidth;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		varWindowWidth = document.body.clientWidth;
	}
	return varWindowWidth;
}
function GetWindowHeight() // Call GetWindowHeight() after body.onload -> Not earlier!
{
	var varWindowHeight = 0;
	if (typeof(window.innerHeight) == 'number')
	{
		//Non-IE		
		varWindowHeight = window.innerHeight;
	}	
	else if (document.documentElement && (document.documentElement.clientHeight || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'	    
		varWindowHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientHeight || document.body.clientHeight))
	{
		//IE 4 compatible
		varWindowHeight = document.body.clientHeight;
	}
	return varWindowHeight;
}
function ValidateEmail(strEmail) {

	return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
		
}
function ResizeToContent(lngWidth, lngHeight)
{
	
	window.resizeTo(lngWidth, lngHeight);
	var w = Math.max(document.body.scrollWidth,document.body.offsetWidth,lngWidth - 50)+50;
	var h = Math.max(document.body.scrollHeight,document.body.offsetHeight,lngHeight - 80)+80;
	window.resizeTo(w,h);
}
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() {obj["e"+type+fn](window.event);}
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}

function fbs_click(u, t) {

	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function Round(dblValue, intNODecimals) {
	
	var dblMultiplier = 1;
	for (x=1; x<=intNODecimals; x++) 
	{ 
		dblMultiplier = dblMultiplier * 10;
	} 
	var dblResult = Math.round(dblValue * dblMultiplier)/dblMultiplier;
	return dblResult;
}
function CleanNumber(control) {
	
	var str = control.value;
	var standardNo = str.replace(/[^\d]/g,'') 
	control.value = standardNo;
}
function SelectBullet(strID, x){
//Control needs to have ID format CONTROLNAME_x
//<a href needs to have ID format TEXT_CONTROLNAME_x
//x can start from 0 or 1
	for (i=0,n=100;i<=n;i++) {
		if(document.getElementById('TEXT_' + strID + '_' + i)){
			document.getElementById('TEXT_' + strID + '_' + i).className='';
		}
		else {
			if (i>0) {
				break;
			}
		}
	}
	document.getElementById('TEXT_' + strID + '_' + x).className='emphasis';
	document.getElementById(strID + '_' + x).checked=true;
}
function WriteUserWait()
{
	var topelem = (top.document.body);
	var divelem = top.document.getElementById('UserWaitOverlay');
	
	if (!divelem)
	{
		var strBodyHTML = topelem.innerHTML;
		var strElem = '';
		strElem += '<div id="UserWaitOverlay" style="text-align:center;position:absolute;top:1px;left:1px;padding:0px;margin:0px;z-index:1000;"></div>' + '\n';
		strElem += '<img id="UserWaitImage" src="/Code/_Images/loader_50.gif" style="position:fixed;height:50px;width:50px;left:0px;top:0px;padding:0px;margin:0px;border:none;z-index:1001;">' + '\n';
		topelem.innerHTML = strElem + strBodyHTML;
		divelem = top.document.getElementById('UserWaitOverlay');				
	}
	
	EndUserWait();
}
function StartUserWait()
{	
	WriteUserWait()
	
	var topelem = (top.document.body);
	var divelem = top.document.getElementById('UserWaitOverlay');
	
	if (divelem)
	{
		divelem.style.width = Math.max(topelem.scrollWidth, (topelem.width||0), (topelem.offsetWidth||0));
		if ((divelem.style.width||0) < 100) divelem.style.width = '100%';
		divelem.style.height = Math.max(topelem.scrollHeight, (topelem.height||0), (topelem.offsetHeight||0));
		if ((divelem.style.height||0) < 100) divelem.style.height = '100%';
		divelem.style.display = 'block';
		var imgelem = top.document.getElementById('UserWaitImage');		
		imgelem.style.marginLeft = parseInt(Math.max((window.innerWidth||0),topelem.offsetWidth) / 2) + 'px';
		imgelem.style.marginTop = parseInt(Math.max((window.innerHeight||0),topelem.offsetHeight, ((top.document.documentElement||topElem).clientHeight||0)) / 2) + 'px';
		imgelem.style.display = 'block';
	}
}
function EndUserWait()
{
	var elem;
	elem = top.document.getElementById('UserWaitOverlay');
	if (elem) elem.style.display = 'none';
	elem = top.document.getElementById('UserWaitImage');
	if (elem) elem.style.display = 'none';
}	
function SendPassword (strConfirmation) {
	
	var strEmail = document.getElementById('Email').value;
	var lngClientID = document.getElementById('CID').value;
	var lngSubClientID = document.getElementById('SCID').value;
	var strURL;
	strURL = '/Code/SendPassword.asp?CID=' + lngClientID + '&SCID=' + lngSubClientID + '&Email=' + strEmail + '&Fullpage=1';
	if (strEmail != '') {
		
		//CallAJAXURL(strURL);
		window.location.href = strURL;
		//alert(strConfirmation + ' ' + strEmail);
	}
}
function IsNumeric(strValue, blnAllowNegative)
{
	if (typeof(blnAllowNegative) == 'undefined') blnAllowNegative = false;
	var strValidChars = '0123456789.';	
	var blnIsNumeric = true;
	var i = 0;
	if (strValue.length>1) if (strValue.charAt(0) == '-' && blnAllowNegative) i++;
	while (i < strValue.length && blnIsNumeric)
	{
		blnIsNumeric = !(strValidChars.indexOf(strValue.charAt(i)) == -1)
		i++;
	}
	return blnIsNumeric;
}
function resizeIFrame(strFrameName, lngMinWidth, lngMinHeight)
{
	if (typeof(lngMinWidth)=='undefined') lngMinWidth = 500;
	if (typeof(lngMinHeight)=='undefined') lngMinHeight = 500;

	var IFr;
	var strTest;
	
	IFr = window.frames[strFrameName];
	try
	{
		document.getElementById(strFrameName).height = lngMinHeight;
		document.getElementById(strFrameName).height = lngMinWidth;
	
		var intRealWidth;
		var intRealHeight;
			
		intRealWidth = Math.max(IFr.document.body.scrollWidth, IFr.document.body.offsetWidth, lngMinWidth-20) + 20;
		intRealHeight = Math.max(IFr.document.body.scrollHeight, IFr.document.body.offsetHeight, lngMinHeight-20) + 20;
	
		if (document.getElementById(strFrameName).width != intRealWidth) document.getElementById(strFrameName).width = intRealWidth;
		if (document.getElementById(strFrameName).height != intRealHeight) document.getElementById(strFrameName).height = intRealHeight;
		
	}
	catch(err)
	{
		alert(err.description)
		return false;
	}
}
function SetElemValue(strElem, varValue)
{
	var elem;
	var elemRadio;
	
	//convert boolean to 1 or 0
	if (varValue!='' && (varValue == true || varValue.toString().toUpperCase() == 'TRUE')) varValue = 1;
	if (varValue!='' && (varValue == false || varValue.toString().toUpperCase() == 'FALSE')) varValue = 0;
	
	elemRadio = document.getElementById(strElem + '_' + varValue);
	if (!elemRadio)	elem = document.getElementById(strElem); 
	
	// do nothing if element doesn't exist
	if (!elem && !elemRadio) return;
	
	// if the element is a radiobutton
	if (elemRadio)
	{
		elemRadio.checked=true;
	}
	
	// if the element is a select
	if (elem) if (elem.options)
	{
		varValue = ',' + varValue + ',';			
		varValue = varValue.replace(',,',',');
		for (var x=0; x<elem.options.length; x++)
		{
			//alert(varValue + ' <- ,'+elem.options[x].value+', : ' + (varValue.indexOf(','+elem.options[x].value+',') >= 0).toString());			
			if (varValue.indexOf(','+elem.options[x].value+',') >= 0) elem.options[x].selected=true;
		}
		return;
	}

	// if the element is a checkbox or text field
	if (elem) if (elem.value)
	{		
		if (CBool(elem.value)==CBool(varValue)) elem.checked=true;
		elem.value=varValue;
	}
	else
		elem.value=varValue;
}
function ResizeMe()
{
	var w = document.body.offsetWidth + 8;
	var h = document.body.offsetHeight + 80;
	var blnResize = false;
	if (document.body.scrollWidth > document.body.offsetWidth - 10) {
		
		w = document.body.scrollWidth + 30;
		blnResize = true;
	}
	if (document.body.scrollHeight > document.body.offsetHeight) {
		
		h = document.body.scrollHeight + 100;
		blnResize = true;
	}
	
	if (blnResize == true) {window.resizeTo(w,h);}
}
function CBool(objValue)
{
	if (objValue.toString().toLowerCase() == 'true') return true;
	if (objValue == 1) return true;
	if (objValue == -1) return true;
	return false;
}
function HasClass(elem,strClassName)
{
	return elem.className.match(new RegExp('(\\s|^)'+strClassName+'(\\s|$)'));
}
function AddClass(elem,strClassName)
{
	if (!HasClass(elem,strClassName)) elem.className += " " + strClassName;
}
function RemoveClass(elem,strClassName)
{
	if (HasClass(elem,strClassName)) elem.className=elem.className.replace(new RegExp('(\\s|^)'+strClassName+'(\\s|$)'),' ');
}
function TelephoneInput_Correct(strInputName)
{
	var strInternal = '';
	var strOldInternal = '';
	var strNumber;
	var strCleanNumber;
	var oldExternalElem;
	var newExternalElem;
	var lngInternalLocation;
	var elem;

	oldExternalElem = document.getElementById('Old_External_' + strInputName);
	if (oldExternalElem) if (oldExternalElem.value) if (oldExternalElem.value.indexOf('-') > 0)
		strOldInternal = oldExternalElem.value.substring(oldExternalElem.value.indexOf('-') + 1);
	//alert("strOldInternal : " + strOldInternal + ' from ' + oldExternalElem.value );
		
	newExternalElem = document.getElementById('External_' + strInputName);
	if (newExternalElem) if (newExternalElem.value) if (newExternalElem.value.indexOf('-') > 0)
		strInternal = newExternalElem.value.substring(newExternalElem.value.indexOf('-') + 1);
	//alert("strInternal : " + strInternal + ' from ' + newExternalElem.value );

    elem = document.getElementById('Number_' + strInputName);
    if (elem && newExternalElem) {
        strNumber = elem.value.replace('(','').replace(')','');
        if (strNumber.charAt(0) == '+' && strNumber.indexOf('-') >= 0) {
            strTempExternal = strNumber.substr(1, strNumber.indexOf('-') - 1);
            for (var i = 0; i < newExternalElem.options.length; i++) {
                strOptionValue = newExternalElem.options[i].value;
                newExternalElem.options[i].selected = false;
                if (strOptionValue.substr(strOptionValue.indexOf('+') + 1, (strOptionValue.indexOf('-') - 1) - strOptionValue.indexOf('+')) == strTempExternal) {
                    if (strNumber.substr(strNumber.indexOf('-') +1).indexOf(strOptionValue.substr(strOptionValue.indexOf('-') + 1)) == 0) {
                        newExternalElem.options[i].selected = true;
                        strInternal = strOptionValue.substr(strOptionValue.indexOf('-') + 1);
                        elem.value = strNumber.substr(strNumber.indexOf('-') + strInternal.length + 1);
                    }
                }
            }
        }
    }

	if (oldExternalElem && newExternalElem) oldExternalElem.value = newExternalElem.value.toString();

	Input_Clean("Number_" + strInputName, strNumbers);
	strNumber = '';
	elem = document.getElementById('Number_' + strInputName);
    if (elem) {
        strNumber = elem.value;
        if (strOldInternal) if (strNumber.substr(0, strOldInternal.length) == strOldInternal) strNumber = strNumber.substr(strOldInternal.length);
        if (strInternal) strNumber = '(' + strInternal + ')' + strNumber
        elem.value = strNumber;
    }
	elem = document.getElementById(strInputName);
	if (elem)
	{
		if (strNumber.length > strInternal.length + 2 || (strNumber.length > 0 && strInternal.length==0))
		{
			if (newExternalElem) elem.value = newExternalElem.value;
			else if (oldExternalElem) elem.value = oldExternalElem.value;
			elem.value += strNumber.replace('(','').replace(')','').substring(strInternal.length);
		}
		else elem.value = '';
		//alert("elem : " + elem.value);
	}
	
	oldExternalElem = null;
	newExternalElem = null;
	elem = null;
	// if there is a function called CopyOrderAddressMasterValuesToSlaves then execute it
	// -> this is to adjust the slave OrderAddress Telephone inputs to the Master OrderAddress Telephone Inputs in WS_Order_Confirm.asp
	if(typeof CopyOrderAddressMasterValuesToSlaves == 'function') CopyOrderAddressMasterValuesToSlaves();
}
function Input_AcceptKey(objEvent, strAcceptedChars)
{
	strAcceptedChars += String.fromCharCode(0); // control chars ~ home, end, etc
	strAcceptedChars += String.fromCharCode(8); // backspace
	strAcceptedChars += String.fromCharCode(13); // enter
	
	if (objEvent.ctrlKey) return true;

	var lngKeyCode;
	lngKeyCode = document.all ? parseInt(objEvent.keyCode) : parseInt(objEvent.which);
	//if (strAcceptedChars.indexOf(String.fromCharCode(lngKeyCode))!=-1) return true; else { alert(lngKeyCode); return false;} // UNCOMMENT TO DEBUG
	return (strAcceptedChars.indexOf(String.fromCharCode(lngKeyCode))!=-1);
}
function Input_Clean(strInputName, strAcceptedChars)
{
	var elem;
	var strOldValue;
	var strCleanValue = '';
	elem = document.getElementById(strInputName);
	if (elem)
	{
		strOldValue = elem.value;
		for (var x=0;x<strOldValue.length;x++) if (strAcceptedChars.indexOf(strOldValue.charAt(x))!=-1) strCleanValue+=strOldValue.charAt(x);
		elem.value = strCleanValue;
	}
}
function CreateCookie(strName,varValue,lngDaysValid)
{
	var strExpires = "";
	if (lngDaysValid)
	{
		var dteDate = new Date();
		dteDate.setTime(dteDate.getTime() + (lngDaysValid*24*60*60*1000) );
		strExpires = "; expires=" + dteDate.toGMTString();
	}
	document.cookie = strName + "=" + varValue + strExpires + "; path=/";
}

function ReadCookie(strName)
{
	var strNameEQ = strName + "=";
	var arCookies = document.cookie.split(';');
	for(var i=0; i < arCookies.length; i++)
	{
		var strCookie = arCookies[i];
		while (strCookie.charAt(0) == ' ') strCookie = strCookie.substring(1, strCookie.length);
		if (strCookie.indexOf(strNameEQ) == 0) return strCookie.substring(strNameEQ.length, strCookie.length);
	}
	return null;
}

function EraseCookie(strName)
{
	createCookie(strName,"",-1);
}

function Common_ResizeFrame(strFrameName, lngMinWidth, lngMinHeight)
{

	var strTest;
	var objFrame = window.frames[strFrameName];
	var objElem = document.getElementById(strFrameName);

	if (typeof(lngMinWidth)=='undefined') lngMinWidth = 500;
	if (typeof(lngMinHeight)=='undefined') lngMinHeight = 500;

	if (lngMinWidth=='LARGER_ONLY')
	{
			lngMinWidth = (objElem.width || objElem.style.width || 500) - 20;
			//alert(objElem.width + ' || ' + objElem.style.width + ' || 500  --> ' +  lngMinWidth);
	}

	var elem;
	try
	{
		if (objElem && objFrame)
		{
			objElem.height = lngMinHeight;
			objElem.width = lngMinWidth;
		
			var intRealWidth;
			var intRealHeight;
			
			//alert(objFrame.document.body.scrollHeight + ' ~ ' + objFrame.document.body.offsetHeight + ' ~ ' + lngMinHeight);
			
			intRealWidth = Math.max(objFrame.document.body.scrollWidth, objFrame.document.body.offsetWidth, lngMinWidth-20) + 20;
			//intRealHeight = Math.max(IFr.document.body.scrollHeight, IFr.document.body.offsetHeight, lngMinHeight-20) + 20;
			intRealHeight = Math.max(objFrame.document.body.scrollHeight, lngMinHeight-20) + 20;
		
			//alert('width : ' + objElem.width + " -> " + intRealWidth);
			//alert('height : ' + objElem.height + " -> " + intRealHeight);
			
			objElem.width = intRealWidth;
			objElem.height = intRealHeight;
			
			elem = document.getElementById('IFrame_' + strFrameName + '_BackGround_Image');
			if (elem)
			{
				elem.style.width = Math.max(850,intRealWidth+50) + 'px';
				elem.style.height = intRealHeight+180 + 'px';
			}
			
			elem = document.getElementById('IFrame_' + strFrameName + '_Dummy');
			if (elem)
			{
				elem.style.width = Math.max(850,intRealWidth+50) + 'px';
				elem.style.height = intRealHeight+180 + 'px';
			}
		}
		
	}
	catch(err)
	{
		alert(err.description)
		return false;
	}
}
function Common_ResizeFrame_AskParentToResizeMe(strIFrameName)
{
	if (window.parent)
		if (window.parent.Common_ResizeFrame)
			window.parent.Common_ResizeFrame(strIFrameName, 'LARGER_ONLY')
}
function JSDbl(varValue)
{
	var strCleaned = varValue.replace(',','.');
	var dblCleaned = parseFloat(strCleaned);
	return dblCleaned;
}
function GetParentForm(elem)
{
	if (typeof(elem) == 'undefined') elem = this;
	
	var parentElem = elem.parentNode;
	var strParentTagName
	
	if (!parentElem) return null;
	
	if (parentElem.tagName)
		strParentTagName = parentElem.tagName.toLowerCase();
	else
		strParentTagName = '';
	while (strParentTagName != 'form' && strParentTagName != 'body' && parentElem.parentNode)
	{
		parentElem = parentElem.parentNode;
		if (parentElem.tagName)
			strParentTagName = parentElem.tagName.toLowerCase();
		else
			strParentTagName = '';
	}
	
	if (strParentTagName == 'form')
		return parentElem;
	else
		return null;
}
function ChangeClientID (intCID, intSCID){
	
	document.frmChangeClient.ChangeCID.value = intCID;
	document.frmChangeClient.ChangeSCID.value = intSCID;
	document.frmChangeClient.submit();
}
function ChangeSubClientID (intSCID){
	
	document.frmChangeClient.ChangeSCID.value = intSCID;
	document.frmChangeClient.submit();
}
function SetDBSUID(strDBSUID) {
	document.getElementById('DBSUID').value = strDBSUID;
	ReloadForm();
}
