window.onload = init;

function init() {
	menuHover();
	if (isSet(document.getElementsByTagName("title")))
		window.defaultStatus = document.getElementsByTagName("title")[0].innerText;
	var elements = document.getElementsByTagName("a")
	for (var i = 0; i < elements.length; i++) {
		var element = elements[i];
		element.onmouseover = function() {window.status=this.innerText; return true;}
		element.onmouseout  = function() {window.status="";}
	}
}

function openenlarge(i,w,h) {
	var x =  (screen.width/2) - (w/2); 
	var y =  ((screen.height/2) - (h/2)) - 80; 
	var mybase = findbase();
	window.open(mybase + "public/enlargeimage.aspx?i=" + i + "&w=" + w + "&h=" + h,"enlarge","width=" + (w - 4) + ",height=" + (h - 4) + ",top=" + y + ",left=" + x)
}

function closeAdsPopup()
{
	 var adspopup = document.getElementById("adspopup");
	 adspopup.style.display = "none";
}

function doTellYourFriends(){
	var mybase = findbase();
	OpenDialog(mybase + 'public/TellYourFriendsForm.aspx','tellyourfriends', '500', '500', 0)
}
		
function doPostcodeCheck(){
	var mybase = findbase();
	if (document.getElementById('txtPostcode').value != ''){
		OpenDialog("http://www.greenwheels.nl/mijngegevens/_asp/akties.asp?postcode=" + document.getElementById('txtPostcode').value, "akties", "450", "760", 1)
//		OpenDialog(mybase + "Public/akties.aspx?postcode=" + document.getElementById('txtPostcode').value, "akties", "700", "700", 1)
	}
}

function doFavorites(){
	window.external.AddFavorite(location.href, document.title);
}	

function doprint() {
	var oldstyle = document.getElementById("stylesheet").href;
	document.getElementById("stylesheet").href = "css/print.css";
	window.print();
	document.getElementById("stylesheet").href = oldstyle;
}

function findbase() {
	myBase = document.getElementsByTagName("base")
	return (myBase[0].getAttribute("href"))
}


function dosearch() {
	var searchfrase = document.getElementById("searchfrase").value;
	var mybase = findbase();
	document.location.href = mybase + "index.aspx?i=search&frase=" + searchfrase;
}

function redirect(url) {
	var mybase = findbase();
	document.location.href = mybase + "index.aspx" + url;
}

function checksearch(e) {
 var keyCode = getKeyCode(e);
 if (keyCode == 13) {
		dosearch()
		return false
	} else {
		return true
	}
}

function getKeyCode(e){
 var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
 return keyCode;
}

function menuHover() {
	if( isSet( document.body.currentStyle ) ) {
		var listItems = document.getElementById("navigation").getElementsByTagName( 'li' );
		for( var i = 0; i < listItems.length; i++ ) {
			if( listItems[ i ].className == 'parent' ) {
				var parent = listItems[ i ];
				if( isSet( parent ) && isSet( parent.lastChild.style ) ) {
					parent.onmouseover = function( ) { this.lastChild.style.display = 'block';}
					parent.onmouseout = function( ) { this.lastChild.style.display = 'none';}
				}
			}
		}		
	}
}

function isSet(el){
	return( typeof el != 'undefined' );
}

function hasProperties(el){
	for( var i in el ){
		return true;	
	}
	return false;
}
  
function OpenDialog( url, name, height, width, scrollbars ) {
	var options = "width = " + width + ", height = " + height + ", menubar = no, scrollbars = " + scrollbars + ", toolbar = no, location = no, directories = no, resizable = no, top = " + top + ", left = " + left + "";
	var top = (screen.height - height) / 2;
	var left = (screen.width - width) / 2;
	myWindow = window.open(url, name, options);
}

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	setCookie(name,"",-1);
}
