﻿//var baseurl = 'http://www.huren.nl/';
var baseurl = 'http://localhost:4119/huren/';

var selectedRubriek = 0;
var selectContainerIsActive = false; 
var docPosX = 0;
var docPosY = 0;
var posLeft,posRight,posTop,posBottom;

document.onmousemove = getMouseXY;

function setSearchSelect(obj){
	document.getElementById("searchSelect").innerHTML = obj.innerHTML; 
	selectedRubriek = obj.id;
	closeSearchSelect(false);
}

is = function(i, w)
{
    var r = Math.floor(Math.random()*10000000000000000000)
    var p = baseurl;
    var d = document;
    
    p += "assets/stats/";
    p += "?i=" + i;
    p += "&w=" + w;
    p += "&r=" + r;
    
    d.write('<img id="CF_STATS" border="0" width="1" height="1" src="'+p+'" >');   
}

is_e = function(i, w)
{
    var r = Math.floor(Math.random()*10000000000000000000)
    var p = baseurl;
    var d = document;
    
    p += "assets/stats/";
    p += "?i=" + i;
    p += "&w=" + w;
    p += "&r=" + r;
    
     var u = $('CF_STATS');
     alert(u);
     if(u!=null)u.src = p;
}


setPrice = function()
{
    var d = document.location.toString();
    var s = document.location.search.toString();
    d = d.replace(s,'?');
    if(s!=''){
        s = s.substr(1);var a = s.split('&');
        a.each(function(q){
            var qe = q.split('=');
            if(qe[0].toLowerCase()=='minprijs')qe[1]=$('minprijs').value;
            if(qe[0].toLowerCase()=='maxprijs')qe[1]=$('maxprijs').value;
            if(qe[0]!=''&&qe[1]!='')d+= '&' + qe[0] + '=' + qe[1];
        });
        if(d.indexOf('minprijs')==-1)d+= '&minprijs=' + $('minprijs').value;
        if(d.indexOf('maxprijs')==-1)d+= '&maxprijs=' + $('maxprijs').value;
    }else d = document.location.toString() + '?&minprijs=' + $('minprijs').value + '&maxprijs=' + $('maxprijs').value;
    
    d = d.replace(/&&/g, '&');
    document.location = d;
}

function openSearchSelect(){
	if(!selectContainerIsActive){
		objSearchSelectHolder = document.getElementById("searchSelect");
		objSelectContainer = document.getElementById("selectContainer");
		xPos = objSearchSelectHolder.offsetLeft;
		yPos = objSearchSelectHolder.offsetTop;
		tempEl = objSearchSelectHolder.offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		
		objSelectContainer.style.left = (xPos - 1) + "px";
		objSelectContainer.style.top  = (yPos + (objSearchSelectHolder.offsetHeight + 2)) + "px";
		objSelectContainer.style.display = "block";
	
		posLeft   = xPos;
		posRight  = xPos + objSelectContainer.offsetWidth;
		posTop    = yPos;
		posBottom = (yPos + (objSearchSelectHolder.offsetHeight + 2)) + objSelectContainer.offsetHeight;
		selectContainerIsActive = true;
	}else{
		closeSearchSelect(false);
	}
}

function closeSearchSelect(closeWithCheck){
	if(selectContainerIsActive){
		if(checkCursorPosition()&&closeWithCheck){ return false; }
		objSelectContainer = document.getElementById("selectContainer");
		objSelectContainer.style.display = "none";
		selectContainerIsActive = false;
	}
}

function setSelectListActions(){

	objSelectList = document.getElementById("selectList");
	list_elements = objSelectList.getElementsByTagName("li");

	for(i=0;i<list_elements.length;i++){
		list_elements[i].className = "dd_custom";
		list_elements[i].onmouseover = new Function("this.className='dd_custom dd_custom_hover';");
		list_elements[i].onmouseout = new Function("this.className='dd_custom dd_custom_normal';");
		list_elements[i].onclick = new Function("setSearchSelect(this);");
	}
}

function getMouseXY(e) {
	if(selectContainerIsActive){
		if (!e) e = window.event;
		docPosX = e.clientX + document.documentElement.scrollLeft;
		docPosY = e.clientY + document.documentElement.scrollTop;
		//window.status = docPosX + ", " + docPosY + ", " + checkCursorPosition();
		if(!checkCursorPosition()){ setTimeout("closeSearchSelect(true);",500); }
	}
}

function checkCursorPosition(){
	var allowedOpen = ((docPosX >= posLeft && docPosX <= posRight) && (docPosY >= posTop && docPosY <= posBottom)) ? allowedOpen = true : allowedOpen = false; return allowedOpen;
}




function getkey(e) {if(e.keyCode == "13") {QS();return false; }return true; }
function QS(){

    if(selectedRubriek!="0"||selectedRubriek!=""){
    document.location = baseurl + "advertenties/" + selectedRubriek + "/index.html?s=" + document.getElementById("QuickSearchText").value;
    }else{alert('Selecteer een rubriek om in te zoeken');}
    return false;
}

function LoadFilters()
{
    new Ajax.Request("filter.aspx", {
      method: 'get',
      onSuccess: function(transport) {
       var notice = $('ctl00_cpL_filterPanel');
       notice.update(transport.responseText);
      }
    });

}


function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}


