	
/* Popup *************************************************************************************************************** */

var map_elements = function() {
	if (typeof(POPUNDER) !="object") {
		return false;
		}
	if (typeof(MAPPER) == "object") {
		//Pop-under function; var POPUNDER is filled in html files (#44805)
		for (var mapped in MAPPER) {
			if ( MAPPER[mapped] && POPUNDER[mapped] != undefined ) {
				if (typeof(MAPPER[mapped]) == 'string') {
					var clicktarget = $(MAPPER[mapped]);
					} 
				else if (typeof(MAPPER[mapped]) == 'object') {
					var clicktarget = MAPPER[mapped];
					}
				if (clicktarget) {
					clicktarget.mapkey = mapped;
					clicktarget.addEvent( 'click', function() { showPu(POPUNDER[this.mapkey]['url'], POPUNDER[this.mapkey]['size']); } );
					}
				}
			}
		}
	else {
		setTimeout(function(){map_elements();}, 1000);
	}
}

	function openWindow(url,width,height) {
		window.open(url,'','scrollbars=yes,width='+width+',height='+height+',resizable=yes');
	} 
	
	function MM_openBrWindow(theURL,winName,features) { 
	  window.open(theURL,winName,features);
	}

	//make it popup! simply add the class 'poplink' to every link!
	window.addEvent('domready', function() {
		var popLinks = $$('a.poplink');
		popLinks.each(function(el) {
			el.set({
				'events': {
					'click': function() {
						window.open(this.href,'','scrollbars=yes,width=400,height=450,resizable=yes');
						return false;
					}
				}
			});
		});
		
		// browser detection (task 49153,54723)
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		var is_firefox36 = navigator.userAgent.toLowerCase().indexOf('firefox/3.6') > -1;
		var is_firefox4 = navigator.userAgent.toLowerCase().indexOf('firefox/4.0') > -1;
		var is_firefox5 = navigator.userAgent.toLowerCase().indexOf('firefox/5.0') > -1;
		var is_ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6.0') > -1;
		var is_ie7 = navigator.userAgent.toLowerCase().indexOf('msie 7.0') > -1;
		var is_ie8 = navigator.userAgent.toLowerCase().indexOf('msie 8.0') > -1;
		var is_ie9 = navigator.userAgent.toLowerCase().indexOf('msie 9.0') > -1;
		
		//deactivate pop under in browser (task 49153,54723):
		if (is_firefox4 || is_firefox5) popIsDead = true;

/*		if($('coregform')) {
			 $('coregform').setProperty('onsubmit', 'return fillcheck();');
		} */
		
		// Ausnahmefall Coreg 42 (sv)
		if($('coregform')) {
			if($('coreg_pk_42')) {
				$$('input').each( function(e) {
					if (e.get('name') == "coreg_42_special_product") {
						e.addEvent('click', function () {
							if ($('coreg_pk_42').checked != true && e.value != '') alertCoreg('coreg_pk_42');
						});
					}
					if (e.get('name') == 'coreg_42_special_birthid') {
						e.addEvent('blur', function() {
							if ($('coreg_pk_42').checked != true && e.value != '') alertCoreg('coreg_pk_42');
						});
					}
				});
			}
		}
		if(window.location.search.search(/test=1/) == -1) map_elements();
	});
	
// Erzeugt ein Alert-Div am ende des Coregs (sv)
function alertCoreg(coregPk) {
	var pk = coregPk.replace('coreg_pk_','');
	var coregAlert = 'coregAlert_'+pk;
	if(!$(coregAlert)) {
		var alertElement  = new Element('div', {id: coregAlert, 'class': 'coregAlert'});
		var alertText = 'Vänligen markera kryssrutan för att beställa dina trisslotter hos Svenska Spel.';
		alertElement.inject($(coregPk).getParents()[1], 'bottom');
		$(coregAlert).set('html',alertText);
		$('coreg_pk_'+pk).addEvent('click', function() {
			$(coregAlert).destroy();
		});
	}
}

// launch "popunder" windows once
function popunder(theURL,winName,features) {
	if (checkPopunder(theURL)) {
	  var win = window.open(theURL,winName,features);
	  win.blur();
	}
}

function arrayContain(url)
{
  return popunderCol.indexOf(url)!=-1;
}  

// check if already launched and add to collection
var popunderCol = new Array;
function checkPopunder(url) {
  var isinarray = arrayContain(url); 
  if (isinarray) {
	return false;
  } else if (url.indexOf('http://') != -1) {
	var newItem = popunderCol.push(url);
	return true;
  }
}

/* PopUnder on click ****************************************************************************************************** */

//switch off Popunder in the meantime:
preventPop = false;
//switch off popunder permanently:
popIsDead = false;
//call the popunder: showPu('url': give different url's for multiple popunder windows)
var showPu = function(url, size) {
	if (size == 'fullscreen') {
		mywidth = screen.width;
		myhight = screen.height;
		}
	else if (size == 'parentsize') {
		var S = window.getSize();
		mywidth = S.x;
		myhight = S.y;
	}
	else if (size && size.match(/\d+x\d+/)) {
		mywidth = size.split('x')[0];
		myhight = size.split('x')[1];
	}
	else {
		mywidth = 600;
		myhight = 600;
	}
	var options = 'scrollbars=yes,width=' + mywidth + ',height=' + myhight + ',resizable=yes';
	if ((!popIsDead) && (!preventPop)) {
		popunder(url,'',options);
	}
}

/* Globales Script das Selectboxen sichtbar und unsichtbar macht ************************************************************************************************* */

	function hidetagsIE(TagNamen){
		if ( navigator.userAgent.indexOf("MSIE 6") != -1 ){
			var no = 0;
			while (document.getElementsByTagName(TagNamen)[no]){
				document.getElementsByTagName(TagNamen)[no].style.visibility = "hidden"; 
				no++;
			}
		}
	}

	function showtagsIE(TagNamen){
		if ( navigator.userAgent.indexOf("MSIE 6") != -1 ){
			var no = 0;
			while (document.getElementsByTagName(TagNamen)[no]){
				document.getElementsByTagName(TagNamen)[no].style.visibility = "visible"; 
				no++;
			}
		}
	}
	

/* Globales Script das DIVs sichtbar und unsichtbar macht ************************************************************************************************* */

function hidelayer(divs) {
		document.getElementById(divs).style.display = "none";
		if(divs == "popinfo") document.getElementById("landselect").style.display = "block";
	}
	
function showlayer(divs) {
		document.getElementById(divs).style.display = "block";
		if(divs == "popinfo") document.getElementById("landselect").style.display = "none";
	}
	
/* Coreg Checkbox anhaken beim Klick aufs Bild ************************************************************************************************* */

function checkthebox(el) {
	document.getElementsByName(el)[0].checked = !document.getElementsByName(el)[0].checked;
}	
	
/* Popunder, das auf Seite 1 eingeblendet wird ******************************************* */
function popUnderP1() {
	/* partner pks einfach hinten in das array packen */
	var notshown = new Array(1088,0,831,1092,941,1042,155,1027,876,1080,983,813,1107,1038)
	
	if (document.getElementById("register")) {
		var ppk = document.getElementById("register").partner_pk.value;
	} else {
		var ppk = document.forms[0].partner_pk.value;
	}
	var nopop = false;
	for (i=0;i<notshown.length;i++) {
		if(ppk == notshown[i] || ppk == '') { 
			nopop = true;
			break;
		}
	}
	//alert('PPK ist '+ppk+' | '+notshown.length+":"+nopop)
	if(!nopop) {
		var pu = window.open("http://www.winmycar.de/perl/lp.pl?file=index1.html&partner_pk=1014&sub_id=GWS-PopUnder","","width=940,height=790,scrollbars=1,resizable=1");
		pu.blur();
	}
}




function sf() {
	if (document.getElementById('option_110_403') && document.getElementById('option_110_403').checked && document.getElementById('option_113_416'))
	{
		if(checkN(document.getElementById('option_113_416').value)) {
			alert("Vänligen ange dina fyra sista siffror i personnumret för de produkter du har valt.");
			document.getElementById('option_113_416').style.backgroundColor = '#FFBFBF';
			return;
		}
	}
	document.survey.submit()
}

// coreg check if radio button was clicked
function checkCoreg(coregID) {
	$(coregID).checked = true;
}

// check/uncheck Radio Buttons coreg_215
window.addEvent('domready', function() {
	if ( $('coreg_pk_215') ) {
		angeklickt = -1;
		var inputs = $$('.coreg215');
		inputs.each( function(e, i) {
			$(e).addEvent('click', function() {
				if ((angeklickt == i) && ($(e).getProperty('checked') == true)) {
					$(e).setProperty('checked', false);
					angeklickt = -1;
				} else {
					angeklickt = i;
				}
			});
		});
	}
});

function checkCoreg42(){
	var obj = document.inter;
	var layer = document.getElementById('werbeflaeche_coreg');
	
	result = true;
	for(i=0;i<(obj.length);i++){
		if(obj.elements[i].name == "coreg_pk_42" && obj.elements[i].checked) {
			if(!obj.coreg_42_special_product[0].checked && !obj.coreg_42_special_product[1].checked && !obj.coreg_42_special_product[2].checked) {
				result = false;
				alert("Vänligen välj antal trisslotter per månad för att gå vidare.");
			}
		}
	}
	return result;
}
//checkt value auf 4-Stellige Nummer und gibt false zurück, wenns stimmt
function checkN(Wert) {
	if (isNaN(Wert)) {
		return true;
	} else {
		if (Wert.length == 4) {
			return false;
		} else {
			return true;
		}
	}
}

var p49_labelInPut = new Object();
/* configuration starts here */
// colors have to be set before p49_labelInPut.initialize()
p49_labelInPut.activeColor = '#000';
p49_labelInPut.inactiveColor = '#999';
/* configuration ends here */
p49_labelInPut.initialize = function(formId, defaultValues) {
// formId = String: 'form_master'
// defaultValues = Array: ['Förnamn','Efternamn','E-post']
	p49_labelInPut.inputs = $$('#'+formId+' input[type=text]');
	p49_labelInPut.inputs.each(function(input, index) {
		input.prefillValue = defaultValues[index];
		if(input.get('value') == '') {
			input.set('value',input.prefillValue);
		}
		if(input.get('value') == input.prefillValue) {
			input.setStyles({
				color: p49_labelInPut.inactiveColor
			});
		}
		input.addEvents({
			focus: function() {
				p49_labelInPut.onFocus(input)
			}, blur: function() {
				p49_labelInPut.onBlur(input)
			}
		});
	});
}
p49_labelInPut.onFocus = function(input) {
// also for mOOlidator onValidationDo: 'p49_labelInPut.onFocus(el);'
	try {
		if(input.get('type') == 'text' && input.prefillValue == input.get('value')) {
			input.set('value','');
			input.setStyles({
				color: p49_labelInPut.activeColor
			});
		}
	} catch(error) {
	}
}
p49_labelInPut.onBlur = function(input) {
// also for mOOlidator afterValidationDo: 'p49_labelInPut.onBlur(el);'
	try {
		if(input.get('type') == 'text' && (input.get('value')).replace(/ /g, '') == '') {
			input.set('value',input.prefillValue);
			input.setStyles({
				color: p49_labelInPut.inactiveColor
			});
		}
		} catch(error) {
	}
}
p49_labelInPut.onSubmit = function() {
// always call onSubmit of the form to delete those prefilled default values
	p49_labelInPut.inputs.each(function(input) {
		p49_labelInPut.onFocus(input);
	});
}

radioChecker = function () {
	$$('input[type=radio]').each(function(el, key) {
		var isChecked = false;
		el.addEvent('click', function() {
			var radioGroup = $$('input[type=radio][name='+el.getProperty('name')+']');
			
			if(!el.hasClass('radioChecked')) {
				radioGroup.each(function(el, key) {
					el.removeClass('radioChecked');
				});
			}
			
			if(el.hasClass('radioChecked')) {
				el.checked = false;
				isChecked = false;
				el.removeClass('radioChecked');
			} else {
				el.checked = true;
				isChecked = true;	
				el.addClass('radioChecked');
			}
		});
	});
}
