/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var map;
var localSearch = new GlocalSearch();

var icon = new GIcon();
icon.image = "http://www.google.com/mapfiles/marker.png";
icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);

function propertySetNumBedrooms(num)
{
	for (x=1;x<11;x++) document.getElementById('search_' + x).style.background = "url(/images/search-number-bg-1.gif)";
	var elem = document.getElementById('searchNumBedrooms');
	var elem_b = document.getElementById('search_' + num);
	
	elem.value = parseInt(num);
	elem_b.style.background = "url(/images/search-number-bg-2.gif)";
}
function propertySetType(type)
{
	var elem = document.getElementById('propertytype_tab');
	elem.value = type;
	propertySetTypeDropdown(elem.value);
        tcbPropDropDown(type);
}

function propertySetTypeDropdown(idx)
{
	var elem = document.getElementById('selectedpropertytype');
	elem.value = idx;
}
function tcbPropDropDown(t){
    if( t == 1){
        $htmlContentVal = document.getElementById("stu").innerHTML;
        $dropDown = document.getElementById("tcbPriceBand");
        $dropDown.innerHTML = $htmlContentVal;
    }else if(t == 2){
        $htmlContentVal = document.getElementById("prof").innerHTML;
        $dropDown = document.getElementById("tcbPriceBand");
        $dropDown.innerHTML = $htmlContentVal;
    }
}
function submitSortForm()
{
	var frm = document.getElementById('propertysearch');
	
	var sortDate = document.getElementById('sortDate').value;
	var sortPrice = document.getElementById('sortPrice').value;
        if(document.getElementById("sortNumBedrooms")!=null){
	var sortNumBedrooms = document.getElementById('sortNumBedrooms').value;
        }
	frm.action = frm.action + "?a=1";
	frm.action = frm.action + "&sortDate=" + sortDate;
	frm.action = frm.action + "&sortPrice=" + sortPrice;
        if(document.getElementById("sortNumBedrooms")!=null){
	frm.action = frm.action + "&sortNumBedrooms=" + sortNumBedrooms;
        }
	frm.submit();
}


function usePointFromPostcode(postcode, callbackFunction) {
    
    localSearch.setSearchCompleteCallback(null, 
        function() {
            
            if (localSearch.results[0])
            {        
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat,resultLng);
                callbackFunction(point);
            }else{
                alert("Postcode not found!");
            }
        });    
        
    localSearch.execute(postcode + ", UK");
}


function setCenterToPoint(point)
{
    map.setCenter(point, 17);
    var marker = new GMarker(point,icon);
    map.addOverlay(marker);
}


function mapLoad() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);
    }
}

function addUnLoadEvent(func) {
    var oldonunload = window.onunload;
    if (typeof window.onunload != 'function') {
      window.onunload = func;
    } else {
      window.onunload = function() {
        oldonunload();
        func();
      }
    }
}


addUnLoadEvent(GUnload);

window.onload = function() {
     
     
     }
function openeditor(url)
{
    window.open(url, "_blank", "width=700px, resizable=yes, scrollbars=yes");
}

function chkyorn(url)
{
    var c = confirm("Are you sure you want to remove this item");

    if (c)
        {
            window.location=url;
        } else return false;
}

function js_required_text(fld, name)
{
    var fld = document.getElementById(fld);
    if (fld.value=="" || fld.value==null)
        {
            alert(name + " cannot be empty");
            return false;
        } else return true;
}

function js_required_file(fld, name)
{
    var fld = document.getElementById(fld);
    if (fld.value=="" || fld.value==null)
        {
            alert(name + " cannot be empty");
            return false;
        } else return true;
}

function js_required_date(fld, name)
{
    alert(fld.value);
}

