YAHOO.namespace("example.calendar");
  var initCal = function() {
   YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");

   // Calendar config
 
   YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_SHORT",   ["jan", "feb", "mrt", "apr", "mei", "jun", "jul", "aug", "sep", "okt", "nov", "dec"]);
   YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG",    ["januari", "februari", "maart", "april", "mei", "juni", "juli", "agustus", "september", "oktober", "november", "december"]);
   YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_1CHAR", ["Z", "M", "D", "W", "D", "F", "Z"]);
   YAHOO.example.calendar.cal1.cfg.setProperty ("WEEKDAYS_SHORT", ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"]);
   YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_MEDIUM",["zon", "maa", "din", "woe", "don", "vri", "zat"]);
   YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_LONG",  ["zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"]);
   YAHOO.example.calendar.cal1.cfg.setProperty("SHOW_WEEK_HEADER",true);
   YAHOO.example.calendar.cal1.cfg.setProperty("MULTI_SELECT",true);
   
   YAHOO.example.calendar.cal1.cfg.setProperty("mindate",new Date());
   
   YAHOO.example.calendar.cal1.cfg
   YAHOO.example.calendar.cal1.render();
  }
  
  var niftyFy = function() {
  	Nifty("div#header", "top");
  	Nifty("div#mid", "bottom fixed-height");
  	Nifty("div#infoform");
  	Nifty("div#tt","top");
  	
  }
  
  var switchTab = function(tabEl) {
  	document.getElementById("uspcontent").style.display = "none";
  	document.getElementById("t4rcontent").style.display = "none";
  	document.getElementById("t4rswitch").parentNode.className = "";
  	document.getElementById("uspswitch").parentNode.className = "";
  	
    document.getElementById(tabEl.rel).style.display = "block";
    tabEl.parentNode.className = "selected";
  }




var AjaxObject = {

	handleSuccess:function(o){
		this.processResult(o);
		// register conversion
    if(document.getElementById("weekendTypeID").value == "1") {
			_gaq.push(['_trackPageview', 'ajax.landingpage.football.submit']);
      		}
		if(document.getElementById("weekendTypeID").value == "2") {
			_gaq.push(['_trackPageview', 'ajax.landingpage.musical.submit']);
		}
		if(document.getElementById("weekendTypeID").value == "3") {
			_gaq.push(['_trackPageview', 'ajax.landingpage.whisky.submit']);
		}
		if(document.getElementById("weekendTypeID").value == "4") {
			_gaq.push(['_trackPageview', 'ajax.landingpage.golf.submit']);
		}
		if(document.getElementById("weekendTypeID").value == "5") {
			_gaq.push(['_trackPageview', 'ajax.landingpage.special.submit']);
		}
		if(document.getElementById("weekendTypeID").value == "6") {
			_gaq.push(['_trackPageview', 'ajax.landingpage.beatles.submit']);
		}

  },

	handleFailure:function(o){
		// Failure handler
	},

	processResult:function(o){
		
		document.getElementById("formheader").firstChild.nodeValue = "Informatie aanvraag verzonden";
		var resultRoot = document.getElementById("info");

		resultRoot.innerHTML = "";
		resultRoot.appendChild(document.createElement("br"));
		
		var msgNode = document.createElement("p");
		var msgTextNode = document.createTextNode("Bedankt voor uw interesse in een reis via Travel4reasons. U ontvangt zo spoedig mogelijk per e-mail een passende aanbieding. Een kopie van deze informatieaanvraag is naar uw e-mail adres verzonden");
		
		msgNode.appendChild(msgTextNode);
		resultRoot.appendChild(msgNode);
		resultRoot.appendChild(document.createElement("br"));
		resultRoot.appendChild(document.createElement("br"));
		resultRoot.appendChild(document.createElement("br"));
		resultRoot.appendChild(document.createElement("br"));
		
	},

	startRequest:function() {
	   if(document.getElementById("weekendTypeID")) {
			var lptype = document.getElementById("weekendTypeID").value;
		 }
	   
	   var rName = document.getElementById("name").value;
		 var rEmail = document.getElementById("email").value;
		 var rPerson = document.getElementById("aantalPersonen").options[document.getElementById("aantalPersonen").selectedIndex].value;
		 
     if (lptype == "3")
     {
       var rFifteen = "";
       if (document.getElementById("restaurantSelectA").checked == true) { rFifteen += document.getElementById("restaurantSelectA").value + ", "; }
       if (document.getElementById("restaurantSelectB").checked == true) { rFifteen += document.getElementById("restaurantSelectB").value + ", "; }
       if (document.getElementById("restaurantSelectC").checked == true) { rFifteen += document.getElementById("restaurantSelectC").value; }
     } else {
       var rFifteen = document.getElementById("restaurantSelect").options[document.getElementById("restaurantSelect").selectedIndex].value;
     }
		 
     var rHotel = document.getElementById("hotelSelect").options[document.getElementById("hotelSelect").selectedIndex].value;
		 var rMusical = document.getElementById("musicalSelect").options[document.getElementById("musicalSelect").selectedIndex].value;
		 if (document.getElementById("aanmeldennieuwsbrief"))
     {
       var rNieuws = document.getElementById("aanmeldennieuwsbrief").value;
     } else {
       var rNieuws = "nee";
     }
     
		 if(lptype == "2") {
		 	
	   }
	   if(lptype == "1") { 
		   var rClub = document.getElementById("fclubSelect").options[document.getElementById("fclubSelect").selectedIndex].value;
		}
	   var rDate = YAHOO.example.calendar.cal1.getSelectedDates();
		
	   YAHOO.util.Connect.asyncRequest('GET', '/lp/lpmailer.php?name=' + rName + '&email=' + rEmail + '&person=' + rPerson + '&hotel=' + rHotel + '&fclub=' + rClub + '&date='+ rDate + '&musical=' + rMusical + '&fifteen=' + rFifteen + '&type=' + lptype + '&nieuws=' + rNieuws, callback);
	}

};


var callback =
{
	success:AjaxObject.handleSuccess,
	failure:AjaxObject.handleFailure,
	scope: AjaxObject
};


function validate_required(field) {
	with (field) {
		if (value==null||value=="") {
			return false
		}
		else {
			return true
		}
	}
}

function validate_email(field) {
	with (field) {
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
			if (apos<1||dotpos-apos<2)  {
				return false
			}
			else {
				return true
			}
	}
}


var checkForm = function() {
	var rv = true;
	var nameField = document.getElementById("name");
	var emailField = document.getElementById("email");
	var formErrorNotify = document.getElementById("formError");
	
	if(!validate_required(nameField)) {
		rv = false;
		YAHOO.util.Dom.addClass(nameField, "inputError");
	}
	else {
			YAHOO.util.Dom.removeClass(nameField, "inputError");
	}
	
	if(!validate_email(emailField)) {
		rv = false;
		YAHOO.util.Dom.addClass(emailField, "inputError");
	}
	else {
			YAHOO.util.Dom.removeClass(emailField, "inputError");
	}
	
	if(!rv) {
			formErrorNotify.innerHTML = "Vul alle velden in!";
			
	} 
	else {
		// ready to send
		formErrorNotify.innerHTML = "";
		AjaxObject.startRequest();
	}
	
	
}
var disableForm = function(e) { 
 YAHOO.util.Event.preventDefault(e); 
} 

var initForm = function() {
	 YAHOO.util.Event.addListener("lpsend", "click", disableForm);
	 YAHOO.util.Event.addListener("lpsend", "click", checkForm);
}

YAHOO.util.Event.addListener(window, "load", initCal);
YAHOO.util.Event.addListener(window, "load", niftyFy);
YAHOO.util.Event.addListener(window, "load", initForm);



