var sVerifyQuestion = "", sVerifyInput = "";

function openWindow(iWidth, iHeight, sURL)
{
	var sFeatures;
	var oDate = new Date();
	var iSeconds = oDate.getSeconds();

	/*make sure the window is in the center of the screen when opened*/
	var iHalfScreenWidth = (screen.Width / 2);
	var iHalfWindowWidth = (iWidth / 2);
	var iLeftPosition = iHalfScreenWidth - iHalfWindowWidth;

	sFeatures = "left=" + iLeftPosition + ",status=no,resizable=no,height=" + iHeight + ",width=" + iWidth + ",location=no,menubar=no,scrollbars=yes,toolbar=no";
	window.open(sURL,"piWindow" + iSeconds,sFeatures);
}

function resetSelects(s1, s2, s3)
{
	var o1 = docGet(s1);
	var o2 = docGet(s2);
	var o3 = docGet(s3);
	var i;

	for(i=0; i<o1.length; i++)
	{
		o1.options[i].selected = false;
	}
	o1.options[0].selected = true;

	for(i=0; i<o2.length; i++)
	{
		o2.options[i].selected = false;
	}
	o2.options[0].selected = true;

	for(i=0; i<o3.length; i++)
	{
		o3.options[i].selected = false;
	}
	o3.options[0].selected = true;
}

function selectLoad()
{
	var i, j, k, l, iLength;

	eval("aComps = new Array(" + docGet("scompanyids").value + ");");
	eval("aFTSEs = new Array(" + docGet("sftsesectorids").value + ");");
	eval("aSICs = new Array(" + docGet("ssicsectorids").value + ");");

	var oComps = docGet('companyids');
	var oFTSEs = docGet('ftsesectorid');
	var oSICs = docGet('sicsectorid');

	iLength	= oComps.length;
	for(i=0; i<=iLength; i++)
	{
		oComps.options[0] = null;
	}

	l = 0;

	for(i=0; i<aComps.length; i++)
	{
		if(oFTSEs.selectedIndex > 1)
		{
			for(k=0; k<oFTSEs.length; k++)
			{
				if(oFTSEs.options[k].selected==true && oFTSEs.options[k].value==aFTSEs[i])
				{
					oComps.options[l] = new Option("# " + aComps[i], aComps[i], false, false);
					l++;
				}
			}
		}
		else if(oSICs.selectedIndex > 1)
		{
			for(k=0; k<oSICs.length; k++)
			{
				if(oSICs.options[k].selected==true && oSICs.options[k].value==aSICs[i])
				{
					oComps.options[l] = new Option("# " + aComps[i], aComps[i], false, false);
					l++;
				}
			}
		}
		else
		{
			for(j=0; j<oFTSEs.length; j++)
			{
				oFTSEs.options[j].selected = false;
			}
			oFTSEs.options[0].selected = true;

			for(j=0; j<oSICs.length; j++)
			{
				oSICs.options[j].selected = false;
			}
			oSICs.options[0].selected = true;

			//oComps.options[l] = new Option("# " + aComps[i], aComps[i], false, false);
			l++;
		}
	}

	if(oSICs.selectedIndex <= 1 && oFTSEs.selectedIndex <= 1)
	{
		oComps.options[0] = new Option("--Please select a sector first--", "", false, false);
	}

	if(l==0)
	{
		oComps.options[l] = new Option("--No companies exist in this sector--", "", false, false);
	}
}

function toggleIndexHeader() {
	var oPIHeader = docGet('piheader');
	var oPILink = docGet('pilink');
	var oPIIcon = docGet('piicon');
	var oPINote = docGet('pinote');

	if(oPIHeader.style.display != "block")
	{
		oPIHeader.style.display = "block";
		oPILink.innerHTML = "Less Info";
		oPIIcon.src = "images/a3.gif";
		oPINote.style.borderBottomWidth = '0px;'
	}
	else
	{
		oPIHeader.style.display = "none";
		oPILink.innerHTML = "More Info";
		oPIIcon.src = "images/a2.gif";
		oPINote.style.borderBottomWidth = '1px;'
	}
}

function btnCl(iButton, bOn) {

	var oBtn = docGet('btn' + iButton).style;
	if(bOn==0)
	{
		oBtn.paddingLeft = '11px';
		oBtn.paddingTop = '2px';
		oBtn.paddingRight = '9px';
		oBtn.paddingBottom = '0px';
		oBtn.borderStyle = 'solid';
		oBtn.borderColor = '#7F7F7F';
	}
	else
	{
		oBtn.paddingLeft = '10px';
		oBtn.paddingTop = '1px';
		oBtn.paddingRight = '10px';
		oBtn.paddingBottom = '1px';
		oBtn.borderStyle = 'outset';
		oBtn.borderColor = '#FFFFFF';
	}
}

function NoSupplierServices(iQID, sOpt)
{
	var oQ = docGet('o-' + iQID + '-1');
	eval("var aQs = new Array(" + sOpt + ");");

	var i;
	var bVal;

	if(oQ.checked==true)
	{
		bVal = true;
	}
	else
	{
		bVal = false;
	}

	for(i=0; i<aQs.length; i++)
	{
		o1 = docGet('o-' + aQs[i] + '-1');
		o2 = docGet('o-' + aQs[i] + '-2');
		o3 = docGet('o-' + aQs[i] + '-4');
		o4 = docGet('i' + aQs[i]);
		o5 = docGet('i' + aQs[i]);
		if(o1){o1.disabled = bVal;}
		if(o2){o2.disabled = bVal;}
		if(o3){o3.disabled = bVal;}
		if(o4){o4.disabled = bVal;}
		if(o5){o5.disabled = bVal;}
	}
}

function SubjectToSpecialRegulations(iQID, sOpt)
{
	var oQ = docGet('o-' + iQID + '-1');
	eval("var aQs = new Array(" + sOpt + ");");

	var i;
	var bVal;

	if(oQ.checked!=true){bVal = true;}else{bVal = false;}

	for(i=0; i<aQs.length; i++)
	{
		o1 = docGet('o-' + aQs[i] + '-1')
		o2 = docGet('o-' + aQs[i] + '-2')
		o3 = docGet('o-' + aQs[i] + '-4')
		o4 = docGet('i' + aQs[i])
		o5 = docGet('t' + aQs[i])
		if(o1){o1.disabled = bVal;}
		if(o2){o2.disabled = bVal;}
		if(o3){o3.disabled = bVal;}
		if(o4){o4.disabled = bVal;}
		if(o5){o5.disabled = bVal;}
	}
}

function PerformanceIndexVerification(iQID)
{
	var oQ = docGet('o-' + iQID + '-1');
	var oT = docGet('t' + iQID);
	var bVal;

	if(oQ.checked!=true){bVal = true;}else{bVal = false;}

	oT.disabled = bVal;
}


/*
	DN 27/05/2008 : Added sPopupId as optional param. if not specified uses the div with id "popuphelp as before"
	otherwise gets div with this id
*/
function popupHelp(sHelpText, bShow, sPopupId)
{
	var oPop 
	
	if (sPopupId)
	{
		oPop = docGet(sPopupId);
	}
	else
	{
		oPop = docGet('popuphelp');
	}
	
	var iX = (event.clientX + document.body.scrollLeft - 100);
	var iY = (event.clientY + getScrollTop() + 20);

	if(bShow==1)
	{
		oPop.style.left = iX+60;
		oPop.style.top = iY;
		oPop.style.display = 'block';
		oPop.innerHTML = sHelpText;
	}
	else
	{
		oPop.style.display = 'none';
		oPop.innerHTML = '';
	}
}

function docGet(sID)
{
	return document.getElementById(sID);
}

function ContractorWorkersInjuryRate(iQID, sOpt)
{
	var oQ = docGet('o-' + iQID + '-1');
	eval("var aQs = new Array(" + sOpt + ");");
	var bVal = oQ.checked;
		
	for(i=0; i<aQs.length; i++)
	{
		o1 = docGet('o-' + aQs[i] + '-1');
		o1.checked = false;
	}
	oQ.checked = bVal;
}

function NoInformation(iQID, sOpt)
{
	var oQ = docGet('o-' + iQID + '-1');
	eval("var aQs = new Array(" + sOpt + ");");
	var bVal = oQ.checked;

	for(i=0; i<aQs.length; i++)
	{
		o1 = docGet('o-' + aQs[i] + '-1');
		o1.checked = false;
	}
	oQ.checked = bVal;
}

function getScrollTop() {
var s = 0;
if (document.documentElement && document.documentElement.scrollTop) {
s = document.documentElement.scrollTop;
}
else if (document.body && document.body.scrollTop) {
s = document.body.scrollTop;
}
return s;
}

function Validate(sUrl) {
	var as = [];
	var iTotal = 0;
	var bNext = false;
	var bValueChosen = false;
	var iSelectCount = 0;
	var iNumSelects = Validate.arguments.length - 1;
	var sType, iQuestionNum;
	
	if (typeof document.forms.fFQ == 'object') {
	
		if (sUrl != '') {
			//Set the action attribute of the form
			SetAction(sUrl);
		}
		
		//put all arguments after first one into an array
		for(i=1;i<Validate.arguments.length;i++) {
			as[as.length] = Validate.arguments[i]
		}
		
		var s = document.forms.fFQ.elements
		
		
		for(i=0;i<s.length;i++) {	
			
			//Select Box where combined value must be a specific number
			if (s[i].type == 'select-one' && ((as).toString()).indexOf(s[i].name) != -1) {
				if (s[i].options[s[i].selectedIndex].value != '') {
					bValueChosen = true;
					iTotal = iTotal + parseInt(s[i].options[s[i].selectedIndex].value)
					iSelectCount++
				}
			}
			
			//Comment boxes
			if (s[i].type == 'textarea' || s[i].type == 'text') {
				
				//Find out the type of value this text area is supposed to have (if given)
				t = eval('document.fFQ.' + s[i].name + '_type');
				
				//Get the question number
				iQuestionNum = eval('document.fFQ.' + s[i].name + '_questionnum').value;
				
				//If there is a type specified for the select box...
				if (t) {

					//perform validation depending on type required
					switch (t.value) {
						case 'numeric':
							if (s[i].value.match(/[^0-9]/ig) != null) {
								alert('Question ' + iQuestionNum + ' box can only contain numerical data.');
								return;
							}
							break;
					}
				} else {
				
					//Is a normal alphanumeric based textarea
					if (s[i].value.length > 3000) {
						alert('Question ' + iQuestionNum + ' box must contain less than 3000 characters.');
						return
					}
				}
				
			}
			
		}
		
		bNext = ((iTotal == 10 && iSelectCount == iNumSelects) || (iTotal == 0 && bValueChosen == false));
		
	} else {
		document.location = sUrl;
		return
	}
	
	if (bNext) {
		document.forms.fFQ.submit();
	} else {
		if (iSelectCount < iNumSelects) {
			alert('You must give a value for each drop down box.');
		} else {
			alert('Drop down boxes must total 10');
		}
	}
	

}

function SetAction(sUrl) {
	document.forms.fFQ.action = sUrl
	document.fFQ.formaction.value = 'navsave';
}

function Show(id,iTotal, sClassName) {
	
	//Hide all Sections
	for(i=1;i<=iTotal;i++) {
		document.getElementById('section_' + i).style.display = '';
		ChangeClass('section_' + i + '_link',sClassName);
	}
	
	//Show just the required section
	document.getElementById(id).style.display = 'block';
	ChangeClass(id + '_link',sClassName + '-on');
	
}

function ChangeClass(a, sClassName) {
	a = document.getElementById(a);
	a.className = sClassName;
}

function LoadElement(sID)
{
	aElements[aElements.length] = sID;
}

function HideElements()
{
	for(i = 0 ; i < aElements.Length ; i++)
	{
		HideElement('home' + aElements[i]);
	}
}

function homeOver(iID, iCounter)
{
	document.getElementById('home' + iID).className = 'home-over';
	if (document.getElementById('box' + iID) != null)
	{
		document.getElementById('box' + iID).style.display = 'block';
	}
}

function homeOut(iID, iCounter)
{

	document.getElementById('home' + iID).className = 'home-def';
	if (document.getElementById('box' + iID) != null)
	{
		document.getElementById('box' + iID).style.display = 'none';
	}
}

function VerifyContactFrm()
{
	
	if (
		docGet('contact_org_to').value != '' && 
		docGet('contact_org_from').value != '' && 
		docGet('contact_section').value != '' && 
		docGet('contact_name').value != '' && 
		docGet('contact_role').value != '' && 
		docGet('contact_email').value != '' && 
		docGet('contact_tel').value != ''
	)
	{
		document.forms.frmContact.submit()
	}
	else
	{
		alert('You did not fill in all mandatory fields.');
	}
	
}

var aRowData	=	[];

function LoadSubRow(sID)
{
	aRowData[aRowData.length] = '<DIV id=' + sID + '>' + docGet(sID).innerHTML.toString() + '</DIV>';
}

function AddNewSubRow()
{
	var	t			=	docGet('Subsidiaries_1');
	var c			=	docGet('SubsidiariesContent');
	var iRowCount	=	parseInt(docGet('subsidiary_count').value);
	var sHTML		=	'<DIV id=Subsidiaries_1>' + t.innerHTML.toString() + '</DIV>';
	
	sHTML						=	sHTML.replace(/value=(.)+?\s/gi,' '); //replace value attributes with empty strings
	sHTML						=	sHTML.replace(/&nbsp;/,'<a href = "javascript:DeleteSubRow(\'Subsidiaries_1\')">Delete</a>');
	sHTML						=	sHTML.replace(/_1/gi,'_' + (aRowData.length + 1)); //make sure we incremement sub number
	aRowData[aRowData.length]	=	sHTML;
	c.innerHTML					=	c.innerHTML + sHTML;
	
	docGet('subsidiary_count').value = aRowData.length;
	
}

function DeleteSubRow(sID)
{

	var removed
	var iRow	=	parseInt(sID.substr(sID.length - 1,1));
	var c		=	docGet('SubsidiariesContent');
	docGet(sID).innerHTML =	'' //clear out div content
	var sHTML	=	c.innerHTML
	removed		=	aRowData.splice((iRow - 1),1); //remove row from memory
	sHTML		=	sHTML.replace('<DIV id=' + sID + '>&nbsp;</DIV>',''); //remove div tabs
	c.innerHTML	=	sHTML
	
	docGet('subsidiary_count').value = aRowData.length; //update new row num
	UpdateRows();
}

function UpdateRows()
{
	var c		=	docGet('SubsidiariesContent');
	c.innerHTML	=	'';
	for ( i = 0 ; i < aRowData.length ; i++)
	{
		aRowData[i] = aRowData[i].replace(/_[0-9]/gi,'_' + (i+1));
		c.innerHTML += aRowData[i];
	}

}

function ResetSelect()
{

	for(i = 0 ; i < ResetSelect.arguments.length ; i++)
	{
		
		s = document.getElementById(ResetSelect.arguments[i]);
		
		if (s!= null)
		{
	
			for(i2 = 0 ; i2 < s.options.length ; i2++)
			{
				s.options[i2].selected = false;
			}
			
			s.selectedIndex = 0;
			
		}
	
	}
}

function Disable(id)
{

	var e = docGet(id);

	if (e != null)
	{
		e.disabled = true;
		
		if (e.type == 'text' || e.type == 'textarea')
		{
			e.value = '';
		}
		
		if (e.type =='checkbox')
		{
			e.checked = false;
		}
		
	}
}

function Enable(id)
{
	if (docGet(id) != null)
	{
		docGet(id).disabled = false;
	}
}

function HideElement(id)
{
	if (docGet(id) != null)
	{
		docGet(id).style.display = 'none';
	}
}

function popForgotPwd()
{
	openWindow(300, 175, 'forgotpwd.asp');
}

function DisableAll(fid)
{
	for ( i = 0 ; i < docGet(fid).elements.length ; i ++ )
	{
		e = docGet(fid).elements[i];
		
		if (e.type != 'hidden' && e.name != 'textnotes' && e.name != 'complete')
		{
		
			e.disabled = true;
			
			if (e.type == 'checkbox' || e.type == 'radio')
			{
				e.checked = false;
			} 
			
			if (e.type == 'text' || e.type == 'textarea')
			{
				e.value = '';
			}
			
		}
		
	}
}

function EnableAll(fid)
{
	for ( i = 0 ; i < docGet(fid).elements.length ; i ++ )
	{
		e = docGet(fid).elements[i];
		
		if (e.type != 'hidden')
		{
			e.disabled = false;
		}
		
		if (e.type == 'text' || e.type == 'textarea')
		{
			e.value = '';
		}
		
	}
}

function Clear()
{

	for ( i = 0 ; i < Clear.arguments.length ; i++)
	{
		//Get first element id and make sure we ignore it in subsequent arguments
		var e1	=	docGet(Clear.arguments[0]);
		
		var e	=	docGet(Clear.arguments[i]);
	
		if (e != null && e1 != null)
		{
		
			if (e.id != e1.id)
			{
		
				if (e.type == 'checkbox')
				{
					e.checked = false;
				}
				
				if (e.type == 'text' || e.type == 'textarea')
				{
					e.value = '';
				}
				
			}
				
		}
		
	}
}

function Check()
{
	for ( i = 0 ; i < Check.arguments.length ; i++)
	{
		var e	=	docGet(Check.arguments[i]);
		
		if (e != null)
		{
			e.checked = true;
		}
			
	}
}

function UpdateSubTotals()
{

	var f			=	docGet('defForm');
	var aAnswers	=	new Array(0,0,0,0,0);
	var aQuestions	=	UpdateSubTotals.arguments;
	var iNum		=	0;

	for (i = 0 ; i < aQuestions.length; i ++)
	{

		for (j = 0 ; j < f.elements.length ; j++)
		{
			
			e = f.elements[j];
			
			if (e.name == ('t' + aQuestions[i].toString()))
			{
				
				aAnswers[iNum] += parseInt(e.value);
				iNum++;
			
			}
			
		}
		
		iNum = 0;
		
	}
	
	for (i = 0; i < 5 ; i++)
	{
		if (typeof aAnswers[i] == 'number')
		{
			docGet('subtotal-' + i).value = parseInt(aAnswers[i]);
		}
	}

}

function VerifyField(sQuestionString, sInput)
{
	sVerifyQuestion = sQuestionString;
	sVerifyInput = sInput;
}

function ResetEmptyValues()
{

	var f	= docGet('defForm');
	
	for ( i = 0 ; i < f.elements.length ; i++)
	{
		e = f.elements[i];
		
		if (e.value == '' && e.type == 'text')
		{
			e.value = 0;
		}
		
	}
}

function VerifyForm()
{

	if (sVerifyQuestion.length > 0 && sVerifyInput.length > 0)
	{

		switch (sVerifyQuestion)
		{
			case 'DirectorsDeclaration.DirectorsDeclaration.Date':
			{
				if (docGet(sVerifyInput))
				{
					var o = docGet(sVerifyInput);
					if (o.value.replace('  ','').length > 0)
					{
						var r = new RegExp();
						if (!/[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}/.test(o.value.replace(' ','')))
						{
							alert('Please enter the date declaration in the format dd/mm/yyyy');
							return false;
						}
					}
				}
				break;
			}
		}
	
	}

	document.getElementById('formaction').value='verify'; 
	document.forms.defForm.submit();
	return true;

}

var aBusinessSectors = []; aBusinessSubs = [];

/* Business Types / Sectors classes */

function BusinessSector(iBusinessSectorID, sDescription, iCompanyTypeID, aBusinessSubs) {
	this.BusinessSectorID = iBusinessSectorID;
	this.Description = sDescription;
	this.BusinessSubs = aBusinessSubs;
	this.CompanyTypeID = iCompanyTypeID;
	
	aBusinessSectors[aBusinessSectors.length] = this;
	
}

function BusinessSub(iBusinessSubID, sDescription, iBusinessSectorID) {
	this.BusinessSubID = iBusinessSubID;
	this.Description = sDescription;
	this.BusinessSectorID = iBusinessSectorID;
}

function LoadBusinessSubs(iDefaultTypeID, iBSID, iBTID, bSelectMatch) {

	var bs = docGet(iBSID);
	var bt = docGet(iBTID);

	var iBusinessSectorID = bs.options[bs.selectedIndex].value;
	
	//Reset Business Type select
	bt.options.length = 0;
	
	if (iDefaultTypeID == '*') {
		bt.options[bt.options.length] = new Option('- All -','*');
	} else {
		bt.options[bt.options.length] = new Option('Please select...','');
	}
	
	bt.options[bt.options.length - 1].selected = true;
	
	for(i=0;i<aBusinessSectors.length;i++) {
		
		if ( (aBusinessSectors[i].BusinessSectorID == iBusinessSectorID) || (iDefaultTypeID == '*')) {
			
			oSector = aBusinessSectors[i];
			oTypes = aBusinessSectors[i].BusinessSubs;

			for (i2=0;i2<oTypes.length;i2++) {
			
				oType = oTypes[i2];
				bt.options[bt.options.length] = new Option(oType.Description, oType.BusinessSubID);
				
				if (iDefaultTypeID == oType.BusinessSubID && bSelectMatch) 
				{
					bt.options[bt.options.length-1].selected = true;
				}
			
			}
		
		}
		
	}
		
	
}

//if no option of a drop down is selected, select the first
function SetSelIndex(sID)
{
	if(docGet(sID) != null)
	{
		if (docGet(sID).selectedIndex == -1)
		{
			docGet(sID).selectedIndex = 0;
		}
	}
}

function SetCriteriaSel(sCompType)
{

	//Hide all elements
	docGet('NumEmployees').style.display = 'none';
	docGet('IndicesDiv').style.display = 'none';
	docGet('Sectors').style.display = 'none';
	
	SetSelIndex('emp_num');
	SetSelIndex('contract_num');
	SetSelIndex('indices');
	SetSelIndex('business_sector');
	SetSelIndex('business_sub_sector');
	SetSelIndex('operating_scope');
	SetSelIndex('company_location');
	
	docGet('OperatingScope').style.display = 'block';
	docGet('CompanyLocation').style.display = 'block';
	
	switch(sCompType)
	{
		case "*":
			docGet('NumEmployees').style.display = 'block';
			break;
			
		case "":
			docGet('NumEmployees').style.display = 'block';
			docGet('company_type').selectedIndex = 0;
			break;		

		case "1":
			docGet('NumEmployees').style.display = 'block';
			docGet('IndicesDiv').style.display = 'block';
			docGet('Sectors').style.display = 'block';
			break;
			
		default:
			docGet('NumEmployees').style.display = 'block';
			docGet('Sectors').style.display = 'block';			
			break;
			
	}
	
}

function setHTML(id, sHTML)
{
	if (docGet(id))
		docGet(id).innerHTML = sHTML;
}

function popPrivacy()
{
	openWindow(550, 500, 'default.asp?action=privacy&ui=compact');
}

function CheckPrivacyPolicy(sID, o)
{
	var h = document.getElementById(sID);
	
	o.checked ? h.value = '1' : h.value = '0';
}

function CheckUserStatusFrm()
{
	var s = document.getElementById('company_type');

	if (s.selectedIndex == -1)
	{
		alert('Please select one or more sectors');
		return false;
	}

	var fd = document.getElementById('from_day');
	var fm = document.getElementById('from_month');
	var fy = document.getElementById('from_year');
	
	var td = document.getElementById('to_day');
	var tm = document.getElementById('to_month');
	var ty = document.getElementById('to_year');

	var from_date = concatDate(selectedValue(fd), selectedValue(fm), selectedValue(fy));
	var to_date = concatDate(selectedValue(td), selectedValue(tm), selectedValue(ty));
	
	if (from_date.invalidDate() || to_date.invalidDate() || from_date.toUdtFormat() > to_date.toUdtFormat())
	{
		alert('Please enter valid \'from\' and \'to\' dates');
		return false;
	}
	
	document.forms.srchFrm.submit();
}

function selectedValue(o)
{
	return o.options[o.selectedIndex].value;
}

function concatDate(str1, str2, str3)
{
	return str1 + '/' + str2 + '/' + str3;
}

function y2k(i)
{ 
	return (i < 1000) ? i + 1900 : i; 
}

String.prototype.invalidDate = function()
{
	if (!/[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}/.test(this.replace(' ','')))
	{
		return true;
	}
	
	var year = this.split('/')[2]
	var month = (this.split('/')[1]) - 1
	var day = this.split('/')[0];
    var d = new Date(year,month,day);

    return !( y2k(d.getYear()) == year && (month) == d.getMonth() && (day) == d.getDate() )

}

String.prototype.toUdtFormat = function()
{
	return (this.split('/')[2]).doubleDigit() + (this.split('/')[1]).doubleDigit() + (this.split('/')[0]).doubleDigit();
}

String.prototype.doubleDigit = function()
{
	return (this.length == 1) ? '0' + this : this
}

function LoadGraphError(e)
{
	if (window.event)
		t = window.event.srcElement;
	else
		t = e.target;
	
	t.src = 'images/graph_error.gif';
}

function checkDate(id)
{
	var d = document.getElementById(id + '_day');
	var m = document.getElementById(id + '_month');
	var y = document.getElementById(id + '_year');
	var day,month,year;
	
	day = d.options[d.selectedIndex].value;
	month = parseInt(m.options[m.selectedIndex].value) - 1 ;
	year = y.options[y.selectedIndex].value;
	
	if (d && m && y)
	{
		if (d.selectedIndex > -1 && m.selectedIndex > -1 && y.selectedIndex > -1)
		{
			var date = new Date();
			date.setFullYear(year, month, day);

			//because they have selected a date with too many days in the month
			if (date.getMonth() != month || date.getDate() != day)
			{
				m.selectedIndex = date.getMonth() - 1;
				d.selectedIndex = getDaysInMonth(date.getMonth() - 1, date.getFullYear()) - 1;
			}
		}
	}
}

function getDaysInMonth(month, year)
{
	var date = new Date();
	var checkDate = true;
	i = 31;
	date.setFullYear(year, month, i)
	while (checkDate && i > 0)
	{
		checkDate = (date.getMonth() != month)
		i--;
		date.setFullYear(year, month, i)
	}
	return i+1;
}

var log;

function AuditLog(iCompanyID, iAdminID, sUsername)
{
	this.CompanyID = iCompanyID;
	this.AdminID = iAdminID;
	this.Username = sUsername;
	this.Filename = document.location.href;
	log = this;
}

function audit(iActionType)
{
	//build up form data
	var formData = 'companyid=' + log.CompanyID + '&adminid=' + log.AdminID + '&username=' + log.Username + '&actiontype=' + iActionType + '&filename=' + escape(log.Filename)
	
	//Connect to emailer
	var engine = new Ace.Engine("", "");
	var request = new Ace.Request(Ace.Method.Post,'log.asp',null,formData);
	var response =	engine.invoke(request,60);
	
	alert(response.text);
}

function ColHeaderOver(sID)
{
	if (sID.length > 0)
	{
		document.getElementById('Col_' + sID).className = 'column-tooltip';
		if (document.getElementById('tooltip') != null)
		{
			document.getElementById('tooltip').style.display = 'block';
			if (document.getElementById(sID) != null) document.getElementById(sID).style.display = 'block';
		}
	}
}

function ColHeaderOut(sID)
{
	if (sID.length > 0)
	{
		document.getElementById('Col_' + sID).className = 'column';
		if (document.getElementById('tooltip') != null)
		{
			document.getElementById('tooltip').style.display = 'none';
			if (document.getElementById(sID) != null) document.getElementById(sID).style.display = 'none';
		}
	}
}
