// JavaScript Document


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function ElementAvailability(){
	
	chkUnavailable = document.getElementById("Unavailable");
	
	if (chkUnavailable.checked){
		
		ShowHide('UnavailableNotes','');
		ShowHide('ElementContent','');
	
	}else{
				
		ShowHide('UnavailableNotes','none');
		ShowHide('ElementContent','');
		
	}
		

	
}

function IncludeElement(strElement,fltPrice,VatNeeded) { 
 		
		 	
		 	strElement = document.getElementById(strElement);
			
			
			SubTotal = document.getElementById("SubTotal");
			AdminFee = document.getElementById("AdminFee");
			AdminFeeValue = document.getElementById("AdminFeeValue");
			Vat = document.getElementById("Vat");
			Total = document.getElementById("Total");
			
			
					
			if (strElement.checked ) {
			
				SubTotalTmp = parseFloat(SubTotal.value) + parseFloat(fltPrice);
				
			
			}else{
				
				SubTotalTmp = parseFloat(SubTotal.value) - parseFloat(fltPrice);
				
			}
			
			SubTotalTmp = SubTotalTmp.toFixed(2);
				
				if (SubTotalTmp > 0){
					AdminFeeTmp = parseFloat(AdminFeeValue.value);
				}else{
					AdminFeeTmp = 0;
				}
				AdminFeeTmp = AdminFeeTmp.toFixed(2);
				
				if (VatNeeded == "True") {
					VatTmp = (parseFloat(SubTotalTmp) + parseFloat(AdminFeeTmp)) * 0.175 ;
				
				}else{
					VatTmp = 0;
					
				}
				VatTmp = VatTmp.toFixed(2);
				
				TotalTmp = parseFloat(SubTotalTmp) + parseFloat(AdminFeeTmp) +  parseFloat(VatTmp);
				TotalTmp = TotalTmp.toFixed(2);
				
				
				SubTotal.value = SubTotalTmp;
				AdminFee.value = AdminFeeTmp;
				Vat.value = VatTmp;
				Total.value = TotalTmp;
		 
		 }
		 
		 
		 function IncludeAmmendment(strAddElement,fltAddPrice,strRemoveElement,fltRemovePrice,VatNeeded) { 
		 
			strAddElement = document.getElementById(strAddElement);
			
			
			
			SubTotal = document.getElementById("SubTotal");
			AdminFee = document.getElementById("AdminFee");
			AdminFeeValue = document.getElementById("AdminFeeValue");
			Vat = document.getElementById("Vat");
			Total = document.getElementById("Total");
			
			
			if (strAddElement.checked ) {
			
				
				
				if (strRemoveElement != "") {
					strRemoveElement = document.getElementById(strRemoveElement);
					
					if (strRemoveElement.checked ) {
					
						strRemoveElement.checked = false;
					
					}else{
						fltRemovePrice = 0;
					
					}
					
					
				}
				
				SubTotalTmp = parseFloat(SubTotal.value) + parseFloat(fltAddPrice) - parseFloat(fltRemovePrice);
				
			}else{
				
				SubTotalTmp = parseFloat(SubTotal.value) - parseFloat(fltAddPrice);
				
			}
			
			SubTotalTmp = SubTotalTmp.toFixed(2);
				
				if (SubTotalTmp > 0){
					AdminFeeTmp = parseFloat(AdminFeeValue.value);
				}else{
					AdminFeeTmp = 0;
				}
				AdminFeeTmp = AdminFeeTmp.toFixed(2);
				
				if (VatNeeded == "True") {
					VatTmp = (parseFloat(SubTotalTmp) + parseFloat(AdminFeeTmp)) * 0.175 ;
				
				}else{
					VatTmp = 0;
					
				}
				VatTmp = VatTmp.toFixed(2);
				
				TotalTmp = parseFloat(SubTotalTmp) + parseFloat(AdminFeeTmp) +  parseFloat(VatTmp);
				TotalTmp = TotalTmp.toFixed(2);
				
				
				SubTotal.value = SubTotalTmp;
				AdminFee.value = AdminFeeTmp;
				Vat.value = VatTmp;
				Total.value = TotalTmp;
		 
		 
		 }
		 
		 
		 
		 
		 
function GenerateSaleStatement(){

	//Initially set the additonal fields as hidden
	ShowHide('BasementFields','none');

	//Element Holding the statement
	txtStatement = document.getElementById("Statement");
	
	//Elements providing the values
	sltYearBuilt = document.getElementById("YearBuilt");
	sltFloors = document.getElementById("Floors");
	sltBasement = document.getElementById("Basement");
	sltBuild = document.getElementById("Build");
	sltBuildOther = document.getElementById("BuildOther");
	sltCovered = document.getElementById("Covered");
	sltCoveredOther = document.getElementById("CoveredOther");
	sltTypeCont = document.getElementById("TypeCont");
	sltTypeContOther = document.getElementById("TypeContOther");
	sltType = document.getElementById("Type");
	sltBedrooms = document.getElementById("Bedrooms");
	sltRoomsInRoof = document.getElementById("RoomsInRoof");
	
	//Get the Values
	strYearBuilt = sltYearBuilt.value;
	strFloors = sltFloors.options[sltFloors.selectedIndex].value;
	strBasement = sltBasement.options[sltBasement.selectedIndex].value;
	strBuild = sltBuild.options[sltBuild.selectedIndex].value;
	strBuildOther = sltBuildOther.value;
	strCovered = sltCovered.options[sltCovered.selectedIndex].value;
	strCoveredOther = sltCoveredOther.value;
	strTypeCont = sltTypeCont.options[sltTypeCont.selectedIndex].value;
	strTypeContOther = sltTypeContOther.value;
	strType = sltType.options[sltType.selectedIndex].value;
	strBedrooms = sltBedrooms.options[sltBedrooms.selectedIndex].value;
	strRoomsInRoof = sltRoomsInRoof.options[sltRoomsInRoof.selectedIndex].value;
	
	
	//Set the string
	if (strFloors == "1"){
		strStatementValue = strFloors + ' Floor';
	}else{
		strStatementValue = strFloors + ' Floors';
	}
	
	if (strBasement == "1"){
		strStatementValue +=  ', plus Basement';
	
	}

	if (strBuild == "Other"){
		if (strBuildOther != ""){
			strStatementValue += ", " + strBuildOther +  " built";
		}
	}else{
		strStatementValue += ", " + strBuild +  " built";
	}
	
	
	if (strCovered == "Other"){
		if (strCoveredOther != ""){
			strStatementValue += ", " + strCoveredOther +  " covered";
		}
	}else{
		strStatementValue += ", " + strCovered +  " covered";
	}
	

	if (strTypeCont == "Other"){
		if (strTypeContOther != ""){
			strStatementValue += ", " + strTypeContOther;
		}
	}else{
		strStatementValue += ", " + strTypeCont;
	}
	
	strStatementValue +=  " " + strType;
	
	if (strBedrooms == "1"){
		strStatementValue += ", with " + strBedrooms + ' Bedroom';
	}else{
		strStatementValue += ", with " + strBedrooms + ' Bedrooms';
	}
	
	if (strRoomsInRoof != "0"){
	
		if (strRoomsInRoof == "1"){
			strStatementValue += " and " + strRoomsInRoof + ' room in the roof';
		}else{
			strStatementValue += " and " + strRoomsInRoof + ' rooms in the roof';
		}
		
	}
	
	if (strYearBuilt != ""){
		
		strStatementValue += ", built in " + strYearBuilt;
	}
		
	strStatementValue += ".";	

	txtStatement.value = strStatementValue;
	
	
	//Show/Hide Elements
	
	//Floors
	if (strFloors == "6+"){
		
		ShowHide('FirstFloorWrap','');
		ShowHide('SecondFloorWrap','');
		ShowHide('ThirdFloorWrap','');
		ShowHide('FourthFloorWrap','');		
		ShowHide('OtherFloorsWrap','');
		
		
	}else if (strFloors == "5"){
		
		ShowHide('FirstFloorWrap','');
		ShowHide('SecondFloorWrap','');
		ShowHide('ThirdFloorWrap','');
		ShowHide('FourthFloorWrap','');		
		ShowHide('OtherFloorsWrap','none');
		
		
	}else if (strFloors == "4"){
		
		ShowHide('FirstFloorWrap','');
		ShowHide('SecondFloorWrap','');
		ShowHide('ThirdFloorWrap','');
		ShowHide('FourthFloorWrap','none');		
		ShowHide('OtherFloorsWrap','none');
		
		
	}else if (strFloors == "3"){
		
		ShowHide('FirstFloorWrap','');
		ShowHide('SecondFloorWrap','');
		ShowHide('ThirdFloorWrap','none');
		ShowHide('FourthFloorWrap','none');		
		ShowHide('OtherFloorsWrap','none');
		
		
	}else if (strFloors == "2"){
		
		ShowHide('FirstFloorWrap','');
		ShowHide('SecondFloorWrap','none');
		ShowHide('ThirdFloorWrap','none');
		ShowHide('FourthFloorWrap','none');		
		ShowHide('OtherFloorsWrap','none');
		
		
	}else{
		
		ShowHide('FirstFloorWrap','none');
		ShowHide('SecondFloorWrap','none');
		ShowHide('ThirdFloorWrap','none');
		ShowHide('FourthFloorWrap','none');		
		ShowHide('OtherFloorsWrap','none');
		
		
	}
	
	//Basement	
	if (strBasement == "1"){
				
		//Show the BasementFields
		ShowHide('BasementFields','');
	}else{
		
		//Hide the BasementFields
		ShowHide('BasementFields','none');
	}


}


function ShowHide(strTarget,strDisplayValue){

	var elementmode = document.getElementById(strTarget).style;
	elementmode.display = strDisplayValue;

}

function ShowRooms(strFloor){

	// Get the number of rooms needed
	sltNoRooms = document.getElementById(strFloor+"NoRooms");
	strNoRooms = sltNoRooms.options[sltNoRooms.selectedIndex].value;

	if (strNoRooms == "6") {
		
		ShowHide(strFloor+'Room2','');
		ShowHide(strFloor+'Room3','');
		ShowHide(strFloor+'Room4','');
		ShowHide(strFloor+'Room5','');
		ShowHide(strFloor+'Room6','');
		
	}else if (strNoRooms == "5") {
		
		ShowHide(strFloor+'Room2','');
		ShowHide(strFloor+'Room3','');
		ShowHide(strFloor+'Room4','');
		ShowHide(strFloor+'Room5','');
		ShowHide(strFloor+'Room6','none');
		
	}else if (strNoRooms == "4") {
		
		ShowHide(strFloor+'Room2','');
		ShowHide(strFloor+'Room3','');
		ShowHide(strFloor+'Room4','');
		ShowHide(strFloor+'Room5','none');
		ShowHide(strFloor+'Room6','none');
		
	}else if (strNoRooms == "3") {
		
		ShowHide(strFloor+'Room2','');
		ShowHide(strFloor+'Room3','');
		ShowHide(strFloor+'Room4','none');
		ShowHide(strFloor+'Room5','none');
		ShowHide(strFloor+'Room6','none');
		
	}else if (strNoRooms == "2") {
		
		ShowHide(strFloor+'Room2','');
		ShowHide(strFloor+'Room3','none');
		ShowHide(strFloor+'Room4','none');
		ShowHide(strFloor+'Room5','none');
		ShowHide(strFloor+'Room6','none');
		
	}else{
		
		ShowHide(strFloor+'Room2','none');
		ShowHide(strFloor+'Room3','none');
		ShowHide(strFloor+'Room4','none');
		ShowHide(strFloor+'Room5','none');
		ShowHide(strFloor+'Room6','none');
		
	}

}


function DirectoryEntry(boolEntryAllowed,EntryChecked){
	
	
	if(boolEntryAllowed == "yes"){
		ShowHide('AgentRegionalDirectory','');	
		
		//setCheckedValue(document.forms['Registration'].elements['RegionalDirectory'], strSelectedValue);
		document.getElementById('AgentRegionalDirectoryDisplayed').value = "yes";
		
	}else{
		ShowHide('AgentRegionalDirectory','none');	
		
		
		//setCheckedValue(document.forms['Registration'].elements['RegionalDirectory'], strSelectedValue);
		document.getElementById('AgentRegionalDirectoryDisplayed').value = "no";
	}
	
	if(EntryChecked == "1"){
		
		setCheckedValue(document.forms['Registration'].elements['RegionalDirectory'],'1');
	}else if(EntryChecked == "0"){
		
		setCheckedValue(document.forms['Registration'].elements['RegionalDirectory'],'0');
	}
	
	
}
		 
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
