Window.resizeEffectDuration = 0.1;

getBaseUrl();

BaseLang = {}
BaseLang.pConfirm_Ok = 'Ok';
BaseLang.pConfirm_Cancel = 'Cancel';

function getBaseUrl(type)
{
	type = type || 'baseRootUrl';

	if ('undefined' == typeof window['baseUrl'])
	{
		var bases = document.getElementsByTagName('base');
		var base;
		if (0 < bases.length)
		{
			base = bases[bases.length - 1].href;
		}
		else
		{
			base = document.location.href
		}
		window['baseRootUrl'] = window['baseUrl'] = base.substr(0, base.lastIndexOf('/') + 1);

		var k = 0, s = 0;

		while (0 < (s = base.indexOf('/', s) + 1) && 2 > k++);

		if (0 < s && 3 == k)
		{
			window['baseRootUrl'] = base.substr(0, s);
		}

		var links = document.getElementsByTagName('link');

		for (k = 0; k < links.length; k++)
		{
			if ('start' == links[k].rel)
			{
				window['appRootUrl'] = links[k].href;
			}
			else if ('section' == links[k].rel)
			{
				window['appParentUrl'] = links[k].href;
			}
		}
	}

	return window[type];
}

function pAlert(msg, params, retDlg)
{
	var dlg = Dialog.alert(msg, Object.extend({
		width: 250, height: null, className: 'popup'
	}, ('object' == typeof params) ? params : {}));

	return retDlg ? dlg : false;
}

function pConfirm(msg, onOk, onCancel, params)
{
	var clbkOk = null, clbkCancel = null;

	if ('object' == typeof onOk  && 'undefiend' != typeof onOk.href)
	{
		if (!onOk.href.empty() && ('#' != onOk.href))
		{
			onOk = function() {
				document.location.href = onOk.href;
			}
		}
	}

	if ('function' == typeof onOk)
	{
		clbkOk = function() {
			Dialog.closeInfo();
			onOk.delay(0.3);
		}
	}

	if ('function' == typeof onCancel)
	{
		clbkCancel = function() {
			Dialog.closeInfo();
			onCancel.delay(0.3);
		}
	}

	Dialog.confirm(msg, Object.extend({
		width: 250,
		height: 'auto',
		className: 'popup',
		onOk: clbkOk,
		onCancel: clbkCancel,
		okLabel: BaseLang.pConfirm_Ok,
		cancelLabel: BaseLang.pConfirm_Cancel
	}, ('object' == typeof params) ? params : {}));

	return false;
}

String.prototype.sprintf = function () {
	var fstring = this.toString();

	var pad = function(str,ch,len) { var ps='';
			for(var i=0; i<Math.abs(len); i++) {
			ps+=ch;
		}
			return len>0?str+ps:ps+str;
	};
	var processFlags = function(flags,width,rs,arg) {
			var pn = function(flags,arg,rs) {
					if(arg>=0) {
							if(flags.indexOf(' ')>=0) {
					rs = ' ' + rs;
				} else if(flags.indexOf('+')>=0) {
					rs = '+' + rs;
				}
					} else {
							rs = '-' + rs;
			}
					return rs;
			};
			var iWidth = parseInt(width,10);
			if(width.charAt(0) == '0') {
					var ec=0;
					if(flags.indexOf(' ')>=0 || flags.indexOf('+')>=0) {
				ec++;
			}
					if(rs.length<(iWidth-ec)) {
				rs = pad(rs,'0',rs.length-(iWidth-ec));
			}
					return pn(flags,arg,rs);
			}
			rs = pn(flags,arg,rs);
			if(rs.length<iWidth) {
					if(flags.indexOf('-')<0) {
				rs = pad(rs,' ',rs.length-iWidth);
			} else {
				rs = pad(rs,' ',iWidth - rs.length);
			}
			}
			return rs;
	};
	var converters = [];
	converters.c = function(flags,width,precision,arg) {
			if (typeof(arg) == 'number') {
			return String.fromCharCode(arg);
		} else if (typeof(arg) == 'string') {
			return arg.charAt(0);
		} else {
			return '';
		}
	};
	converters.d = function(flags,width,precision,arg) {
			return converters.i(flags,width,precision,arg);
	};
	converters.u = function(flags,width,precision,arg) {
			return converters.i(flags,width,precision,Math.abs(arg));
	};
	converters.i =  function(flags,width,precision,arg) {
			var iPrecision=parseInt(precision, 10);
			var rs = ((Math.abs(arg)).toString().split('.'))[0];
			if(rs.length<iPrecision) {
			rs=pad(rs,' ',iPrecision - rs.length);
		}
			return processFlags(flags,width,rs,arg);
	};
	converters.E = function(flags,width,precision,arg) {
			return (converters.e(flags,width,precision,arg)).toUpperCase();
	};
	converters.e = function(flags,width,precision,arg) {
			iPrecision = parseInt(precision, 10);
			if(isNaN(iPrecision)) {
			iPrecision = 6;
		}
			rs = (Math.abs(arg)).toExponential(iPrecision);
			if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) {
			rs = rs.replace(/^(.*)(e.*)$/,'$1.$2');
		}
			return processFlags(flags,width,rs,arg);
	};
	converters.f = function(flags,width,precision,arg) {
			iPrecision = parseInt(precision, 10);
			if(isNaN(iPrecision)) {
			iPrecision = 6;
		}
			rs = (Math.abs(arg)).toFixed(iPrecision);
			if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) {
			rs = rs + '.';
		}
			return processFlags(flags,width,rs,arg);
	};
	converters.G = function(flags,width,precision,arg) {
			return (converters.g(flags,width,precision,arg)).toUpperCase();
	};
	converters.g = function(flags,width,precision,arg) {
			iPrecision = parseInt(precision, 10);
			absArg = Math.abs(arg);
			rse = absArg.toExponential();
			rsf = absArg.toFixed(6);
			if(!isNaN(iPrecision)) {
					rsep = absArg.toExponential(iPrecision);
					rse = rsep.length < rse.length ? rsep : rse;
					rsfp = absArg.toFixed(iPrecision);
					rsf = rsfp.length < rsf.length ? rsfp : rsf;
			}
			if(rse.indexOf('.')<0 && flags.indexOf('#')>=0) {
			rse = rse.replace(/^(.*)(e.*)$/,'$1.$2');
		}
			if(rsf.indexOf('.')<0 && flags.indexOf('#')>=0) {
			rsf = rsf + '.';
		}
			rs = rse.length<rsf.length ? rse : rsf;
			return processFlags(flags,width,rs,arg);
	};
	converters.o = function(flags,width,precision,arg) {
			var iPrecision=parseInt(precision, 10);
			var rs = Math.round(Math.abs(arg)).toString(8);
			if(rs.length<iPrecision) {
			rs=pad(rs,' ',iPrecision - rs.length);
		}
			if(flags.indexOf('#')>=0) {
			rs='0'+rs;
		}
			return processFlags(flags,width,rs,arg);
	};
	converters.X = function(flags,width,precision,arg) {
			return (converters.x(flags,width,precision,arg)).toUpperCase();
	};
	converters.x = function(flags,width,precision,arg) {
			var iPrecision=parseInt(precision, 10);
			arg = Math.abs(arg);
			var rs = Math.round(arg).toString(16);
			if(rs.length<iPrecision) {
			rs=pad(rs,' ',iPrecision - rs.length);
		}
			if(flags.indexOf('#')>=0) {
			rs='0x'+rs;
		}
			return processFlags(flags,width,rs,arg);
	};
	converters.s = function(flags,width,precision,arg) {
			var iPrecision=parseInt(precision, 10);
			var rs = arg;
			if(rs.length > iPrecision) {
			rs = rs.substring(0,iPrecision);
		}
			return processFlags(flags,width,rs,0);
	};

	farr = fstring.split('%');
	retstr = farr[0];
	fpRE = /^([-+ #]*)(?:(\d*)\$|)(\d*)\.?(\d*)([cdieEfFgGosuxX])(.*)$/;
	for(var i = 1; i<farr.length; i++) {
			fps=fpRE.exec(farr[i]);
			if(!fps) {
			continue;
		}
		var my_i = fps[2] ? fps[2] : i;
			if(arguments[my_i-1] || !isNaN(arguments[my_i-1]) ) {
					retstr+=converters[fps[5]](fps[1],fps[3],fps[4],arguments[my_i-1]);
			}
			retstr += fps[6];
	}
	return retstr;
};

if('undefined' != typeof window['Prototype'])
{
	Prototype.ScriptFragment = '<script.*?>((\n|\r|.)*?)(?:<\/script>)';
}

if('undefined' != typeof window['Hash'])
{
	Hash.toQueryString.addPair = function(key, value, prefix) {
	  key = encodeURIComponent(key);
	  if (value === undefined) this.push(key);
	  else this.push(key + '=' + (value == null ? '' : escape(value)));
	};
}

String.prototype.extractScripts =  function() {
		var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
		var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
		return (this.match(matchAll) || []).map(function(scriptTag) {
			return (scriptTag.match(matchOne) || ['', ''])[0];
		});
};

evalGlobally = function(script)
{
	var ret;
	script = script.replace(/(^\s+)|(<!--)/gim, "");
	script = script.replace(/(\/\/-->)|(\s+$)/gim, "");

	if (!script.blank())
	{
		//try
		{
			ret = (
				window.execScript ? window.execScript(script) : (
					Prototype.Browser.WebKit ? setTimeout(script, 0) : eval.apply(window, [script])
				)
			);
		}
		//catch(e)
		{
		}
	}
	return ret;
};

normalizeUrl = function(url)
{
	if (!url.match(/^http(s)?:\/\//i))
	{
		if ('/' == url.charAt(0))
		{
			url = window['baseRootUrl'] + url.substr(1);
		}
		else
		{
			url = window['baseRoot'] + url.substr(1);
		}
	}
	return url;
}

String.prototype.stripScripts =  function() {
	if (Prototype.Browser.WebKit)
	{
		return this;
	}

	return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
};

window['loadedScripts'] = {};

Event.observe(window, 'load', function() {
		var scripts = document.getElementsByTagName('script');

		for (var i = 0; i < scripts.length; i++)
		{
			var src = new String(scripts[i].src);

			if (!src.blank())
			{
				window['loadedScripts'][normalizeUrl(src)] = true;
			}
		}
	}
);

String.prototype.evalScripts = function()
{
 	if (Prototype.Browser.WebKit)
	{
		var div = document.createElement('DIV');
		div.innerHTML = this;
		var scripts = div.getElementsByTagName('SCRIPT');

		for (var i = 0; i < scripts.length; i++)
		{
			if (!scripts[i].src.blank())
			{
				var src = normalizeUrl(scripts[i].src);

				if ('undefined' == typeof(window['loadedScripts'][src]))
				{
					window['loadedScripts'][src] = true;
					new Ajax.Request(src, {method: 'get', asynchronous: false, evalJS: false, onFailure: function(){alert('@');}, onSuccess: function(t){evalGlobally(t.responseText);}});
				}
			}
			else if (!scripts[i].innerHTML.blank())
			{
				if (window.extractExternalScript)
				{
					if (!window.internalScript)
					{
						window.internalScript = new String();
					}

					window.internalScript += scripts[i].innerHTML;
				}
				else
				{
					evalGlobally(scripts[i].innerHTML);
				}
			}
		}
		delete div;
		return;
	}


    return this.extractScripts().map(function(script) {
	    var match_src = new RegExp('<script.*?src="([^"].*?)"', 'im');
		var arr = [];

		if (arr = script.match(match_src))
		{
			if (!arr[1].blank())
			{
				var src = normalizeUrl(arr[1]);

				if ('undefined' == typeof(window['loadedScripts'][src]))
				{
					window['loadedScripts'][src] = true;
					new Ajax.Request(src, {method: 'get', evalJS: false, asynchronous: false, onFailure: function(){alert('@');}, onSuccess: function(t){evalGlobally(t.responseText);}});
				}
			}
		}
		else
		{
		    var match_all = new RegExp('<script.*?>((\n|\r|.)*?)</script>', 'im');

    		if (arr = script.match(match_all))
    		{
				if (!arr[1].blank())
				{
					if (window.extractExternalScript)
					{
						if (!window.internalScript)
						{
							window.internalScript = new String();
						}

						window.internalScript += arr[1];
					}
					else
					{
						evalGlobally(arr[1]);
					}
				}
    		}
		}
	});
};

function ProtoWndCreate(id, url, width, height, location)
{
	var location = location ? location : false, showCentred = location ? false : true;

	url += (-1 == url.indexOf('?')) ? '?pwnd=1' : '&pwnd=1';

	if ((wnd_js = Windows.getWindow(id)) != undefined)
	{
		if (width && height)
		{
			wnd_js.setSize(width, height);
		}

		if (!width || !height)
		{
			var size = wnd_js.getSize();
			width = width || size.width;
			height = height || size.height;
		}

		wnd_js.setHTMLContent('<div class="bigWaiting" style="width: ' + width + 'px; height: ' + height + 'px;"></div>');

		wnd_js.setAjaxContent(url,{method: 'get'});

		if (true == showCentred)
		{
			wnd_js.showCenter();
		}
		else
		{
			wnd_js.toFront();
		}
	}
	else
	{
		var wnd_js = new Window(id, {
		 	className:		"popup",
		 	width:			width,
		 	height:			height,
		 	resizable: 		false,
		 	title:			null,
		 	draggable:		true,
		 	closable:		true,
			minimizable:	false,
			maximizable:	false,
			destroyOnClose: true,
			recenterAuto: false
		});

		wnd_js.setHTMLContent('<div class="bigWaiting" style="width: ' + width + 'px; height: ' + height + 'px;"></div>');

		if (0 || true == showCentred)
		{
			wnd_js.showCenter(false);
		}
		else
		{
			wnd_js.show(false);
		}

		wnd_js.setAjaxContent(url,{method: 'get'}, showCentred);

		if (location)
		{
			wnd_js.setLocation(location['top'],location['left']);
		}
	}
}

function ProtoWndDestroy(id)
{
	Windows.close(id);

	/*if (Windows.getWindow(id))
	{
		Windows.getWindow(id).destroy();
	}*/
}

function ProtoWndResize(id, width, heigth, url,location)
{
	if ((wnd_js = Windows.getWindow(id)) == undefined)
	{
		return;
	}

	var url = url?url:false;
	var location = location?location:false;

	if (url)
	{
		wnd_js.setAjaxContent(url,{method: 'get'},false);
	}

	if (location)
	{
		wnd_js.setLocation(location['top'],location['left']);
	}

	wnd_js.setSize(width,heigth);
}

function ProtoWndReloadParent(id, prerequest_url)
{
	prerequest_url = prerequest_url ? prerequest_url : false;

	var href = document.location.href;

	if ('undefined' != typeof(wnd_js = Windows.getWindow(id)))
	{
		ProtoWndStoreAll();
	}
	else
	{
		prerequest_url = false;
	}

	if (prerequest_url)
	{
		new Ajax.Request(prerequest_url,{method: 'get',onComplete: function() { window.location.href = (href.charAt(href.length-1) == '#')?href.substr(0,href.length-1):href; }});
	}
	else
	{
		window.location.href = (href.charAt(href.length-1) == '#') ? href.substr(0,href.length-1) : href;
	}
}

function ProtoWndStoreAll(){
	var cData = '';

	for (var i = 0; i < Windows.windows.length; i++)
	{
		var id		= Windows.windows[i].getId();
		var url 	= Windows.windows[i].url;
		var loc 	= Windows.windows[i].getLocation();
		var size 	= Windows.windows[i].getSize();

		cData = cData + id + ';'  + url + ';' + loc['left'] + ';' +  loc['top'] + ';' + size['width'] + ';' + size['height'] + ';';
	}

	var exp = new Date();
	exp.setTime(exp.getTime() + (60*1000));

	setCookie('protownd_store', cData, exp, '/');
}

function ProtoWndRestoreAll(){
	var cData = getCookie('protownd_store');
	deleteCookie('protownd_store','/');

	if (cData)
	{
		var wndData = {0:[],1:[],2:[],3:[],4:[],5:[]};

		var curr = 0;
		var next = 0;
		var i = 0;
		var j = 0;

		while((next = cData.indexOf(';',curr)) != -1)
		{
			wndData[i++].push(cData.substr(curr,next-curr));
			if ((i) == 6) i = 0;
			curr = next + 1;
		}

		for (i = 0; i < wndData[0].length; i++)
		{
			var id		= wndData[0][i];
			var url		= wndData[1][i];
			var left	= wndData[2][i];
			var top		= wndData[3][i];
			var width	= wndData[4][i];
			var height	= wndData[5][i];

			top = top.substr(0,top.length-2);
			left = left.substr(0,left.length-2);

			ProtoWndCreate(id,url,width,height,{'top':top,'left':left});
			//ProtoWndResize(id,width,height,url,{'top':top,'left':left});
		}
	}
}

function ProtoWndSubmitForm(id, form, onSuccess, submit_btn)
{
	submit_btn = submit_btn?submit_btn:false;
	var postData = '';
	for (var i = 0; i < form.elements.length; i++)
	{
		var v = form.elements[i].value;
		v = escape(v);
		if ((form.elements[i].type != 'radio') && (form.elements[i].type != 'checkbox'))
		{
			postData = postData + form.elements[i].name + "=" + v + "&";
		}
		else
		{
			if (form.elements[i].checked)
			{
				postData = postData + form.elements[i].name + "=" + v + "&";
			}
		}
	}
	valFunc = form.name + '_gfieldsCheck';

	if (submit_btn !== false)
	{
		postData = postData + '_ia=' + submit_btn;
	}

	if (form.action == '')
	{
		url = Windows.getWindow(id).url;
	}
	else
	{
		url = form.action;
	}

	onSuccess = onSuccess ? onSuccess : null;

	var subm = false;
	var submFunc = form.onsubmit;
	if (window[valFunc])
	{
		if (window[valFunc](form))
		{
			if (submFunc)
			{
				submFunc();
			}
			subm = true;
		}
	}
	else
	{
		if (submFunc)
		{
			submFunc();
		}
		subm = true;
	}
	if (subm)
	{
		var w = Windows.getWindow(id);
		w.setHTMLContent('<div class="bigWaiting" style="width: ' + w.width + 'px; height: ' + w.height + 'px;"></div>');
		w.setAjaxContent(url, {method: 'post',postBody: postData, onSuccess: onSuccess});
	}
}

function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")

	if ((name + "=" + escape(value)).length <= 4000)
	{
		document.cookie = curCookie;
	}
}

function getCookie(name)
{
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name+"="+
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}

function popup(element, width, height, additional)
{
	additional = additional ? additional : {};

	if (element)
	{
		switch (element.tagName)
		{
			case 'A':
				ProtoWndCreate('popup', element.href, width ? width : 600, height ? height : 400);
				break;
			case 'IMG':
				var img, wnd = ProtoWndOpen(
					'popup', (parseInt(width ? width : element.width) + 2), (parseInt(height ? height : element.height) + 2), null, {}
				);

				if (element.title || element.alt)
				{
					wnd.setTitle(element.title ? element.title : element.alt);
				}

				wnd.setContent(
					(img = new Element('img', {
						src : additional['src'] ? additional['src'] : element.src,
						width : width,
						height : height
					})).setStyle({visibility: 'hidden'})
				);

				img.startWaiting('bigWaiting');
				img.observe('load', function(img) {
					img.setStyle({visibility: 'visible'});
					img.stopWaiting();
				}.curry(img));
				break;
			default:
				var wnd = ProtoWndOpen(
					'popup', (parseInt(width ? width : 100) + 2), (parseInt(height ? height : 100) + 2), null, {}
				);

				if (additional.title)
				{
					wnd.setTitle(additional.title);
				}

				wnd.setContent($(element.cloneNode(true)).removeClassName('x-hidden'));

				break;
		}
	}

	return false;
}

function ProtoWndOpen(id, width, height, location, parameters)
{
	var location = location ? location : false;

	if (wnd_js = Windows.getWindow(id))
	{
		if (width || height)
		{
			wnd_js.setSize(width, height);
		}

		if (!width || !height)
		{
			var size = wnd_js.getSize();
			width = width || size.width;
			height = height || size.height;
		}

		wnd_js.setHTMLContent('<div style="padding-top:' + (height/2 - 8) + 'px;text-align:center;"><img src="' + getBaseUrl('appRootUrl') + 'images/progress.gif" width="16" heigth="16" /></div>');
		wnd_js.toFront();
	}
	else
	{
		var wnd_js = new Window(id, {
			className:		"popup",
			width:			width,
			height:			height,
			resizable: 		true,
			title:			null,
			draggable:		true,
			closable:		true,
			minimizable:	false,
			maximizable:	false,
			destroyOnClose: true
		});

		showCentred = location ? false : true;

		var contentPWO = '<div style="padding-top:' + (height/2 - 8) + 'px;text-align:center;"><img style="padding-bottom: 12px;" src="' + getBaseUrl('appRootUrl') + 'images/progress.gif" width="16" heigth="16"></div>';
		if (parameters.cancel)
		{
		   var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'";
	       parameters.className = parameters.className ? parameters.className : '';

	       var contentAdd = "\
	    	<div class='" + parameters.className + "_buttons'>\
	          <input type='button' value='" + parameters.title + "' onclick='" + parameters.cancel + "();' " + cancelButtonClass + "/>\
	        </div>";
			wnd_js.setHTMLContent(contentPWO + contentAdd);
		}
		else
		{
			wnd_js.setHTMLContent(contentPWO);
		}

		if (true == showCentred)
		{
			wnd_js.showCenter(parameters.modal);
		}
		else
		{
			wnd_js.show(parameters.modal);
		}

		//wnd_js.setAjaxContent(url,{method: 'get'}, showCentred);

		if (location)
		{
			wnd_js.setLocation(location['top'],location['left']);
		}
	}

	return wnd_js;
}

/*
function verifyPasswordStrength(passwd)
{
	var intLevel = 0;
	var intLen = passwd.length;

	// regular expressions
	var lc = /^([a-z]*)$/; //lowercase letters
	var uc = /^([A-Z]*)$/; //uppercase letters
	var sc = /^([!@#$%^&*?.,_+]*)$/; //special symbols
	var uclc = /^([A-Za-z]*)$/; //upper & lower case letters
	var nm = /^([0-9]*)$/; //numbers
	var lcnm = /^([a-z0-9]*)$/; //lower-case letters and numbers
	var ucnm = /^([A-Z0-9]*)$/; //upper-case letters and numbers
	var uclcnm = /^([A-Za-z0-9]*)$/; //upper- and lower-case letters and numbers

	if (0 == intLen)
	{
		return 0;
	}

	if (passwd.match(nm))
	{
		if (intLen < 6)
		{
			intLevel = 1;
		}
		else if (intLen > 5 && intLen < 8)
		{
			intLevel = 2;
		}
		else {
			intLevel = 3;
		}
	}
	else if (passwd.match(lc))
	{
		if (intLen < 6)
		{
			intLevel = 1;
		}
		else if (intLen > 5 && intLen < 8)
		{
			intLevel = 2;
		}
		else {
			intLevel = 3;
		}
	}
	else if (passwd.match(uclc))
	{
		if (intLen < 6)
		{
			intLevel = 1;
		}
		else if (intLen > 5 && intLen < 8)
		{
			intLevel = 3;
		}
		else {
			intLevel = 3;
		}
	}
	else if (passwd.match(lcnm))
	{
		if (intLen < 6)
		{
			intLevel = 2;
		}
		else if (intLen > 5 && intLen < 8)
		{
			intLevel = 3;
		}
		else {
			intLevel = 4;
		}
	}
	else if (passwd.match(ucnm))
	{
		if (intLen < 6)
		{
			intLevel = 2;
		}
		else if (intLen > 5 && intLen < 8)
		{
			intLevel = 4;
		}
		else {
			intLevel = 5;
		}
	}
	else if (passwd.match(uclcnm))
	{
		if (intLen < 6)
		{
			intLevel = 3;
		}
		else if (intLen > 5 && intLen < 8)
		{
			intLevel = 5;
		}
		else {
			intLevel = 6;
		}
	}

	return intLevel;
}
*/
function verifyPasswordStrength(password,username)
{
    score = 0

    //password < 4
    if (password.length < 4 ) { return 0 }

    //password == username
    if (password.toLowerCase()==username.toLowerCase()) return 0

    //password length
    score += password.length * 4
    score += ( checkRepetition(1,password).length - password.length ) * 1
    score += ( checkRepetition(2,password).length - password.length ) * 1
    score += ( checkRepetition(3,password).length - password.length ) * 1
    score += ( checkRepetition(4,password).length - password.length ) * 1

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5

    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5

    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10

    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15

    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15

    //password is just a nubers or chars
    if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10
    if (score > 100) return 100
  return (score)

}

// checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
// checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
// checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'

function checkRepetition(pLen,str) {
    res = ""
    for ( i=0; i<str.length ; i++ ) {
        repeated=true
        for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
            repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
        if (j<pLen) repeated=false
        if (repeated) {
            i+=pLen-1
            repeated=false
        }
        else {
            res+=str.charAt(i)
        }
    }
    return res
}

function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte
    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}

    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};

    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';

    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }

    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }

    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';


    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }

    return hash_map;
}

function htmlspecialchars (string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nathan
    // +   bugfixed by: Arno
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // -    depends on: get_html_translation_table
    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'

    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();

    if (false === (hash_map = this.get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
        return false;
    }

    hash_map["'"] = '&#039;';
    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }

    return tmp_str;
}

Event.onReady(function() {
	window['ProtoWndRestoreAll']();
});