var selectprop = "0";
var sortorder ="";
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

var sortorder="";

function rentlistshort(message){
 newmessage="";
 if(message){
   newmessage=message;
 }
   document.write("<table class=cellborderalb cellpadding=1 width=90% cellspacing=1 >");
document.write("<tr><td width=100></td><td align=center class=mediumblue colspan=2><b>Properties for Rent (Summary)</b></td><td width=100 class=smallblue>"+ newmessage+"</td></tr>");

	for( i=0 ; i < rent.length ; i++ ) {
		document.write("<tr> ") ;
		document.write("<td class=smallblueb valign=Top>" + rent[i].location + "</td>");
		document.write("<td class=smallblueb valign=Top align=left >");
		document.write(rent[i].shortdesc + "</td>");
		document.write("<td class=smallblueb>");
		document.write(rent[i].caption);
		document.write("</td><td class=smallblueb valign=Top align=right><b>&euro; " + rent[i].rent +"</b></td>");
		document.write("</tr>");

	}
	document.write("</table>");
}


function rentlist(){
   document.write("<table class=cellborderall cellpadding=1 width=90% cellspacing=1 >");
	for( i=0 ; i < rent.length ; i++ ) {
		document.write("<tr class='smallblack'  ") ;
		document.write( " >");

		document.write("<td class=mediumblueb valign=Top>" + rent[i].location + "</td>");
		document.write("<td class=mediumblueb valign=Top align=left >");
		document.write(rent[i].shortdesc + "</td>");
		document.write("<td class=mediumblueb valign=Top align=center>" + rent[i].type + "</td>");

		document.write("<td class=mediumblueb valign=Top align=center>" + rent[i].period + "</td>");
		document.write("<td class=mediumblueb valign=Top align=right><b>&euro; " + rent[i].rent +"</b></td>");
		document.write("</tr>");
		document.write("<tr><td valign=top class=smallblackb rowspan=2><img height=60 width=80 src='../"+rent[i].img1+"'>");

		document.write("</td><td class=smallblue colspan=4>");
		document.write(rent[i].caption);
		document.write("</td></tr>");


		document.write("</td><td valign=top class=smallblackb colspan=4>");
		document.write(rent[i].description +"<br>&nbsp;");
		document.write("</td></tr>");

	}
	document.write("</table>");
}



function proplist(area){
	for( i=0 ; i < prop.length ; i++ ) {

		if(area){
			if(prop[i].location!=area){
				continue;
			}
		}

		document.write("<tr ");
		var excess="";
		if(prop[i].excess){
		 excess="+";
		}
		newimg = "";
		if(prop[i].newprop){
		  newimg="<img src='images/fixed/newimg.jpg'></img>";
		}

		if ((i % 2) == 1){ document.write( " class='listrow'  ") ; }
		else {
			document.write( " class='listrowodd'  ") ;
		}

		document.write( " >");

		document.write("<td valign=top align=left> <div class=shortlist style='width:110px;' >" + prop[i].location + "</div></td>");
		//document.write("<td valign=Top align=left ><div style='text-align:left;' ><a class=smallblue href=" + prop[i].href + "?prop=" + (i).toString() + "&sort=" + sortorder);
		document.write("<td valign=Top align=left ><div class=shortlist style='width: 304px;'> <a class=smallblue href=" + prop[i].href + "?prop=" + prop[i].num + "&sort=" + sortorder);
		document.write(" onmouseout=\"showtext('h" + (i+1).toString() +"',0)\"   ");
		document.write(" onmouseover=\"showtext('h" + (i+1).toString() +"',");
		document.write((i+1).toString() +")\">");
		document.write(prop[i].shortdesc +"</a></div></td>");
		document.write("<td>"+newimg+"</td>");

		document.write("<td class=smallblue valign=Top align=center>" + prop[i].type + "</td>");

		document.write("<td class=smallblue valign=Top align=center>" + prop[i].status + "</td>");
		document.write("<td valign=Top align=right>&euro; " + prop[i].price +excess+"</td>");
		document.write("</tr>");
	}

}

/**
 *
 * @access public
 * @return void
 **/
function locationlist(){

	var allLocation = [];
	var arrLocation = [];
	//arrLocation[0]=prop[0].location;
	//temploc=prop[0].location;

	for( i=0 ; i < prop.length ; i++ ) {
			allLocation[i]=prop[i].location;
	}

	allLocation.sort();

    arrLocation[0]=allLocation[0];

	var j=0;
	for( i=1 ; i < allLocation.length ; i++ ) {
		if(arrLocation[j]==allLocation[i]){

		} else {
			j++;
			arrLocation[j]=allLocation[i];
		}
	}

	//arrLocation.sort;

	document.write("<form name='sortloc' style='margin-bottom:0;' >");
	document.write("<SELECT class=sfield name='newlocation' onChange='location.href=sortloc.newlocation.options[selectedIndex].value'>");
	document.write("<OPTION value=\"index.html\">All </option>");


	for( i=0 ; i < arrLocation.length ; i++ ) {

		if (args.area==arrLocation[i]) {
			theselected='SELECTED';
		}else {
			theselected="";
		}

		document.write("<OPTION " +  theselected+"  value=\"index.html?area="+arrLocation[i]+"\">"+arrLocation[i]+"</option>");
	}
	document.write("</SELECT>");
	document.write("</form>");

}

function addstyle(){
	document.write("<style type=\"text/css\">");
	for( i=0 ; i < prop.length ; i++ ) {
		document.write("#h" + (i+1).toString() + "  { visibility : hidden ; position : absolute ; display : none; top : 70px ; z-index : 2 ; left  : 50px; background-color : #ffffff; filter:alpha(opacity=100); opacity: 1.0; } ") ;
	}
	document.write("</style>");
}


function sortprop(param, obj){
		prop.sort( function(o1,o2) {

		if (param=="price" ) {
			var price1=parseInt(o1.price.replace(/,/g, ""));
			if(!price1){
				price1=0;
			}
			var price2=parseInt(o2.price.replace(/,/g, ""));
			if(!price2){
				price2=0;
			}

			return price1 - price2 ;

		} else if ( param=="location") {

			return o1.location < o2.location ? -1 : 1 ;

		} else if ( param=="status") {
			return o1.status < o2.status ? -1 : 1 ;
		} else if ( param=="type") {
			return o1.type < o2.type ? -1 : 1 ;
		} else {
			return o1.location < o2.location ? -1 : 1
		}
	}


	);
}

function adddesc(){

 	var excess="";
	for( i=0 ; i < prop.length ; i++ ) {
		if(prop[i].excess){
			excess = prop[i].excess;
		}
		document.write("<DIV class='hypertext' id='h" +(i+1).toString()+ "' ><div class='windowb'>" + prop[i].shortdesc + "</div><div class=windows>" + prop[i].caption + "</div><br><div class=windowc>Price Region:  " +excess + "<b> &euro;"+prop[i].price + "</b></div></div>") ;
		excess="";
	}
}

function getArgs(){

	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");

	for (i=0 ; i< pairs.length ; i++){
		var pos = pairs[i].indexOf('=');
		if ( pos == -1 ) continue;
		var argname=pairs[i].substring(0,pos);
		var value=pairs[i].substring(pos+1);
		args[argname]=unescape(value);

	}
	return args;
}

	function toggleImage(imgName, num){

		if (document.images && imgName){
			imgName.src = im[num].src;
		}
      	  return;

	}

	function showtext(id, num){
		domStyle=findDOM(id, 1);
		blankStyle=findDOM( 'blankhyper', 1);
		state=domStyle.visibility;

		if (state=="visible" || state=="show"){
			if(isLayers!=1){
				toggleImage(i1, 0);
			}
			domStyle.visibility='hidden';
			domStyle.display='none';
			blankStyle.visibility='hidden';
			blankStyle.display='none';

		}
		else {
			if(isLayers!==1){
				toggleImage(i1, num);
			}
			domStyle.visibility='visible';
			domStyle.display='block';
			blankStyle.visibility='visible';
			blankStyle.display='block';
		}
	}



	function show(id){
		domStyle=findDOM(id, 1);
		state=domStyle.visibility;
		if (state=="visible" || state=="show"){
			domStyle.visibility='hidden';
			domStyle.display='none';
		}
		else {
			domStyle.visibility='visible';
			domStyle.display='block';
		}
	}

	function loadimages(){
		if (document.images){

			//load images...
			im = new Array();
			im[0] = new Image();

			im[0].src="images/fixed/blank.gif";
			for (var i = 1; i <= prop.length; i++){
				im[i] = new Image();
				//im[i].src = prop[i-1].imagesmall;
				im[i].src = prop[i-1].img1;
			}

		}

	}

	function displaydate(){

	<!-- This script and many more are available free online at -->
	<!-- The JavaScript Source!! http://javascript.internet.com -->
	<!-- Original:  Chris (javascript@crashedstar.com) -->
	<!-- Web Site:  http://www.crashedstar.com/ -->

	<!-- Begin
		var mydate=new Date()
		var year=mydate.getYear()
		if (year < 1000)
			year+=1900
		var day=mydate.getDay()
		var month=mydate.getMonth()
		var daym=mydate.getDate()
		if (daym<10)
			daym="0"+daym
		var hours=mydate.getHours()
		var minutes=mydate.getMinutes()
		//var seconds=mydate.getSeconds()
		var dn="AM"
		if (hours>=12)
			dn="PM"
		if (hours>12){
			hours=hours-12
		}
		{
		 d = new Date();
		 //Time24H = new Date();
		 //Time24H.setTime(d.getTime() + (d.getTimezoneOffset()*60000) + 3600000);
		 //InternetTime = Math.round((Time24H.getHours()*60+Time24H.getMinutes()) / 1.44);
		 //if (InternetTime < 10) InternetTime = '00'+InternetTime;
		 //else if (InternetTime < 100) InternetTime = '0'+InternetTime;
		}
		if (hours==0)
			hours=12
		if (minutes<=9)
		minutes="0"+minutes
	//	if (seconds<=9)
	//	seconds="0"+seconds
		//change font size here

		var cdate=dayarray[day]+" <br> "+daym+"-"+montharray[month]+ "-"+year+" <br> "+hours+":"+minutes + " "+dn
		if (document.all)
			document.all.clock.innerHTML=cdate
		else if (document.getElementById)
			document.getElementById("clock").innerHTML=cdate
		else
		document.write(cdate)
	}

	function goforit(){
		if (document.all||document.getElementById)
		setInterval("displaydate()",60000)
	}

	function showdate() {
		displaydate();
		if (!document.all&&!document.getElementById)
			displaydate()
		window.onload=goforit ;
	}

	// Gallery script.
	// With image cross fade effect for those browsers that support it.
	// Script copyright (C) 2004 www.cryer.co.uk.
	// Script is free to use provided this copyright header is included.
	function LoadGallery(pictureName,imageFile,titleCaption,captionText)
	{
	  if (document.all)
	    {
			//alert(pictureName);
	        document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
		    document.getElementById(pictureName).filters.blendTrans.Apply();
	     }
	      document.getElementById(pictureName).src = imageFile;

	     // alert(imageFile);
	      if (document.all)
	      {
	     	document.getElementById(pictureName).filters.blendTrans.Play();
	      }
	   // document.getElementById(titleCaption).innerHTML=captionText;
	}

function Morgcal()
{
        form = document.myform
        LoanAmount= form.LoanAmount.value
	LoanAmount = LoanAmount.replace(/,/g, '');

        DownPayment= "0"
        AnnualInterestRate = form.InterestRate.value/100
        Years= form.NumberOfYears.value
        MonthRate=AnnualInterestRate/12
        NumPayments=Years*12
	Prin=LoanAmount-DownPayment

  	MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100
        form.NumberOfPayments.value=NumPayments
        form.MonthlyPayment.value=MonthPayment
}

function FormatNumber(num)
{
        var sVal='';
        var minus='';
        var CommaDelimiter=',';

        try
       {

           num = parseInt(num);

           var samount = new String(num);

           for (var i = 0; i < Math.floor((samount.length-(1+i))/3); i++)
          {
             samount = samount.substring(0,samount.length-(4*i+3)) + CommaDelimiter + samount.substring(samount.length-(4*i+3));
           }

        }
         catch (exception) { AlertError("Format Number",e); }
        return samount;
}




/**
 *
 * @access public
 * @return void
 **/
function getSDPreBudget08(type, val){

    value = val.replace(/,/g, '');
    var v=parseInt(value);

/**  Change in pre election 2007
*	if (type=="first") {
*
*		if(v > 635000){
*			return(9);
*		} else if( v > 381000){
*			return(6);
*		} else if( v > 317501){
*			return(3);
*		} else {
*			return(0);
*		}
*
*	}
**/

    if (type=="first") {

			return(0);

	}

    if (type=="exist") {
		if(v > 635000){
			return(9);
		} else if( v > 381000){
			return(7.5);
		} else if( v > 317500){
			return(6);
		} else if( v > 254000){
			return(5);
		} else if( v > 190500){
			return(4);
		} else if( v > 127000){
			return(3);
		} else {
			return(0);
		}
	}

    if (type=="land") {
		if(v > 150000){
			return(9);
		} else if( v > 120000){
			return(8);
		} else if( v > 100000){
			return(7);
		} else if( v > 80000){
			return(6);
		} else if( v > 70000){
			return(5);
		} else if( v > 40000){
			return(4);
		} else if( v > 30000){
			return(3);
		} else if( v > 20000){
			return(2);
		} else if( v > 10000){
			return(1);
		} else {
			return(0);
		}
	}
}



/**
 *
 * @access public
 * @return void
change for budget 08

 **/
function getStampDuty(type, val){

    value = val.replace(/,/g, '');
    var v=parseInt(value);

/**  Change in pre election 2007
*	if (type=="first") {
*
*		if(v > 635000){
*			return(9);
*		} else if( v > 381000){
*			return(6);
*		} else if( v > 317501){
*			return(3);
*		} else {
*			return(0);
*		}
*
*	}
**/

    if (type=="first") {

			return(0);

	}

    if (type=="exist") {
		if(v > 1000000){
			return(9);
		} else {
			return(7);
		}
	}

    if (type=="land") {
		if(v > 150000){
			return(9);
		} else if( v > 120000){
			return(8);
		} else if( v > 100000){
			return(7);
		} else if( v > 80000){
			return(6);
		} else if( v > 70000){
			return(5);
		} else if( v > 40000){
			return(4);
		} else if( v > 30000){
			return(3);
		} else if( v > 20000){
			return(2);
		} else if( v > 10000){
			return(1);
		} else {
			return(0);
		}
	}
}


// Javascript validation functions
// http://www.designplace.org/


//function to check empty fields

function isEmpty(strfield1, strfield2, strfield3) {


//change "Email, Firstname and Surname" to your field names
//strfield1 = .email.value

//strfield1 = .value
//strfield2 = document.forms[0].FirstName.value
//strfield3 = document.forms[0].Surname.value

  //name field
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    alert("\"Email\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //url field
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
    alert("\"First Name\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }

  //title field
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("\"Surname\" is a mandatory field.\nPlease amend and retry.")
    return false;
    }
    return true;
}


function isEmptyNew(strfield1, strfield2) {

    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    	alert(strfield2 + " is a mandatory field.\nPlease amend and retry.");
    	return true;
    }
    return false;
}

//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  //strEmail = document.forms[0].email.value;


   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
   {
      alert('A valid e-mail address is required.\nPlease amend and retry');
      return false;
    }
    return true;
}


//function that performs all functions, defined in the onsubmit event handler

function check(form){
	if (isEmpty(form.email.value, form.FirstName.value, form.Surname.value)){
  		//if (isEmpty(form.FirstName)){
    	//	if (isEmpty(form.Surname)){
				if (isValidEmail(form.email.value)){
		  			return true;
				}
	  	//	}
  		//}
	}
	return false;
}

function checkemailafriend(form){
	if(isEmptyNew(form.frname.value,"Friends Name" )){
		return false;
	}else {
		if (isEmptyNew(form.fremail.value,"Friends Email" )) {
			return false;
		} else {
			if(isEmptyNew(form.yourname.value,"Your Name" )){
				return false
			}
		}
	}

	if (isValidEmail(form.fremail.value)){
			return true ;
	} else {
			return false;
	}

 }


  /**
    *
    * @access public
    * @return void
    **/
   function popemailafriend(propno){
   		var propadr = "emailafriend.html?prop="+propno;
   		window.open(propadr, 'emailafriend','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=460,height=330,left = 212,top = 159');
   }


function changeimg(startno){

	var thenum=parseInt(startno);
	eval("document.getElementById('featureimg').src="+"featured[thenum].img1;");
	eval("document.getElementById('featurelink').innerHTML="+"featured[thenum].shortdesc;");
	eval("document.getElementById('featurelink').href='html/housetemplate.html?prop="+featured[thenum].num+"'");
	eval("document.getElementById('featureimglink').href='html/housetemplate.html?prop="+featured[thenum].num+"'");

	thenum++;

	if (thenum==(featured.length)) {
		thenum=0;
	}

	window.setTimeout('changeimg('+thenum+')', 5000);
}
