var popUpWin=0;


function sh_popup(URLStr,widthw,heightw)
{
  var width=(widthw>0) ? widthw:380;
  var height=(heightw>0) ? heightw:470;
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));

  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr+'?popup', 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

var preloadFlag = false;

function setHeight(){
var a1 = document.getElementById('textureFixBody').clientHeight;
var b1 = a1 % 16;
	if (b1!=0) a1=a1-b1+16;
	document.getElementById('textureFixBody').height=a1;


document.getElementById('textureFixContent').style.height=document.getElementById('2xInfoboxFix').clientHeight+'px';
var a2 = document.getElementById('textureFixContent').clientHeight;
var b2 = a2 % 96;
	if (b2!=0) a2=a2-b2+96;
	document.getElementById('textureFixContent').style.height=a2+'px';
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var timer;


function popImage(imageURL,imgTitle) {
	imageURL=location.protocol+'//'+location.host+imageURL;
	var defWidth=0.75*screen.availWidth;
	var defHeight=0.75*screen.availHeight;
	var defWidth1=10;
	var defHeight1=10;
	var f="width="+defWidth1+",height="+defHeight1;
	f+=",left="+((screen.availWidth-defWidth)/2)+",scrollbars=yes,resizable=yes,top="+((screen.availHeight-defHeight)/2);
	imgWin=window.open('about:blank','',f);
	imDoc=imgWin.document;
	with (imDoc) {
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);if (width>0.75*screen.availWidth) width=0.75*screen.availWidth;');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);if (height>0.75*screen.availHeight) height=0.75*screen.availHeight;');
		writeln('window.resizeTo(width,height);}');writeln('else {');
		writeln('window.innerWidth=document.images["George"].width<0.75*screen.availWidth ? document.images["George"].width:0.75*screen.availWidth;');
		writeln('window.innerHeight=document.images["George"].height<0.75*screen.availHeight ? document.images["George"].height:0.75*screen.availHeight;}}');
		writeln('function doTitle(){document.title="'+imgTitle+'";}');writeln('</sc'+'ript>');
		writeln('</head><body bgcolor="#FFFFFF" onload="reSizeToImage();doTitle();self.focus()">')
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');

		close();
	}
}


function sitemap_open(img, id){
	if (document.getElementById(id).style['display']=='block'){
		document.getElementById(id).style['display']='none';
		img.src='/images/plus.gif';
	}
	else{
		document.getElementById(id).style['display']='block';
		img.src='/images/minus.gif';
	}
}

function fixPNG(element)
{
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;

		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				element.width = element.clientWidth;
				element.height = element.clientHeight;
				src = element.src;
				element.src = "/images/x.gif";
			}
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}

		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
	}
}


function getCookie(name) {
	var cookies = document.cookie.split(";");
	for (var i = 0; i < cookies.length; ++i) {
		var a = cookies[i].split("=");
		if (a.length == 2) {
			a[0] = a[0].trim();
			a[1] = a[1].trim();
			if (a[0] == name) {
				return unescape(a[1]);
			}
		}
	}
	return "";
};

function delCookie(name) {
	document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
};


prelimg=[];

/* jQuery menu */
jQuery(document).ready(function($){
  //$("div[class*=for_menu_0]").hide();
  $("div[id*=menu_karkas_0]").hover(show_div, hidden_div);

  $('.picturebox_plus a').lightBox();
  
  $('td.prel img').each(function(){
	prelimg.push(newImage( $(this).attr('onmouseover').toString().match(/\/.+(png|jpg|gif)/)[0]));
  });
})

function show_div(event)
{
	var x = this.id.length - 1;
	var y = this.id.substring(x);
	var my_div = 'div.for_menu_0' + y;
	//$(my_div).show('fast');
	$(my_div).show();
}

function hidden_div(event)
{
	var x = this.id.length - 1;
	var y = this.id.substring(x);
	var my_div = 'div.for_menu_0' + y;
	//$(my_div).hide('fast');
	$(my_div).hide();
}

function check_jobs_step1_from(){
	if ($("#i_sex").val()=='' ||
		$("#i_name").val()=='' ||
		$("#i_surname").val()=='' ||
		$("#i_phone").val()=='' ||
		$("#i_street").val()=='' ||
		$("#i_hn").val()=='' ||
		$("#i_zip").val()=='' ||
		$("#i_city").val()=='' ||
		$("#i_email").val()==''
	){
			alert('Bitte beachten Sie, dass die fett markierten Felder unbedingt ausgefüllt werden müssen!');
			return false;
	}
	return true;
}

function add_training_data(id, tpl_id){
	var tpl = $("#"+tpl_id).html();
	if (id=='jobs_step2_exp')
		var count = 4;
	else
		var count = 3;
	var index = Math.floor( $("#"+id+" .jobs_element").size()/count + 0.5 );
	tpl = tpl.replace(/%NUMBER%/g, index);
	$("#"+id).append(tpl);
}

function jobs_upload_change(elem, number){
	var tmp = elem.value;
	if (tmp.lastIndexOf('\\')!=-1){
		$("#jobs_upload_text"+number).val( tmp.substring( tmp.lastIndexOf('\\')+1 ) );
		return;
	}else{
		if (tmp.lastIndexOf('/')!=-1)
			$("#jobs_upload_text"+number).val( tmp.substring( tmp.lastIndexOf('/')+1 ) );
		else
			$("#jobs_upload_text"+number).val(tmp);
	}
}

function jobs_add_upload(){
	var tpl = $("#jobs_upload_tpl").html();
	var index = $("#jobs_upload_list .jobs_upload").size()+1;
	tpl = tpl.replace(/%NUMBER%/g, index);
	$("#jobs_upload_list").append(tpl);
}

function check_step3_jobs_form(){
	var is_dat = document.getElementById("datenschutz").checked ? true : false;
	if (!is_dat){
		alert('Sie sollen den Datenschutzbestimmungen zustimmen');
		return false;
	}
	return true;
}

function change_position(){
	var pos = $("#jobs_position").val();
	$("#jobs_region")[0].disabled = true;
	$("#jobs_city")[0].disabled = true;
	$("#jobs_filial")[0].disabled = true;
	while ($("#jobs_region")[0].options.length>1)
		$("#jobs_region")[0].options[ $("#jobs_region")[0].options.length-1 ] = null;
	while ($("#jobs_city")[0].options.length>1)
		$("#jobs_city")[0].options[ $("#jobs_city")[0].options.length-1 ] = null;
	while ($("#jobs_filial")[0].options.length>1)
		$("#jobs_filial")[0].options[ $("#jobs_filial")[0].options.length-1 ] = null;
	
	if (pos=='')
		return;
	
	var tmp_arr = [];
	var i = 0;
	var j = 0;
	for (i=0; i<filials.length; i++){
		if (filials[i]==undefined)
			continue;
		if (pos==filials[i][0]){
			var is_find = false;
			for (j=0; j<tmp_arr.length; j++)
				if (filials[i][1]==tmp_arr[j]){
					is_find = true;
					break;
				}
			if (!is_find)
				tmp_arr.push(filials[i][1]);
		}
	}
	tmp_arr.sort();
	if (tmp_arr.length==0){
		alert('Leider sind für diese Positionen keine Stellen verfügbar.');
		return;
	}
	for (i=0; i<tmp_arr.length; i++)
		$("#jobs_region")[0].options[ $("#jobs_region")[0].options.length ]= new Option(tmp_arr[i], tmp_arr[i]);
	$("#jobs_region")[0].disabled = false;
}

function change_land(){
	var land = $("#jobs_region").val();
	var pos = $("#jobs_position").val();
	$("#jobs_city")[0].disabled = true;
	$("#jobs_filial")[0].disabled = true;
	while ($("#jobs_city")[0].options.length>1)
		$("#jobs_city")[0].options[ $("#jobs_city")[0].options.length-1 ] = null;
	while ($("#jobs_filial")[0].options.length>1)
		$("#jobs_filial")[0].options[ $("#jobs_filial")[0].options.length-1 ] = null;
	
	if (land=='')
		return;
	
	var tmp_arr = [];
	var i = 0;
	var j = 0;
	for (i=0; i<filials.length; i++){
		if (filials[i]==undefined)
			continue;
		if (pos==filials[i][0] && land==filials[i][1]){
			var is_find = false;
			for (j=0; j<tmp_arr.length; j++)
				if (filials[i][2]==tmp_arr[j]){
					is_find = true;
					break;
				}
			if (!is_find)
				tmp_arr.push(filials[i][2]);
		}
	}
	tmp_arr.sort();
	for (i=0; i<tmp_arr.length; i++)
		$("#jobs_city")[0].options[ $("#jobs_city")[0].options.length ]= new Option(tmp_arr[i], tmp_arr[i]);
	$("#jobs_city")[0].disabled = false;
}

function change_city(){
	var city = $("#jobs_city").val();
	var land = $("#jobs_region").val();
	var pos = $("#jobs_position").val();
	$("#jobs_filial")[0].disabled = true;
	while ($("#jobs_filial")[0].options.length>1)
		$("#jobs_filial")[0].options[ $("#jobs_filial")[0].options.length-1 ] = null;
	
	if (city=='')
		return;
	
	var tmp_arr = [];
	var i = 0;
	var j = 0;
	for (i=0; i<filials.length; i++){
		if (filials[i]==undefined)
			continue;
		if (pos==filials[i][0] && land==filials[i][1] && city==filials[i][2]){
			var is_find = false;
			for (j=0; j<tmp_arr.length; j++)
				if (filials[i][3]==tmp_arr[j]){
					is_find = true;
					break;
				}
			if (!is_find)
				tmp_arr.push(filials[i][3]);
		}
	}
	tmp_arr.sort();
	for (i=0; i<tmp_arr.length; i++)
		$("#jobs_filial")[0].options[ $("#jobs_filial")[0].options.length ]= new Option(tmp_arr[i], tmp_arr[i]);
	$("#jobs_filial")[0].disabled = false;
}

function check_jobs_filials_form(){
	if ($("#jobs_filial").val()==''){
		alert('Bitte wählen Sie die Position, Ihr Bundesland, Ihre Stadt sowie unsere Filiale in Ihrer Stadt');
		return false;
	}
	return true;
}
