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 fnValid(me)
	{
		if(me.statusch.value=="0")
		{
			alert("Please Select Payment Status");
			me.statusch.focus();
			return false;
		}
		return true;
	}

	function fnFocus()
	{
		document.frmAdmLogin.admuserid.focus();

	}
	function checkdate(bdDay, dbMonth, dbYear)
	{
		if(!IsValidDate(bdDay, dbMonth, dbYear)) 
		{
			return false;
		}
		return true;
	}

	function DaysInMonth(CMonth,CYear)
	{
		 var intMonth = parseInt(CMonth);
		 var intYear = parseInt(CYear);
		 if ((intMonth == 4) ||
		  (intMonth == 6) ||
		  (intMonth == 9) ||
		  (intMonth == 11))
		  return 30;
		 if (intMonth==2) {  // Leap year stuff
		  if ((intYear % 400)==0) return 29;
		  if ((intYear % 100)==0) return 28;
		  if ((intYear % 4)==0) return 29;
		  return 28;
		 }
		 return 31;
	}

	function IsDate(CDay, CMonth, CYear)
	{
		if ((CDay <= 0) || (CDay > 31) ||
		(CMonth <= 0) || (CMonth > 12) ||
		(CYear <= 0))
		return false;
		var intDay = parseInt(CDay);
		var intMonth = parseInt(CMonth);
		var intYear = parseInt(CYear);
		if (intDay <= DaysInMonth(intMonth, intYear)) return true;
		return false;
	}

	function IsValidDate(CDay, CMonth, CYear)
	{
		if(!IsDate(CDay, CMonth, CYear)) 
		{
			alert("Please select valid date");
			return false;
		}
		Today = new Date();
		DayBeforeYesterday = new Date((Today.getTime() - 172800000));
		Hours = Today.getHours();
		Minutes = Today.getMinutes()+1;
		Seconds = Today.getSeconds();
		StartDate= new Date(CYear,(CMonth - 1),CDay,Hours,Minutes,Seconds);
		if (StartDate<Today) 
		{ 
			alert("Date must be above current date!");
			return false;
		}
		return true;
	}
	function y2k(number) 
	{
		return (number < 1000) ? number + 1900 : number;
	}
	function isDate (day,month,year) 
	{
		var today = new Date();
		var test = new Date(year,month,day);
		if ( (test.getYear() == year) && (month == test.getMonth()) && (day == test.getDate()))
			return true;
		else
			return false;
	}

	function checkAdmin(mf)
	{
		if(mf.admuserid.value=="")
		{
			alert("Please enter administrator userid");
			mf.admuserid.focus();
			return false;
		}
		if(mf.admuserpass.value=="")
		{
			alert("Please enter administrator password");
			mf.admuserpass.focus();
			return false;
		}
		return true;
	}

	function checkAdminDetails(mf)
	{
		if(mf.admuserid.value=="")
		{
			alert("Please enter administrator userid");
			mf.admuserid.focus();
			return false;
		}
		if(mf.admuserpass.value=="")
		{
			alert("Please enter administrator password");
			mf.admuserpass.focus();
			return false;
		}
		if(mf.admcuserpass.value!=mf.admuserpass.value)
		{
			alert("Passwords not matching. Please re-enter your password");
			mf.admcuserpass.focus();
			return false;
		}
		return true;
	}

	function checkEmail(myForm)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.Email.value))
		{
			return (true);
		}
		alert("Invalid e-mail address! please re-enter");
		return (false);
	}


	function trim(inputString) 
	{
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") 
		{ 
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") 
		{
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1) 
		{ 
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
		}
		return retValue; 
	}
function NumValidation(strFld)
{
	var valid= "+- 0123456789()";
	if (strFld !="")
	{
		var length = strFld.length;
		for(var i=0;i<=length;i++)
		{
			var substring = strFld.substr(i,1);
			if(valid.indexOf(substring)== -1)
			{
				return 0;
			}
		}
	}
	return 1;
}

function validateform(mf)
{
	if(mf.name.value=="")
		{
			alert("Please enter name");
			mf.name.focus();
			return false;
		}
	if(mf.address.value=="")
		{
			alert("Please enter full address");
			mf.address.focus();
			return false;
		}
	if(mf.gen_postcode.value=="")
	{
		alert("Please enter postcode");
		mf.gen_postcode.focus();
		return false;
	}
	if(mf.phone.value=="")
		{
			alert("Please enter contact telephone no.");
			mf.phone.focus();
			return false;
		}
	if(NumValidation(mf.phone.value)==0)
		{
			alert("Invalid contact number, Please enter valid contact number\nValid entries are 0123456789+-()");
			mf.phone.focus()
			return false;
		}
	if(mf.Email.value=="")
	{
		alert("Please enter email address");
		mf.Email.focus();
		return false;
	}
	if(mf.Email.value !="")
	{
		if(checkEmail(mf)==false)
		{
			mf.Email.focus();
			return false; 
		}
	}	
	if(mf.property_name.value=="")
	{
		alert("Please enter property name");
		mf.property_name.focus();
		return false;
	}
	if(mf.property_address.value=="")
	{
		alert("Please enter property address");
		mf.property_address.focus();
		return false;
	}
	if(mf.postcode.value=="")
	{
		alert("Please enter postcode");
		mf.postcode.focus();
		return false;
	}
	if(mf.no_unit.value=="")
	{
		alert("Please enter number of units");
		mf.no_unit.focus();
		return false;
	}
	if(mf.sel_property.value=="")
	{
		alert("Please select property");
		mf.sel_property.focus();
		return false;
	}
	if(mf.sel_property.value=="1" && mf.const_year.value=="")
	{
		alert("Please enter approximate year of construction");
		mf.const_year.focus();
		return false;
	}
	if(mf.sel_property.value=="1" && mf.res_managed[0].checked==true && mf.name_mang_company.value=="")
	{
		alert("Please enter name of residential management company");
		mf.const_year.focus();
		return false;
	}	
	return true;
}

function validate_maintenance(mf)
{
	if(mf.name.value=="")
		{
			alert("Please enter name");
			mf.name.focus();
			return false;
		}
	if(mf.address.value=="")
		{
			alert("Please enter full address of property");
			mf.address.focus();
			return false;
		}
	if(mf.phone.value=="")
		{
			alert("Please enter contact telephone no.");
			mf.phone.focus();
			return false;
		}
	if(NumValidation(mf.phone.value)==0)
		{
			alert("Invalid contact number, Please enter valid contact number\nValid entries are 0123456789+-()");
			mf.phone.focus()
			return false;
		}
	if(mf.Email.value=="")
	{
		alert("Please enter email address");
		mf.Email.focus();
		return false;
	}
	if(mf.Email.value !="")
	{
		if(checkEmail(mf)==false)
		{
			mf.Email.focus();
			return false; 
		}
	}
	if(mf.detail_issue.value=="" )
	{
		alert("Please enter details of issue");
		mf.detail_issue.focus();
		return false;
	}
	
	return true;
}

function checkform(mf)
{
	if(mf.txttitle.value=="" )
	{
		alert("Please enter title");
		mf.txttitle.focus();
		return false;
	}
	return true;
}
function openURL(imgfile)
{
	window.open(imgfile, 'LargeImage', 'width=400, height=300, scrollbars=yes')
}
function openURL_Terms(imgfile)
{
	window.open(imgfile, 'LargeImage', 'width=600, height=500, scrollbars=yes')
}


function callPropertytype()
{
	
	var mySelect_val=document.getElementById('sel_property');
	if(mySelect_val.value=="1")
	{
		document.getElementById('InsertOptions').innerHTML="<table><tr><td colspan='2' class='black11' style='height:28px;'>Approximate Year of Construction:</td></tr><tr><td colspan='2' style='height:28px;'><input type='text' name='const_year' /></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>Is The Property Owned By An Outside Freeholder?</td></tr><tr><td colspan='2' style='height:28px;'><table width='30%' border='0' cellspacing='1' cellpadding='2'><tr><td style='width:10%'><input name='prop_owner' type='radio' value='Yes' selected /></td><td class='black11' style='width:40%'>Yes</td><td style='width:10%'><input name='prop_owner' type='radio' value='No' /></td><td class='black11' style='width:40%'>No</td></tr></table></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>Is There A Residential Management Company In Place At This Property?</td></tr><tr><td colspan='2' style='height:28px;'><table width='30%' border='0' cellspacing='1' cellpadding='2'><tr><td style='width:10%'><input name='res_managed' type='radio' value='Yes' selected /></td><td class='black11' style='width:40%'>Yes</td><td style='width:10%'><input name='res_managed' type='radio' value='No' /></td><td class='black11' style='width:40%'>No</td></tr></table></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>If Yes, Name of Residential Management Company</td></tr><tr><td colspan='2' style='height:28px;'><input type='text' name='name_mang_company' /></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>Are You A Director Of This Company?</td></tr><tr><td colspan='2' style='height:28px;'><table width='30%' border='0' cellspacing='1' cellpadding='2'><tr><td style='width:10%'><input name='director_yes' type='radio' value='Yes' selected /></td><td class='black11' style='width:40%'>Yes</td><td style='width:10%'><input name='director_yes' type='radio' value='No' /></td><td class='black11' style='width:40%'>No</td></tr></table></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>Briefly, What Are Your Reasons For Considering Moving Agents?</td></tr><tr><td colspan='2' style='height:28px;'><input type='text' name='moving_agent' /></td></tr></table>";
	}
	else if(mySelect_val.value=="2")
	{
		
		document.getElementById('InsertOptions').innerHTML="<table><tr><td colspan='2' class='black11' style='height:28px;'>Type of Use:</td></tr><tr><td colspan='2' style='height:28px;'><select name='type_of_use'><option value='Retail'>Retail</option><option value='Industrial'>Industrial</option><option value='Mixed Use'>Mixed Use</option></select></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>Lease Terms:</td></tr><tr><td colspan='2' style='height:28px;'><select name='lease_terms'><option value='FRI'>FRI</option><option value='IRI'>IRI</option><option value='Combination'>Combination</option></select></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>Is There a Service Charge?</td></tr><tr><td colspan='2' style='height:28px;'><table width='30%' border='0' cellspacing='1' cellpadding='2'><tr><td style='width:10%'><input name='ser_charge' type='radio' value='Yes' selected /></td><td class='black11' style='width:40%'>Yes</td><td style='width:10%'><input name='ser_charge' type='radio' value='No' /></td><td class='black11' style='width:40%'>No</td></tr></table></td></tr><tr><td colspan='2' class='black11' style='height:28px;'>What Is The Year End?</td></tr><tr><td colspan='2' style='height:28px;'><input type='text' name='year_end' /></td></tr></table>";
	}
	else
	{
		document.getElementById('InsertOptions').innerHTML="";
	}

}

function validate_insurance_form(mf)
{
	if(mf.name_insured.value=="")
	{
		alert("Please enter name of insured.")
		mf.name_insured.focus();
		return false;
	}
	if(mf.risk_address.value=="")
	{
		alert("Please enter risk address.")
		mf.risk_address.focus();
		return false;
	}
	if(mf.postcode.value=="")
	{
		alert("Please enter postcode.")
		mf.postcode.focus();
		return false;
	}
	if(mf.note_for_interest.value=="")
	{
		alert("Please enter note for interest.")
		mf.note_for_interest.focus();
		return false;
	}
	if(mf.building_dec_value.value=="")
	{
		alert("Please enter building declared value.")
		mf.building_dec_value.focus();
		return false;
	}
	if(mf.loss_of_rent.value=="")
	{
		alert("Please enter loss of rent.")
		mf.loss_of_rent.focus();
		return false;
	}
	if(mf.cover_req_from.value=="")
	{
		alert("Please enter cover required from.")
		mf.cover_req_from.focus();
		return false;
	}
	if(mf.property_build_of.value=="")
	{
		alert("Is the property build of standard construction?")
		mf.property_build_of.focus();
		return false;
	}

	if(mf.listed_building[0].checked==true && mf.constuct_year.value=="")
	{
		alert("When it was constructed?")
		mf.constuct_year.focus();
		return false;
	}
	if(mf.premises_occupied[1].checked==true && mf.how_long_occupied.value=="")
	{
		alert("How long have they been unoccupied??")
		mf.how_long_occupied.focus();
		return false;
	}
	if(mf.any_claims[0].checked==true && mf.claim_yes_details.value=="")
	{
		alert("Please provide details.")
		mf.claim_yes_details.focus();
		return false;
	}
	if(mf.phone.value!="")
	{
		if(NumValidation(mf.phone.value)==0)
		{
			alert("Invalid contact number, Please enter valid contact number\nValid entries are 0123456789+-()");
			mf.phone.focus()
			return false;
		}
	}
	if(mf.chkAgrred.checked==false)
	{
		alert("Please check.\nI/we declare that the answers given are true and complete to the best of...")
		mf.chkAgrred.focus();
		return false;
	}
	return true;
}

function checktypeofwork(mf)
{
	if(mf.type_ofwork_name.value=="")
	{
		alert("Please enter type of work undertaken.");
		mf.type_ofwork_name.focus();
		return false;
	}
	return true;
}
function checklocation(mf)
{
	if(mf.location_name.value=="")
	{
		alert("Please enter location covered.");
		mf.location_name.focus();
		return false;
	}
	return true;
}
function checkContracts(mf)
{
	if(mf.contractor_name.value=="")
	{
		alert("Please enter contractor name");
		mf.contractor_name.focus();
		return false;
	}
	/*if(mf.work_undertaken.value=="")
	{
		alert("Please select work undertaken");
		mf.work_undertaken.focus();
		return false;
	}*/
	if(mf.approval_date.value=="")
	{
		alert("Please enter approval date");
		mf.approval_date.focus();
		return false;
	}
	if(mf.contact_details.value=="")
	{
		alert("Please enter contact details");
		mf.contact_details.focus();
		return false;
	}
	/*
	if(mf.location_covered.value=="")
	{
		alert("Please select location covered");
		mf.location_covered.focus();
		return false;
	}*/
	return true;
}
function checkSearch(mf)
{
	if(mf.work_undertaken.value=="")
	{
		alert("Please select workundertaken.");
		mf.work_undertaken.focus();
		return false;
	}
	if(mf.location_covered.value=="")
	{
		alert("Please select location covered.");
		mf.location_covered.focus();
		return false;
	}
	return true;
}
function checkPage(mf)
{
	if(mf.pagetitle.value=="")
	{
		alert("Please enter page title");
		mf.pagetitle.focus();
		return false;
	}
	return true;
}