//  prevent using the right mouse key -- uncomment to use!!
//document.oncontextmenu = handleContextMenu
//function handleContextMenu(){return false;}

//	function handleKeyUp(e){
//		if(!e)
//		var e = window.event;
//		key = e.keyCode;
//		alert("You pressed the " + String.fromCharCode(key) + " key (keycode "+ key +").");
//	}

	function mediaCaptBg(myInput){
	mySTR = myInput.value;
		if(mySTR == "" || mySTR == null || mySTR.charAt(0) == ' '){
			myInput.style.background = 'url(/templates/fresh/images/caption_media.gif) no-repeat center center';
		}
	}
	
	 function changeInhArt(inhArt,myFormName){
		switch(inhArt){
			case "rtt": // regional-touristischer Tipp
				document.getElementById('kts').style.display = 'block';
			break;
			case "rfg":  // regional-fantastische Geschichte
				document.getElementById('kts').style.display = 'none';
			break;
		}
	 }
	 
	function tippVorschau(tippPK){
		MeinFenster = window.open("/templates/fresh/vorschau.php?part=manage_tipps&tippPK="+tippPK, "WMWH_adm_manage_tipps","width=930,height=750,left=200,top=50,menubar=no,status=no,dependent=yes,location=no,resizable=no,scrollbars=yes,toolbar=no");
		MeinFenster.focus();
	}

	function submitTipp(myform){ 
		if(myform.tippstatus.options[myform.tippstatus.selectedIndex].value=='publish'){
			Check = confirm('Mit dem Klick auf "OK" erkennen Sie unsere folgenden Teilnahmebedingungen an.\nBrechen Sie den Vorgang ab, wenn Sie nicht einverstanden sind.\n\nDer Autor versichert, dass er allein berechtigt ist, über die\nurheberrechtlichen Nutzungsrechte an seinem Text und Bild\nzu verfügen und tritt seine Rechte ab der Text und\nBildveröffentlichung unter "http://www.was-machen-wir-heute.de"\nan die Portalbetreiber lt. Impressum ab.\nBild und Text sind danach im Internet für jedermann frei verfügbar.\nDer Autor wird unter jedem Text namentlich erwähnt.');
			if ( Check == false ){ return false; }
		}
		
		if(myform.inhalt_art[0].checked!=true && myform.inhalt_art[1].checked!=true){
			alert("Soll Ihr Beitrag eine regional-touristische Geschichte\noder ein regional-touristischer Tipp sein?");
			return false;
		}
		
		if(myCheck(myform.plz.value,'anytext')==false){
			alert('Bitte füllen Sie noch das feld "PLZ" aus!');
			myform.plz.focus();
		return false;
		}
	
	return true();
	}

	function confEditAbbr(myform){
		Check = confirm('Wollen Sie wirklich abbrechen, ohne die Änderungen zu speichern?');
		if (Check == true){ window.location.href = "/addtipps"; }	
	}
	
	function mtcheck(myform,isEdit){
		switch(document.forms[myform].myaction.value){
			case "drop":
				switch(isEdit){
					case "edit":
						 Check = confirm('Ein Freizeittipp befindet sich gerade im Bearbeitungsmodus. Klicken Sie auf "OK",\nwenn Sie sicher sind, dass alle benötigten Änderungen gespeichert wurden.\nSonst klicken Sie auf "abbrechen".');
						 if (Check == false){ return false; }
					break;
					case "wrbkndn":
						 Check = confirm('Ein Freizeittipp befindet sich gerade im Werbekunden-Bearbeitungsmodus. Klicken Sie auf "OK",\nwenn Sie sicher sind, dass alle benötigten Änderungen gespeichert wurden.\nSonst klicken Sie auf "abbrechen".');
						 if (Check == false){ return false; }
					break;
				}
				Check = confirm('Wollen Sie diesen Freizeittipp wirklich komplett löschen?');
				if (Check == false){ return false; }
			break;
			case "wrbkndn":
				switch(isEdit){
					case "edit":
						 Check = confirm('Ein Freizeittipp befindet sich gerade im Bearbeitungsmodus. Klicken Sie auf "OK",\nwenn Sie sicher sind, dass alle benötigten Änderungen gespeichert wurden.\nSonst klicken Sie auf "abbrechen".');
						 if (Check == false){ return false; }
					break;
					case "wrbkndn":
						 Check = confirm('Ein Freizeittipp befindet sich gerade im Werbekunden-Bearbeitungsmodus. Klicken Sie auf "OK",\nwenn Sie sicher sind, dass alle benötigten Änderungen gespeichert wurden.\nSonst klicken Sie auf "abbrechen".');
						 if (Check == false){ return false; }
					break;
				}
			break;
			default:
				switch(isEdit){
					case "edit":
						 Check = confirm('Ein Freizeittipp befindet sich gerade im Bearbeitungsmodus. Klicken Sie auf "OK",\nwenn Sie sicher sind, dass alle benötigten Änderungen gespeichert wurden.\nSonst klicken Sie auf "abbrechen".');
						 if (Check == false){ return false; }
					break;
					case "wrbkndn":
						 Check = confirm('Ein Freizeittipp befindet sich gerade im Werbekunden-Bearbeitungsmodus. Klicken Sie auf "OK",\nwenn Sie sicher sind, dass alle benötigten Änderungen gespeichert wurden.\nSonst klicken Sie auf "abbrechen".');
						 if (Check == false){ return false; }
					break;
				}
			break;
		}
	return true;
	}
	
	function mysetactpk(myform,pk,myact,isEdit){
		switch(myact){
			case "add":
				document.forms[myform].Item.value='';
				document.forms[myform].myaction.value='add';
			break;
			case "wrbkndn":
				document.forms[myform].Item.value=pk;
				document.forms[myform].myaction.value='wrbkndn';
			break;
			case "edit":
				document.forms[myform].Item.value=pk;
				document.forms[myform].myaction.value='edit';
			break;
			case "drop":
				document.forms[myform].Item.value=pk;
				document.forms[myform].myaction.value='drop';
			break;
		}
		if(mtcheck(myform,isEdit)==true){
			document.forms[myform].submit();
		}
	}
	
	function dropTippConfirm(myform){
		Check = confirm("Wollen Sie diesen Freizeittipp wirklich komplett löschen?");
			if (Check == false)
			history.back();
	}

	function navtabover(deftab,overtab){
		document.getElementById('li_'+deftab).className = 'inactiveli';
		document.getElementById('li_'+overtab).className = 'activeli';
		document.getElementById('sub_'+deftab).style.display='none';
		document.getElementById('sub_'+overtab).style.display='block';
	}
	
	function navtabout(deftab,overtab){
		document.getElementById('li_'+overtab).className = 'inactiveli';
		document.getElementById('li_'+deftab).className = 'activeli';
		document.getElementById('sub_'+overtab).style.display='none';
		document.getElementById('sub_'+deftab).style.display='block';
	}

	function clearlogininput(inputstr,passstr,who){
		if(document.forms[who].login.value==inputstr && document.forms[who].passwd.value==passstr){
			document.forms[who].login.value="";
			document.forms[who].passwd.value="";
		} else if(document.forms[who].login.value=="" && document.forms[who].passwd.value==""){
			document.forms[who].login.value=inputstr;
			document.forms[who].passwd.value=passstr;
		}
	}
	
	function clearinput(inputstr,who){
		if(document.forms[who].plzortfield.value==inputstr){
			document.forms[who].plzortfield.value="";
		} else if(document.forms[who].plzortfield.value==""){
			document.forms[who].plzortfield.value=inputstr;
		}
	}
	
	function authcheck(myform){
		if(document.forms[myform].login.value=="[Ihre.email@adresse.de]" && document.forms[myform].passwd.value=="12345"){
			document.forms[myform].login.value = "";
			document.forms[myform].passwd.value = "";	
		}
		document.forms[myform].buttonlogin.disabled = true;
		document.forms[myform].loginaction.value = "login";
	return true;
	}
	
	function linkpost(mylink,myform){
		document.forms[myform].link.value = mylink;
		document.forms[myform].postaction.value = "ok";
		document.forms[myform].submit();
	}
	
	function updUserForm(myFormName){
		if(myCheck(document.forms[myFormName].email.value,'emailfield')==false){
			alert('Bitte eine gültige Email-Adresse eingeben!');
		return false;
		}
		
		if(document.forms[myFormName].passw.value!=document.forms[myFormName].passw_confirm.value){
			alert('Die Angaben in den Feldern "Passwort" und "Password wiederholen" stimmen nicht überein!');
		return false;
		}
		
		if(document.forms[myFormName].anrede.selectedIndex<=0){
			alert('Bitte wählen Sie eine für Sie passende Anrede aus der Liste!');
		return false;
		}
		
		if(myCheck(document.forms[myFormName].vorname.value,'textfield')==false){
			alert('Bitte tragen Sie Ihren Vornamen ein!');
		return false;
		}

		if(myCheck(document.forms[myFormName].nachname.value,'textfield')==false){
			alert('Bitte tragen Sie Ihren Namen ein!');
		return false;
		}
		
//		if(document.forms[myFormName].strasse.value){
		
//		return false;
//		}

//		if(document.forms[myFormName].plz.value){
		
//		return false;
//		}

//		if(document.forms[myFormName].telefon.value){
		
//		return false;
//		}

//		if(document.forms[myFormName].handy.value){
		
//		return false;
//		}

//		if(document.forms[myFormName].fax.value){
		
//		return false;
//		}

		document.forms[myFormName].buttonUpd.disabled = true;
		document.forms[myFormName].goupdate.value = "ok";	
	return true;
	}
	
	function preCheckRegister(myFormName){
		if(document.forms[myFormName].register_art[0].checked!=true){
			document.getElementById('strasse_tr').style.visibility='visible';
			document.getElementById('wohnort_tr').style.visibility='visible';
			document.getElementById('plz_tr').style.visibility='visible';
			document.getElementById('telefon_tr').style.visibility='visible';
			document.getElementById('handy_tr').style.visibility='visible';
			document.getElementById('fax_tr').style.visibility='visible';
		} else {
			document.getElementById('strasse_tr').style.visibility='collapse';
			document.getElementById('wohnort_tr').style.visibility='collapse';
			document.getElementById('plz_tr').style.visibility='collapse';
			document.getElementById('telefon_tr').style.visibility='collapse';
			document.getElementById('handy_tr').style.visibility='collapse';
			document.getElementById('fax_tr').style.visibility='collapse';
		}
	
//	alert(document.getElementsByName("register_art").length);

	}
	
	function checkRegForm(myFormName){
	
		if(document.forms[myFormName].register_art[0].checked!=true && document.forms[myFormName].register_art[1].checked!=true && document.forms[myFormName].register_art[2].checked!=true && document.forms[myFormName].register_art[3].checked!=true){
			alert('Bitte wählen Sie einen für Sie passenden Benutzerprofiltyp aus der Liste!');
//			document.forms[myFormName].register_art[0].focus();
		return false;
		}
	
		if(myCheck(document.forms[myFormName].email.value,'emailfield')==false){
			alert('Bitte eine gültige Email-Adresse eingeben!');
			document.forms[myFormName].email.focus();
		return false;
		}
		
		if(myCheck(document.forms[myFormName].username.value,'username')==false){
			alert('Ein Benutzername muss mindestens vier Zeichen lang sein und darf keine Leerzeichen beinhalten!\nErlaubt sind Klein- sowie Großbuchstaben und Zahlen.');
			document.forms[myFormName].username.focus();
		return false;
		}
		
		if(document.forms[myFormName].passw.value!=document.forms[myFormName].passw_confirm.value){
			alert('Die Angaben in den Feldern "Passwort" und "Password wiederholen" stimmen nicht überein!');
			document.forms[myFormName].passw_confirm.focus();
		return false;
		}
		
		if(myCheck(document.forms[myFormName].passw.value,'passwdfield')==false){
			alert('Das Passwort muss mindestens fünf Zeichen lang sein und darf keine Leerzeichen beinhalten!\nErlaubt sind Klein- und Großbuchstaben, Zahlen und Sonderzeichen.');
			document.forms[myFormName].passw.focus();
		return false;
		}
		
		if(myCheck(document.forms[myFormName].passw_confirm.value,'passwdfield')==false){
			alert('Das Passwort muss mindestens fünf Zeichen lang sein und darf keine Leerzeichen beinhalten!\nErlaubt sind Klein- und Großbuchstaben, Zahlen und Sonderzeichen.');
			document.forms[myFormName].passw_confirm.focus();
		return false;
		}
		
		if(document.forms[myFormName].anrede.selectedIndex<=0){
			alert('Bitte wählen Sie eine für Sie passende Anrede aus der Liste!');
			document.forms[myFormName].anrede.focus();
		return false;
		}
		
		if(myCheck(document.forms[myFormName].vorname.value,'textfield')==false){
			alert('Bitte tragen Sie Ihren Vornamen ein!');
			document.forms[myFormName].vorname.focus();
		return false;
		}

		if(myCheck(document.forms[myFormName].nachname.value,'textfield')==false){
			alert('Bitte tragen Sie Ihren Namen ein!');
			document.forms[myFormName].nachname.focus();
		return false;
		}
		
		if(document.forms[myFormName].register_art[0].checked!=true){

			if(myCheck(document.forms[myFormName].strasse.value,'textfield')==false){
				alert('Bitte tragen Sie Ihre Strasse und die Hausnummer ein!');
				document.forms[myFormName].strasse.focus();
			return false;
			}

			if(myCheck(document.forms[myFormName].plz.value,'anytext')==false){
				alert('Bitte tragen Sie Ihre Postleitzahl ein!');
				document.forms[myFormName].plz.focus();
			return false;
			}
			
			if(myCheck(document.forms[myFormName].wohnort.value,'textfield')==false){
				alert('Bitte tragen Sie Ihren Wohnort ein!');
				document.forms[myFormName].wohnort.focus();
			return false;
			}

			if(myCheck(document.forms[myFormName].telefon.value,'anytext')==false){
				alert('Verraten Sie uns auch Ihre Telefonnummer? ;-)');
				document.forms[myFormName].telefon.focus();
			return false;
			}


		}
		


//		if(document.forms[myFormName].handy.value){
		
//		return false;
//		}

//		if(document.forms[myFormName].fax.value){
		
//		return false;
//		}

		document.forms[myFormName].buttonReg.disabled = true;
		document.forms[myFormName].register.value = "ok";	
	return true;
	}
	
	function trim(myinput){
		return myinput.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	}

	function myCheck(mySTR,myType) {
		switch(myType){
			case "textfield":
				if (mySTR == "" || mySTR == null || isFinite(mySTR) || mySTR.charAt(0) == ' '){
					return false;
				}
			break;
			case "anytext":
				if (mySTR == "" || mySTR == null || mySTR.charAt(0) == ' '){
					return false;
				}
			break;
			case "username":
				validRegExp = /\s/i;
				if (mySTR == "" || mySTR == null || mySTR.charAt(0) == ' ' || strlen(mySTR)<4 || mySTR.search(validRegExp) != -1){
					return false;
				}	
			break;
			case "passwdfield":
				validRegExp = /\s/i;
				if (mySTR == "" || mySTR == null || mySTR.charAt(0) == ' ' || strlen(mySTR)<5 || mySTR.search(validRegExp) != -1){
					return false;
				}	
			break;
			case "emailfield":
				validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
				if (mySTR.search(validRegExp) == -1) {
					return false;
				}
			break;
//			case "urlfield":
//				if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' '){
//					alert("\"Field 2\" is a mandatory field.\nPlease amend and retry.")
//				return false;
//				}				
//			break;
		}
		return true;
	}
	
	function strlen (string) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Sakimori
    // +      input by: Kirk Strobeck
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +    revised by: Brett Zamir
    // %        note 1: May look like overkill, but in order to be truly faithful to handling all Unicode
    // %        note 1: characters and to this function in PHP which does not count the number of bytes
    // %        note 1: but counts the number of characters, something like this is really necessary.
    // *     example 1: strlen('Kevin van Zonneveld');
    // *     returns 1: 19
    // *     example 2: strlen('A\ud87e\udc04Z');
    // *     returns 2: 3
 
    var str = string+'';
    var i = 0, chr = '', lgth = 0;
 
    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { // High surrogate(could change last hex to 0xDB7F to treat high private surrogates as single characters)
            if (str.length <= (i+1))  {
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str[i]+str[i+1];
        } else if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if (0xD800 > prev || prev > 0xDBFF) { //(could change last hex to 0xDB7F to treat high private surrogates as single characters)
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; // We can pass over low surrogates now as the second component in a pair which we have already processed
        }
        return str[i];
    };
 
    for (i=0, lgth=0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {
            continue;
        } // Adapt this line at the top of any loop, passing in the whole string and the current iteration and returning a variable to represent the individual character; purpose is to treat the first part of a surrogate pair as the whole character and then ignore the second part
        lgth++;
    }
    return lgth;
}

	
	

