/*
PW Security gives a test rating how secure your password appears.

*/

function PWSecurity(password)
{
	var points = 0;							// total points
	var j = 0								// counter (points)
	var n = '0123456789'					// numbers
	var a = 'abcdefghijklmnopqrstuvwxyz'	// alpha letters
	var u = 0								// upper case count
	var l = 0								// lower case count
	var an = a + n + a.toUpperCase()		// alpha numeric
	
	// Length of password - 8 characters recomended
	points = points + (password.length * 2.5)
	if(points > 20){points = 20}

	// Amount of Numbers - 2 recomended, 3 prefered
	j = 0
	for(var i = 0;i<password.length;i++)
		{if(n.indexOf(password.substring(i,i+1))!=-1){j+=6.67}}
	if(j>20){j=20}
	points += j

	// Non-Repeating characters - 8 recomended
	j = 0
	for(var i=0;i<password.length-1;i++)
		{if(password.substring(i,i+1) != password.substring(i+1, i+2)){j+= 2.86}}
	if(j>20){j=20}
	points += j

	// Pairs of mixed-case - 2 recomended
	for(var i=0;i<password.length;i++)
	{
		if(a.indexOf(password.substring(i, i+1)) != -1){l++}
		if(a.toUpperCase().indexOf(password.substring(i, i+1)) != -1){u++}
	}
	if(u>l){j=l*10}else{j=u*10}
	if(j>20){j=20}
	points += j

	// non-alpha-numeric characters - 2 recomended
	j = 0
	for(var i = 0;i<password.length;i++)
		{if(j < 20){if(an.indexOf(password.substring(i,i+1)) == -1){j+=10}}}
	if(j>20){j=20}
	points += j

	return(points)
}
/*
make sureyou would like to submit a form

*/
function confirmSubmit()
	{
		var agree=confirm("This action can not be undone. Are you sure you want to continue?");
		if (agree)
			return true ;
		else
			return false ;
	}
	/*
check all check boxes in a form.

*/
	function CheckAll(formObject) 
	{
		var chk = formObject.checkAll.checked;
		var len = formObject.elements.length;
		for(var i=0; len >i; i++) 
		{
			var elm = formObject.elements[i];
			if (elm.type == "checkbox")
			{
				elm.checked = chk;
			}
		}
	}
		/*
open a new window

*/
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

		/*
sync up cute edtor in firefox

*/

function synceditor(ClientID,formfield,formname){
	var theForm = document.forms[formname];
	var editor1 = document.getElementById(ClientID);
	var content = editor1.getHTML();
	theForm[formfield].value = content;
}

/*
write cookie

*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
/*
read cookie

*/
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/*
erase cookie

*/
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*
Show menu for admin

*/
function showmenu(thename){
	var doc = document.getElementsByTagName('li');
	var thesting = '';
	for (var i = 0; i < doc.length; i++){
		thestring = doc[i].id;
		indexofthestring = thestring.indexOf(thename);
		if (indexofthestring > -1 ){
			document.getElementById(thestring).style.display='';
		}else {
			if (thestring != ''){
				document.getElementById(thestring).style.display='none';
			}
		}
	
	}	
}

/*
Show last clicked menu for admin

*/
function checkmenu(){
	var lastmenu = readCookie('lastmenue');
	if (lastmenu != ''){
		showmenu(lastmenu);
	}
}

function btnRollIcon(curCell, state){
	if(state == "ON"){
		curCell.className = "ccmIconBtnOn";
	}else{
		curCell.className = "ccmIconBtn";
	}
}
