var inInfo = false;
var top = 0
var left = 0
var arrAnload = new Array();

function show(infoId, content){
	inInfo = true;

	if(content == "")
	{
		content = " --- no text --- ";
	}
	
	document.getElementById('helpContent').innerHTML = content

	top = (getIntValue(DL_GetElementTop(document.getElementById(infoId)), 10) - (getIntValue(document.all.helpTable.clientHeight, 10) / 2)) + 5
	left = getIntValue(DL_GetElementLeft(document.getElementById(infoId)), 10) + 23
	
	document.getElementById('infoItem').style.top = top;
	document.getElementById('infoItem').style.left = left;
	
	hideBehind(top, left, document.all.helpTable.clientHeight, document.all.helpTable.clientWidth);
	document.getElementById('infoItem').style.visibility = 'visible';
	
}

function hide(layer){
	var e = document.getElementById('infoItem')
	if(e != null && inInfo == false)
	{
		if(e.style.visibility != 'hidden')
		{
			e.style.visibility = 'hidden';
			unhideBehind();
		}
	}
}

function DL_GetElementLeft(eElement)
{
	var nLeftPos = eElement.offsetLeft; 
	var eParElement = eElement.offsetParent;    
	while (eParElement != null)
	{  
		nLeftPos += eParElement.offsetLeft;      
		eParElement = eParElement.offsetParent;  
	}
	return nLeftPos;                            
}

function DL_GetElementTop(eElement)
{
	var nTopPos = eElement.offsetTop;
	var eParElement = eElement.offsetParent;
	while (eParElement != null)
	{                                           
		nTopPos += eParElement.offsetTop;      
		eParElement = eParElement.offsetParent; 
	}
	return nTopPos;
}

function hideSelect()
{
	for (j=0; j<document.forms.length; j++) 
	{
		var theForm = document.forms[j]
		for(i=0; i<theForm.elements.length; i++)
		{
			if(theForm.elements[i].type == "select-one") 
			{
				theForm.elements[i].style.visibility = "hidden";
			}
		}
	}
} 

function unhideSelect()
{
	for (j=0; j<document.forms.length; j++) 
	{
		var theForm = document.forms[j]
		for(i=0; i<theForm.elements.length; i++)
		{
			if(theForm.elements[i].type == "select-one") 
			{
				theForm.elements[i].style.visibility = "visible";
			}
		}
	}
}

document.write('<IFRAME style="DISPLAY: none; LEFT: 100px; POSITION: absolute; TOP: 100px;zIndex : 9;width : 10px;height:10px;filter: alpha(opacity=0)"  frameBorder="0" scrolling="no" id="ifameShim2"></IFRAME>')

function hideBehind(top, left, height, width)
{ 
	IfrRef = document.getElementById('ifameShim2');
	
	IfrRef.style.width = width;
	IfrRef.style.height = height;
	IfrRef.style.top = top;
	IfrRef.style.left = left;
	IfrRef.style.display = "block";
}

function unhideBehind()
{ 
	var IfrRef = document.getElementById('ifameShim2');
	IfrRef.style.display = "none";
}

function checkMenuVisibility(){
	if (inInfo == false) {
		hide('infoItem');
	}
	setTimeout("checkMenuVisibility()", 300);
}

function addtoOnload(funcName)
{
	index = 0
	while(arrAnload[index] != '' && arrAnload[index] != null)
	{
		index++;
	}
	arrAnload[index] = funcName;
}

addtoOnload("checkMenuVisibility");

function windowOnLoad()
{
	index = 0
	while(arrAnload[index] != '' && arrAnload[index] != null)
	{
		var txtCall = arrAnload[index].toString();
		
		if(txtCall.indexOf("(") == -1)
		{
			eval(txtCall + "()");
		}
		else
		{
			eval(txtCall);
		}
		index++;
	}
}

window.onload = windowOnLoad;

//------------------------------------//
//--	Single Project Functions	--//
//------------------------------------//

function SetSingleProjectVisibility(){

	//--------------------//
	//--	Section 1	--//
	//--------------------//
	if (nSectionID == 1){
		ShowIfYes('rdoInsuranceCancelled', 'trInsuranceCancelledDetails');
		ShowIfYes('rdoContractor', 'trContractorExperience');
		ShowIfYes('rdoClaimed', 'trClaimedDetails');
		ShowIfYes('rdoFinanciersInterests', 'trFinanciersInterests');
	}

	//--------------------//
	//--	Section 2	--//
	//--------------------//
	if (nSectionID == 2){
		//--| ShowIfYes('rdoDemolitionInvolved', 'trDemolitionInvolved'); |--// Might be put back in.
		ShowIfYes('rdoDemolitionInvolved', 'trDemolitionGreaterThan25pc');
		ShowIfYes('rdoAlterationsRequired', 'trAlterationsRequired');


		var ddl = Obj("ddlProjectEntails");
		if (ddl.options[ddl.selectedIndex].text == "Other"){
			trProjectEntails.style.display = 'block';
			Obj("ddlCommissioningPeriod").disabled = false;
		}
		else{
			trProjectEntails.style.display = 'none';
			Obj("ddlCommissioningPeriod").disabled = true;
		}
	}

	//--------------------//
	//--	Section 3	--//
	//--------------------//
	if (nSectionID == 3){

		if(SingleQuestions_ProjectInvolves())
			Obj("trProjectInvolves").style.display = "block";
		else
			Obj("trProjectInvolves").style.display = "none";

		
		if(SingleQuestions_ProjectActivities())
			Obj("trProjectActivities").style.display = "block";
		else
			Obj("trProjectActivities").style.display = "none";

	}

	//--------------------//
	//--	Section 4	--//
	//--------------------//
	if (nSectionID == 4){
		ShowIfYes('rdoPublicLiabilityRequired', 'tblPublicLiability');
		ShowIfYes('rdoVibrationWeakening', 'trVibrationWeakening');
	}
}


//-------------------------------------//
//-- Common Single Project Functions --//
//-------------------------------------//
function SingleQuestions_ProjectInvolves(){
	if(
		isRadioTrue("rdoPilingVibration") ||
		isRadioTrue("rdoUnderpinningShorting") ||
		isRadioTrue("rdoRemovalWeakeningSupports") ||
		isRadioTrue("rdoRetainingWalls") ||
		isRadioTrue("rdoExcavationDeeperThan2") ||
		isRadioTrue("rdoExcavationUndergroundServices") ||
		isRadioTrue("rdoBlastingExplosives") ||
		isRadioTrue("rdoFlameCuttingWelding") ||
		isRadioTrue("rdoHazardousChemicalsFlammableLiquids") ||
		isRadioTrue("rdoLoweringGroundWater") ||
		isRadioTrue("rdoDemolitionAbove10Meters")
	)
		return true;
	else
		return false;
}


function SingleQuestions_ProjectActivities(){
	if(
		isRadioTrue("rdoRoadConstruction") ||
		isRadioTrue("rdoTunnelsDeclinesShafts") ||
		isRadioTrue("rdoBridgeConstruction") ||
		isRadioTrue("rdoErectionDismantlingMachinery") ||
		isRadioTrue("rdoPipelineCulvertsDrains") ||
		isRadioTrue("rdoSubdivisionEstablishment") ||
		isRadioTrue("rdoHeritageListed") ||
		isRadioTrue("rdoPermanentBodiesOfWater") ||
		isRadioTrue("rdoAirports") ||
		isRadioTrue("rdoSwimmingPools") ||
		isRadioTrue("rdoRefurbishmentSchoolsHostpitalsEtc")
	)
		return true;
	else
		return false;
}



//------------------------------------//
//--	Annual Project Functions	--//
//------------------------------------//

function SetAnnualProjectVisibility(){

	//--------------------
	//--	Section 1	--
	//--------------------
	if (nSectionID == 1){
		ShowIfYes('rdoInsuranceCancelled', 'trInsuranceCancelledDetails');
		ShowIfYes('rdoClaimed', 'trClaimedDetails');
		ShowIfYes('rdoFinanciersInterests', 'trFinanciersInterests');
	}

	//--------------------//
	//--	Section 2	--//
	//--------------------//
	if (nSectionID == 2){
		ShowIfYes('rdoAlterationsRequired', 'trAlterationsRequired');
	}
	
	//--------------------//
	//--	Section 3	--//
	//--------------------//
	if (nSectionID == 3){
		ShowIfYes('rdoMoreThan25pcDemolition', 'trMoreThan25pcDemolition');
		ShowIfYes('rdoProjectChangeInNext12mths', 'trProjectChangeInNext12mths');


		var ddl = Obj("ddlTypesOfProjectsUndertaken");
		if (ddl.options[ddl.selectedIndex].text == "Other")
			trProjectEntails.style.display = 'block';
		else
			trProjectEntails.style.display = 'none';

	}
	
	
	//--------------------//
	//--	Section 4	--//
	//--------------------//
	if (nSectionID == 4){

		if(AnnualQuestions_ProjectInvolves())
			Obj("trProjectInvolves").style.display = "block";
		else
			Obj("trProjectInvolves").style.display = "none";

	}
	
	
	//--------------------//
	//--	Section 5	--//
	//--------------------//
	if (nSectionID == 5){
		ShowIfYes('rdoPublicLiabilityRequired', 'tblPublicLiability');
		ShowIfYes('rdoVibrationWeakening', 'trVibrationWeakening');
	}
}

//-------------------------------------//
//-- Common Single Project Functions --//
//-------------------------------------//
function AnnualQuestions_ProjectInvolves(){
	if(
		isRadioTrue("rdoExcavationDeeperThan3m") ||
		isRadioTrue("rdoBlastingOrExplosives") ||
		isRadioTrue("rdoHistoricalBuildings") ||
		isRadioTrue("rdoUndergroundWorks") ||
		isRadioTrue("rdoRoadRailBridges") ||
		isRadioTrue("rdoNorthOf25thParallelSouth") ||
		isRadioTrue("rdoPipelinesGreaterThan250m") ||
		isRadioTrue("rdoIrrigationCanalReserviorDamORSiphon") ||
		isRadioTrue("rdoWaterConstructions") ||
		isRadioTrue("rdoDemolitionAbove10m") ||
		isRadioTrue("rdoDrillingOrBoringGreaterThan50cm") ||
		isRadioTrue("rdoAirports") ||
		isRadioTrue("rdoSwimmingPools") ||
		isRadioTrue("rdoRefurbishmentSchoolsHostpitalsEtc")
	)
		return true;
	else
		return false;
}


//----------------------------------------//
//--	Common Functions				--//
//----------------------------------------//

	function CalculateProj(argProjType, allowEdit, ele){
		var nProjectValue;
		var sProjectValueField;
		var txt = Obj("dhnSumContractorsToolsReal");
		var nContractorsToolsValue = txt.value;
		if(nContractorsToolsValue == '')
		{
			nContractorsToolsValue = 0;
		}

		if (argProjType.toLowerCase() == 'single'){
			sProjectValueField = "txtSumContractWorks";
		}
		else if (argProjType.toLowerCase() == 'annual'){
			sProjectValueField = "txtMaximumProjectValue";
		}
		
		var nProjectValue = getIntValue(Obj(sProjectValueField).value.replace(/,/g, ""));
		if(isNaN(nProjectValue))
		{
			nProjectValue = 0;
		}
		
		Obj(sProjectValueField).value = formatInteger(Obj(sProjectValueField).value)
		
		var SPSI = Obj("txtSumPrincipalSuppliedItems").value.replace(/,/g, "")
		if(SPSI == '')
		{
			SPSI = 0;
		}
		var SES = Obj("txtSumExistingStructures").value.replace(/,/g, "")
		if(SES == '')
		{
			SES = 0;
		}
		
		var nProjectAndItems = getIntValue(nProjectValue, 10) + getIntValue(SPSI, 10);
									
		var nAllProjectCosts = getIntValue(nProjectValue, 10) + getIntValue(SPSI, 10) + 
								getIntValue(SES, 10) + 
								getIntValue(nContractorsToolsValue, 10);
								
		if(nProjectAndItems == '')
		{
			nProjectAndItems = 0;
		}
		if(nAllProjectCosts == '')
		{
			nAllProjectCosts = 0;
		}
		if(nProjectAndItems == '')
		{
			nProjectAndItems = 0;
		}
		if(nProjectValue == '')
		{
			nProjectValue = 0;
		}
		if(nProjectAndItems == '')
		{
			nProjectAndItems = 0;
		}
		if(nProjectValue == '')
		{
			nProjectValue = 0;
		}
		if(nContractorsToolsValue == '')
		{
			nContractorsToolsValue = 0;
		}
		
		var SVE = Math.round(getIntValue(nProjectAndItems, 10)	* 0.20);
		var RD = Math.round(getIntValue(nAllProjectCosts, 10)	* 0.10);
		var PF = Math.round(getIntValue(nProjectAndItems, 10)	* 0.10);
		var EE = Math.round(getIntValue(nProjectValue, 10)	* 0.05);
		var MC = Math.round(getIntValue(nProjectAndItems, 10)	* 0.05);
		
		if(isNaN(SVE))
		{
			SVE = 0;
		}
		if(isNaN(RD))
		{
			RD = 0;
		}
		if(isNaN(PF))
		{
			PF = 0;
		}
		if(isNaN(EE))
		{
			EE = 0;
		}
		if(isNaN(MC))
		{
			MC = 0;
		}
		
		if(!allowEdit)
		{
			Obj("txtSumVariationsEscalation").value		= formatInteger(SVE);
			Obj("txtSumVariationsEscalation").className = "cls_Width_Small_Disabled";
			Obj("divSumVariationsEscalation").style.visibility='hidden';
			
			Obj("txtRemovalDebris").value				= formatInteger(RD);
			Obj("txtRemovalDebris").className = "cls_Width_Small_Disabled";
			Obj("divRemovalDebris").style.visibility='hidden';
				
			Obj("txtProfessionalFees").value			= formatInteger(PF);
			Obj("txtProfessionalFees").className = "cls_Width_Small_Disabled";
			Obj("divProfessionalFees").style.visibility='hidden';
				
			Obj("txtExpeditingExpenses").value			= formatInteger(EE);
			Obj("txtExpeditingExpenses").className = "cls_Width_Small_Disabled";
			Obj("divExpeditingExpenses").style.visibility='hidden';
				
			Obj("txtMitigationCosts").value				= formatInteger(MC);
			Obj("txtMitigationCosts").className = "cls_Width_Small_Disabled";
			Obj("divMitigationCosts").style.visibility='hidden';
		}
		else
		{
			Obj("lnkSumVariationsEscalation").innerHTML		= formatInteger(SVE);
			Obj("lnkRemovalDebris").innerHTML				= formatInteger(RD);
			Obj("lnkProfessionalFees").innerHTML			= formatInteger(PF);
			Obj("lnkExpeditingExpenses").innerHTML			= formatInteger(EE);
			Obj("lnkMitigationCosts").innerHTML				= formatInteger(MC);
			
			//alert(ele);
		
			if(Obj("txtSumVariationsEscalation").className == 'cls_Width_Small_Disabled' || getIntValue(Obj("txtSumVariationsEscalation").value, 10) == getIntValue(SVE, 10))
			{
				if(ele == Obj("txtSumVariationsEscalation") || ele == null)
				{
					Obj("txtSumVariationsEscalation").value		= formatInteger(SVE);
					Obj("txtSumVariationsEscalation").className = "cls_Width_Small_Disabled";
					Obj("divSumVariationsEscalation").style.visibility='hidden';
					Obj("hdn106a").value = "0";
				}
			}
			else
			{
				Obj("divSumVariationsEscalation").style.visibility='visible';
				Obj("hdn106a").value = "1";
			}
			if(Obj("txtRemovalDebris").className == 'cls_Width_Small_Disabled' || getIntValue(Obj("txtRemovalDebris").value, 10) == getIntValue(RD, 10))
			{
				if(ele == Obj("txtRemovalDebris") || ele == null)
				{
					Obj("txtRemovalDebris").value				= formatInteger(RD);
					Obj("txtRemovalDebris").className = "cls_Width_Small_Disabled";
					Obj("divRemovalDebris").style.visibility='hidden';
					Obj("hdn107a").value = "0";
				}
			}
			else
			{
				Obj("divRemovalDebris").style.visibility='visible';
				Obj("hdn107a").value = "1";
			}
			if(Obj("txtProfessionalFees").className == 'cls_Width_Small_Disabled' || getIntValue(Obj("txtProfessionalFees").value, 10) == getIntValue(PF, 10))
			{
				if(ele == Obj("txtProfessionalFees") || ele == null)
				{
					Obj("txtProfessionalFees").value			= formatInteger(PF);
					Obj("txtProfessionalFees").className = "cls_Width_Small_Disabled";
					Obj("divProfessionalFees").style.visibility='hidden';
					Obj("hdn108a").value = "0";
				}
			}
			else
			{
				Obj("divProfessionalFees").style.visibility='visible';
				Obj("hdn108a").value = "1";
			}
			if(Obj("txtExpeditingExpenses").className == 'cls_Width_Small_Disabled' || getIntValue(Obj("txtExpeditingExpenses").value, 10) == getIntValue(EE, 10))
			{
				if(ele == Obj("txtExpeditingExpenses") || ele == null)
				{
					Obj("txtExpeditingExpenses").value			= formatInteger(EE);
					Obj("txtExpeditingExpenses").className = "cls_Width_Small_Disabled";
					Obj("divExpeditingExpenses").style.visibility='hidden';
					Obj("hdn109a").value = "0";
				}
			}
			else
			{
				Obj("divExpeditingExpenses").style.visibility='visible';
				Obj("hdn109a").value = "1";
			}
			
			if(Obj("txtMitigationCosts").className == 'cls_Width_Small_Disabled' || getIntValue(Obj("txtMitigationCosts").value, 10) == getIntValue(MC, 10) || getIntValue(Obj("txtMitigationCosts").value, 10) == getIntValue(Obj("hdnMitigationCosts").value, 10))
			{
				if(ele == Obj("txtMitigationCosts") || ele == null)
				{
					Obj("txtMitigationCosts").value				= formatInteger(MC);
					Obj("txtMitigationCosts").className = "cls_Width_Small_Disabled";
					Obj("divMitigationCosts").style.visibility='hidden';
					Obj("hdn110a").value = "0";
				}
			}
			else
			{
				Obj("divMitigationCosts").style.visibility='visible';
				Obj("hdn110a").value = "1";
			}
		}
		
		Obj("hdnSumVariationsEscalation").value		= formatInteger(SVE);
		Obj("hdnRemovalDebris").value				= formatInteger(RD);
		Obj("hdnProfessionalFees").value			= formatInteger(PF);
		Obj("hdnExpeditingExpenses").value			= formatInteger(EE);
		Obj("hdnMitigationCosts").value				= formatInteger(MC);
		
		var SVE1 = Obj("txtSumVariationsEscalation").value.replace(/,/g, "")
		if(SVE1 == '')
		{
			SVE1 = 0;
		}
		var RD1 = Obj("txtRemovalDebris").value.replace(/,/g, "")
		if(RD1 == '')
		{
			RD1 = 0;
		}
		var PF1 = Obj("txtProfessionalFees").value.replace(/,/g, "")
		if(PF1 == '')
		{
			PF1 = 0;
		}
		var EE1 = Obj("txtExpeditingExpenses").value.replace(/,/g, "")
		if(EE1 == '')
		{
			EE1 = 0;
		}
		var MC1 = Obj("txtMitigationCosts").value.replace(/,/g, "")
		if(MC1 == '')
		{
			MC1 = 0;
		}
		
		Obj("txtTotalSumInsured").value = formatInteger(getIntValue(nProjectValue, 10) + 
											getIntValue(SPSI, 10) + 
											getIntValue(SES, 10) + 
											getIntValue(nContractorsToolsValue, 10) + 
											getIntValue(SVE1, 10) + 
											getIntValue(RD1, 10) + 
											getIntValue(PF1, 10) + 
											getIntValue(EE1, 10) + 
											getIntValue(MC1, 10));
											
		
	}


	function SetPublicLiability(){
		if(iHandleReferals == 1)
		{
			//Obj("txtPublicLiability").value = 0;
			//Obj("txtProductsLiability").value = 0;
			//Obj("txtPropertyControl").value = 0;
		}
		else
		{
			//Obj("ddlPublicLiability").selectedIndex = 0;
			//Obj("ddlProductsLiability").selectedIndex = 0;
			//Obj("ddlPropertyControl").selectedIndex = 0;
			Obj("rdoVibrationWeakening").checked = false;
			Obj("txtVibrationWeakening").value = "";
		}
	}

	
	function CheckPostCode(argCtrl){
		var isValid = true;
	
		if (isValid){
			isValid = isNull(Obj(argCtrl), "You must enter a Postcode.");
			if (isValid){
				isValid = isInteger(Obj(argCtrl), "An invalid Postcode has been entered.\n\n Please only enter numbers for the postcode.");
				if (isValid){
					isValid = isLengthEqual(Obj(argCtrl), 4, "An invalid Postcode has been entered.\n\n Please enter 4 numbers for the postcode.");
					//if (isValid){
					//	isValid = CheckForState(Obj(argCtrl), "An invalid Postcode has been entered.\n\n Please check the postcode and try again.");
					//}
				}
			}
		}
		
		return isValid;
		
	}
	
	function CheckTerrorPostCode(argCtrl){
		var isValid = true;
		
		isValid = clsAjax.checkTerrorPostcode(Obj(argCtrl).value).value
	
		if (!isValid){
			alert('The Postcode you have entered is not a valid ARPC postcode.\n\nThis is most likely because the postcode you have entered does not represent the true location of the project, it may be a PO Box, a Postal redirect or a non-physical location, for ratings reasons we require the postcode of the physical location of the project.\n\nPlease check the postcode and try again, if you continue to have this problem contact MECON Insurance for assistance.')
		}
		
		return isValid;
		
	}


//----------------------------------------//
//--	Standard Functions				--//
//----------------------------------------//

	function Obj(arg){
		return document.getElementById(arg);
	}


	function ShowIfYes(sCtrl, sSubject){
		var objYes = Obj(sCtrl + "_0");
		var objSubject = Obj(sSubject);
		
		if(objYes != null && objSubject != null){
			
			if(objYes.checked)
				objSubject.style.display = "block";
			else
				objSubject.style.display = "none";
		}
	}


	function ToggleSection(argSection){
		var ctrlDiv = Obj("div" + argSection);
		
		if(ctrlDiv.style.display == "block"){
			ctrlDiv.style.display = "none";
		}
		else{
			ctrlDiv.style.display = "block";
		}

		SetSection(argSection);

	}

	function SetSection(argSection){
		var ctrlDivHeader = Obj("divHeader_" + argSection);
		var ctrlDiv = Obj("div" + argSection);
		var ctrlImg = Obj("imgToggle_" + argSection)
		
		if (ctrlDiv != null){
			if(ctrlDiv.style.display == "block"){
				ctrlDivHeader.style.marginBottom = "0px";
				ctrlImg.src = "images/Icon_SectionCollapse.gif";
			}
			else{
				ctrlDivHeader.style.marginBottom = "10px";
				ctrlImg.src = "images/Icon_SectionExpand.gif";
			}
		}
	}


	function ShowReport(){
		window.open('ReportViewer.aspx', '_blank');
	}



//------------------------------------//
//--	Validation Functions		--//
//------------------------------------//
	
	function isNull(argObj,msg)
	{
		if (argObj.value.length == 0){
			alert(msg);
			if (!argObj.disabled)
				argObj.focus();
			return false;
		}
		return true;
	}

	
	function isZero(argObj,msg)
	{
		if (argObj.value == 0){
			alert(msg);
			if (!argObj.disabled)
				argObj.focus();
			return false;
		}
		return true;
	}


	function isInteger(argObj,msg)
	{
		for (var i=0; i < argObj.value.length; i++){
			if (!isDigit(argObj.value.charAt(i))){ 
				alert(msg);
				argObj.focus();
				return false; 
			}
		}
		return true;
	}
	
	function MoneyNoCents(argObj, min)
	{
		isOk = true;
		isAlert = false;
		isLessThanMin = false;
		retValue = ""
		for (var i=0; i < argObj.value.length; i++){
			if (!isDigit(argObj.value.charAt(i))){ 
				isOk = false
				isAlert = true;
			}
			else
			{
				retValue = retValue + argObj.value.charAt(i)
			}
		}
		
		if(retValue == '')
		{
			isOk = false
			retValue = '0';
		}
		
		if(getIntValue(retValue, 10) <= getIntValue(min, 10))
		{
			minVal = getIntValue(min, 10) + 1
			isOk = false
			retValue = minVal.toString();
			isLessThanMin = true;
		}
		
		if(isOk)
		{
			return true
		}
		else
		{
			argObj.value = retValue;
			if(isAlert)
			{
				alert('The amount enter must be numeric value and must contain only whole numbers.\n\nIt can not contain any symbols such as $ , .');
				argObj.focus()
			}
			else if(isLessThanMin)
			{
				alert('The amount enter must be greater than : ' + min);
				argObj.focus()
			}
			return true
		}
	}
	
	function MoneyValidate(argObj, min)
	{
		isOk = true;
		isAlert = false;
		isLessThanMin = false;
		retValue = ""
		decimals = 0;
		for (var i=0; i < argObj.value.length; i++){
			if (!isPercent(argObj.value.charAt(i))){ 
				isOk = false
				isAlert = true;
			}
			else
			{
				if(argObj.value.charAt(i) == ".")
				{
					decimals++;
				}
				
				if(decimals < 2)
				{
					retValue = retValue + argObj.value.charAt(i)
				}
			}
		}
		
		if(retValue == '')
		{
			isOk = false
			retValue = '0.00';
		}
		
		if(getIntValue(retValue, 10) <= getIntValue(min, 10))
		{
			minVal = getIntValue(min, 10) + 1
			isOk = false
			retValue = minVal.toString();
			isLessThanMin = true;
		}
		
		if(isOk && decimals < 2)
		{
			argObj.value = money(retValue);
			return true
		}
		else
		{
			argObj.value = money(retValue);
			if(isAlert)
			{
				alert('The amount enter must be numeric value.\n\nIt can not contain any symbols.');
				argObj.focus()
			}
			else if(isLessThanMin)
			{
				alert('The value entered must be greater than : ' + min);
				argObj.focus()
			}
			return true
		}
	}
	
	function MoneyValidateNoCents(argObj, min)
	{
		isOk = true;
		isAlert = false;
		isLessThanMin = false;
		argObj.value = argObj.value.replace(/,/g, "")
		
		retValue = ""
		decimals = 0;
		for (var i=0; i < argObj.value.length; i++){
			if (!isPercent(argObj.value.charAt(i))){ 
				isOk = false
				isAlert = true;
			}
			else
			{
				if(argObj.value.charAt(i) == ".")
				{
					decimals++;
				}
				
				if(decimals < 2)
				{
					retValue = retValue + argObj.value.charAt(i)
				}
			}
		}
		
		if(retValue == '')
		{
			isOk = false
			retValue = '0';
		}
		
		if(getIntValue(retValue, 10) <= getIntValue(min, 10))
		{
			minVal = getIntValue(min, 10) + 1
			isOk = false
			retValue = minVal.toString();
			isLessThanMin = true;
		}
		
		if(isOk && decimals < 2)
		{
			argObj.value = formatInteger(moneyNoCents(retValue));
			return true
		}
		else
		{
			argObj.value = formatInteger(moneyNoCents(retValue));
			if(isAlert)
			{
				alert('The amount enter must be numeric value.\n\nIt can not contain any symbols.');
				argObj.focus()
			}
			else if(isLessThanMin)
			{
				alert('The value entered must be greater than : ' + min);
				argObj.focus()
			}
			return true
		}
	}
	
	function money(val)
	{
		val = val.toString();
		val = val.replace(/,/g, "")
		
		floatVal = Math.round(getFloatValue(val))
		
		if(isNaN(floatVal))
		{
			floatVal = '0';
		}
		strVal = floatVal.toString();
		
		decPos = strVal.indexOf('.');
		
		//if(decPos == -1)
		//{
			return formatInteger(strVal) + '.00';
		//}
		//else if(decPos == (strVal.length - 2))
		//{
		//	return formatInteger(strVal) + '0';
		//}
		//else
		//{
		//	return formatInteger(strVal);
		//}
	}
	
	function moneyDollarsAndCents(val)
	{
		val = val.toString();
		val = val.replace(/,/g, "")
		
		floatVal = (Math.round((getFloatValue(val) * 100))) / 100;
		
		if(isNaN(floatVal))
		{
			floatVal = '0';
		}
		strVal = floatVal.toString();
		
		decPos = strVal.indexOf('.');
		
		decPlaces = strVal.substr(decPos, (strVal.length - decPos))
		
		if(decPos == -1)
		{
			return formatInteger(strVal) + '.00';
		}
		else if(decPos == (strVal.length - 2))
		{
			return formatInteger(strVal.substr(0, decPos)) + decPlaces + '0';
		}
		else
		{
			return formatInteger(strVal.substr(0, decPos)) + decPlaces;
		}
	}
	
	function getFloatValue(val)
	{
		val = val.toString();
		val = val.replace(/,/g, "");
		return parseFloat(val);
	}
	
	function getIntValue(val)
	{
		val = val.toString();
		val = val.replace(/,/g, "");
		return parseInt(Math.round(val), 10);
	}
	
	function formatInteger(integer)
	{
		integer = integer.toString();
		integer = integer.replace(/,/g, "")
		integer = getIntValue(integer);
		integer = integer.toString();
		
		pattern = "###,###,###,###"
		var result = '';

		integerIndex = integer.length - 1;
		patternIndex = pattern.length - 1;

		while ( (integerIndex >= 0) && (patternIndex >= 0) )
		{
			var digit = integer.charAt( integerIndex );
			integerIndex--;
			
			if ( (digit < '0') || (digit > '9') )  continue;
		
			while ( patternIndex >= 0 )
			{
				var patternChar = pattern.charAt( patternIndex );
				patternIndex--;
				
				if ( patternChar == '#' )
				{
					result = digit + result;
					break;
				}
				else
				{
					result = patternChar + result;
				}
			}
		}
		
		return result;
	}
	
	function moneyNoCents(val)
	{
		floatVal = getFloatValue(getIntValue(Math.round((getFloatValue(val) * 100)), 10) / 100)
		if(isNaN(floatVal))
		{
			floatVal = '0';
		}
		strVal = floatVal.toString();
		
		decPos = strVal.indexOf('.');
		
		if(decPos == -1)
		{
			return getIntValue(strVal, 10);
		}
		else if(decPos == (strVal.length - 2))
		{
			return getIntValue(strVal.substr(0, (strVal.length - 2)), 10);
		}
		else
		{
			return getIntValue(strVal.substr(0, (strVal.length - 3)), 10);
		}
	}

	function Percent(argObj, min)
	{
		isOk = true;
		isAlert = false;
		isLessThanMin = false;
		retValue = ""
		decimals = 0;
		for (var i=0; i < argObj.value.length; i++){
			if (!isPercent(argObj.value.charAt(i))){ 
				isOk = false
				isAlert = true;
			}
			else
			{
				if(argObj.value.charAt(i) == ".")
				{
					decimals++;
				}
				
				if(decimals < 2)
				{
					retValue = retValue + argObj.value.charAt(i)
				}
			}
		}
		
		if(retValue == '')
		{
			isOk = false
			retValue = '0';
		}
		
		if(getIntValue(retValue, 10) <= getIntValue(min, 10))
		{
			minVal = getIntValue(min, 10) + 1
			isOk = false
			retValue = minVal.toString();
			isLessThanMin = true;
		}
		
		if(isOk && decimals < 2)
		{
			argObj.value = getFloatValue(retValue);
			return true
		}
		else
		{
			argObj.value = getFloatValue(retValue);
			if(isAlert)
			{
				alert('The amount enter must be numeric value.\n\nIt can not contain any symbols.');
				argObj.focus()
			}
			else if(isLessThanMin)
			{
				alert('The percent entered must be greater than : ' + min);
				argObj.focus()
			}
			return true
		}
	}

	function isDigit(num) 
	{
		var string="1234567890,";
		if (string.indexOf(num) !=-1)
			return true;

		return false;
	}
	
	function isPercent(num) 
	{
		var string="1234567890.,";
		if (string.indexOf(num) !=-1)
			return true;

		return false;
	}


	function isRadioSelected(argObj,msg){
		var bYes;
		var bNo;

		bYes = Obj(argObj + "_0").checked;
		bNo = Obj(argObj + "_1").checked;
		
		if (bYes == true || bNo == true)
			return true;

		alert(msg);
		Obj(argObj + "_0").focus();
		return false;
	}


	function isRadioTrue(argObj){
		return Obj(argObj + "_0").checked;
	}


	function isInRange(argObj, min, max, msg)
	{
		if (argObj.value < min || argObj.value > max){
			alert(msg);
			argObj.focus();
			return false;
		}
		return true;
	}


	function isLengthInRange(argObj, min, max, msg)
	{
		if (argObj.value.length < min || argObj.value.length > max){
			alert(msg);
			argObj.focus();
			return false;
		}
		return true;
	}

	
	function isLengthEqual(argObj, num, msg)
	{
		if (!(argObj.value.length==num)){
			alert(msg);
			argObj.focus();
			return false;
		}
		return true;
	}


	function CheckForState(argObj, msg)
	{
		var StateCode = argObj.value.charAt(0);

		switch (StateCode){
		case '0': 
			if ( argObj.value.charAt(1) ==  '8'){
				return true ; break;
			}
			alert(msg);
			argObj.focus(); return false; break;
		case '1': 
			return true; break;
		case '2': 
			return true; break;
		case '3': 
			return true; break;
		case '4': 
			return true; break;
		case '5': 
			return true; break;
		case '6': 
			return true; break;
		case '7': 
			return true; break;
		default : 
			alert(msg);
			argObj.focus();
			return false;
		}
	}
	
	
	function isEmail(argEmail, msg) {
		if (argEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			return true;
		else{
			alert(msg);
			return false;
		}
	}
	
	function isTBA(argObj, msg)
	{
	if (argObj.value.toLowerCase() == 'tba') 
	{
	alert(msg);
	return false;
	}
	else
	{return true;}
	}



//===========================================================================
//	DATE FUNCTIONS
//	- For use with the Date Picker User Control. (uclDatePicker.ascx)
//===========================================================================

	function isDate(objDate, msg){
		var isValid = CheckDate(objDate.value);

		if (!isValid){
			alert(msg);
			objDate.focus();
		}

		return isValid;
		
	}
	
	function IsNum(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;

		 
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
			{
			IsNumber = false;
			}
		}
		
		return IsNumber;
   }

	function CheckDate(sDate){
		var nDay, nMonth, nYear;
		var arrDate = sDate.split("/");
		var arrMonthDays = new Array(12);
		var nMaxDay;
		var isValid = true;
		
		if(arrDate.length < 3)
		{
			return false;
		}
		
		arrMonthDays[1] = 31;	arrMonthDays[2] = 28;	arrMonthDays[3] = 31;	arrMonthDays[4] = 30; 
		arrMonthDays[5] = 31;	arrMonthDays[6] = 30;	arrMonthDays[7] = 31;	arrMonthDays[8] = 31;	
		arrMonthDays[9] = 30;	arrMonthDays[10] = 31;	arrMonthDays[11] = 30;	arrMonthDays[12] = 31; 
		
		if(!IsNum(arrDate[0]) || !IsNum(arrDate[1]) || !IsNum(arrDate[2]))
		{
			isValid = false;
		}
		
		nDay	= getIntValue(arrDate[0], 10);
		nMonth	= getIntValue(arrDate[1], 10);
		nYear	= getIntValue(arrDate[2], 10);
		
		if (String(nYear).length != 4)
			isValid = false;
		
		if (nMonth > 12)
			isValid = false;
		
		nMaxDay = arrMonthDays[nMonth];
		
		if (nMonth == 2 && nYear % 4 == 0)
			nMaxDay += 1;
		
		if (isValid && (nDay > nMaxDay))
			isValid = false;

		return isValid;
	}


	function GetTodaysDate(){
		var dToday = new Date();
		var sDay, sMonth, sYear;
		var sReturn;
		
		sDay	= String(dToday.getDate());
		sMonth	= String(dToday.getMonth() + 1);
		sYear	= String(dToday.getYear());
		
		sDay	= (sDay.length > 1 ? sDay : "0" + sDay);
		sMonth	= (sMonth.length > 1 ? sMonth: "0" + sMonth);
		
		sReturn = sDay + "/" + sMonth + "/" + sYear;
		
		return sReturn;
	}

	function GetCompareDate(argDate, bBackdate){
		var sDay, sMonth, sYear;
		var arrDate = argDate.split("/");
		var nReturn;
		
		sDay	= String(arrDate[0]);
		sMonth	= String(arrDate[1]);
		sYear	= String(arrDate[2]);
		
		//Start - Backdates 2 months
		if (bBackdate){
			if (getIntValue(sMonth) == 1){
				sMonth = "11";
				sYear = sYear - 1;
			}
			else if (getIntValue(sMonth) == 2){
				sMonth = "12";
				sYear = sYear - 1;
			}
			else
				sMonth = sMonth - 2;
		}
		//End - Backdates 2 months
		
		sDay = sDay.toString();
		sMonth = sMonth.toString();
		sYear = sYear.toString();
		
		sDay	= (sDay.length > 1 ? sDay : "0" + sDay);
		sMonth	= (sMonth.length > 1 ? sMonth: "0" + sMonth);
		
		nReturn = getIntValue(sYear + sMonth + sDay, 10);
		
		return nReturn;
	}


	function DateAdd(argDate){
		var sDay, sMonth, sYear;
		var arrDate = argDate.split("/");
		var nReturn;
		
		sDay	= String(arrDate[0]);
		sMonth	= String(arrDate[1]);
		sYear	= String(arrDate[2]);
		
		sDay	= (sDay.length > 1 ? sDay : "0" + sDay);
		sMonth	= (sMonth.length > 1 ? sMonth: "0" + sMonth);
		
		sReturn = sDay + "/" + sMonth + "/" + (getIntValue(sYear) + 1);
		
		return nReturn;
	}

/*
	function isValidStartDate(ctrl, min, max, msg){
		var argObj;
		var cvStartDate;
		
		argObj = Obj(ctrl + "_txtDate");
		cvStartDate = GetCompareDate(ctrl)
		
		if (cvStartDate < min || cvStartDate > max){
			alert(msg);
			Obj(ctrl + "_ddlDay").focus();
			return false;
		}
		return true;
	}
*/

