function checkFrames(code) {
	if (top.location==self.location){
		top.location = "/property/"+code;
	}
}


function printNewContactField() {
	
	// increment the contactcount
	contactCount++;
	
	var myTable = document.getElementById('myTable');
	
	// clone the last TR item in the table and append it to the table
	var clone = document.getElementById('myTR').cloneNode(true);
	
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		// Internet Explorer
		myTable.firstChild.appendChild(clone);
	} else {
		// Safari, Mozilla, Firefox etc.
		myTable.appendChild(clone);
	}
		
	// find the last select tag and rename it.
	var selects = myTable.getElementsByTagName('select');
	selects[selects.length-1].setAttribute('name', 'type'+contactCount);
	selects[selects.length-1].setAttribute('id', 'type'+contactCount);
	
	// find the text input tag and rename it.
	var inputs = myTable.getElementsByTagName('input');
	inputs[inputs.length-1].setAttribute('name', 'contact'+contactCount);
	inputs[inputs.length-1].setAttribute('id', 'contact'+contactCount);
	inputs[inputs.length-1].setAttribute('value', '');
	
	// find the hidden input tag and rename it.
	if(inputs[inputs.length-2].type == "hidden") {
		inputs[inputs.length-2].setAttribute('name', 'recid'+contactCount);
		inputs[inputs.length-2].setAttribute('id', 'recid'+contactCount);
		inputs[inputs.length-2].setAttribute('value', '');
	}
	
	// find the last img tag and rename it.
	var imgs = myTable.getElementsByTagName('a');	
	imgs[imgs.length-1].setAttribute('href', "javascript:deleteContactField("+contactCount+");");
		
	// save the number of teams in the hidden value
	document.getElementById('contactcount').setAttribute('value', contactCount);
	
	new Effect.Highlight(clone);
	

}


function deleteContactField(id) {

	//alert(id);
	
	if (id == 1) {
		alert("Sorry, the first contact must remain.");
	} else {
		var myTable = document.getElementById('myTable');
		
		if (navigator.appVersion.indexOf("MSIE")!=-1) { // Internet Explorer
			var myTR = document.getElementById('type'+id).firstChild.parentNode.parentNode;
		} else { // Safari, Mozilla, Firefox etc.
			var myTR = document.getElementById('type'+id).parentNode.parentNode;
		}
	
		var recid = document.getElementById('recid'+id).value;
		var deletedcontacts = document.getElementById('deletedcontacts');
		
		deletedcontacts.value = deletedcontacts.value + recid + ',';
		
		myTR.innerHTML = "";
	}	

}

function toggleEnabledState(id) {
    field = document.getElementById(id);
    field.disabled = (! field.disabled );
}

function toggleDateFieldEnabledState(name) {
	dayF = eval("document.Form1." + name + "Day");
	monthF = eval("document.Form1." + name + "Month");
	yearF = eval("document.Form1." + name + "Year");
	
	dayF.disabled = (!dayF.disabled);
	monthF.disabled = (!monthF.disabled);
	yearF.disabled = (!yearF.disabled);
}

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;

  DaysForThisSelection = DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;
  if (CurrentDaysInSelection > DaysForThisSelection)
  {
    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}

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_validateForm() { //v4.0
		  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
		  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
			if (val) { nm=val.name; if ((val=val.value)!="") {
			  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
			  } else if (test!='R') { num = parseFloat(val);
				if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
				if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
				  min=test.substring(8,p); max=test.substring(p+1);
				  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
			} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
		  } if (errors) alert('The following error(s) occurred:\n'+errors);
		  document.MM_returnValue = (errors == '');
		}
		
		
function addPropertyToEnquiry(code) {

    var url  =  "http://www.factotumletting.com/common/ajax.php?"
                + "cmd=addPropertyToEnquiry&code=" + code;
        
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = addPropertyToEnquiry_ret;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = addPropertyToEnquiry_ret;
            req.open("GET", url, true);
            req.send();
        }
    }
    
}

function addPropertyToEnquiry_ret() {
    if (req.readyState == 4) { // Complete
        if (req.status == 200) { // OK.
        
            sn = document.getElementById('EnquiryList');
            sn.innerHTML = req.responseText;
            new Effect.Highlight(sn);
            
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function deletePropertyFromEnquiry(code) {

    var url  =  "http://www.factotumletting.com/common/ajax.php?"
                + "cmd=deletePropertyFromEnquiry&code=" + code;
        
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = deletePropertyFromEnquiry_ret;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = addPropertyToEnquiry_ret;
            req.open("GET", url, true);
            req.send();
        }
    }
    
}

function deletePropertyFromEnquiry_ret() {
    if (req.readyState == 4) { // Complete
        if (req.status == 200) { // OK.
        
            sn = document.getElementById('EnquiryList');
            sn.innerHTML = req.responseText;
            new Effect.Highlight(sn);
            
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}


function fireEvent(obj,evt){
	
	var fireOnThis = obj;
	if( document.createEvent ) {
	  var evObj = document.createEvent('MouseEvents');
	  evObj.initEvent( evt, true, false );
	  fireOnThis.dispatchEvent(evObj);
	} else if( document.createEventObject ) {
	  fireOnThis.fireEvent('on'+evt);
	}
}

function divSwap(element,container){
    var div = document.getElementById(container);
    var nodeList = div.childNodes;
    var queue = Effect.Queues.get('menuScope');

    if(queue.toArray().length<1){
        if(Element.visible(element)==false){
            for(i=0;i<nodeList.length;i++){
                if(nodeList.item(i).nodeName=="DIV" && nodeList.item(i).id!=element){
                    if(Element.visible(nodeList.item(i))==true){
                        Effect.Fade(nodeList.item(i),{queue:{position:'end',scope:'menuScope',limit:2}})
                    }
                }
            }
            Effect.Appear(element,{queue:{position:'end',scope:'menuScope',limit:2}})
       }
   }
}


