var xmlhttp;
var xmlhttp2;
var nlemail;
var popup = 'popup_tastethem';

function validateEmail(elementValue){  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue);  
}  



function sendNewsLetter()
{
	var nlonw = 'Nieuwsbrief aanmelding';
	var nlnaam = document.getElementById('nlname').value;
	var nlemail = document.getElementById('nlemail').value;
	var nlmsg = '';

	if (nlnaam == '' ){
	var  nlmsg = 'Please tell us your name';
	//document.getElementById('nlname').style.backgroundPosition = '0px -1px';
	}else{
	//document.getElementById('nlname').style.backgroundPosition = '0px -32px';
	}
	
	if (nlemail == ''){
		var  nlmsg = 'Please fill out your e-mailaddress';
		//document.getElementById('nlemail').style.backgroundPosition = '0px -1px';
		}else{
		
		if (validateEmail(nlemail)==false){
			var  nlmsg = 'Please fill out your correct e-mailaddress';
		}else{
			//document.getElementById('nlemail').style.backgroundPosition = '0px -32px';
		}

	}

	if (nlmsg != ''){

		document.getElementById('nlerrmsg').innerHTML = nlmsg;
		document.getElementById('nlerrmsg').style.color = '#ff0000';
		
		return;
	}


		
xmlhttp2=GetXmlHttpObject();
if (xmlhttp2==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
  
if (nlnaam && nlemail ){
var url="http://www.lamaitreya.com/mail/newsletter.php";
url=url+"?naam="+nlnaam+"&email="+nlemail+"&onw="+nlonw;
url=url+"&sid="+Math.random();
xmlhttp2.onreadystatechange=stateChanged2;
xmlhttp2.open("GET",url,true);
xmlhttp2.send(null);
}

}

function stateChanged2()
{

if (xmlhttp2.readyState==4)
  {
	  var nlnaam = document.getElementById('nlname').value;
	var nlemail = document.getElementById('nlemail').value;
	// document.getElementById("nwform").innerHTML = "test"
	 document.getElementById("nwform").innerHTML = "Hi "+nlnaam+"<br /><br />You&#39;re been added to our newsletter mailinglist.<br />	 We have this e-mailaddress: <br /><span style='color:#7b7b7b'>"+nlemail+"</span>";
	 	  
  }
}


function sendMail()
{
   	onw = 'contactformulier van Lamaitreya';
	naam = document.getElementById('naam').value;
	email = document.getElementById('e-mail').value;
	bericht = document.getElementById('message').value;
	msg = '';
	
	if (naam == '' ){
	var  msg = 'Please tell us your name';
	document.getElementById('naam').style.backgroundPosition = '0px -1px';
	}else{
	document.getElementById('naam').style.backgroundPosition = '0px -32px';
	}
	
	if (bericht == ''){
	var  msg = "Don't you wanna tell uncle Mick what's up?";
	document.getElementById('message').style.backgroundPosition = '0px -72px';
	}else{
	document.getElementById('message').style.backgroundPosition = '0px 3px';
	}
	
	if (email == ''){
	var  msg = 'Please fill out your e-mailaddress';
	document.getElementById('e-mail').style.backgroundPosition = '0px -1px';
	}else{
		if (validateEmail(email)==false){
				document.getElementById('e-mail').style.backgroundPosition = '0px -1px';
			var  msg = 'Please fill out your correct e-mailaddress';
		}else{
	
	document.getElementById('e-mail').style.backgroundPosition = '0px -32px';
		}
	}
		
	
	if (msg != ''){
	document.getElementById('errmsg').innerHTML = msg;
	document.getElementById('errmsg').style.color = '#ff0000';
	return;
	}

		
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
  
if (naam && email && bericht){
	document.getElementById("contactform").style.display = 'none';
var url="http://www.lamaitreya.com/mail/mail.php";
url=url+"?naam="+naam+"&email="+email+"&bericht="+bericht+"&onw="+onw;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
	  document.getElementById("contactform").style.display = 'block';
	  

	    document.getElementById('contactform').innerHTML = "<br />Hi "+naam+"<br /> your e-mailaddress is:<br /><span>"+email+"</span><br /><br />And your message was:<br /><span>"+bericht+"</span><br /><br /><a onclick='showForm()'>Send a new message &#0187;</a>";
	  
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
	  
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


function showForm(){
document.getElementById('contactform').innerHTML = "<form action=''><input type='text' id='naam' value='Your name here' onclick='this.value = \"\"'/><br /><input type='text' id='e-mail' value='Your e-mail address here' onclick='this.value = \"\"'><br /><textarea id='message' class='cms_textarea' rows='4' cols='30' onclick='this.innerHTML = \"\"'>So, tell grandpa what's up</textarea><br /><span id='errmsg'></span><br /><input type='button' onclick='sendMail()' id='contact_send' value=''/></form>";
}



function firstLoad(){

	var url =""+window.location
	var urlparts = url.split('/');
	var anchor1 = urlparts[3];
	var anchor1 = anchor1.replace("#", "");
	
	

	
	if (anchor1 != ''){
				
	savePage(anchor1);
	}else{
	
	lightup('curpage_welcome2', 100);
	//lightup('curpage_welcome2', 100);
	document.getElementById('welcomelink2').style.color = '#FF0000';
	//document.getElementById('welcomelink2').style.color = '#FF0000';
	document.getElementById('curpage').value = 'welcome';
	savePage('welcome');

	}

}




function switchPage(newpage){


$.fancybox.close();
		var el = document.getElementById('curpage');
		oldpage = el.value;		
	
		//lightup('curpage_'+newpage, 100);
		lightup('curpage_'+newpage+'2', 100);
		
		/*document.getElementById('bottom_menu').style.display = 'none';
		document.getElementById('bottomTrigger').style.display = 'none';		
		document.getElementById('bottomLinks').style.display = 'none';	
		document.getElementById('bottom_arrow').style.display = 'block';
		document.getElementById('bottomArrow2').style.display = 'none';*/
		
		
		if (oldpage != ""){
			if (oldpage != newpage){
			//lightup('curpage_'+oldpage, 0);
			lightup('curpage_'+oldpage+'2', 0);
			//document.getElementById(oldpage+'link').style.color = '#555555';
			document.getElementById(oldpage+'link2').style.color = '#555555';
			}
		}
		
		
		//document.getElementById(newpage+'link').style.color = '#FF0000';	
		document.getElementById(newpage+'link2').style.color = '#FF0000';		
		document.getElementById('curpage').value = newpage;

		
}

function showMenu(){
		/*document.getElementById('menu').style.display = 'block';
		document.getElementById('topLinks').style.display = 'block';
		document.getElementById('topTrigger').style.display = 'block';
		document.getElementById('topArrow2').style.display = 'block';
		document.getElementById('top_arrow').style.display = 'none';*/
		document.getElementById('bottom_menu').style.display = 'block';	
		document.getElementById('bottomLinks').style.display = 'block';		
		//document.getElementById('bottomTrigger').style.display = 'block';		
		document.getElementById('bottom_arrow').style.display = 'none';
		//document.getElementById('bottomArrow2').style.display = 'block';
}



function hideMenu(){
		/*document.getElementById('menu').style.display = 'none';
		document.getElementById('topTrigger').style.display = 'none';	
		document.getElementById('topLinks').style.display = 'none';
		document.getElementById('topArrow2').style.display = 'none';
		document.getElementById('top_arrow').style.display = 'block';*/
		document.getElementById('bottom_menu').style.display = 'none';
		document.getElementById('bottomTrigger').style.display = 'none';		
		document.getElementById('bottomLinks').style.display = 'none';	
		document.getElementById('bottom_arrow').style.display = 'block';
		//document.getElementById('bottomArrow2').style.display = 'none';
}

function lightup(object, opacity){
 if (navigator.appName.indexOf("Netscape")!=-1
  &&parseInt(navigator.appVersion)>=5){

	document.getElementById(object).style.opacity=opacity/100;
    document.getElementById(object).style.MozOpacity=opacity/100;
	
 }
 else if (navigator.appName.indexOf("Microsoft")!= -1 
  &&parseInt(navigator.appVersion)>=4){

    document.getElementById(object).filters.alpha.opacity=opacity
 }
}

function savePage(page){

	var el = document.getElementById('curpage');

	oldpage = el.value;	
	switchPage(page);
	popup = document.getElementById('curpopup').value;	
	if (popup != ''){

	closePopup(popup);
	}
}


function showPopup(which){
	document.getElementById(which).style.display = 'block';
	document.getElementById(which).style.zIndex = 1701;
	document.getElementById('curpopup').value = which;
	showBg();
}

function closePopup(popup){
	popup = document.getElementById('curpopup').value;
	document.getElementById(popup).style.display = 'none';
	document.getElementById(popup).style.zIndex = -1;
	document.getElementById('curpopup').value = '';

	closeBg();
	
	
}

function switchPopup(newpopup){

	oldpopup = document.getElementById('curpopup').value;

	closePopup(oldpopup);
	showPopup(newpopup);
	
}

function showBg(){
	document.getElementById('overlay').style.display='block';
}

function closeBg(){
	document.getElementById('overlay').style.display='none';
}


