var nCrackrate = 1000;
var nTreshholddays = 365 * 10;
var nSteps = 10;

function contains(strText, strPattern)
{
	for (i = 0; i < strText.length; i++)
	{
		if (strPattern.indexOf(strText.charAt(i)) > -1) return true;
	}
	return false;
}

function checkPass(strPass, strId, strClassname, strTextId, aTexts)
{
	nCombinationCount = 0;
	
	strToCheck = "0123456789";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	strToCheck = "abcdefghijklmnopqrstuvwxyz";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	strToCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;
	strToCheck = ",;:-_=+\|//?^&!.@$Â£#*()%~<>{}[]";
	if (contains(strPass, strToCheck)) nCombinationCount += strToCheck.length;

	var nDays = ((Math.pow(nCombinationCount, strPass.length) / nCrackrate) / 2) / 86400;
	var nStrongness = Math.round(nDays / nTreshholddays * 100);
	if (nStrongness < (strPass.length * 5)) nStrongness += strPass.length * 5;
	if (nStrongness > 100) nStrongness = 100;
	nStrongness = Math.round(nStrongness / (100 / nSteps));

	if(document.getElementById(strId))
	{
		oId = document.getElementById(strId);
		oId.className = strClassname + "-" + nStrongness;
	}
	
	otId = document.getElementById(strTextId);
	
	if (aTexts)
	{
		nKey = Math.round((aTexts.length - 1) / nSteps * nStrongness);
		otId.innerHTML = aTexts[nKey];
	}
}

function set_zip(value)
{
	var country = new Array();
	
	country['DE'] = 5;
	country['FR'] = 5;
	country['AT'] = 4;
	country['CH'] = 4;
	country['CN'] = 6;
	
	if(country[value])
	{
		document.getElementById('zip_code').value = '';
		document.getElementById('zip_code').maxLength = country[value];
	}
	else
	{
		document.getElementById('zip_code').value = '';
		document.getElementById('zip_code').maxLength = 5;
	}
}

function check_advert()
{
	var	element = document.getElementById('advert');
	if(element.value==-1)
	{
		if(document.all)
		{
			document.getElementById('advert_by').style.display = 'block';	
			document.getElementById('advert_city').style.display = 'block';	
		}
		else
		{
			document.getElementById('advert_by').style.display = 'table-row';	
			document.getElementById('advert_city').style.display = 'table-row';	
		}
	}
	else
	{
		document.getElementById('advert_by').style.display = 'none';	
		document.getElementById('advert_city').style.display = 'none';	
	}
}

function load_username()
{
	window.setTimeout("set_username()", 10);
}

function set_username()
{
	var firstname = document.getElementById('firstname').value;
	var lastname = document.getElementById('lastname').value;
	
	if(firstname != '' && lastname != '')
	{
		firstname = firstname+'_';
	}
	var newuser = firstname+lastname;
	
	document.getElementById('new_user').value = newuser;
}

function load_dom_name()
{
	window.setTimeout("set_dom_name()", 10);
}

var url_always_started = false;

function set_dom_name()
{
	//var string = document.getElementById('page_name').value;
	var string = document.getElementById('firstname').value;
	string = string+' '+document.getElementById('lastname').value;
	
	var allowed_chars = new Array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 
								  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
								  '-');
	string = string.replace('Ä', 'ae');
	string = string.replace('Ö', 'oe');
	string = string.replace('Ü', 'ue');
	string = string.replace('ä', 'ae');
	string = string.replace('ö', 'oe');
	string = string.replace('ü', 'ue');
	string = string.replace('ß', 'ss');
	
	var newstring = '';
	var last_char = false;
	
	for(var i = 0; i < string.length; i++)
	{
		if(in_array(string[i], allowed_chars))
		{
			newstring = newstring + string[i];			   
			last_char = false;
		}
		
		if(string[i] == ' ' && last_char === false)
		{
			last_char = true;
			newstring = newstring + '-';	
		}
	}
	
	if(newstring.length > 0)
	{
		if(newstring[0] == '-')
		{
			newstring = substr(newstring, 1);
		}
		
		if(newstring[(newstring.length-1)] == '-')
		{
			newstring = substr(newstring, 0, -1);
		}
	}
	
	var url_value = document.getElementById('url_part').value;
	url_value = trim(url_value);
	
	if(url_value == '' || url_always_started === true)
	{
		document.getElementById('url_part').value = newstring.toLowerCase();
		url_always_started = true;
	}
	
}

function in_array(needle, array)
{
	for(var i = 0; i < array.length; i++)
	{
		if(array[i] == needle)
		{
			return true;
		}
	}
	
	return false;
}

function check_shopusage(obj)
{
	if(obj.value == '-1')
	{
		document.getElementById('shopusage_dsp').style.display = display;
	}
	else
	{
		document.getElementById('shopusage_dsp').style.display = 'none';
	}
}
