var strhost = window.location.hostname;
var strpath = window.location.pathname;
var blnRTE    = false;
var blnMSIE   = false;
var blnNOCHECK = true;
var brsIndex  = 0;
var oMenuSel = null;
var MSIEIndex = navigator.userAgent.indexOf("MSIE");
var seltab = null;

strpath = "http://"+ strhost + strpath.substr(0, strpath.indexOf("/",1)) + "/";

if( MSIEIndex > 0) 
{	
	blnMSIE  = true;
	brsIndex = -1;
}

function onclickitem(shref, target, rel)
{
    if(target != "")
    {
        window.open( shref , target, rel);
    }
    else
    {
        window.location = shref;
    }
}

function fourdigits(number)
{
      return (number < 1000) ? number + 1900 : number;
}


function onChangeFlag( currency, sdis)
{
	var aflag = new Array("us","ne","en");
	
	document.getElementById("flag_"+ sdis).src = "images/" + sdis + "_on.gif";	

	for(var i=0; i< aflag.length;i++)
	{		if( aflag[i] != sdis)
		{			var imgobject = document.getElementById("flag_"+ aflag[i]);			if( imgobject != null)
				imgobject.src = "images/" + aflag[i] + ".gif";
		}		
	}
		
	setCookie("language", sdis.toUpperCase(), 1);	
	setCookie("lchange","yes", 1);
	setCookie("currency", currency, 1);
		
	document.location.reload();	
}


function datediff(interval, date1, date2)
{
    var seconds = date2 - date1;

    switch(interval)
    {
        case "y":
			var year1 = date1.getYear();
			var month1 = date1.getMonth();
			var day1 = date1.getDate();

			var year2 = date2.getYear();
			var month2 = date2.getMonth();
			var day2 = date2.getDate();
						            
 			var time1 = (date1.getHours()*3600) + (date1.getMinutes()*60) + (date1.getSeconds());
			var time2 = (date2.getHours()*3600) + (date2.getMinutes()*60) + (date2.getSeconds());

           var diff = year2 - year1;
            
            if(month1 > month2)
            {
                diff -= 1;
            } elseif(month1 == month2) 
            {
                if(day1 > day2)
                {
                    diff -= 1;
                } elseif(day1 == day2)
                {
                    if(time1 > time2) 
                    {
                        diff -= 1;
                    }
                }
            }
            break;
        case "m":
			var year1 = date1.getYear();
			var month1 = date1.getMonth();
			var day1 = date1.getDate();

			var year2 = date2.getYear();
			var month2 = date2.getMonth();
			var day2 = date2.getDate();
			
			var time1 = (date1.getHours()*3600) + (date1.getMinutes()*60) + (date1.getSeconds());
			var time2 = (date2.getHours()*3600) + (date2.getMinutes()*60) + (date2.getSeconds());
                   
            var diff = (year2 * 12 + month2) - (year1 * 12 + month1);
            if(day1 > day2) 
            {
                diff -= 1;
            } else if(day1 == day2) 
            {
                if(time1 > time2) {
                    diff -= 1;
                }
            }
            break;
        case "w":
            var diff = Math.floor(seconds / 604800);
            break;
        case "d":
            var diff = Math.floor(seconds / 86400000);
            break;
        case "h":
            var diff = Math.floor(seconds / 3600);
            break;        
        case "i":
            var diff = Math.floor(seconds / 60);
            break;        
        case "s":
            var diff = seconds;
            break;        
    }    
    return diff;
}

function stringtodate(dt)
{
	//var newDateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])
	
	var locode = getCookie("language");
	switch( locode)
	{
		case "US":
			return new Date(dt.substr(6,4), dt.substr(0,2)-1, dt.substr(3,2));
		break;
		default:
			return new Date(dt.substr(6,4), dt.substr(3,2)-1, dt.substr(0,2));
		break;
	}
}

function datetostring(dt)
{
	var locode = getCookie("language");
	var day   = (dt.getDate()).toString();
	var month = (dt.getMonth()+1).toString();
				
	if(day.length == 1)
		day = "0"+day;
	if(month.length == 1)
		month = "0"+ month;

	switch( locode)
	{
		case "US":		
			return month +"-"+ day +"-"+ fourdigits(dt.getYear());
		break;
		default:
			return day +"-"+ month +"-"+ fourdigits(dt.getYear());
		break;
	}
}

function fillmassage()
{	
	var locode = getCookie("language");
	switch( locode)
	{
		case "US":
			return "mm-dd-yyyy";
		break;
		default:
			return "dd-mm-yyyy";
		break;
	}
}

// Functions http request controls
/*****************************************************/
var xmlhttp = null;
var schanges = null;

function selectmonth(oThis, objid)
{
	document.getElementById("ddate").value = oThis.value;	
	getbeschikbaarheid(objid);
}

function gonextorprev(strval, objid)
{
	document.getElementById("txtnextprev").value = strval;
	getbeschikbaarheid(objid);
}

function changecurrency(sid)
{
	seltab = null;
	getPropertiespage(sid, document.getElementById("currency").value);
}

function changeRefControls( othis, objid)
{
	var objEl = document.getElementById(objid);
	var strval = othis.value;
	
	if( objEl != null)
	{
		if( objEl.value != "")
			return;

		if (window.XMLHttpRequest)
		{
			var xmlhttp=new XMLHttpRequest()
			xmlhttp.open("GET",strpath + "httprequest.php?objid=" + objid + "&val=" + strval,false)
			xmlhttp.send(null)
		} else if (window.ActiveXObject) // code for IE
		{
			var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		    if (xmlhttp)
		    {
				xmlhttp.open("GET",strpath + "httprequest.php?objid=" + objid + "&val=" + strval,false)
				xmlhttp.send()
		    }
		}

		var objNodeList = xmlhttp.responseXML.selectNodes("//xml/option");
		
		var cbocount = objEl.length;
		for(var i=0; i < cbocount; i++)
		{
			objEl.remove(0);
		}

		for(var i=0; i < objNodeList.length; i++)
		{
			var svalue = objNodeList[i].getAttribute("value") == null ? "" : objNodeList[i].getAttribute("value");
			var node = objNodeList[i].selectNodes("text()");	
			var stext = node.length > 0 ? node[0].nodeValue : "";
								
			objEl.options[objEl.options.length] = new Option(stext, svalue);
		}
	}
}

var timeoutID = null;
function getbeschikbaarheid(sid)
{		
	if(timeoutID != null)
		clearTimeout(timeoutID);

	var objEl = document.getElementById("content_Tab3");
	if( objEl != null)
	{					
		var startup = "";
				
		if(document.getElementById("ddate") != null)
			sdate = document.getElementById("ddate").value;
		else
		{	
			sdate = datetostring(new Date());
			startup = "yes";
		}

		if(document.getElementById("txtnextprev") != null)
			var snextprev = document.getElementById("txtnextprev").value;
		else
			var snextprev = "";
			
		setWaitMessage(objEl);
		senthttpdatas(strpath + "httpbeschikbaarheid.php?objid=" + sid + 
			"&sstart=" + startup + 
			"&ddate=" + sdate + 
			"&nextprev=" + snextprev);				

		/*
		window.clipboardData.setData("Text", strpath + "httpbeschikbaarheid.php?objid=" + sid + 
			"&sstart=" + startup + 
			"&ddate=" + sdate + 
			"&nextprev=" + snextprev);
		*/
	}
}

function getPropertiespage(sid, scur)
{
	if( typeof(scur) == "undefined")
		scur = "";

	var objEl = document.getElementById("detailstabsection");	
	if( objEl != null)
	{		
		setWaitMessage(objEl);
		senthttpdatas( strpath + "httprequestdetails.php?objid=" + sid + "&curr="+ scur);

//		window.clipboardData.setData("Text", strpath + "httprequestdetails.php?objid=" + sid + "&curr="+ scur);
	}
}


function loadadvancesearch()
{
	var objEl = document.getElementById("advancesearch");	
	if( objEl != null)
	{					
		setWaitMessage(objEl);
		senthttpdatas( strpath + "httprequestadvancesearch.php");		
//		window.clipboardData.setData("Text", strpath + "httprequestadvancesearch.php?" + ssrch);
	}
}

function showflashobject(flash, ids, oThis)
{
	oThis.src = "images/pictures_on.gif";
	
	var objEl = document.getElementById("objectheader");	
	if( objEl != null)
	{					
		setWaitMessage(objEl);
		senthttpdatas( strpath + "httpflashobject.php?sfile=" + flash + "&id=" + ids);		

//		window.clipboardData.setData("Text",  strpath + "httpflashobject.php?sfile=" + flash + "&id=" + ids);
	}
}

function senthttpdatas( url)
{
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange = handlehttpdatas;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);			
	} else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange = handlehttpdatas;
			xmlhttp.open("GET", url, true);
			xmlhttp.send()
		}
	}		
}


function setWaitMessage( oThis)
{
	oThis.innerHTML = "<br><br><font size=2 color=blue>" + mssgwait + "</font>";
	schanges = oThis.id;
}

function handlehttpdatas()
{
	if(xmlhttp.readyState == 4)
		if(schanges != null)
		{
			document.getElementById(schanges).innerHTML = xmlhttp.responseText;

			if( schanges == "detailstabsection")
			{
				if( document.getElementById("content_Tab3")	!= null)
					timeoutID = setTimeout("getbeschikbaarheid('" + document.getElementById("objectid").value +"')", 10);
				else
					resizecontrols();
				
			}
			if( schanges == "content_Tab3")
				resizecontrols();
				
			schanges = null;
		}
}

function resizecontrols()
{
	var inxctrl = 1;
	var maxheight = 0;
	while( (octrl = document.getElementById("content_Tab" + inxctrl)) != null)
	{
		var odisp = document.getElementById("Tab" + inxctrl).style.display;
		document.getElementById("Tab" + inxctrl).style.display = "";
		
		if( maxheight < octrl.offsetHeight)
			maxheight = octrl.offsetHeight;

		document.getElementById("Tab" + inxctrl).style.display = odisp;
		
		inxctrl++;
	}

	inxctrl = 0;
	while( (octrl = document.getElementById("div_all_" + inxctrl)) != null)
	{
		octrl.style.height = maxheight + 10;
		inxctrl++;
	}	
}

function main_setactivetabform( name)
{
	var oform = document.getElementById(name);
	
	if( seltab == null)
		seltab = document.getElementById("Tab1");
		
	if( seltab != oform)
	{
		seltab.style.display = "none";
		oform.style.display = "";				
		seltab = oform;
	}
}

function resizecontrols()
{
	var inxctrl = 1;
	var maxheight = 0;
	while( (octrl = document.getElementById("content_Tab" + inxctrl)) != null)
	{
		var odisp = document.getElementById("Tab" + inxctrl).style.display;
		document.getElementById("Tab" + inxctrl).style.display = "";
		
		if( maxheight < octrl.offsetHeight)
			maxheight = octrl.offsetHeight;

		document.getElementById("Tab" + inxctrl).style.display = odisp;
		
		inxctrl++;
	}

	inxctrl = 0;
	while( (octrl = document.getElementById("div_all_" + inxctrl)) != null)
	{
		octrl.style.height = maxheight + 10;
		inxctrl++;
	}	
}


/* This section containing cookie for reserve object */
/*****************************************************/
var cookiename = "reservering";

function setCookie(name, value, expires)
{
    var expDate = new Date();
    
    if( expires > 0)
        expDate.setTime (expDate.getTime() + (expires*24*60*60*1000));
    else
        expDate.setTime (expDate.getTime() + expires);
    
    window.top.document.cookie = name + "=" + escape(value) + "; expires=" + expDate.toGMTString();
}

function getCookie(name)
{
	var search = name + "=";
	if (window.top.document.cookie.length > 0) 
	{
		offset = window.top.document.cookie.indexOf(search)
		if (offset != -1)
		{
			offset += search.length;
			end = window.top.document.cookie.indexOf(";", offset)

			if (end == -1)
			{
				end = window.top.document.cookie.length;
			}

			return unescape(window.top.document.cookie.substring(offset, end));
		}
	}
	return "";	
}


function preparecookie( aprods, objid)
{
	var strcookie="";
	var fchr = String.fromCharCode(182);
	var achr = String.fromCharCode(38);
	
	for(var idx=0; idx < aprods.length; idx++)
	{	
		strcookie += "subid=" + aprods[idx][0] + achr;
        strcookie += "item=" + aprods[idx][1] + achr;		
		strcookie += fchr;
	}

	return strcookie;
}

function getvalueof(prods, name)
{
	var achr = String.fromCharCode(38);
	
	var search = name + "=";
	if( prods.length > 0) 
	{
		offset = prods.indexOf(search)
		if (offset != -1)
		{
			offset += search.length;
			end = prods.indexOf(achr, offset)

			if (end == -1)
			{
				end = prods.length;
			}

			return prods.substring(offset, end);
		}
	}
	return ""	
}

function getcookievalue( name)
{
	var fchr = String.fromCharCode(182);
	var achr = String.fromCharCode(38);
	var source = getCookie(name);
	
	var aprods = new Array();

	var idx=0;
	while(source.indexOf(fchr, 1) != -1)
	{		
		var prod = source.substr(0, source.indexOf(fchr, 1)-1);
		source = source.substr(source.indexOf(fchr, 1)+1);

		var aitem = new Array();
		aitem[0] = getvalueof(prod, "subid");
		aitem[1] = getvalueof(prod, "item");
		aprods[idx] = aitem;
		
		idx++;
	}
	return aprods;	
}

function cleanupemptyitem()
{
	var aprods = getcookievalue(cookiename);	
	var aobject = new Array();
	var blnFound = false;
	var nidx=0;
	
	for(var idx=0; idx < aprods.length; idx++)
	{	
		if( aprods[idx][1] != "")		
		{
			var aitem = new Array();
			aitem[0] = aprods[idx][0];
			aitem[1] = aprods[idx][1];	
			aobject[nidx] = aitem;		
			nidx++;
		} else
			blnFound = true;
	}		
	
	if(blnFound)
	{
		var strcookie = preparecookie( aobject, "");
		setCookie(cookiename, strcookie, 1);
	}
}

function setvalueof( aprods, prodid, value, expires)
{
	var sepchr = String.fromCharCode(124);
	
	for(var idx=0; idx < aprods.length; idx++)
	{	
		if( aprods[idx][0] == prodid)
		{
			if( expires == 0)
			{
				var curval = aprods[idx][1];
				aprods[idx][1] = "";
				while(curval.indexOf(sepchr, 1) != -1)
				{		
					var val = curval.substr(0, curval.indexOf(sepchr, 1));				
					curval = curval.substr(curval.indexOf(sepchr, 1)+1);

					if( val != value)
						aprods[idx][1] += val + sepchr;
				}				
			} else
			{				
				var curval = aprods[idx][1];			
				if( curval.search(value) == -1)
					aprods[idx][1] += value + sepchr;
			}

			var strcookie = preparecookie( aprods, "");
			setCookie(cookiename, strcookie, 1);
			break;
		}
	}	
}

function searchforexisting( aprods, objectid)
{
	var blnFound = false;
	
	for(var idx=0; idx < aprods.length; idx++)
	{	
		if( aprods[idx][0] == objectid)
		{
			blnFound = true;
			break;
		}
	}

	if(blnFound)
		return idx;
	else
		return -1;
}

function setvalueofCookie( objectid, values, expires)
{
	var aprods = getcookievalue(cookiename);

	if( objectid != "" && values != "")
	{
		var indx = searchforexisting( aprods, objectid);
		if(indx != -1)
		{										
			setvalueof( aprods, objectid, values, expires);
		} else
		{
			if( expires != 0)
			{
				if( typeof(aprods.length) != "undefined")
					nidx = aprods.length;
				else
					nidx = 0;

				var aitem = new Array();
				var sepchr = String.fromCharCode(124);
				aitem[0] = objectid;			
				aitem[1] = values + sepchr;
				aprods[nidx] = aitem;

				var strcookie = preparecookie( aprods, "");
				setCookie(cookiename, strcookie, 1);
			}
		}
				
	} else
	{
		setCookie(cookiename, "", 0);
	}		
}

function detailsinfom(sThis)
{
	window.open("detailsinfom.php?objID="+ sThis , "detailsinfo", "location=no,height=590,width=620,scrollbars=1", 0).focus();
}

function openhelpscreen()
{
	window.open("helpscreen.php", "helpscreen", "location=no,height=625,width=620,scrollbars=1", 0).focus();
}


function MO(e)
{
	if (!e)
		var e=window.event;

	var S= e;
	
	while (S.tagName!="TD")
	{S=S.parentElement;}
		S.className="T";
}

function MU(e)
{
	if (!e)
		var e=window.event;

	var S= e;
	
	if(window.top.ctrlframe != null)
		if( e == window.top.ctrlframe.mselect)
			return;
			
	while (S.tagName!="TD")
		{S=S.parentElement;}

	if( oMenuSel == S)
		return;
				
	S.className="P";
}


function controlleftframe(show, hide)
{	
	if( document.getElementById("leftframeflash").style.display == '')
	{
		document.getElementById("leftframenav").style.display="";
		document.getElementById("leftframeflash").style.display = "none";
		document.getElementById("showmaptitle").innerHTML = show;
	} else
	{
		document.getElementById("leftframenav").style.display="none";
		document.getElementById("leftframeflash").style.display = "";
		document.getElementById("showmaptitle").innerHTML = hide;
	}		
}


function clearqkcontrols()
{
	document.getElementById("streek").value = "";
	document.getElementById("regio").value = "";
	document.getElementById("kamer").value = "";
	document.getElementById("slkamer").value = "";
}

function callsearch()
{
	var count = 0;

	if( document.getElementById("streek").value != "")
		count++;
		
	if( document.getElementById("regio").value != "")
		count++;

	if( document.getElementById("kamer").value != "")
		count++;

	if( document.getElementById("slkamer").value != "")
		count++;

	if( count < 2)
	{
		alert(mssg_alert_4);
		return false;
	} else
	{
		document.ctrlmain.action = "advsearch.php";	
		document.ctrlmain.submit();
	}
}

function clearreserv(objid)
{
	setCookie(cookiename, "", 0);
	getbeschikbaarheid(objid);
}


function reqisteraction( type, action)
{		
	if (window.XMLHttpRequest)
	  {
		var xhttp =new XMLHttpRequest();
		xhttp.open("GET", strpath + "httprequest.php?objid=regiaction" + "&actiontype=" + type + "&actionvalue=" + action, false);
		xhttp.send(null);
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
		var xhttp =new ActiveXObject("Microsoft.XMLHTTP")
	    if (xhttp)
	    {
		    xhttp.open("GET", strpath + "httprequest.php?objid=regiaction" + "&actiontype=" + type + "&actionvalue=" + action, false);
		    xhttp.send();
	    }
	  }		
}

function checkreservering( sThis)
{
	if( getCookie(cookiename) != "")
		window.open("bookinginfo.php?objID="+ sThis, "typeverzoek", "location=no,height=650,width=820,scrollbars=1", 0).focus();
	else
		alert(mssg_alert_16);
}

function checkmark(sThis, ids, opwk)
{
	var oThis = document.getElementById("r_"+sThis+"_"+ids);	
	if( oThis != null)
	{
		var pertest = getvalueof(opwk, document.getElementById("seizoen_"+ids).title);
		var sdt = oThis.value;

		//var newDateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]]) 		
		var dt = new Date(sdt.substr(0,4), sdt.substr(4,2)-1, sdt.substr(6,2));
		var dw = dt.getDay();

		if( oThis.checked)
			var exp = 1;
		else
			var exp = 0;

		setvalueofCookie( sThis, sdt, exp);
	
		if( dw > 0 && dw < 5)
		{
			if( pertest.search("mw") != -1)
				checkmidweek(sThis, ids, dw, exp);
			else
				checkweekendag(pertest, sThis, ids, dw, exp);
		}

		if( dw == 5 || dw == 6 || dw == 0)
		{
			if( pertest.search("wd") != -1)
				checkweekend(sThis, ids, dw, exp);	
			else
				checkweekendag(pertest, sThis, ids, dw, exp);
		}

		cleanupemptyitem();
		
		checkinview(sThis);
	}		
}

function checkinview(objectid)
{
	var checkdate = getcookievalue(cookiename);
	var sepchr = String.fromCharCode(124);		
	var newdt = new Array();
	
	for(var idx=0; idx < checkdate.length; idx++)
	{	
		if( checkdate[idx][0] == objectid)
		{
			var nn=0;
			var curval = checkdate[idx][1];
			while(curval.indexOf(sepchr, 1) != -1)
			{
				newdt[nn] = curval.substr(0, curval.indexOf(sepchr, 1));				
				curval = curval.substr(curval.indexOf(sepchr, 1)+1);
				nn++;
			}
		}
	}
	
	if( newdt.length > 0)
	{
		newdt.sort();

		var ckleft = new Date(newdt[0].substr(0,4), newdt[0].substr(4,2)-1, newdt[0].substr(6,2));
		var ckright = new Date(newdt[newdt.length-1].substr(0,4), newdt[newdt.length-1].substr(4,2)-1, newdt[newdt.length-1].substr(6,2));
		var startdt = stringtodate(document.getElementById("ddate").value);
		var enddt =  stringtodate(document.getElementById("ddate").value);
		enddt.setDate(enddt.getDate() + 15);

		if( ckleft < startdt)
			gonextorprev( datediff("d", startdt, ckleft) - 2, document.getElementById("objectid").value);
		else if(enddt < ckright)
			gonextorprev( datediff("d", enddt, ckright), document.getElementById("objectid").value);

	}

}


function checkweekendag(pertest, sThis, ids, dw, exp)
{
	if( pertest.search("wp") != -1 && pertest.search("dp") == -1)
		checkweek(sThis, ids, dw, exp);	
	else
	{
		if( pertest.search("dp") != -1)
			checkdag(sThis, ids, exp);
		else
		{
			var oThis = document.getElementById("r_"+sThis+"_"+ids);
			if( oThis != null)
			{
				oThis.checked = false;
				setvalueofCookie( sThis, oThis.value, 0);
			}
		}
	}				
}

function checkweekend(sThis, ids, dw, exp)
{
	if( dw == 5)
	{
		checkThisObject(sThis, ids+1, exp);
		checkThisObject(sThis, ids+2, exp);
	} else
	if( dw == 6)
	{
		checkThisObject(sThis, ids-1, exp);
		checkThisObject(sThis, ids+1, exp);
	} else
	{	
		checkThisObject(sThis, ids-1, exp);
		checkThisObject(sThis, ids-2, exp);
	}
}

function checkmidweek(sThis, ids, dw, exp)
{
	if( exp == 0)
		checkinrange(sThis, ids, exp);
	else
	{	
		var lids = ids;
		for( var nids = dw ; nids < 5; nids++)
		{
			checkThisObject(sThis, lids, exp);
			lids++;
		}

		lids = ids;
		for( var nids = dw ; nids > 0; nids--)
		{
			checkThisObject(sThis, lids, exp);
			lids--;
		}
	}
}

function checkweek(sThis, ids, dw, exp)
{
	if( dw==6)
	{
		var lids = ids;
		for( var nids = 0 ; nids < 7; nids++)
		{
			checkThisObject(sThis, lids, exp);
			lids++;
		}
	} else
	{
		var lids = ids+1;
		for( var nids = dw+1 ; nids < 6; nids++)
		{
			checkThisObject(sThis, lids, exp);
			lids++;
		}

		lids = ids-1;
		for( var nids = dw-1 ; nids >= -1; nids--)
		{	
			checkThisObject(sThis, lids, exp);		
			lids--;
		}
	}
}

function checkinrange(sThis, ids, exp)
{
	var cntdown = 0;
	var cntup = 0;
			
	var dids = ids-1;
	var oTest = document.getElementById("r_"+sThis+"_"+dids);
	while(oTest != null && oTest.checked)
	{
		oTest = document.getElementById("r_"+sThis+"_"+dids);
		cntdown++;
		dids--;
	}
			
	var uids = ids+1;
	oTest = document.getElementById("r_"+sThis+"_"+uids);
	while(oTest != null && oTest.checked)
	{
		oTest = document.getElementById("r_"+sThis+"_"+uids);
		cntup++;
		uids++;
	}

	if( cntdown != 0)
		for( var nids = dids ; nids < ids; nids++)
			checkThisObject(sThis, nids, exp);
		
	if(cntup != 0)		
		for( var nids = uids ; nids > ids; nids--)
			checkThisObject(sThis, nids, exp);
}


function checkdag(sThis, ids, exp)
{
	if( exp == 1)
	{
		var blndown = false;
		var blnup = false;
			
		for( var sids = ids-1; sids > 0; sids--)
		{
			var oTest = document.getElementById("r_"+sThis+"_"+sids);
			if( oTest != null)
			{
				if(oTest.checked)
				{
					blndown = true;
					break;
				}
			} else
				break;			
		}

		if( ! blndown)
		{
			for( var sids = ids+1; sids < 32; sids++)
			{
				var oTest = document.getElementById("r_"+sThis+"_"+sids);
				if( oTest != null)
				{
					if(oTest.checked)
					{
						blnup = true;
						break;
					}
				} else
					break;			
			}
		}
			
		if( blndown)
		{
			for( var nids = sids ; nids < ids; nids++)
				checkThisObject(sThis, nids, exp);
		} else 
		if( blnup)
		{
			for( var nids = sids ; nids > ids; nids--)
				checkThisObject(sThis, nids, exp);
		}
	} else
	{	
		var cntdown = 0;
		var cntup = 0;
			
		var dids = ids-1;
		var oTest = document.getElementById("r_"+sThis+"_"+dids);
		while(oTest != null && oTest.checked)
		{
			oTest = document.getElementById("r_"+sThis+"_"+dids);
			cntdown++;
			dids--;
		}
			
		var uids = ids+1;
		oTest = document.getElementById("r_"+sThis+"_"+uids);
		while(oTest != null && oTest.checked)
		{
			oTest = document.getElementById("r_"+sThis+"_"+uids);
			cntup++;
			uids++;
		}

		if( cntdown != 0 && cntup != 0)
		{
			if( cntdown < cntup)
				for( var nids = dids ; nids < ids; nids++)
					checkThisObject(sThis, nids, exp);
			else
				for( var nids = uids ; nids > ids; nids--)
					checkThisObject(sThis, nids, exp);
		}	
	}
}


function checkThisObject(sThis, lids, exp)
{
	var objThis = document.getElementById("r_"+sThis+"_"+lids);

	if(objThis != null)
	{
		if( exp == 0)
			objThis.checked = false;
		else
			objThis.checked = true;
		
		setvalueofCookie( sThis, objThis.value, exp);
	}
}

var curgallid = null;
function loadgallery(imgid)
{
	
	if( curgallid != null)
		document.getElementById("gallery_" + curgallid).style.zIndex = -100;

	document.getElementById("gallery_" + imgid).style.zIndex = 1;

	if( curgallid != null)
		document.getElementById("imgsub_" + curgallid).className = "trumbnail_off";
	
	oThis = document.getElementById("imgsub_" + imgid);
	if( oThis != null)
		oThis.className = "trumbnail_on";

	curgallid = imgid;
}

/*
function loadgallery( imgid)
{
	var subimg = document.getElementById("sub_gallery");
	if( subimg != null)
	{
		subimg.src = strpath + "images.php?coll=subgallery&id=" + imgid;
		subimg.focus();
	}
	
	oThis = document.getElementById("imgsub_" + imgid);
	if( oThis != null)
	{
		oThis.className = "trumbnail_on";
		if( currsub != null)
			currsub.className = "trumbnail_off";

		currsub = oThis;
	}
}
*/

// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
   // prototying the XMLDocument
   XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
   {
      if( !xNode ) { xNode = this; } 
      var oNSResolver = this.createNSResolver(this.documentElement)
      var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
      var aResult = [];
      for( var i = 0; i < aItems.snapshotLength; i++)
      {
         aResult[i] =  aItems.snapshotItem(i);
      }
      return aResult;
   }

   // prototying the Element
   Element.prototype.selectNodes = function(cXPathString)
   {
      if(this.ownerDocument.selectNodes)
      {
	     return this.ownerDocument.selectNodes(cXPathString, this);
      }
      else{throw "For XML Elements Only";}
   }
}

// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
   // prototying the XMLDocument
   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
   {
      if( !xNode ) { xNode = this; } 
      var xItems = this.selectNodes(cXPathString, xNode);
      if( xItems.length > 0 )
      {
         return xItems[0];
      }
      else
      {
         return null;
      }
   }
   
   // prototying the Element
   Element.prototype.selectSingleNode = function(cXPathString)
   {	
      if(this.ownerDocument.selectSingleNode)
      {
         return this.ownerDocument.selectSingleNode(cXPathString, this);
      }
      else{throw "For XML Elements Only";}
   }
}		


