// JavaScript Document
function makeActive(Image) {
  if(Image.src.indexOf("_active")==-1)
	Image.src=Image.src.substring(0,Image.src.length-4)+"_active"+Image.src.substring(Image.src.length-4,Image.src.length);
}
function makeNormal(Image) {
  Image.src=Image.src.substring(0,Image.src.length-11)+Image.src.substring(Image.src.length-4,Image.src.length);
}

function myHighlight(obj) 
{
  obj.style.background = "#F1F4D6";
}

function myUnhighlight(obj) 
{
  obj.style.background = "#FFFFFF";
}

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us> -- geekwisdom.com
Description: This is a quick and dirty password quality meter 
		 written in JavaScript so that the password does 
		 not pass over the network.
License: MIT License (see below)
Modified: 20060620 - added MIT License
Modified: 20061111 - corrected regex for letters and numbers
                     Thanks to Zack Smith -- zacksmithdesign.com
---------------------------------------------------------------
Copyright (c) 2006 Steve Moitozo <god at zilla dot us>

Permission is hereby granted, free of charge, to any person 
obtaining a copy of this software and associated documentation 
files (the "Software"), to deal in the Software without 
restriction, including without limitation the rights to use, 
copy, modify, merge, publish, distribute, sublicense, and/or 
sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following 
conditions:

   The above copyright notice and this permission notice shall 
be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
OR OTHER DEALINGS IN THE SOFTWARE. 
---------------------------------------------------------------


Password Strength Factors and Weightings

password length:
level 0 (3 point): less than 4 characters
level 1 (6 points): between 5 and 7 characters
level 2 (12 points): between 8 and 15 characters
level 3 (18 points): 16 or more characters

letters:
level 0 (0 points): no letters
level 1 (5 points): all letters are lower case
level 2 (7 points): letters are mixed case

numbers:
level 0 (0 points): no numbers exist
level 1 (5 points): one number exists
level 1 (7 points): 3 or more numbers exists

special characters:
level 0 (0 points): no special characters
level 1 (5 points): one special character exists
level 2 (10 points): more than one special character exists

combinatons:
level 0 (1 points): letters and numbers exist
level 1 (1 points): mixed case letters
level 1 (2 points): letters, numbers and special characters 
					exist
level 1 (2 points): mixed case letters, numbers and special 
					characters exist


NOTE: Because I suck at regex the code might need work
	  
NOTE: Instead of putting out all the logging information,
	  the score, and the verdict it would be nicer to stretch
	  a graphic as a method of presenting a visual strength
	  guage.

************************************************************ */
function testPassword(oPassword, oCount)
{
	var intScore   = 0
	passwd = oPassword.value
	
	// PASSWORD LENGTH
	if (passwd.length<5)                         // length 4 or less
		intScore = (intScore+3)
	else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		intScore = (intScore+6)
	else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		intScore = (intScore+12)
	else if (passwd.length>15)                    // length 16 or more
		intScore = (intScore+18)
	
	
	
	// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
	if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		intScore = (intScore+1)
	
	if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		intScore = (intScore+5)
	
	// NUMBERS
	if (passwd.match(/\d+/))                                 // [verified] at least one number
		intScore = (intScore+5)
	
	if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		intScore = (intScore+5)
	
	// SPECIAL CHAR
	if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		intScore = (intScore+5)
	
	
									// [verified] at least two special characters
	if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		intScore = (intScore+5)
	
	// COMBOS
	if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		intScore = (intScore+2)
	
	if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		intScore = (intScore+2)
	
	// [verified] letters, numbers, and special characters
	if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		intScore = (intScore+2)
	
	val = (intScore/50)*100 // intScore/50 because max points are 50 get prozent of password
	oWidth = 1.1*val //1.1 because 110 px is 100%
	oCount.style.width = oWidth+"px";
}

function openPopUp(url, wWidth, wHeight, wScrollbar)
{
	myWin=window.open(url, 'windowPopUp','width='+wWidth+'px,height='+wHeight+'px,resizable,scrollbars='+wScrollbar);
	myWin.moveTo((screen.width/2)-(500/2),(screen.height/2)-(wHeight/2));
	myWin.focus();
	return false;
}

function getCount(objId)
{
	obj = document.getElementById(objId)
	
	if(obj.value.trim()!="")
		return 9;
	else
		return 0;
}

function getCountDDL2(objId)
{
	obj = document.getElementById(objId)
	if(obj[obj.selectedIndex].value.trim()!="N")
		return 9;
	else
		return 0;
}

function getCountDDL(objId)
{
	obj = document.getElementById(objId)
	if(obj[obj.selectedIndex].value.trim()!="")
		return 9;
	else
		return 0;
}

String.prototype.trim = function() {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return this.replace (/^\s+/, '').replace (/\s+$/, '');
}

function changeImage(sourceId, targetId)
{
	newsrc = document.getElementById(sourceId).value;
	
	if(newsrc.trim()!="")
	{
		i = new Image();
		i.src = newsrc;
		oi = document.getElementById(targetId)
		oi.src = i.src
		if(i.width>i.height)
		{
			oi.style.width = "100px";
			oi.style.height = "auto";
		}
		else
		{
			oi.style.width = "auto";
			oi.style.height = "100px";
		}
			
	}
}

function setGruppe(val)
{
	obj = document.getElementById('pageTemplate_SubNavigation_Overlay_hiddenGruppe')
	if(obj)
		obj.value=val;
	obj2 = document.getElementById('pageTemplate_Overlay_hiddenGruppe')
	if(obj2)
		obj2.value=val;
		
	if(val=="")
		document.getElementById('empfaehlenHeaderTag').innerHTML = "Seite weiterempfehlen";
	else
		document.getElementById('empfaehlenHeaderTag').innerHTML = "In diese Gruppe einladen";
}

function openMyOverlay(objId)
{
	hideSelectTags();
	
	//get overlay object
	objOverlay = document.getElementById("myOverlay");
	objOverlay.style.display ="block";
	//set overlay 
	setOverlay(objOverlay);
	
	//get object to show
	objLayer = document.getElementById(objId);
	objLayer.style.display = "block";
	//set object to show in the middel of window
	setPosition(objLayer)
	
	if(window.onresize!=null && window.onresize.toString().indexOf("setProfileImage")>=0)
	{	
		//add resize listener
		window.onresize = function() { 
				setOverlay(objOverlay); 
				setPosition(objLayer);
				setProfileImage();
		}
	}
	else
	{
		//add resize listener
		window.onresize = function() { 
				setOverlay(objOverlay); 
				setPosition(objLayer);
		}
	}
}

function setOverlay(obj)
{
	maxSize = getMaxOverlaySize();
	obj.style.width = maxSize[0]+"px";
	obj.style.height = maxSize[1]+"px";
}

function closeMyOverlay(objId)
{
	showSelectTags();
	
	//hide layer
	layer = document.getElementById(objId);
	layer.style.display = "none";
	//hide overlay
	obj = document.getElementById("myOverlay");
	obj.style.display ="none";	
	
	//remove listener 
	if(window.onresize!=null && window.onresize.toString().indexOf("setProfileImage")>=0)
	{
		window.onresize -= function() { 
			setProfileImage();
		}		
	}
	else
		window.onresize = null
}

function getMaxOverlaySize()
{
	//get container size 
	objContainer = document.getElementById("container");
	contSize = findPos(objContainer);
	///get body size
	bodySize = findPos(document.body);
	//alert( contSize[5]+" "+bodySize[5] )
	//get bigest unit
	maxWidth = (contSize[4]>bodySize[4]) ? contSize[4] : bodySize[4]
	maxHeight = (contSize[5]>bodySize[5]) ? contSize[5] : bodySize[5]
	return [maxWidth, maxHeight]
}

function setPosition(layer)
{
	//get size of the window 
	winSize = windowSize()
	//visibleWidth = (totalSize[0])
	//find size
	layerSize = findPos(layer);
	//get width of the layer
	width = layerSize[4]//-layerSize[3]
	//get height of the layer
	height = layerSize[5]//-layerSize[0]
	//set layer position
	leftPos = Math.ceil( (winSize[0]/2)-(width/2) )
	layer.style.left = (leftPos<0) ? "0px" : (leftPos)+"px";
	//set layer position
	topPos= Math.ceil((winSize[1]/2)-(height/2))
	layer.style.top = (topPos<0) ? "0px" : topPos+"px";
	//set visibility
	layer.style.visibility = "visible";
	//set focus
	objInput = layer.getElementsByTagName("input")
	if(objInput[0])
	{
		try 
		{
			objInput[0].focus()
		}
		catch (e)
		{
		
		}
	}
	else
	{
		layer.focus();
	}
	
		
	
	//scroll
	window.scrollTo(0, 0)
}

function findPos(obj) {
	var curleft = curtop = 0;
	var curwidth = curheigt = 0;
	
	curwidth = obj.offsetWidth;
	curheight = obj.offsetHeight;
	
	//alert(obj.offsetParent.offsetLeft)
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		curwidth = obj.offsetWidth;
		curheight = obj.offsetHeight;
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	//top, right, bottom, left, width, height
	return [curtop, (curleft+curwidth), (curtop+curheight), curleft, curwidth, curheight];
}

function windowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight]
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

function setProfileImage()
{
	pro = document.getElementById("profil");
	flashImage = document.getElementById("flashProfilImage");
	profilSize = findPos(pro)
	flashImage.style.left = (profilSize[3]-50)+"px"
	
	if(window.onresize==null || window.onresize.toString().indexOf("setProfileImage")==-1)
		window.onresize = setProfileImage
}

function showSelectTags()
{
	arr = document.getElementsByTagName("select");
	for(i=0; i<arr.length;i++)
		arr[i].style.visibility = "visible";
}

function hideSelectTags()
{
	arr = document.getElementsByTagName("select");
	for(i=0; i<arr.length;i++)
		arr[i].style.visibility = "hidden";
	
}

function show(index)
{
	arrLi = new Array ('forumsLi', 'groupLi', 'bilderLi', 'termineTabLi', 'freundeLi');
	arrCont = new Array ('containerForum', 'containerGroup', 'containerBilder', 'containerTermineTab', 'containerInvites');
	
	
	for(i=0; i<arrLi.length; i++)
	{
		if(i==index)
		{
			o = document.getElementById(arrLi[i])
			o.className = arrLi[i].replace("Li", "")+"Active";
			document.getElementById(arrCont[i]).style.display = "block";
			
		}
		else
		{
			o = document.getElementById(arrLi[i])
			if(o)
			{
				o.className = arrLi[i].replace("Li", "");
				document.getElementById(arrCont[i]).style.display = "none";
			}
		}
	}
}

function showMy(objIds)
{
	for(i=1; i<showMy.arguments.length;i++)
	{
		obj0 = document.getElementById(showMy.arguments[i]+"Li");
		obj0c = document.getElementById(showMy.arguments[i]+"Content");
		obj0.className = obj0.className.replace("Active", "")
		obj0c.style.display = "none";
	}
	//first argument shows div
	obj0 = document.getElementById(showMy.arguments[0]+"Li");
	obj0c = document.getElementById(showMy.arguments[0]+"Content");
	
	obj0.className = obj0.className.replace("Active", "")+"Active"
	obj0c.style.display = "block";
}

function showDiv(showObjId, hideObjId)
{
	document.getElementById(showObjId).style.display="block";
	document.getElementById(hideObjId).style.display="none";
}

function setGroupName(objId, destObjId)
{
	val = "Gruppenname";
	valObj = document.getElementById(objId)
	if(valObj && valObj.value.length>0)
		val = valObj.value
	
	destObj = document.getElementById(destObjId)
	
	if(destObj)
	{
		arr = destObj.getElementsByTagName("h1");
		for(i=0; i<arr.length;i++)
			arr[i].innerHTML = val; 
	}
}

function fixPng(destObjId)
{
	if (navigator.userAgent.indexOf("MSIE") >-1 && getBrowserVersion() <= 6)
	{
		destObj = document.getElementById(destObjId)
		if(destObj)
		{
			arr = destObj.getElementsByTagName("div");
			for(i=0; i<arr.length;i++) {
				if(arr[i].style.backgroundImage.indexOf(".png") > 0 )
					fixMe(arr[i])
			}
		}
	}
}

function correctInlinePNG()
{
	if (navigator.userAgent.indexOf("MSIE") >-1 && getBrowserVersion() <= 6) 
	{ 
		arr = document.getElementsByTagName("img");
		for(i=0; i<arr.length;i++) 
			if(arr[i].src.indexOf(".png") > 0 )
				correctPNG(arr[i]);
	}
}

function correctPNG(myImage) // correctly handle PNG transparency in Win IE 5.5 & 6.
{
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
		var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
		var imgStyle = "display:inline-block;" + myImage.style.cssText 
		if (myImage.align == "left") imgStyle = "float:left;" + imgStyle
		if (myImage.align == "right") imgStyle = "float:right;" + imgStyle
		if (myImage.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>" 
		myImage.outerHTML = strNewHTML
}


function fixMe(obj)
{
	if(obj)
	{
		src = obj.style.backgroundImage.replace("url(", "").replace(")", "");
		obj.style.backgroundImage = "url(/bummbumm/img/leer)";
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='crop', src='" + src + "')";
	}
}

function setImage(obj, src)
{
	obj.onload=null;
	if (navigator.userAgent.indexOf("MSIE") >-1 && getBrowserVersion() <= 6)
	{
		obj.src = "/bummbumm/img/leer.gif";
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='" + src + "')";
	}
	else
		obj.src = src;
}

function getBrowserVersion()
{
	//test for MSIE x.x;
	var myReg = /MSIE (\d+\.\d+);/
	if ( myReg.test(navigator.userAgent) )
		return new Number(RegExp.$1);
	else
		return -1;
	
}

function setPreviewImage(objAuswahlId, objBearbId, src)
{
	objA = document.getElementById(objAuswahlId)
	objB = document.getElementById(objBearbId)
	objA.style.display = "none";
	objB.style.display = "block";
	
	arr = objB.getElementsByTagName("img");
	setImage(arr[0], src);
}

function setHeader(objId, val)
{
	valObj = document.getElementById(objId)
	if(valObj)
		valObj.value = val;
}

function checkLength(obj, zCount)
{
	if(obj.value.length>150)
	{
		obj.value = obj.value.substring(0,150);
	}
	objSpan = document.getElementById(zCount);
	objSpan.innerHTML = 150-obj.value.length;
	

}

function setOnLoad(val)
{
	var sTemp = "";
	if(window.onload != null) {
      sTemp = window.onload.toString();
      iStart = sTemp.indexOf("{") + 2;
      sTemp = sTemp.substr(iStart,sTemp.length-iStart-2);
      
      
    }
    if (sTemp.indexOf(val) == -1)
    {
      window.onload = new Function(val + sTemp);
    }
}

function setParentTitle(self, objId)
{
	obj = document.getElementById(objId)
	self.parentNode.longDesc = obj.innerHTML;
}
