//alert(document.compatMode);
var NamedWindow;
var AscDescColor;
var strNumbers = '0123456789';
var strLetters = 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var CorrectClose = false;
var strHrefExtension;
MM_preloadImages('/Code/_Images/progress-bar.gif','/Code/_Images/Loadbar_100.gif','/Code/_Images/loader_16.gif');

Array.prototype.clear = function () { this.length = 0; };
Array.prototype.add = function (parElem) {
    this[(this.length || 0)] = parElem;
    return this.length - 1;
} // Array.prototype.add = function (parElem)

window.center = function(){

	// obviously only works when this isn't an iframe
	if (window.parent == window) {

		var lngWidth = $(window.document).width();
		var lngHeight = $(window.document).height();
	
		//half the screen width minus half the window width (plus 5 pixel borders).
		var lngLeft = (this.screen.availWidth - lngWidth)/2;
		
		//half the screen height minus half the window height (plus title and status bars).
		var lngTop = (this.screen.availHeight - lngHeight)/2;
		
		//Move the window.
		this.moveTo(lngLeft, lngTop);

	} // if (window.parent == window)

} // window.center

function Querystring(parKey, parDefault)
{
  if (parDefault==null) parDefault='';
  parKey = parKey.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
  var regex = new RegExp('[\\?&]' + parKey + '=([^&#]*)');
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return parDefault;
  else
    return unescape(qs[1]);
}

function isObject() {
	if (typeof arguments[0] != 'object') return false;
	return (arguments[0].constructor == null || arguments[0].constructor.toString().match(/string/i) == null);
}

function isString() {
	if (typeof arguments[0] == 'string') return true;
	if (typeof arguments[0] == 'object'){
		return (arguments[0].constructor != null && arguments[0].constructor.toString().match(/string/i) != null);
	}
	return false;
}

function isArray()
{
	if (typeof arguments[0] == 'object'){
		var criterion = arguments[0].constructor.toString().match(/array/i); 
		return (criterion != null);
	}
	return false;
}

function setCorrectClose(){
	CorrectClose = true; 
}

function setRadioValue(radioObj, newValue)
{
	//var radioObj = document.getElementsByName(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 == newValue.toString());
		return;
	};

	for (var i = 0; i < lngRadioLength; i++)
	{
		radioObj[i].checked = false;
		if (radioObj[i].value == newValue.toString()) radioObj[i].checked = true;
	}
}

function getRadioValue(radioObj)
{	
	// if no radio element 	with that name exists, just quit
	// if (!radioObj) alert(strRadioName + ' does not exist');
	if (!radioObj) return;
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return '';
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return '';
}
function getCheckboxValue(checkboxObj)
{	
	// if no radio element 	with that name exists, just quit
	// if (!radioObj) alert(strRadioName + ' does not exist');
	var varValue = '';
	if (!checkboxObj) return;
	var checkboxLength = checkboxObj.length;
	if(checkboxLength == undefined)
		if(checkboxObj.checked)
			return checkboxObj.value;
		else
			return '';
	for(var i = 0; i < checkboxLength; i++) {
		if(checkboxObj[i].checked) {
			if (varValue != '') {varValue += ','};
			varValue += checkboxObj[i].value;
		}
	}
	return varValue;
}
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, blnPrint)
{  

	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 blnPrint == 'undefined') blnPrint = false;
	if (blnPrint) NamedWindow.print();
	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 ReloadIfEnter(e){
	if (event.keyCode == 13) {
		ReloadForm();
 		}
}
function nextField(current){
	for (i = 0; i < current.form.elements.length; i++){
		if (current.form.elements[i].tabIndex == current.tabIndex+1) {
			current.form.elements[i].focus();                 
			if (current.form.elements[i].type == "text")  {                      
				current.form.elements[i].select();                 
			}
		}
	}
}
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) {
		SetSubmitLoader();
		document.forms[0].submit();
	}
}
function resizeToContent(strIframeName, lngMinWidth, lngMinHeight){

	if (window.resize) { window.resize(); return; }
	
	//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);
	
	var varDBSUID = Querystring("DBSUID")
	if (varDBSUID == '') {
		varDBSUID = document.getElementById('DBSUID');
		if (varDBSUID) varDBSUID = varDBSUID.value;
	} // if (varDBSUID == '')
	
	var varURL = '/code/pop_select_person.asp?FormName=' + strFormName + '&ControlName=' + strControlName + '&ControlNameFullName=' + strControlNameFullName + '&ForPersonID=' + ForPersonID + '&CID=' + CID + '&ShortName=' + bitShortName + '#' + ForPersonID;
	if (varDBSUID) varURL += '&DBSUID=' + escape(varDBSUID)
	
	PersonIDSelector = window.open(varURL , '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 = 700;
	var varheight = 800;
	var vartop = Math.floor((screen.availHeight-varheight)/2);
	var varleft = Math.floor((screen.availWidth-varwidth)/2);
	
	var varDBSUID = Querystring("DBSUID")
	if (varDBSUID == '') {
		varDBSUID = document.getElementById('DBSUID');
		if (varDBSUID) varDBSUID = varDBSUID.value;
	} // if (varDBSUID == '')
	
	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
	if (varDBSUID) varURL += '&DBSUID=' + escape(varDBSUID)
	
	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 varDBSUID = Querystring("DBSUID")
	if (varDBSUID == '') {
		varDBSUID = document.getElementById('DBSUID');
		if (varDBSUID) varDBSUID = varDBSUID.value;
	} // if (varDBSUID == '')

	var varURL = '/code/pop_select_company.asp?FormName=' + strFormName + '&ControlName=' + strControlName + '&CompanyID=' + lngCompanyID + '&Company=' + escape(strCompany) + '&CID=' + CID + '&SCID=' + SCID + '&OnSelectFunctions=' + strOnSelectFunctions
	if (varDBSUID) varURL += '&DBSUID=' + escape(varDBSUID)
	
	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 varDBSUID = Querystring("DBSUID")
	if (varDBSUID == '') {
		varDBSUID = document.getElementById('DBSUID');
		if (varDBSUID) varDBSUID = varDBSUID.value;
	} // if (varDBSUID == '')
	
	var strURL = '/Code/ToDo/ToDoFolderBrowser.asp?CID=' + CID + '&AID=' + AID + '&MFID=' + lngMainFolderID + '&CurrentFID=' + lngCurrentFolderID  + '&StopAtCurrentFID=' + bitStopAtCurrentFID + '&FunctionToExcute=' + strFunctionToExcute;
	if (varDBSUID) strURL += '&DBSUID=' + escape(varDBSUID)
	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 = 120;

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++;
	//	}
	//}
	var elem = document.getElementById('PF_Progressbar');
	if (elem) {
		if (intCounter == intMaxCount)
		{	
			document.getElementById('PF_ProgressTD').align = (document.getElementById('PF_ProgressTD').align=='left') ? 'right':'left';
			intCounter=0;
		}	
			elem.width = (document.getElementById('PF_ProgressTD').align == 'left') ? intCounter : intMaxCount-intCounter;
			intCounter++;
			
	} else {
		
		var elem = document.getElementById('Progressbar');
		if (!elem) {
			var elem = document.getElementById('Progress');
			if (elem) {
				var strText = '<br><table width="120" height="12" border="0" cellpadding="0" cellspacing="0"><tr><td id="ProgressTD" align="left" style="overflow:hidden"><img src="/Code/_Images/progress-bar.gif" id="Progressbar" width="0" height="12"></td></tr></table>';
				//if (elem.innerText != undefined) elem.innerText = strText;
				//if (elem.innerHTML != undefined) elem.innerHTML = strText;
				elem.innerHTML = strText;
			} else {
				var elem = document.getElementById('ProgressSL');
				if (elem) {
					var strText = '<table width="120" height="12" border="0" cellpadding="0" cellspacing="0"><tr><td id="ProgressTD" align="left" style="overflow:hidden"><img src="/Code/_Images/progress-bar.gif" id="Progressbar" width="0" height="12"></td></tr></table>';
					//if (elem.innerText != undefined) elem.innerText = strText;
					//if (elem.innerHTML != undefined) elem.innerHTML = strText;
					elem.innerHTML = strText;
				} 	
			}
		}
		var elem = document.getElementById('Progressbar');
		if (elem) {
			if (intCounter == intMaxCount)
			{	
				document.getElementById('ProgressTD').align = (document.getElementById('ProgressTD').align=='left') ? 'right':'left';
				intCounter=0;
			}	
				elem.width = (document.getElementById('ProgressTD').align == 'left') ? intCounter : intMaxCount-intCounter;
				intCounter++;
			
		}
	}
	if (window.resize) window.resize();
}
function ActivateProgress (){
	document.body.style.cursor = 'wait';
	setCorrectClose(); 
	//return true;
	setInterval(UpdateProgress, 25);
	var elem;
	elem = document.getElementById('PF_SubmitLine');
	if (elem) {
		elem.style.display = 'none';
		elem = document.getElementById('PF_ProgressLine');
		if (elem) elem.style.display = '';
	} else {
		
		elem = document.getElementById('SubmitLine');
		if (elem) elem.style.display = 'none';
		elem = document.getElementById('CloseLine');
		if (elem) elem.style.display = 'none';
		elem = document.getElementById('ProgressLine');
		if (elem) elem.style.display = '';	
	}
	UpdateProgress();
	
	return false;
}
function DeActivateProgress (){
	document.body.style.cursor = 'default';
	var elem;
	elem = document.getElementById('PF_SubmitLine');
	if (elem) {
		elem.style.display = '';
		elem = document.getElementById('PF_ProgressLine');
		if (elem) elem.style.display = 'none';
	} else {
		elem = document.getElementById('SubmitLine');
		if (elem) elem.style.display = '';
		elem = document.getElementById('ProgressLine');
		if (elem) elem.style.display = 'none';
	}
}
function resizeToContent_TM(strIframeName){
	
	if (window.resize) { window.resize(); return; }
	
	//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 AJAXUpdateSingleField(strTable, strField, lngID, strNewValue)
	{
		var strURL = '/Code/_CommonCode/AJAX_Generic.asp?Proc=UpdateSingleField&' + strHrefExtension;
		strURL += '&Table=' + strTable;
		strURL += '&Field=' + strField;
		strURL += '&ID=' + lngID;
		strURL += '&NewValue=' + strNewValue;
		//prompt('url',strURL);
		CallAJAXURLNoReturn(strURL);	
	}
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 LoaderImage(lngSize){
	
	var strImg = '<img src="/Code/_Images/loader_16.gif" border="0">';
	
	return strImg;
}
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)
{
	
	if (window.resize) { window.resize(); return; }
	
	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(objElement, strEventName, strCodeToExecute) {
	
	if (isString(objElement)) objElement = document.getElementById(objElement);
	
	if (!objElement) return;
	if (!strEventName) return;
	if (!strCodeToExecute) return;
	
	if (typeof (strCodeToExecute) != "function") strCodeToExecute = Function(strCodeToExecute);
	
	if (objElement.addEventListener)
		objElement.addEventListener(strEventName, strCodeToExecute, false);
		
	// Internet Explorer
	else if (objElement.attachEvent)
		objElement.attachEvent("on"+strEventName, function(){ strCodeToExecute.call(objElement); });
}

function triggerEvent(objElement, strEventName) {
	
	if (isString(objElement)) objElement = document.getElementById(objElement);
	
	if (!objElement) return;
	if (!strEventName) return;
	
    if (document.createEvent) {
		var objEvent = document.createEvent('HTMLEvents');
		objEvent.initEvent(strEventName, true, true);
        return objElement.dispatchEvent(objEvent);
    }
 
    // Internet Explorer
    else if (objElement.fireEvent)
        return objElement.fireEvent('on' + strEventName);
}

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>10) {
				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;			
	}
	
	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 (strEmail) {
	
	var strEmail;
	if (document.getElementById('Login_Email')) {
		strEmail = document.getElementById('Login_Email').value;
	} else {
		strEmail = document.getElementById('Email').value;
	}
	if (strEmail != '') {
		
		var lngClientID = document.getElementById('CID').value;
		var lngSubClientID = document.getElementById('SCID').value;
		var strLanguage = document.getElementById('LC').value;
		
		var varDBSUID = Querystring("DBSUID")
		if (varDBSUID == '') {
			varDBSUID = document.getElementById('DBSUID');
			if (varDBSUID) varDBSUID = varDBSUID.value;
		} // if (varDBSUID == '')
		
		var strURL = '/Code/SendPassword.asp?CID=' + lngClientID + '&SCID=' + lngSubClientID + '&LC=' + strLanguage + '&Email=' + strEmail + '&AJAX=1&Popup=1';
		if (varDBSUID) strURL += '&DBSUID=' + escape(varDBSUID)
		
		var response;
		response = GetSJAXSingleValue(strURL);
		alert (response);
	}
}
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 (window.resize) { window.resize(); return; }
	
	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()
{
	if (window.resize) { window.resize(); return; }
	
	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 SetProcessFlowCookie(lngProcessFlowID, strVarName, varValue) {
	
	CreateCookie('PF_' + lngProcessFlowID + '_' + strVarName,varValue);
	
}
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 + escape(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)
{
	if (window.resize) { window.resize(); return; }

	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.resize) { window.resize(); return; }
	
	if (window.parent)
		if (window.parent.Common_ResizeFrame)
			window.parent.Common_ResizeFrame(strIFrameName, 'LARGER_ONLY')
}
function JSDbl(varValue)
{
	var strCleaned = String(varValue);
	strCleaned = strCleaned.replace(',','.');
	if (strCleaned=='') strCleaned = 0;
	var dblCleaned = parseFloat(strCleaned);
	return dblCleaned;
}
function JSBit(blnValue)
{
	var bitValue = 0;
	if (blnValue==true) bitValue = 1;
	return bitValue;
}
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();
}
function CBit(blnValue) {
	
	if (blnValue) {
		return 1;
	}
	else {
		return 0;
	}
}
function SetSubmitLoader() {
	var submits,i;
	 submits=document.getElementsByTagName('input');
	  for (i=0,n=submits.length;i<n;i++) {
		if(submits[i].type.toLowerCase() == 'submit') {
			submits[i].style.background = 'url(/Code/_Images/Loadbar_100.gif)';
			submits[i].style.backgroundColor = 'transparent';
			submits[i].style.backgroundPosition = 'center';
			submits[i].style.backgroundRepeat = 'no-repeat';
			submits[i].style.color = 'transparent';
			submits[i].style.border = '0px';
			submits[i].style.borderColor = 'transparent';
			submits[i].blur();
			};
	  }

}
function imposeMaxLength(Object, MaxLen)
{
	return (Object.value.length <= MaxLen);
}

function GetOffsetX()
{
	if (window.pageXOffset)
		return window.pageXOffset
	else 
		return document.body.scrollLeft;
}

function GetOffsetY()
{
	if (window.pageYOffset)
		return window.pageYOffset
	else 
		return document.body.scrollTop;
}

function CancelBubble(event){
	event.cancelBubble = true;
	if (event.stopPropagation) event.stopPropagation();	
} // function CancelBubble

function ReloadParent(){
	try { if (window.opener) if (window.opener.ReloadForm) window.opener.ReloadForm(); } catch(err) {}
	try { if (window.parent) if (window.parent.ReloadForm) window.parent.ReloadForm(); } catch(err) {}
}
function isValidCreditCard(type, ccnum) {
    if (type =='' || type == undefined) return false;
	if (type == "VISA") {
       // Visa: length 16, prefix 4, dashes optional.
       var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
    } else if (type == "MASTERCARD") {
       // Mastercard: length 16, prefix 51-55, dashes optional.
       var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
    } else if (type == "DISCOVER") {
       // Discover: length 16, prefix 6011, dashes optional.
       var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
    } else if (type == "AMERICAN EXPRESS") {
       // American Express: length 15, prefix 34 or 37.
       var re = /^3[4,7]\d{13}$/;
    } else if (type == "DINERS") {
       // Diners: length 14, prefix 30, 36, or 38.
       var re = /^3[0,6,8]\d{12}$/;
    }
    if (!re.test(ccnum)) return false;
    // Remove all dashes for the checksum checks to eliminate negative numbers
    ccnum = ccnum.split("-").join("");
    // Checksum ("Mod 10")
    // Add even digits in even length strings or odd digits in odd length strings.
    var checksum = 0;
    for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
       checksum += parseInt(ccnum.charAt(i-1));
    }
    // Analyze odd digits in even length strings or even digits in odd length strings.
    for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
       var digit = parseInt(ccnum.charAt(i-1)) * 2;
       if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
    }
    if ((checksum % 10) == 0) return true; else return false;
 }
 
var varDebugWindow = null;
function DebugWindow(parMessage, parEscape){

    if (!varDebugWindow) {

        varDebugWindow = window.open('', 'DebugWindow' + Math.random()); //OpenNamedWindowWS('DebugWindow' + Math.random(), '', 500, 500, true, false);
        varDebugWindow.document.title = 'Debug Window for ' + window.location.toString();
        varDebugWindow.document.body.innerHTML = '<div style="font-weight: bold;">' + varDebugWindow.document.title + '</div>';
    }

    varDebugWindow.document.body.innerHTML += '<br /><hr />' + parMessage;
}
function setGeoLocation(position) {
	document.getElementById('LAT').value = position.coords.latitude;
	document.getElementById('LON').value = position.coords.longitude;
	if (window.applyGeoFilter) applyGeoFilter();
	if (document.getElementById('GeoStatus')) {
		document.getElementById('GeoStatus').innerHTML = '<img src="/Code/_Images/greencheck.gif" title="' + position.coords.latitude + ',' + position.coords.longitude + '">';	
	}
	if (window.frames[0]) {
		if (window.frames[0].document.getElementById('GeoStatus')) {
			window.frames[0].document.getElementById('GeoStatus').innerHTML = '<img src="/Code/_Images/greencheck.gif" title="' + position.coords.latitude + ',' + position.coords.longitude + '">';	
		}
		if (window.frames[0].document.getElementById('LAT')) {
			window.frames[0].document.getElementById('LAT').value = position.coords.latitude;
			window.frames[0].document.getElementById('LON').value = position.coords.longitude;
		}
		if (window.frames[0].applyGeoFilter) window.frames[0].applyGeoFilter();
	}
}
function GeoError(msg) {
	var varMessage = typeof msg == 'string' ? msg : "failed";
	alert(varMessage);
	if (document.getElementById('GeoStatus')) {
		document.getElementById('GeoStatus').innerHTML = '<img src="/Code/_Images/full.gif" title="' + varMessage + '">';	
	}
}
function getGeoLocation () {
	if (top == self) {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(setGeoLocation, GeoError);
		} 
		else{
			GeoError('Not supported'); //HTML Support
		}
	}
	else {
		if (window.parent.getGeoLocation) {
			window.parent.getGeoLocation();
		}
	}
}
