// JavaScript Document

// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

function updateTextField(source, target) {
	var s = document.getElementById(source);
	var t = document.getElementById(target);
	
	t.value = s.value;
}

function formvalidate(of,requiredField,errorField)
{
	if (requiredField == null){
	
		requiredField = 'required';
	}
	if (errorField == null){
		errorField = 'error';
	}
	 
	//Testen of DOM beschikbaar is en of er een element beschikbaar is met id required
	if(!document.getElementById || !document.createTextNode)
	{	
		return;
	}
	
	if(!document.getElementById(requiredField))
	{
		return;
	}
	//leegmaken van het errorveld
	var div=document.getElementById(errorField);
	while(div.hasChildNodes()) 
	{ 
		div.removeChild(div.firstChild);
	}
 
	var errorMsg="Check the fields marked in red:<br/>";
	var counter=0;
	//var mySpan=document.createElement("span");
	var reqfields=document.getElementById(requiredField).value.split(',');
	//Doorlopen van alle verplichte velden
	for(var i=0;i<reqfields.length;i++)
	{
	
		// Controleren of verplichte veld aanwezig is
		
		var field=document.getElementById(reqfields[i]);
		if(!field)
		{
			continue;
		}
		
		
		field.style.backgroundColor='#FFFFFF';
		//Controleren of het verplichte veld een fout bevat gebaseerd op het type
		switch(field.type.toLowerCase())
		{
			
			case 'text':			
				if(field.value=='')
				{
					adderror(field);
				}
				//Als het een email adres is pas specifieke check toe
				if(field.id.match('email'))
				{
					if(!isEmailAddr(field.value))
					{
						adderror(field);
					}
				}
			break;
			case 'password' :
				if(field.value=='')
				{
					adderror(field);
				}
			break;
			case 'textarea':
				if(field.value=='')
				{
					adderror(field);
				}							
			break;
			case 'checkbox':
				if(!field.checked)
				{	
					adderror(field);
				}							
			break;
			case 'select-one':
				if(!field.selectedIndex && field.value=='-')
				{
					adderror(field);
				}							
			break;
			case 'select-multiple':
			var hasSelections = false;

			for(var i = 0; i < field.options.length; i++)
			{
				hasSelections = true;
			}
			if(!hasSelections)
			{
				// nothing is selected
				adderror(field);
			}
			
			break;
			}
	}
	
	naamcheck=document.getElementById('naamcheck');
	if(naamcheck!=null)
	{
		if(naamcheck.value==0)
		{
			counter++;
			document.getElementById('txtSearch').style.backgroundColor='#FF0000';
			errorMsg=errorMsg + ' Geen geldige naam ingevuld <br/>';
		}
	
	}
	naamcheck=document.getElementById('naamcheck1');
	if(naamcheck!=null)
	{
		if(naamcheck.value==0)
		{
			counter++;
			document.getElementById('txtSearch').style.backgroundColor='#FF0000';
			errorMsg=errorMsg + ' Geen geldige naam ingevuld <br/>';
		}
	
	}
		
	//Er zijn 1 of meerdere fouten
	if(counter>0)
	{
		var errordiv=document.getElementById(errorField);
		//http://www.yoursurprise.nl/
		image='assets/templates/ysp/images/themas/winkelmand/stip_foutmelding.jpg';
		errordiv.innerHTML='<img src="' + image + '" alt="foutmelding" align="center"/>' + errorMsg; 
		//errordiv.appendChild(mySpan);
		//MOOdalBox.open("error","Fout","400 200");
		window.scrollTo(0,0);
		return false;
	}
	else
	{
		return true;
	}
			
	function adderror(o)
	{
		counter++;
		//mySpan.innerHTML =mySpan.innerHTML + o.name + "<br/>";
		o.style.backgroundColor='#FF0000';
	}
			
	/* Simpele controle of iets een emailadres is */
	function isEmailAddr(str) 
	{
	    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
	}
}


function addOntvanger()
{
	numOntv = document.formulier.num_ont.value;
	numOntv++;
	if(numOntv<=15)
	{	
		document.formulier.num_ont.value = numOntv.toString();
		document.formulier.required_tell.value += ',ont_naam'+numOntv+',ont_email'+numOntv+'';
		
		var divToShow='ontvanger'+numOntv;
		showHide2(divToShow,2);
	}
}

function Counter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
	else
	countfield.value = maxlimit - field.value.length;
}

/** showhide **/

function showHide(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function showHide2(obj,value) {
	var el = document.getElementById(obj);
	if(el!=null)
	{
	if ( value == 0 ) {
		el.style.display = 'none';
	}
	else 
	{
		el.style.display = '';
	}
	}
}


function showHideTweedeOntvanger(value){
	var el= document.getElementById('tweepersonen');
	if(value=='een persoon'){
		showHide('tweepersonen',0);
	}
	else
	{
		showHide('tweepersonen',1);
	}
}

function toonVerbergDiv(value,divToDo){
	if(value.toUpperCase() =='JA'){
		showHide2(divToDo,1);
	}
	else{
		showHide2(divToDo,0);
	}
}

function hideWinkelmandButton(){
	showHide2('winkelmandbutton',0);
	showHide2('winkelmand-trans',1);
}

function showWinkelmandButton(){
	showHide2('winkelmandbutton',1);
	showHide2('winkelmand-trans',0);
}

function toonTaartEditor(value)
{
	if(value=='nee')
	{
		showHide2('winkelmandbutton1',1);
		showHide2('winkelmandbutton',0);
		showHide2('Photoeditor',0);
	}
	else{
		showHide2('winkelmandbutton1',0);
		showHide2('Photoeditor',1);
		showHide2('winkelmandbutton',0);
	}
}


function toonChat(){
	var chatnr=document.getElementById("chatcode").value;
	launch_support(chatnr);
}
/** einde showhide **/

function alertBericht(value){
	if(value=='taf') {
		alert("Bedankt!\nHet bericht is verzonden.");
	} else if(value=='newPass') {
		alert("Uw nieuwe wachtwoord wordt nu naar het ingvoerde e-mailadres gestuurd.")
	} else {
		alert("U hoort hier een bericht te krijgen, maar er is niet goed meegegeven wat.\n"
		+"Laat ons dit s.v.p. weten via info@yoursurprise.nl");
	}
}

function showHideLanden(input) {
	var tabel = document.getElementById('tabel');
	
	if(input!='geen-keuze') {
		tabel.style.display = '';
	} else {
		tabel.style.display = 'none';
	}
}

function gaEvent(mySection,myEvent,myContent) {
	pageTracker._trackEvent(mySection, myEvent, myContent);
} 

function getAfdelingTekst(afdeling)
{
	var dept = afdeling;
	switch (dept) 
	{
	case 'it':
		wijzigAfdelingsTekst('it.png', "IT","The IT Department at YourSurprise.com is the largest and most important department within the company.  It’s the beating heart supporting all the websites and technology you use when ordering. Our talented and enthusiastic team of technicians devotes many hours of work and a great deal of attention to make sure your ordering experience is a pleasant one!");
		break;
	
	case 'internationaal':
		wijzigAfdelingsTekst('internationaal.png',"INTERNATIONAL","Five different languages are represented in the International Department at YourSurprise.com! We cross borders on a daily basis and conduct research continuously. Our aim is to surprise the whole world with our gifts!");
	break;
	
	case 'design':
		wijzigAfdelingsTekst('design.png',"DESIGN","Maybe you hadn’t thought about it, but we created all of the pages, pictures and designs that you see on our websites and gifts ourselves. A lot of effort and creativity have gone into the process and produced great results. With a growing number of daily visitors, customers and websites, this part of the business is becoming more and more important. Our originality is endless!");
		break;
		
	case 'management':
		wijzigAfdelingsTekst('management.png',"MANAGEMENT","Working for a company like YourSurprise.com is different every day and just as surprising as our product selection. YourSurprise.com is dedicated to making our gift concepts accessible to as large a demographic as possible with the help of a young and fresh outlook. The drive behind this concept is our team of enthusiastic employees who are directed in their efforts by the two founders of the company: Gerbrand Verton and Wouter de Vries.");
		break;
		
	case 'productie':
		wijzigAfdelingsTekst('productie.png',"PRODUCTION","All of our products are unique and made especially for you! We think this is pretty exceptional and so is the Production Department at YourSurprise.com. A strong team of production staff does everything within its power to produce your order correctly and deliver it on time.");
		break;
		
	case 'helpdesk':
		wijzigAfdelingsTekst('helpdesk.png',"CUSTOMER SERVICE","Do you have a question concerning our website, our gifts, your order or something completely different? We are here to assist you!");
		break;
	
	case 'marketing':
		wijzigAfdelingsTekst('marketing.png',"MARKETING","Are you already familiar with YourSurprise.com or have you just found us? In either case, our marketing strategy worked! We have experience ranging from advertising to sponsoring and can also help you with your own marketing plans. Our strength in creative marketing goes further: when it comes to business orders for example, we contribute very specifically to your vision while remaining flexible.");
		break;
	}
	
}

function wijzigAfdelingsTekst(iconName, titelTekst, tekst) {
    $('#' +'afdelingsTekst').html('<img class="medewerker_icon" src="assets/templates/ysp/images/promotie/medewerkers/icons/'+iconName+'"/><p class="medewerker_naam">'+titelTekst+'</p><span class="omschrijving"><p>'+tekst+'</p></span>');
 }

 /**
* Gets called from flex apps (albumeditor currently) to display help pages in a popup
*/
function onHelpRequest(helpid)
{
    //alert('héééélp!!! '+helpid);
    test2('http://www.yoursurprise.com/index.php?id=1548&helpid='+helpid, 'Albumeditor help', 300, 400);
}

// End -->