function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(doScrollbar);						
addLoadEvent(segmentMenuList);
addLoadEvent(navigationtMenuList);
addLoadEvent(send2friend);
addLoadEvent(register);
addLoadEvent(contact);
addLoadEvent(samples);

function doScrollbar() {
	var scrollbar = document.getElementById("textfield");
	if (scrollbar) {
		$(function()
		{
			$('#textfield').jScrollPane({showArrows:true,scrollbarWidth:13,arrowsize: 9,nanimateTo:true});
			var $textfield = $('#textfield');
			$('a.scroll-to-element').bind(
				'click',
				function() {
					var targetElementSelectorString = $(this).attr('rel');
					$textfield[0].scrollTo(targetElementSelectorString);
					return false;
				}
			);
		});
	}
}	

function samples() {
	var frm = document.sampleform;
	if (frm) {
		frm.onsubmit = function() {	
			return validate_sample(this);
		}
	}

}

function validate_sample(theForm) {
	var msg = ""
	if(theForm.company.value == "") {
		msg += "-" + lbl_samples_company + " \n";	
	}
	if(theForm.name.value == "") {
		msg += "-" + lbl_samples_name + " \n";	
	}
	if(theForm.firstname.value == "") {
		msg += "-" + lbl_samples_firstname + " \n";	
	}
	if(theForm.address.value == "") {
		msg += "-" + lbl_samples_address + " \n";	
	}
	if(theForm.zip.value == "") {
		msg += "-" + lbl_samples_zip + " \n";	
	}
	if(theForm.city.value == "") {
		msg += "-" + lbl_samples_city + " \n";	
	}
	if(theForm.country.value == "") {
		msg += "-" + lbl_samples_country + " \n";	
	}
	if(theForm.tel.value == "") {
		msg += "-" + lbl_samples_telephone + " \n";	
	}
	if(theForm.email.value == "") {
		msg += "-" + lbl_samples_email + " \n";	
	}
	if (msg != "") {
		msg = lbl_sample_mandatory + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

function do_showSpecify(str) {
	var spec = document.getElementById("specifyactivity");
	if (spec) {
		if (str == "Other") {
			spec.style.display = "block";
		}
		else {
			spec.style.display = "none";
		}
	}	
}

function contact() {
	var sel = document.getElementById("scountry_select");
	if(sel) {
		sel.onchange = function() {
			document.countryform.submit();
		}
	}
	var frm = document.contactform;
	if (frm) {
		frm.onsubmit = function() {	
			return validate_contact(this);
		}
		frm.business.onchange = function() {
			do_showSpecify(this.value);
		}
	}
}

function validate_contact(theForm) {
	var msg = ""
	var rad_val = ""
	for (var i=0; i < theForm.title.length; i++) {
	   if (theForm.title[i].checked) {
		  rad_val = theForm.title[i].value;
	   }
	}
	if (rad_val == "") {
		msg += "-" + lbl_lounge_title + " \n";	
	}
	if(theForm.name.value == "") {
		msg += "-" + lbl_lounge_name + " \n";	
	}
	if(theForm.firstname.value == "") {
		msg += "-" + lbl_lounge_fist_name + " \n";	
	}
	if(theForm.companyname.value == "") {
		msg += "-" + lbl_lounge_company + " \n";	
	}
	if(theForm.country.value == "") {
		msg += "-" + lbl_lounge_country + " \n";	
	}
	if(theForm.business.value == "") {
		msg += "-" + lbl_lounge_business_activity + " \n";	
	}	
	if(theForm.email.value == "") {
		msg += "-" + lbl_lounge_email + " \n";	
	}
	if (msg != "") {
		msg = lbl_lounge_mandatory + " : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}
				
function register() {
	var frm = document.registerform;
	if (frm) {
		frm.onsubmit = function() {	
			return validate_register(this);
		}
		frm.business.onchange = function() {
			do_showSpecify(this.value);
		}
	}
}

function validate_register(theForm) {
	var msg = ""
	var rad_val = ""
	for (var i=0; i < theForm.title.length; i++) {
	   if (theForm.title[i].checked) {
		  rad_val = theForm.title[i].value;
	   }
	}
	if (rad_val == "") {
		msg += "-" + lbl_lounge_title + " \n";	
	}
	if(theForm.name.value == "") {
		msg += "-" + lbl_lounge_name + " \n";	
	}
	if(theForm.firstname.value == "") {
		msg += "-" + lbl_lounge_fist_name + " \n";	
	}
	if(theForm.companyname.value == "") {
		msg += "-" + lbl_lounge_company + " \n";	
	}
	if(theForm.country.value == "") {
		msg += "-" + lbl_lounge_country + " \n";	
	}
	if(theForm.business.value == "") {
		msg += "-" + lbl_lounge_business_activity + " \n";	
	}	
	if(theForm.email.value == "") {
		msg += "-" + lbl_lounge_email + " \n";	
	}
	if(theForm.password.value == "") {
		msg += "-" + lbl_lounge_password + " \n";	
	}
	if(theForm.checkpw.value == "") {
		msg += "-" + lbl_lounge_check_password + " \n";	
	}
	if (msg != "") {
		msg = lbl_lounge_mandatory + " : \n" + msg;
		alert(msg);
		return false;
	}
	if (theForm.password.value != theForm.checkpw.value) {
		alert(lbl_lounge_passwords_notok);
		return false;
	}
	return true;
}

// functie die zorgt dat hover op li van segmentenmenu werkt in IE
function segmentMenuList() {
	if (document.all&&document.getElementById) {
		if (document.getElementById("segmentmenulist")) {
			navRoot = document.getElementById("segmentmenulist");
			if (navRoot) {
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" iehover";
						}
						node.onmouseout=function() {
							this.className=this.className.replace(" iehover", "");
						}
					}
				}
			}	
		}
	}
}

// functie die zorgt dat hover op li van navigatiemenu werkt in IE
function navigationtMenuList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navigationmenu");
		if (navRoot) {
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" iehover";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" iehover", "");
					}
				}
			}
		}	
	}
	if (document.all&&document.getElementById) {
		theButton = document.getElementById("submitbutton");
		if (theButton) {
			theButton.onmouseover=function() {
				this.className+=" iehover";
			}
			theButton.onmouseout=function() {
				this.className=this.className.replace(" iehover", "");
			}
		}
	}
}

function validate_friendform(theForm) {
	var msg = ""
	if(theForm.email.value == "") {
		msg += "-" + lbl_sendtofriend_friends_email + " \n";	
	}
	if(theForm.name.value == "") {
		msg += "-" + lbl_sendtofrien_friends_name + " \n";	
	}
	if(theForm.sender.value == "") {
		msg += "-" + lbl_sendtofriend_your_name + "\n";	
	}
	if(theForm.senderemail.value == "") {
		msg += "-" + lbl_sendtofriend_your_email + "\n";	
	}
	if (msg != "") {
		msg = lbl_sendtofriend_mandatory + " : \n" + msg;
		alert(msg);
		return false;
	}
	if(!validateEmail(theForm.email.value) || !validateEmail(theForm.senderemail.value)) {
		alert(lbl_sendtofriend_correctemail);
		return false;
	}
	return true;
}


function validateEmail(email) {
	
	if (email != null && email != "") {
		a = email.lastIndexOf("@");
		b = email.lastIndexOf(".");
		c = email.indexOf(":");
		d = email.indexOf("/");
		e = email.substring(0,a);
		f = e.indexOf("@");
		g = email.substring(a+1,email.length);
		h = g.indexOf("[");
		i = g.indexOf("]");
		j = g.indexOf("<");
		k = g.indexOf(">");
		l = email.substring(a+1,b);
		m = email.substring(b+1,email.length);
		n = email.substring(0,a);
		p = email.indexOf("'");
		q = email.indexOf("\"");
		o = 0;
		if (a > b) {o++};
		if (c != -1) {o++};
		if (d != -1) {o++};
		if (f != -1) {o++};
		if (h != -1) {o++};
		if (i != -1) {o++};
		if (j != -1) {o++};
		if (k != -1) {o++};
		if (l.length < 2) {o++};
		if (m.length < 2) {o++};
		if (n.length < 1) {o++};
		if (p != -1) {o++};
		if (q != -1) {o++};
		if (o != 0) {
			return false;
		}
	}
	return true;
}


function send2friend() {
	var lnk = document.getElementById("sendtofriendalink");
	if(lnk) {
		lnk.onclick = function() {
			show_popup(this.href,430,390);
			return false;
		}
	}
	var frm = document.send2friendform;
	if (frm) {
		frm.onsubmit = function() {
			return validate_friendform(this);
		}
	}
}

function show_popup(url,theWidth,theHeight) {
	theTop = (screen.height-theHeight*1.5)/2;
	theLeft = (screen.width-theWidth)/2;
	winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width="+theWidth+",height="+theHeight+",top="+theTop+",left="+theLeft;
	smallwindow=window.open(url,"Detail",winopts);
	smallwindow.focus();
}

