var addtolist_0 = "property NOT added";
var addtolist_1 = "<img src='"+site_url+"/images/btn_addedToList_off.gif' alt='added to list'/>";
var addtolist_2 = "<img src='"+site_url+"/images/btn_alreadyAdded_off.gif' alt='already in list'/>";

var removetolist_0 = "property NOT removed";
var removetolist_1 = "property removed";

function mo(el){
      if(el.firstChild.src.match("_on.gif"))
         el.firstChild.src=el.firstChild.src.replace("_on.gif","_off.gif");
      else
        el.firstChild.src=el.firstChild.src.replace("_off.gif","_on.gif");
    }
function mo2(el){
    if(el.firstChild.src.match("_over.gif")) {
		el.firstChild.src=el.firstChild.src.replace("_over.gif","_off.gif");
	} else if(el.firstChild.src.match("_off.gif")) {
		el.firstChild.src=el.firstChild.src.replace("_off.gif","_over.gif");
	} else if (el.firstChild.src.match("_over.png")) {
		el.firstChild.src=el.firstChild.src.replace("_over.png","_off.png");
	} else if (el.firstChild.src.match("_off.png")) {
		el.firstChild.src=el.firstChild.src.replace("_off.png","_over.png");
	}        
}

function mo3(el){
	if(el.src.match("_over.gif")) {
		el.src=el.src.replace("_over.gif","_off.gif");
	} else if(el.src.match("_off.gif")) {
		el.src=el.src.replace("_off.gif","_over.gif");
	} else if (el.src.match("_over.png")) {
		el.src=el.src.replace("_over.png","_off.png");
	} else if (el.src.match("_off.png")) {
		el.src=el.src.replace("_off.png","_over.png");
	}        	
}



function showPassword(val)
{
        $("msg").style.display='none';
        if (val) $("msg").innerHTML= "Your password has been emailed to you";
        else{
        $("msg").innerHTML="Couldn't send an email. Please try again";
        $("msg").style.display='block';
        }
}


function feedbackLogin(val)
{
        $("msg").style.display='none';
        if (val=="true")
        {
        //hideDiv("registerorlogin");
		hidePopUp('generalIfr');
		parent.document.getElementById("mysiteTop").innerHTML="My Home Hunter <b><a href='"+site_url+"/pages/my_home_hunter/my_details.php' style='color:#FFFFFF;'>Go</a></b> | <b><a href='javascript:void(logoutLink())' style='color:#FFFFFF;'>Log out</a></b>";
		//$("mysiteTop").innerHTML="My Home Hunter <b><a href='../pages/my_home_hunter/my_details.php' style='color:#FFFFFF;'>Go</a></b> | <b><a href='javascript:void(logoutLink())' style='color:#FFFFFF;'>Log out</a></b>";
                loggedIn=true;
        }
        else{
        $("msg").innerHTML='Sorry, could not log in';
        $("msg").style.display='block';
        }
}

function logoutLink(){
  window.location=site_url+'/pages/my_home_hunter/my_details.php?action=logout';
}

function unregister() {
	window.location=site_url+'/pages/my_home_hunter/my_details.php?action=remove';
}

function confirmationPopUp(actionYes,actionNo,width,height,offLeft,offTop,txt) {
	
	/*
	txt = '';
	actionYes = 'unregister()';
	actionNo = 'hideDiv(\'confirmationPopUp\')';
	height = 150;
	width = 350;
	*/
	
	setVisibleTop('confirmationPopUp',offTop,offLeft);
	$('confirmationPopUpInner').style.width = width+'px';
	$('confirmationPopUpInner').style.height = height+'px';
	$('confirmationPopUpContent').innerHTML = txt;
	document.getElementById('confirm-action-yes').href = actionYes;
	document.getElementById('confirm-action-no').href = actionNo;
	document.getElementById('confirmationPopUp').style.display='block';
}
function forgottenPassword(email)
{
        $("msg").style.display='none';
        if (email==""){
          $('msg').innerHTML="Sorry, please enter an email address";
	   $('msg').style.display='block'; return false;
        }
        rm2.doRequest ("handleRequestGeneric","../xml/forgottenpassword.php?email="+email,"showPassword");
        $('msg').innerHTML="An email with your password has been sent to your email address.";
        $('msg').style.display='block';
        return true;
}


function refresh_boxes() {}

function useplace (place)
{
	document.forms.rss.place.value=place;
	document.getElementById("pricerange").style.display="block";
	document.getElementById("chosenplace").innerHTML=place;
	
}

function useprices (from,to,type)
{
	window.open ("../rss/index.php?type="+type+"&minprice="+from+"&maxprice="+to+"&place=" + document.forms.rss.place.value);
}

function _setMapSize() {}
function _initExtra() {
zoom.hide();
}

function _registerEvents() {}

function _doDefaults(){}

if(typeof($)!="function"){
function $(element) {
  if (arguments.length > 1) {
    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
      elements.push($(arguments[i]));
    return elements;
  }
  if (Object.isString(element))
    element = document.getElementById(element);
  return Element.extend(element);
}

/*
function $(elid){
	i= document.getElementById(elid);
	return i;
}*/
}

function _populateBubbleInner (pin)
{
        mapmanager.requestmanager.div = "bubblediv";
        mapmanager.requestmanager.lat = pin.lat;
        mapmanager.requestmanager.lng = pin.lng;
        mapmanager.requestmanager.doRequest ("handleHTMLRequest",site_url+"/panes/pane_property.php?type="+settings.type+"&id="+pin.id+"&config="+settings.configuration+"&bubble="+mapmanager.bubbleStyle+"&lat="+pin.lat+"&lng="+pin.lng)
}
function tnav(el,sr)
{
	if (sr.match('_off.gif'))
	{ 
		el.src=sr.replace("_off.gif","_on.gif");
	}else{
		el.src=sr.replace("_on.gif","_off.gif");
	}
}

function showDiv(div){		
        $(div).style.display="block";
}

function hideDiv(div){
		if ($(div)) {
			$(div).style.display='none';
		}
}


function tmo(img,marker)
{
	el=$(img);
	sr=el.src;
	tnav(el,sr);
	
	el=$(marker);
	sr=el.src;
	tnav(el,sr);
}
/*
function mo(a)
{
	el=$($(a.id).firstChild.id);
	sr=el.src;
	tnav(el,sr);
}
*/
var navStop="";
function navPointer(el){
	if(el!= navStop){
	cl=$(el).className;
	if(cl.indexOf("t_nav_elem_off")>=0){
		$(el).className="t_nav_elem_on";	
	}else{
		$(el).className="t_nav_elem_off";
	}
}
}
function removePointer(){
	var elements = (document.all)? document.all : document.getElementsByTagName('div');
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(current.className.indexOf("t_nav_elem_on")>=0){
			current.className="t_nav_elem_off";
		}
	}
}

function navSelector(el){
	removePointer();
	$(el).className="t_nav_elem_on";
	navStop=el;
}
var subInView="";
if(navigator.userAgent.indexOf("MSIE")>0){
var block=18;
}else{
var block=9;
}
function showSub(sub){
	if(subInView !=sub){
		if(subInView != ""){
			h=$(subInView).offsetHeight;
			tween1=new Tween($(subInView).style,'height',Tween.regularEaseOut,h,2,0.4,'px');
		}
		h=block*($(sub).childNodes.length);
		$(sub).style.display='block';
		tween2=new Tween($(sub).style,'height',Tween.regularEaseIn,2,h,0.4,'px');
		if(subInView != ""){
			tween2.start();
			tween2.onMotionFinished=tween1.start();
		}else{
			tween2.start();
		}
		subInView=sub;
	}
}

function removeSavedProperty(p,s,t,e){
	removeproperty2(p,s,t,e,site_url);
	$("property_"+p).style.display='none';

 }
// returns true if oNode is contained by oCont (container) 
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}
function menuB2()
{
	$('menuB2').style.display='block';
	$('menu1').style.display='none';
}
function menuB1()
{
	$('menuB2').style.display='none';
	$('menu1').style.display='block';
}


function navResize(){
        if($('t-content')){
                if($('t-content').offsetHeight>$('t-nav').offsetHeight){
                        $("t-nav").style.height=$("t-content").offsetHeight;
                }
        }else{
		if($('t-content-flush')){
			  if($('t-content-flush').offsetHeight>$('t-nav').offsetHeight){
                        	$("t-nav").style.height=$("t-content-flush").offsetHeight;
               		 }
		}else{
                	if($('th-content').offsetHeight>$('t-nav').offsetHeight){
                	       	 $("t-nav").style.height=($("th-content").offsetHeight);
                	}
       		 }
	}
}
function loginlist(el){
		/*$('registerorlogin').style.top=$(el).offsetTop + 'px';
		$('registerorlogin').style.left=($(el).offsetLeft + 300)+ 'px';*/
		//setVisibleTop('popUpFrame','350','-200');
        //$('popUpFrame').style.display='block';
		
		//setVisibleTop('registerorlogin','520','-200');
		//$('registerorlogin').style.display='block';
		var txt='';
		setVisibleTop('generalIfr','320','-300');
		showPopUp('login','generalIfr','popUpsGeneral.php','340','300','top-left.png','top-right.png','bottom-left.png','bottom-right.png',txt,'0','0');
        
}


var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isNS = navigator.appName == "Netscape";

function getRef(id) {
if (isDOM) return document.getElementById(id);
if (isIE4) return document.all[id];
if (isNS4) return document.layers[id];
}

function moveRightEdge() {
var yMenuFrom, yMenuTo, yOffset, timeoutNextCheck ;
if (isNS4) {
var divMenu = document["divMenu"];
yMenuFrom = divMenu.top;
yMenuTo = windows.pageYOffset + 137;
} else if (isDOM) {
var divMenu = getRef('divMenu');
yMenuFrom = parseInt (divMenu.style.top, 10);
yMenuTo = (isNS ? window.pageYOffset : document.body.scrollTop) + 30; //Specify the distance of the Floating Object from top.
}
timeoutNextCheck = 50;
if (yMenuFrom != yMenuTo) {
yOffset = Math.ceil(Math.abs(yMenuTo - yMenuFrom) / 20);//Specify the floating Speed high=0,slow=500. etc
if (yMenuTo < yMenuFrom)
yOffset = -yOffset;
if (isNS4)
divMenu.top += yOffset;
else if (isDOM)
//divMenu.style.left = 120;//Specifies the distance of the floating object from left.
divMenu.style.top = parseInt (divMenu.style.top, 10) + yOffset;
return parseInt (divMenu.style.top, 10) + yOffset;
timeoutNextCheck = 0; //Specifies the speed of reaction .
}
//setTimeout ("moveRightEdge()", timeoutNextCheck);
}

function setVisibleTop(id,adjTop,adjLeft){
if (isNS4) {
var divMenu = document["divMenu"];
divMenu.top = top.pageYOffset + 0;
divMenu.visibility = "visible";
tmp = moveRightEdge();
} else if (isDOM) {

var divMenu = getRef('divMenu');
divMenu.style.top = (isNS ? window.pageYOffset : document.body.scrollTop) + 0;
//divMenu.style.visibility = "visible";
tmp = moveRightEdge();

}

if (adjTop) {tmp=parseInt(tmp)+parseInt(adjTop);}
document.getElementById(id).style.top=tmp-70;//changed from -150 as popups were appearing below nav

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
}
winW = winW/2;
if (document.getElementById(id+'Inner')) {
	myWidth = document.getElementById(id+'Inner').offsetWidth/2;
	myHeight = document.getElementById(id+'Inner').offsetHeight;
} else {
	myWidth = 0;
}
if (adjLeft==''){adjLeft=0;}
myLeft = parseInt(winW)-parseInt(myWidth)+ parseInt(adjLeft);
document.getElementById(id).style.left=myLeft;
}


function fetchPage(page){

new Ajax.Request(site_url+"/php/get_page_contet.php?page="+page,
  {	
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
	tmp = response.split(":::");
	$('header').innerHTML=tmp[0];
	$('nav').innerHTML=tmp[1];
	$('contentBlock').innerHTML=tmp[2];
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
 
}

function fetchPage2(page){
	new Ajax.Request(page,
  {	
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
	$('debug').innerHTML = response;
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
}

function openPage(page,target){
	if (target=="_blank") {
		alert(page);
		window.open(page);
	} else if (target="") {
		document.location.href=page;
	}	
}


function payonline(){
	var paymentform = document.Payment;
	var worldpayform = document.worldpay;
	var missing = '';
	var pointer = null;
	var invalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	var rows=0;
	if(paymentform.firstname.value == ''){
		missing+='\nEnter your first name.';
		rows++;
		if(pointer==null)
			pointer=paymentform.firstname;}
	if(paymentform.lastname.value == ''){
		missing+='\nEnter your last name.';
		rows++;
		if(pointer==null)
			pointer=paymentform.lastname;}
	if(paymentform.address.value == ''){
		missing+='\nEnter your address.';
		rows++;
		if(pointer==null)
			pointer=paymentform.address;}
	if(paymentform.postcode.value == ''){
		missing+='\nEnter your post code.';
		rows++;
		if(pointer==null)
			pointer=paymentform.postcode;}
	if(paymentform.telno.value == ''){
		missing+='\nEnter your telephone number.';
		rows++;
		if(pointer==null)
			pointer=paymentform.telno;}
	if(paymentform.emailadd.value == ''){
		missing+='\nEnter your email address.';
		rows++;
		if(pointer==null)
			pointer=paymentform.emailadd;}
	else{
		if(invalid.test(paymentform.emailadd.value) || !valid.test(paymentform.emailadd.value)){
			missing+='\nThe email address is invalid.';
			rows++;
			if(pointer==null)
				pointer=paymentform.emailadd;}}
	if(paymentform.dept[paymentform.dept.selectedIndex].value == ''){
		missing+='\nSelect the department.';
		rows++;
		if(pointer==null)
			pointer=paymentform.dept;}
	if(paymentform.ref.value == ''){
		missing+='\nEnter your payment reference.';
		rows++;
		if(pointer==null)
			pointer=paymentform.ref;}
	if(paymentform.amount.value == '' || isNaN(paymentform.amount.value)){
		missing+='\nEnter your payment amount.';
		rows++;
		if(pointer==null)
			pointer=paymentform.amount;}
	if(paymentform.desc.value == ''){
		missing+='\nEnter your payment description.';
		rows++;
		if(pointer==null)
			pointer=paymentform.desc;}
	if(pointer==null){
		// worldpay
		worldpayform.desc.value = 'Payment Reference : ' + paymentform.ref.value + '<br>Department : ' + paymentform.dept.value + '<br>' + paymentform.desc.value;
		worldpayform.amount.value = paymentform.amount.value;
		worldpayform.name.value = paymentform.firstname.value + ' ' + paymentform.lastname.value;
		worldpayform.address.value = paymentform.address.value;
		worldpayform.postcode.value = paymentform.postcode.value;
		worldpayform.tel.value = paymentform.telno.value;
		worldpayform.email.value = paymentform.emailadd.value;
		worldpayform.submit();}
	else{
		txt = ('Please fill in these details' + missing);
		//setVisibleTop('generalpopup','300','-280');
		//document.getElementById('generalPopUpContent').innerHTML=txt.replace(/\n/g,'<br />');		
		//setVisibleTop('popUpFrame','200','400');
        //$('popUpFrame').style.display='block';
		//document.getElementById('generalpopup').style.display='block';
		
		hh = parseInt(rows)*36;
		hh = hh+90;
		
		txt = txt.replace(/\n/g,'<br />');
		setVisibleTop('generalIfr','300','-280');
		showPopUp('general','generalIfr','popUpsGeneral.php','400',hh,'top-left.png','top-right.png','bottom-left.png','bottom-right.png',txt,'0','0');
		/*paymentform.pointer.focus();*/}
}


function checkFields(MyForm,fields)
{	
	ff = fields.split(";;;");
	var frm = document.getElementById(MyForm);
	var txt ='';
	for(i in ff){
		if (document.getElementById(ff[i]).value==''){
			txt += "* "+ff[i].replace("_", " ")+"\n";
		}
	}
	
	if(txt)
	{
		txt = '<b>Please fill in following fields:<b><br /><br />'+txt;
		setVisibleTop('generalpopup','325','-155');
		document.getElementById('generalPopUpContent').innerHTML=txt.replace(/\n/g,'<br />');		
		//setVisibleTop('popUpFrame','325','-155');
        //$('popUpFrame').style.display='block';
		document.getElementById('generalpopup').style.display='block';
		return false;
	}
	else frm.submit();
}


var inView="";
function showRSSDiv(divID){
                if(inView==divID){
                        $(divID).style.display='none';
                        inView="";
                }else{
                        if(inView!=""){
                                $(inView).style.display="none";
                        }
                        $(divID).style.display="block";
                        inView=divID;
                }
        }
//----------------------------------------------------------------------------------------------------------------------------------------------------------

/*
**  Functions for the feature property boxes with slider information
*/
var closingDiv="";
var openDiv="";
function easeIn(divId){
        if($(divId)){
        if(closingDiv==divId){
                delayedEaseIn(divId);
                return;
        }
                T1= new Tween($(divId).style,'top',Tween.regularEaseIn,159,105,0.4,'px');
                T1.onMotionStarted = function (){
                        openDiv=divId.id;
//                      debug2("openDiv='"+$(divId).id+"'");
                }
                T1.onMotionFinished = function (){
                        openDiv="";
//                      debug2("openDiv=''");
                }
                T1.start();
        }else{
                //alert(divId+" does not exist");
                return;
        }
}
function delayedEaseOut(divId){
        setTimeout("easeOut('"+divId+"')",700);
//      debug2("delay ease out");
}
function delayedEaseIn(divId){
        setTimeout("easeIn('"+divId+"')",700);
//      debug2("delay ease in");
}
function easeOut(divId){
        if(!$(divId)) return;
        if(openDiv==divId){
                 delayedEaseOut(divId);
                return;
        }
                T2 = new Tween(document.getElementById(divId).style,'top',Tween.regularEaseOut,105,159,0.35,'px');
                T2.onMotionStarted = function () {
                        closingDiv=divId;
//                      debug2("closingDiv='"+divId+"'");
                }
                T2.onMotionFinished = function (){
                        closingDiv="";
//                      debug2("closingDiv=''");
                }
                T2.start()
}
function toohigh(){
		txt = 'Too high. Please zoom in for schools to be displayed on the map.';
		setVisibleTop('generalpopup','500','-200');
		document.getElementById('generalPopUpContent').innerHTML=txt.replace(/\n/g,'<br />');		
		//setVisibleTop('popUpFrame','200','-200');
        //$('popUpFrame').style.display='block';
		document.getElementById('generalpopup').style.display='block';
}
//------------------------------------------------------------
function debug(txt){
        $("debug_div").innerHTML=txt;
}
function debug2(txt){
        $("debug_div").innerHTML +=txt+'<br>';
}

function showOfficeMap(el,src) {
	if($(el).style.display=='block'){
		$(el).style.display='none';
		$(el).src='';
	} else {
		$(el).style.display='block';
		$(el).src=src;
	}
}

function toggleDiv(el){
	if($(el).style.display=='block'){
		$(el).style.display='none';
	} else {
		$(el).style.display='block';
	}
}

function showOfficeDiv(el)
{
	$('cu_frm_Contact_Us').style.display='none';
	$('cu_vacancies').style.display='none';
	$('cuOfficeMap').style.display='none';
	$(el).style.display='block';
}

//navigation functions///
var navCount=5;
var blockSet=1;
var inView="";
 	
    function $(el){
       return document.getElementById(el);
    }    

	function hideAll(exception){
		exception="navBlock"+exception;
		for(var i=0;i<=navCount;i++){
			var tmp="navBlock"+i;
			if($(tmp)){
				if(tmp!=exception && $(tmp) && $(tmp).style){
					$(tmp).style.display='none';
				}
			}
		}
	}

    function showNavBlock(el_id){
		hideAll(el_id);
       inView=el_id;
       var left=$("navBlockMark"+el_id).offsetLeft;
       var top=$("navBlockMark"+el_id).offsetTop+$("navBlockMark"+el_id).offsetHeight;
	   top = top+7;
       var ver = navigator.appVersion;
	if (ver.indexOf("MSIE") > -1){
		//var top=top-10;
	}       
       left=left;
       top=top -2;
       $("navBlock"+el_id).style.left=left+"px";
       $("navBlock"+el_id).style.top=top+"px";
       $("navBlock"+el_id).style.display='block';
       blockSet=2;
	   debug($("navBlock"+el_id).style.display);
    }
    function cancelHide(){
       blockSet=0;
    }
    function hideNavBlock(el_id){
      setTimeout("hideBlock("+el_id+")",50);
    }
    function hideBlock(el_id){
	if(blockSet!=0){
	    $("navBlock"+el_id).style.display='none';
	}
    }
    function hideNav(el_id){
        blockSet=1;
  	hideNavBlock(el_id);
    }
//navigation functions

function hidePropImg(){
	document.getElementById(settings.url_boxover_img_div).style.zIndex=-1;
	document.getElementById(settings.url_boxover_img_id).style.visibility='hidden';
}


function vacancy_detail(txt) {
     var hh = 650;
	txt = txt.replace(/\n/g,'');
	setVisibleTop('generalIfr','250','-150');
	showPopUp('vacancy','generalIfr','popUpsGeneral.php','600',hh,'top-left.png','top-right.png','bottom-left.png','bottom-right.png',txt,'0','0');
}
