	
/* 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;
				}
			}
		});
	});
});
	
// 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 = 970;
		myhight = 720;
	}
	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,118,144);
	
	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();
	}
}

/* Funktion für die Erstellung der SkyScrapper der gewinner auf der 1. Seite  */
var winnerH1 = "Some of our recent winners";
var winnerImages = "12,13,14,15,7";
var winnerTitle = "Winner of an iPhone,Winner of a laptop,Winner of a Samsung flatscreen TV,Winner of a car (Volkswagen),Winner of a car (Audi),Winner of a car (Volkswagen)";
function writeImages(h1, images, title) {
	var folder = sponsor_switch_wingame;
	if(sponsor_switch_wingame == "39") folder = "voting_2009";
	var winnerlinks = images.split(",");             
	var winnertitles = title.split(",");
	var content = "";
	for (i=0;i<winnerlinks.length;i++) {
		//document.write('<img src="http://de.static.planet49.com/gewinner/winners/images/'+winnerlinks[i]+'.jpg" id="winner'+i+'" title="' +winnertitles[i]+ '" alt="' +winnertitles[i]+ '" /><br\/>');
		content += '<img src="http://de.static.planet49.com/gewinner/winners/images/'+winnerlinks[i]+'.jpg" id="winner'+i+'" title="' +winnertitles[i]+ '" alt="' +winnertitles[i]+ '" /><br\/>';
	}
	document.getElementById("sky_content").innerHTML = content;
  document.getElementById("skyH1").innerHTML = h1;
}

/* Coreg */
window.addEvent('domready', function() {
	if($('coreg_pk_10')) show_coreg_tc(10, 'http://www.planet49.us/cgi-bin/global.pl?todo=show_coreg_agb&agb_pk=10');
	if($('coreg_pk_11')) show_coreg_content(11);
	if($('coreg_pk_7'))  show_coreg_content(7);
	if($('coreg_pk_3'))  show_coreg_content(3);
	//Task 43332: If the user is interested in this coreg, please have the options as a drop down that they can select from.
	if($('coreg_pk_24')) {
		$('coreg_pk_24').addEvent('click', function() {
			var el = $('coreg_24_hide_content');
			if (el) {
				el.setStyle('visibility','visible');
			}
		});
	}
	if($('coreg_pk_19')) show_coreg_content(19);
	//init Popunder:
	 map_elements();
});
// shows the content-div of the coreg by ticking the checkbox
var show_coreg_content = function(coreg_pk) {
	$('coreg_pk_' + coreg_pk).addEvent('click', function () {
		display_coreg_content(coreg_pk);
	});
	if($('img_href_' + coreg_pk)) $('img_href_' + coreg_pk).addEvent('click', function() {
		display_coreg_content(coreg_pk);
	});
}
// displays the content of the coreg by ticking the checkbox
var display_coreg_content = function(coreg_pk) {
	if($('coreg_' + coreg_pk + '_content').getStyle('display') == 'none') $('coreg_' + coreg_pk + '_content').setStyle('display', 'block');
	else $('coreg_' + coreg_pk + '_content').setStyle('display', 'none');
}
// shows the t&c-div of the coreg by ticking the checkbox
var show_coreg_tc = function(coreg_pk, link) {
	$('coreg_pk_' + coreg_pk).addEvent('click', function() { 
		display_coreg_tc(coreg_pk, link);
	});
	if($('img_href_' + coreg_pk)) $('img_href_' + coreg_pk).addEvent('click', function() { 
		display_coreg_tc(coreg_pk, link);
	});
}
// displays the content of the t&c's by ticking the checkbox
var display_coreg_tc = function(coreg_pk, link) {
	if($('coreg_' + coreg_pk + '_tc').getStyle('display') == 'none') {
		$('coreg_' + coreg_pk + '_tc_iframe').src = link;
		$('coreg_' + coreg_pk + '_tc').setStyle('display', 'block');
	}
	else $('coreg_' + coreg_pk + '_tc').setStyle('display', 'none');
}
/* Coreg */

/* filling city from zipcode */
control_form = new Object();
control_form.initialize = function() {
	if($('city').get('value') == '') {
		control_form.readonlyElement($('city'), true);
	}
	$('zipcode').addEvents({
		keyup: function() {
			if(control_form.check_conditions() == true) control_form.request_city();
		},
		blur: function() {
			if(control_form.check_conditions() == true) control_form.request_city();
			else setTimeout(function() {
				control_form.readonlyElement($('city'), false);
			},100);
		},
		focus: function() {
			control_form.readonlyElement($('city'), true);
		}
	});
	$('city').addEvents({
		click: function() {
		}
	});
}
control_form.readonlyElement = function(element, option) {
	if($('country').get('value') == '1') {
		if(option == true) {
			element.addClass('readonly');
			element.setProperty('readonly', 'readonly');
		} else {
			element.removeClass('readonly');
			element.removeProperty('readonly');
		}
	}
}
control_form.check_conditions = function() {
	var result = false;
	if($('zipcode').get('value').search(/^\d{5}$/i) > -1 && $('country').get('value') == '1') result = true;
	return result;
}
control_form.request_city = function() {
	control_form.request = new Request.JSON({
		url: "/cgi-bin/wingame.pl?todo=get_address_info_by_zipcode&ajax=1&zipcode="+$('zipcode').get('value'),
		method: 'GET',
		onComplete: function(response) {
			control_form.process_results(response);
			control_form.readonlyElement($('city'), false);
			if(mooli != false) mooli.validate($('city'));
		},
		onFailure: function() {
			control_form.readonlyElement($('city'), false);
		}
	}).send();
}
control_form.process_results = function(response) {
	if(control_form.check_conditions() == true && response.status == 'valid') {
		$('city').set('value', response.city);
		var temp_provinces = $$('#province option').get('html');
		temp_provinces.each(function(value, index) {
			temp_provinces[index] = value.toLowerCase();
		});
		if(temp_provinces.contains(response.state.toLowerCase())) {
			$('province').selectedIndex = temp_provinces.indexOf(response.state.toLowerCase());
		}
	}
	$('city').removeProperty('disabled');
	$('city').removeClass('disabled');
}
control_form.enabled_fields = function() {
	$$('#register *:disabled').removeProperty('disabled');
}

/* press enter to continue */
enter_proceed = new Object();
enter_proceed.form_ids = {};
enter_proceed.initialize = function(form_ids) {
	if(form_ids) {
		enter_proceed.form_ids = form_ids;
		if(Object.keys(enter_proceed.form_ids).contains($(document.body).get('id'))) {
			$(document).addEvent('keyup', function(event) {
				var temp_event = event || window.event;
				if(temp_event.event.keyCode == 13) {
					enter_proceed.next(enter_proceed.form_ids[$(document.body).get('id')]);
				}
			});
		}
	}
}
enter_proceed.next = function(execute_object) {
	if(typeOf(execute_object) == 'function') {
		execute_object.apply();
	}
}
