﻿function switchImg(obj,par){
	if(document.getElementById(obj))
		obj=document.getElementById(obj);
	imgName=obj.src;
	imgName=imgName.split("/");
	imgName=imgName[(imgName.length)-1];
	imgPath=obj.src.split(imgName);
	imgPath=imgPath[0];
	imgName=imgName.split(".");
	imgSuffix=imgName[1];
	imgName=imgName[0];
	if(par==1)
		imgName=imgName+"_over."+imgSuffix;
	else{
		imgName=imgName.split("_");
		imgName=imgName[0]+"."+imgSuffix;
	}
	obj.src=imgPath+imgName;
}

function findPosition(obj){
	x=0; y=0; w=0; h=0; var el,temp;
	if(typeof(obj)=="string")
		obj=getE(obj);
	if(obj.offsetParent){
		temp=obj;
		while(temp.offsetParent){
			temp=temp.offsetParent; 
			x+=temp.offsetLeft;
			y+=temp.offsetTop;
		}
	}
	x+=obj.offsetLeft;
	y+=obj.offsetTop;
	w=obj.offsetWidth;
	h=obj.offsetHeight;
	return [x,y,w,h];
}

function extLinks(){ 
	if(!document.getElementsByTagName)
		return; 
	var anchors=document.getElementsByTagName("a"); 
	for(var i=0;i<anchors.length;i++){			
		if(anchors[i].getAttribute("href")&&anchors[i].getAttribute("rel")) 
			anchors[i].target=anchors[i].getAttribute("rel");
		if(!anchors[i].onclick&&p==1)
			anchors[i].onclick=showWin;
	}
}

function bookmark(title,url){
	if(window.sidebar)
		window.sidebar.addPanel(title,url,"");
	else if(window.opera && window.print){
		el=document.createElement('a');
		el.setAttribute('href',url);
		el.setAttribute('title',title);
		el.setAttribute('rel','sidebar');
		el.click();
	}
	else if(document.all)
		window.external.AddFavorite(url,title);
}

function getE(obj){
	return document.getElementById(obj);	
}

function getEe(e){
	return e?e.target:window.event.srcElement;
}

function showE(obj,par){
	if(typeof(obj)=="string")
		obj=getE(obj);
	if(par==1)
		obj.style.display=obj.style.display=="block"?"none":"block";
	else
		obj.style.display="block";	
}

function hideE(obj){
	if(typeof(obj)=="string")
		obj=getE(obj);
	obj.style.display="none";	
}

function isDigit(e){
	e=e||event;
	iCode=(e.keyCode||e.charCode);
	return((iCode>=48&&iCode<=57)||(iCode>=37&&iCode<=40)||iCode==8||iCode==46);
}

function sendMessage(str1,str2,str3,str4){
	tmp="ma" +"ilto:";
	tmp+=str3;
	tmp+="@";
	tmp+=str2;
	tmp=tmp+"."+str1+(str4!=""?"?subj"+ "ect="+str4:"");
	window.location=tmp;
	return false;
}

var wm=null,p=0;

onload=function(){
	menu_onload();
	extLinks();
	if(wm)webmin_init();
	if(getE("wm_search")){
		el=getE("wm_search");
		el.onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		el.onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}
	if(getE("login_userName")){
		el=getE("login_userName");
		el.onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		el.onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}
	if(getE("login_userPassword")){
		el=getE("login_userPassword");
		el.onfocus=function(){
			if(this.value==this.title)
				this.value='';
		}
		el.onblur=function(){
			if(this.value=='')
				this.value=this.title;
		}
	}
};

/*  */
function select_all_boxes(el){
	chck=el.checked;
	while(el.nodeName!="FORM"&&el.nodeName!="HTML")
		el=el.parentNode;
	for(c=0;c<el.elements.length;c++){
		if(el.elements[c].id!="platt6"&&el.elements[c].id!="platt9")
			el.elements[c].checked=chck;
	}
}

function checkDate(obj){
	d=new Date();
	y=d.getFullYear();

	var val=obj.value,
		invalid=0,
		months=new Array(),
		day="",
		month="",
		year="";
	if(val=="")
		return false;
	
	if(val.indexOf(".")>0)
		separator=".";
	else
		separator=",";
	tmp=val.split(separator);
	
	if(tmp[0]!=undefined&&tmp[1]!=undefined&&tmp[2]!=undefined){
		for(c=0;c<3;c++){
			while(tmp[c].charAt(0)=="0")
				tmp[c]=tmp[c].substr(1);
		}
		obj.value=tmp[0]+'.'+tmp[1]+'.'+tmp[2];
	
		day=tmp[0];
		month=tmp[1];
		year=tmp[2];
		lyear=1904;
		months[1]=31;months[2]=((year-lyear)%4==0?29:28);months[3]=31;
		months[4]=30;months[5]=31;months[6]=30;
		months[7]=31;months[8]=31;months[9]=30;
		months[10]=31;months[11]=30;months[12]=31;
	}
	else
		invalid=1;
	if(month<1||month>12||day<1||day>months[month]||year>(y+1)||year<1800||invalid==1){
		alert('Falsches Datumformat. Bitte verwenden Sie das Format TT.MM.JJJJ');
		obj.select();
		obj.focus();
	}
}

function agbs_check(obj){
	chck=obj.checked;
	el=getE("weiter");
	el.style.display=chck==true?"block":"none";
}

function delById(par){
	if(confirm("Möchten Sie den Eintrag wirklich löschen?"))
		location.href="?action_type=delete&id="+par;
}

function forgot_pass(){
	el=getE("sms_login");
	if(el.login.value==""){
		alert("Bitte geben Sie Ihren Benutzername ein.");
		el.login.focus();
	}
	else{
		el.action_type.value="forgot_pass";
		el.submit();
	}
}

function checkSMS(obj){
	el=getE("char_cnt");
	if(obj.value.length>120){
		obj.value=obj.value.substr(0,120);
		el.value=0;
		return false;
	}
	
	el.value=120-obj.value.length;
}
/*  */
function ajaxRequest(url){
	var ajaxRequest=new AjaxRequest(url);
	ajaxRequest.sendRequest();
}
function show_form_segment(obj){
	val=obj.value;
	if(val!=0)
		ajaxRequest(absPath+"de/pap/meine-jobs/?webmin_ajax=1&action_type=get_form_segment&bereich="+val);
	else
		getE("ajax_result").innerHTML='Bitte wählen Sie eine Berufsgruppe.';
}