getBaseUrl();

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)
{
/*
	var p = $H({
		width: 200,
		height: 100,
		className: 'ma',
		buttonClass: 'buttons',
		options: {}
	}).merge(('object' == typeof params) ? params : {})
*/

	var p = Object.extend({
		width: 200,
		height: 100,
		className: 'ma',
		buttonClass: 'buttons'
	}, ('object' == typeof params) ? params : {});


	Dialog.alert(msg, p);

	return 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)
		{
			var url = onOk.href;
			onOk = function() {
				document.location.href = url;
			}
		}
	}

	if ('function' == typeof onOk)
	{
		clbkOk = function() {
			Dialog.closeInfo();
			setTimeout(onOk, 300);
		}
	}

	if ('function' == typeof onCancel)
	{
		clbkCancel = function() {
			Dialog.closeInfo();
			setTimeout(onCancel, 300);
		}
	}

/*	Dialog.confirm(msg, $H({
		width: 200,
		height: 100,
		className: 'ma',
		buttonClass: 'buttons',
		onOk: clbkOk,
		onCancel: clbkCancel
	}).merge(('object' == typeof params) ? params : {}));
*/

	var p = Object.extend({
		width: 200,
		height: 100,
		className: 'ma',
		buttonClass: 'buttons',
		onOk: clbkOk,
		onCancel: clbkCancel,
		okLabel: MyAmphiLang.pConfirm_Ok,
		cancelLabel: MyAmphiLang.pConfirm_Cancel
	}, ('object' == typeof params) ? params : {});

	Dialog.confirm(msg, p);

	return false;
}
/*
function p2Confirm(msg, onOk, onCancel, params)
{
	var clbkOk = null, clbkCancel = null;

	if ('object' == typeof onOk  && 'undefiend' != typeof onOk.href)
	{
		if (!onOk.href.empty() && '#' != onOk.href)
		{
			var url = onOk.href;
			onOk = function() {
				document.location.href = url;
			}
		}
	}

	if ('function' == typeof onOk)
	{
		clbkOk = function() {
			Dialog.closeInfo();
			onOk();
		}
	}

	if ('function' == typeof onCancel)
	{
		clbkCancel = function() {
			onCancel();
			Dialog.closeInfo();
		}
	}

	Dialog.confirm(msg, $H({
		width: 200,
		height: 100,
		className: 'ma',
		buttonClass: 'buttons',
		onOk: clbkOk,
		onCancel: clbkCancel
	}).merge(('object' == typeof params) ? params : {}));

	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:		"ma",
			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(false);
		}
		else
		{
			wnd_js.show(false);
		}

		//wnd_js.setAjaxContent(url,{method: 'get'}, showCentred);

		if (location)
		{
			wnd_js.setLocation(location['top'],location['left']);
		}
	}

	return wnd_js;
}

function ProtoWndCreateMaximazed(id, url)
{
	url += (-1 == url.indexOf('?')) ? '?pwnd=1' : '&pwnd=1';

	if (undefined != (wnd_js = Windows.getWindow(id)))
	{
		//document.documentElement.style.overflow = document.body.style.overflow = 'hidden';
		document.documentElement.style.overflow = 'hidden';
		wnd_js.setSize(850, 550);
		wnd_js.setAjaxContent(url, { method: 'get' }, true, true);
		wnd_js.toFront();
	}
	else
	{
		var wnd_js = new Window(id, {
		 	className:		"ma",
		 	resizable: 		false,
		 	title:			null,
		 	draggable:		false,
		 	closable:		true,
			minimizable:	false,
			maximizable:	false,
			destroyOnClose: true,
			closeCallback:  function(wnd_js) {
				//document.documentElement.style.overflow = document.body.style.overflow = 'auto';
				document.documentElement.style.overflow = 'auto';
				return true;
			}
		});

		//document.documentElement.style.overflow = document.body.style.overflow = 'hidden';
		document.documentElement.style.overflow = 'hidden';
		wnd_js.setSize(850, 550);
		wnd_js.setAjaxContent(url, { method: 'get' }, true, true);
	}
}

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 wnd = ProtoWndOpen(
					'popup', width = width ? width : element.width, height = height ? height : element.height, null, {}
				);

				if (element.title || element.alt)
				{
					wnd.setTitle(element.title ? element.title : element.alt);
				}

				wnd.setContent(
					Element.writeAttribute(
							document.createElement('IMG'), {
							src : additional['src'] ? additional['src'] : element.src,
							width : width,
							height : height
						}
					)
				);
				break;
		}
	}

	return false;
}

function ProtoWndCreate(id, url, width, height, location)
{
	var location = location ? location : false;

	if (-1 == url.indexOf('?'))
	{
		url += '?pwnd=1';
	}
	else
	{
		url += '&pwnd=1';
	}
	if ((wnd_js = Windows.getWindow(id)) != undefined)
	{
		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.setAjaxContent(url,{method: 'get'});
		wnd_js.toFront();
	}
	else
	{
		var wnd_js = new Window(id,
		 {
		 	className:		"ma",
		 	width:			width,
		 	height:			height,
		 	resizable: 		true,
		 	title:			null,
		 	draggable:		true,
		 	closable:		true,
			minimizable:	false,
			maximizable:	false,
			destroyOnClose: true
		 });

		showCentred = location ? false : true;

		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>');

		if (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 style="padding-top:' + (w.height/2 - 8) + 'px;text-align:center;"><img src="' + getBaseUrl('appRootUrl') + 'images/progress.gif" width="16" heigth="16" /></div>');
		w.setAjaxContent(url, {method: 'post',postBody: postData, onSuccess: onSuccess});
	}
}

function AjaxLoadForm(target_id,form_url)
{
	new Ajax.Request(form_url,{method: 'get',onSuccess:function(t){Element.update(target_id,t.responseText); }});
}

/*
function AjaxSubmitForm(target_id, form_url, form)
{
	var onsubmit = form ? (form.onsubmit ? form.onsubmit : false) : false;
	var validate = form ? (window[form.name + '_gfieldsCheck'] ? window[form.name + '_gfieldsCheck'] : false) : false;

	if ( false == ((validate ? validate(form) : true) && (onsubmit ? onsubmit() : true)))
	{
		return false;
	}


	var post = '';
	for(var i = 0; i < form.elements.length; i++)
	{
		post = post + form.elements[i].name + "=" + form.elements[i].value + "&";
	}

	valFunc = form.name + '_gfieldsCheck';

	var submFunc = form.onsubmit;

	if (window[valFunc](form))
	{
		if (submFunc)
		{
			submFunc();
		}
		new Ajax.Request(form_url,{method: 'post',postBody: post,onSuccess:function(t){Element.update(target_id,t.responseText); setTimeout(function(){ location.reload(); }, 2000);}});
	}
}
*/

function AjaxLoadTplControl(baseUrl, target_id, options , form, url, onSuccessIn)
{
	form = form ? form : false;
	var onsubmit = form ? (form.onsubmit ? form.onsubmit : false) : false;
	var validate = form ? (window[form.name + '_gfieldsCheck'] ? window[form.name + '_gfieldsCheck'] : false) : false;

	if ( false == ((validate ? validate(form) : true) && (onsubmit ? onsubmit() : true)))
	{
		return false;
	}

	postData = '';
	for(name in options)
	{
		postData = postData + name + '=' + options[name] + '&';
	}

	if (form)
	{
		for(var i = 0; i < form.elements.length; i++)
		{
			var v = form.elements[i].value;
			//v = v.replace(/[\x80-\xFF]/g, function($0){return ('&#' + $0.charCodeAt(0) + ';');});
			//v = encodeURIComponent(v);
			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 + "&";
				}
			}
		}
	}

	postData = postData + 'load_mode=ajax&' + 'target_id=' + target_id;

	var onSuccess = function(t){
		if ($(target_id).parentNode.parentNode.style['display'] == 'none')
		{
			$(target_id).parentNode.parentNode.style['display'] = '';
		}
		if ($(target_id).style['display'] == 'none')
		{
			$(target_id).style['display'] = '';
		}

		Element.update(target_id,t.responseText);
	}

	onSuccess = onSuccessIn ? onSuccessIn : onSuccess;

	if (url)
	{
		new Ajax.Request(baseUrl + url, {method: 'post',postBody: postData,onSuccess:onSuccess});
	}
	else
	{
		new Ajax.Request(baseUrl + 'control_handler/', {method: 'post',postBody: postData, onSuccess:onSuccess});
	}
}
/*
function()
{
function entities(e)
{
f=e.value;
t='';
for(i=0;i<f.length;i++)
{
if(f.charCodeAt(i)>127)
{
t+=';&#'+f.charCodeAt(i)+';';
}
else
{t += f.charAt(i);}
}
e.value=t;
}
*/

function pWndClose(id)
{
	if (id != window['undefined'])
	{
		Windows.close(id);
		//Windows.getWindow(id).destroy();
	}
}

function processAjaxContent(originalRequest)
{

}

function pWndOpen(id, url, width, height)
{
	var wnd;

		if (-1 == url.indexOf('?'))
	{
		url += '?pwnd=1';
	}
	else
	{
		url += '&pwnd=1';
	}

	if (id != window['undefined'] && (wnd = Windows.getWindow(id)))
	{
		wnd.setAjaxContent(url, {method: 'get', asynchronous : true}, true, 1);
		//wnd.show(true);
	}
	else
	{
		wnd = new Window(id, {
		 	closable:		true,
		 	className:		"ma",
		 	width:			width,
		 	height:			height,
		 	zIndex: 		100,
		 	resizable: 		true,
		 	title:			null,
		 	draggable:		true,
			minimizable:	false,
			maximizable:	false,
			destroyOnClose: true
		 });

		wnd.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.showCenter(true);

		wnd.setAjaxContent(url, {method: 'get', asynchronous : true/*, onComplete : processAjaxContent*/}, true, 2);
	}
}

function setClass(obj, cl){
	if (obj.className!=cl) obj.className = cl;
}

function setClassById(objid, cl){
	if (!cl) cl = '';
	document.getElementById(objid).className = cl;
}

function changeDisplayById(objId){
	for (c = 0; c < changeDisplayById.arguments.length; c++){
		obj = document.getElementById(changeDisplayById.arguments[c]);
		if (obj.style.display == 'none') obj.style.display = 'block';
		else obj.style.display = 'none';
	}
}

function gotoURL(url, target, callback){
	if (!url) url = "/";

	if(typeof callback == "function")
		callback(url);

	if(target && target!='_self'){
		popupURL(url, target);
	}
	else{
		if (window.event){
			var src = window.event.srcElement;
			if((src.tagName != 'A') && ((src.tagName != 'IMG') || (src.parentElement.tagName != 'A'))){
				if (window.event.shiftKey) window.open(url);
				else document.location = url;
			}
		} else document.location = url;
	}
}


function popupURL(url, target){
	window.open(url, target);
}

function getLeftPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return res;
}

function getTopPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return res;
}

function chbCheckAll(formObj, checkName, checkVal){
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]')
			if (!el[count].disabled) el[count].checked = checkVal;
}

function chbExamAll(formObj, checkName, resName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	formObj.elements[resName].checked = (checkCount == boxCount);
}

function chbIsAllEmpty(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	return(checkCount == 0);
}

function chbIsOnlyOne(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++){
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	return(checkCount == 1);
}

function disableAll(){
	for (c1 = 0; c1 < document.forms.length;  c1++){
		var formElements = document.forms[c1].elements;
		for (c2 = 0; c2 < formElements.length;  c2++) formElements[c2].disabled = true;
	}
}


function blocks_view2(lnk, block_id, images )
{
	var bl = lnk.parentNode.parentNode.parentNode.getElementsByTagName('DIV')[4];
	//var bl = lnk.parentNode.parentNode.parentNode.getElementsByTagName('DIV')[6];
	//var bl_mrg = lnk.parentNode.parentNode.parentNode.getElementsByTagName('DIV')[5];
	// var img = lnk.parentNode.getElementsByTagName('img')[0];
	//var arr_selector = lnk.parentNode.parentNode.parentNode.getElementsByTagName('DIV')[3];
	var exp = new Date();
	var oneMonthFromNow = exp.getTime() + (30*24*60*60*1000);
	exp.setTime (oneMonthFromNow);

	if(bl.style.display=='none')
	{
		bl.style.display='block';
		if(block_id)setCookie(block_id,'block',exp,"/");
		lnk.className = 'arr_block';
		// img.src=images+'arr_block.gif';
	}
	else
	{
		bl.style.display='none';
		if(block_id)setCookie(block_id,'none',exp,"/");
		lnk.className = 'arr_none';
		// img.src=images+'arr_none.gif';
	}
	//bl_mrg.style.display = bl.style.display;

}


// name - cookie name
// value - cookie value
// [expires] - Date object (by default cookie expires at the end of browser session)
// [path]
// [domain]
// [secure]
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" : "")

	//alert(curCookie);
	if ((name + "=" + escape(value)).length <= 4000)
	{
		document.cookie = curCookie;
	}
}

// name - cookie name
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))
}

// name - cookie name
// [path]
// [domain]
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 viewcard (url, w, h, wname) {
	/*scr_left = (screen.availWidth - w)/2;
	scr_top = (screen.availHeight - h)/2;*/
	scr_left = 0;
	scr_top = 0;
	wname = wname || 'vcard';
	new_window = window.open (url, wname , "title=image,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width="+w+",height="+h+",top="+scr_top+",left="+scr_left);
	new_window.focus();
	return new_window;
}


function onMenuClick(url)
{
	var exp = new Date();
	var oneMonthFromNow = exp.getTime() + (30*24*60*60*1000);
	exp.setTime (oneMonthFromNow);
	setCookie('menuclick',(url||1),exp,"/");
}

//Small image functions
function image_show(this_obj, id, cl)
{
	obj = document.getElementById(id);
	if (obj.className != cl)
	{
		obj.className = cl;
	}
	obj.style.zIndex = 2000;
}

function image_hide(this_obj, id, cl)
{
	obj = document.getElementById(id);
	if (obj.className != cl)
	{
		obj.className = cl;
	}
}

function set_img_pos (formObj, checkName)
{
	if (!document.forms[formObj])
	{
		return false;
	}

	var el = document.forms[formObj].elements;
	var left, top;
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name == checkName + '[]')
		{
			var thmb = document.getElementById('sm_' + el[count].value);
			var img = document.getElementById('b_' + el[count].value);
			if (thmb)
			{
				var p = Position.positionedOffset(thmb);
				//left = getLeftPos(thmb);
				left = p[0];
				left += 19;
				//top = getTopPos(thmb);
				top = p[1];
				img.style.left = left + 'px';
				img.style.top = top + 'px';
				img.style.zIndex = 20;
			}
		}
	}
}

function insertAtCursor(myField, myValue)
{
	//IE support
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
			+ myValue
			+ myField.value.substring(endPos, myField.value.length);
	}
	else
	{
		myField.value += myValue;
	}
}


function setSelectionRange(input, selectionStart, selectionEnd)
{
	if (input.setSelectionRange)
	{
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}
	else if (input.createTextRange)
	{
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
}



var feedbackPopup;
function openFeedbackPopup(popupUrl) {
	if(!feedbackPopup || feedbackPopup.closed)
		if(popupUrl) feedbackPopup = window.open(popupUrl,'','left=0,top=0,toolbar=0,location=0,status=1,scrollbars=1,width=400,height=550');
	if(feedbackPopup['focus']) feedbackPopup.focus();
	return false;
}

function zoom()
{
	zmode = GetCookie('zoom');
	if (zmode != 'null')
	{
		if (zmode=='out') zmode='in';
		else if (zmode=='in') zmode='out';
		else zmode='in';
	}
	else zmode='in';
	SetCookie ('zoom', zmode, null, "/");
	document.getElementById('css').href = '/css/'+zmode+'.css';
}

function changeFont(val)
{
	var newUseMap, imgMap;
	var expt = new Date();
	var oneMonthFromNow = expt.getTime() + (30*24*60*60*1000);
	expt.setTime (oneMonthFromNow);
	setCookie('font_size',val,expt,"/");

	if(!document.getElementById('font_size_img').useMap)
	{
		document.location.href = document.location.href+"";
	}
	else if(document.getElementById('font_size_stylesheet_'+val))
	{
		document.getElementById('font_size_stylesheet').href=document.getElementById('font_size_stylesheet_'+val).href;

		imgMap = document.getElementById('font_size_img');
		if(imgMap)
		{
			newUseMap = new String(imgMap.useMap.replace(/#font_size_.*/,'#font_size_'+val));
			imgMap.useMap = newUseMap;
			if(imgMap.useMap!=newUseMap)
			{
				imgMap.setAttribute('usemap',newUseMap,0);
				imgMap.outerHTML = imgMap.outerHTML+"";
			}
		}
	}
	return;
}

function chbConfirm(inp, qst, inf)
{
	var form = inp.form;

	if (!form)
	{
		return;
	}

	if(!chbIsAllEmpty(form, 'ch'))
	{
		if (false == qst || (confirm(qst) && window[form.name+'_gAct']))
		{
			window[form.name+'_gAct'](inp.name, '', '', 1);
		}
	}
	else
	{
		alert(inf);
	}

	if (inp.tagName == 'SELECT' && false == inp.multiple)
	{
		var selectedIndex = 0;
		for (var i = 0; i < inp.options.length; i++)
		{
			if (inp.options.defaultSelected)
			{
				selectedIndex = i;
				break;
			}
		}
		inp.selectedIndex = selectedIndex;
	}
}


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]);
					}
				}
    		}
		}
	});
};

if('undefined' != typeof window['Windows'])
{
	Windows.maxZIndex = 20;

	Windows.addModalWindow = function(win) {
		if (this.modalWindows.length == 0)
		{
			WindowUtilities.disableScreen(win.options.className, 'overlay_modal', win.overlayOpacity, win.getId(), win.options.parent);
		}
		else
		{
			if (win == this.modalWindows[this.modalWindows.length - 1])
			{
				return;
			}

			if (Window.keepMultiModalWindow)
			{
				$('overlay_modal').style.zIndex = Windows.maxZIndex + 1;
				Windows.maxZIndex += 20;
				WindowUtilities._hideSelect(this.modalWindows.last().getId());
			}
			else
			{
				this.modalWindows.last().element.hide();
			}

			WindowUtilities._showSelect(win.getId());
		}

		this.modalWindows.push(win);
	};

	//Window.prototype.setAjaxContentOrig = Window.prototype.setAjaxContent;
	Window.prototype.setAjaxContent = function(url, options, showCentered, showModal) {
			this.url = url;
			this.centered = showCentered ? true : false;

		    this.showFunction = showCentered ? "showCenter" : "show";
		    this.showModal = showModal || false;

		    options = options || {};
		    options['evalJS'] = false;

		    this.onComplete = options.onComplete;
		    if (! this._onCompleteHandler)
		      this._onCompleteHandler = this._setAjaxContent.bind(this);
		    options.onComplete = this._onCompleteHandler;

		    new Ajax.Request(url, options);
		    options.onComplete = this.onComplete;
			//this.setAjaxContentOrig(url, options, showCentered, showModal);
	};

	Window.prototype._setAjaxContent =  function(originalRequest) {
		var content = originalRequest.responseText;

		if (content.isJSON() && (data = content.evalJSON()))
		{
			if (data.title)
			{
				this.setTitle(data.title);
			}

			content = data.content;
		}

		Element.update(this.getContent(), content);

		if (this.onComplete)
		{
			this.onComplete(originalRequest);
		}

		this.onComplete = null;

		this[this.showFunction](this.showModal);
	  };

	  Dialog.info2 = function(content, parameters) {
    // Get Ajax return before
    if (content && typeof content != "string") {
      Dialog._runAjaxRequest(content, parameters, Dialog.info);
      return
    }
    content = content || "";

    // Backward compatibility
    parameters = parameters || {};
    parameters = Object.extend(parameters, parameters.windowParameters || {});
    parameters.windowParameters = parameters.windowParameters || {};

    parameters.className = parameters.className || "alert";

    var content = "<div id='modal_dialog_message' class='" + parameters.className + "_message'>" + content  + "</div>";
    if (parameters.showProgress)
      content += "<div id='modal_dialog_progress' class='" + parameters.className + "_progress'>  </div>";

	var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";
	if (parameters.cancel)
    {
      var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " cancel_button'";
      content += "\
    	 <div class='" + parameters.className + "_buttons'>\
          <input type='button' value='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "/>\
        </div>";
    }

    parameters.ok = null;

    return this._openDialog(content, parameters)
  };

  Dialog.confirm = function(content, parameters)
  {
    // Get Ajax return before
    if (content && typeof content != "string")
    {
      Dialog._runAjaxRequest(content, parameters, Dialog.confirm);
      return
    }
    content = content || "";

    parameters = parameters || {};
    var okLabel = parameters.okLabel ? parameters.okLabel : "Ok";
    var cancelLabel = parameters.cancelLabel ? parameters.cancelLabel : "Cancel";

    // Backward compatibility
    parameters = Object.extend(parameters, parameters.windowParameters || {});
    parameters.windowParameters = parameters.windowParameters || {};

    parameters.className = parameters.className || "alert";

    var okButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " ok_button'"
    var cancelButtonClass = "class ='" + (parameters.buttonClass ? parameters.buttonClass + " " : "") + " buttons2 cancel_button'"
    var content = "\
      <div class='" + parameters.className + "_message'>" + content  + "</div>\
        <div class='" + parameters.className + "_buttons'>\
          <input type='button' value='" + cancelLabel + "' onclick='Dialog.cancelCallback()' " + cancelButtonClass + "/>\
          <input type='button' value='" + okLabel + "' onclick='Dialog.okCallback()' " + okButtonClass + "/>\
        </div>\
    ";
    return this._openDialog(content, parameters)
  };

}

InlineEditor = Class.create();

InlineEditor.prototype = {
	initialize : function(container, locName, field, url, postParams, locStrings, addFields){
		if (!$(container))
		{
			return;
		}

		this.container  = container;
		this.locName = locName;
		this.field = field;
		this.url = url;
		this.postParams = postParams;
		this.locStrings = locStrings;
		//this.content = $(this.container).innerXHTML();
		this.addFields = addFields ? addFields : false;

		if ($(this.container).innerHTML.blank())
		{
			$(this.container).innerHTML = this.locStrings['empty'];
		}

		$(this.container).ondblclick = this.showForm.bind(this);
	},

	showForm : function(){
		$(this.container).ondblclick = null;
		new Ajax.Request(
			this.url,
			{
				method    : 'get',
				parameters    : {'loc_name' : this.locName, 'loc_field' : this.field},
				onSuccess : function (t) {
				this.content = t.responseText;
				var formHTML = '';

				if (this.addFields)
				{
					for (var field in this.addFields)
					{
						switch (this.addFields[field].type)
						{
							case 'text':
								formHTML += '<input type="' + this.addFields[field].type + '" name="' + field + '" value="' + this.addFields[field].value + '" class="txt-field" style="width:40%;margin-bottom:10px;">';
								break;
						}
					}
				}

				formHTML += '<textarea name="data" class="txt-area" style="width:99%;">' + this.content + '</textarea>';
				formHTML += '<input name="cancel" class="buttons" type="button" value="' + this.locStrings['cancel']  + '">';
				formHTML += '<input name="save" class="buttons" type="button" value="' + this.locStrings['save']  + '">';

				$(this.container).innerHTML = formHTML;

				for (i = 0; i < $(this.container).childNodes.length; i++)
				{
					if ('cancel' == $(this.container).childNodes[i].name)
					{
						$(this.container).childNodes[i].onclick = this.onCancel.bind(this);
					}

					if ('save' == $(this.container).childNodes[i].name)
					{
						$(this.container).childNodes[i].onclick = this.onSave.bind(this);
					}

					if ('data' == $(this.container).childNodes[i].name)
					{
						this.data = $(this.container).childNodes[i];
					}

					if (this.addFields && 'undefined' != typeof this.addFields[$(this.container).childNodes[i].name])
					{
						this.addFields[$(this.container).childNodes[i].name]['ref'] = $(this.container).childNodes[i];
					}
				}
			}.bind(this)
		}
		);

	},

	onCancel : function(){
		$(this.container).innerHTML = this.content.blank() ? this.locStrings['empty'] : this.content;
		$(this.container).ondblclick = this.showForm.bind(this);
	},

	onSave : function (){
		var query = {};

		query[this.field] = this.data.value.blank() ? '' : this.data.value.stripScripts();

		if (this.addFields)
		{
			for (var field in this.addFields)
			{
				this.addFields[field].value = query[field] = this.addFields[field].ref.value.blank() ? '' : this.addFields[field].ref.value.stripScripts();
			}
		}
		var queryString = '';
		for (var i in query)
		{
			queryString += (queryString ? '&' : '') + i + '=' + escape(query[i]);
		}
		new Ajax.Request(
			this.url,
			{
				method    : 'post',
				postBody  : (this.postParams.blank() ? '' : this.postParams + '&') + queryString/*Hash.toQueryString(query)*/,
				onSuccess : this.onSuccess.bind(this)
			}
		);
	},

	onSuccess : function(t){
		if (t.responseText.blank())
		{
			if (this.data.value.blank())
			{
				this.content = '';
				$(this.container).innerHTML = this.locStrings['empty'];
			}
			else
			{
				$(this.container).innerHTML = this.content = this.data.value;
			}
		}
		else
		{
			$(this.container).innerHTML = this.content.blank() ? this.locStrings['empty'] : this.content;
			alert(t.responseText);
		}
		$(this.container).ondblclick = this.showForm.bind(this);
	}
}

/*function addGetParam(url, key, value)
{
	var separator = '?';

	if (-1 !== (startPos = url.indexOf(key)))
	{
		right = '';
		left  = url.substr(0, startPos);

		if (-1 !== (endPos = url.indexOf('&', startPos)))
		{
			right = url.substr(endPos);
		}

		url = left + key + '=' + value + right;
	}
	else
	{
		if (-1 !== (url.indexOf('?')))
		{
			separator = '&';
		}

		url = url + separator + key + '=' + value
	}

	return url;
}*/

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 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 viewObject(name)
	{
	 var obj = eval(name), i;
	 if(!obj)  {
	   alert("?????? \""+name+"\" ?? ??????????");
	   return;
	 }
	 var w_Test = open("","Test","width=600,height=500,scrollbars=1");
	 if(!w_Test)  {
	   alert("?? ???? ??????? ???? ??? ????????? ??????? ??????? "+name);
	   return;
	 }
	 w_Test.document.open();
	 for(i in obj)
	   w_Test.document.write(name+"."+i+"="+obj[i]+"<br>");
	 w_Test.document.close();
	}

	function replaceLinks(className)
	{

		var divs = document.getElementsByClassName(className);

		//var url_match = /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/g;
		var url_match = /(href\s*?=\s*?["'])?(https?:\/\/.*?)(\s|$|<)/g;

		var mail_match = /[-\w\.]+@{1}[-\w\.]+\.{1}[\w]+/g;

		for (var i = 0; i < divs.length; i++)
		{
			divs[i].innerHTML = divs[i].innerHTML.replace(url_match, function ()
			{
				if (-1 < arguments[1].indexOf('href'))
				{
					return arguments[0];
				}

				var val = arguments[2];
				var postfix = '';
				var postpostfix = arguments[3]
				val = val.replace(/[^\w\d\/]+$/, function () {postfix = arguments[0]; return '';});
				return '<a href="' + val + '">' + val + '</a>' + postfix + postpostfix;
			});
			divs[i].innerHTML = divs[i].innerHTML.replace(mail_match, '<a href="mailto:$&">$&</a>');
		}
	}
	Event.observe(window,'load', function(){ replaceLinks('autolink'); });


/*
Element.addMethods({
innerXHTML: function(element, content) { return innerXHTML(element, content); }
});

Element.addMethods({innerXHTML : function (element, xhtml)
{
	if (xhtml)
	{
		for (var i=0, n; n=element.childNodes[i]; i++) element.removeChild(n);
		var r = document.createRange();
		r.selectNode(element);
		var x = r.createContextualFragment(xhtml);
		element.appendChild(x);
		return x;
	}
	else
	{
		var xhtml = "";
		for (var i=0, n; n=element.childNodes[i]; i++)
		{
			xhtml += (new XMLSerializer()).serializeToString(n);
		}
		alert(xhtml);
		return xhtml;
	}
}});
*/

Event.observe(window, 'load', function() {
	if (window['doRedirect'])
	{
		window['doRedirect']();
	}

	if (window['ProtoWndRestoreAll'])
	{
		window['ProtoWndRestoreAll']();
	}

	document.getElementsByClassName('ttl_backbtn').each(function(s){
		s.onclick = function(){
			var exp = new Date();
			var oneMonthFromNow = exp.getTime() + (30*24*60*60*1000);
			exp.setTime(oneMonthFromNow);
			setCookie('backclick', 1, exp, "/");
		};
		Element.setStyle(s, {visibility: 'visible'});
	});

});


var MD5 = function (string) {

    function RotateLeft(lValue, iShiftBits) {
        return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
    }

    function AddUnsigned(lX,lY) {
        var lX4,lY4,lX8,lY8,lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    }

    function F(x,y,z) { return (x & y) | ((~x) & z); }
    function G(x,y,z) { return (x & z) | (y & (~z)); }
    function H(x,y,z) { return (x ^ y ^ z); }
    function I(x,y,z) { return (y ^ (x | (~z))); }

    function FF(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function GG(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function HH(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function II(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWords_temp1=lMessageLength + 8;
        var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
        var lWordArray=Array(lNumberOfWords-1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount-(lByteCount % 4))/4;
        lBytePosition = (lByteCount % 4)*8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
        lWordArray[lNumberOfWords-2] = lMessageLength<<3;
        lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
        for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
        }
        return WordToHexValue;
    };

    function Utf8Encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    };

    var x=Array();
    var k,AA,BB,CC,DD,a,b,c,d;
    var S11=7, S12=12, S13=17, S14=22;
    var S21=5, S22=9 , S23=14, S24=20;
    var S31=4, S32=11, S33=16, S34=23;
    var S41=6, S42=10, S43=15, S44=21;

    string = Utf8Encode(string);

    x = ConvertToWordArray(string);

    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

    for (k=0;k<x.length;k+=16) {
        AA=a; BB=b; CC=c; DD=d;
        a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
        d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
        c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
        b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
        a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
        d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
        c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
        b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
        a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
        d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
        c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
        b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
        a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
        d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
        c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
        b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
        a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
        d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
        c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
        b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
        a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
        d=GG(d,a,b,c,x[k+10],S22,0x2441453);
        c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
        b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
        a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
        d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
        c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
        b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
        a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
        d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
        c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
        b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
        a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
        d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
        c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
        b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
        a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
        d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
        c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
        b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
        a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
        d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
        c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
        b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
        a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
        d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
        c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
        b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
        a=II(a,b,c,d,x[k+0], S41,0xF4292244);
        d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
        c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
        b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
        a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
        d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
        c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
        b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
        a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
        d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
        c=II(c,d,a,b,x[k+6], S43,0xA3014314);
        b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
        a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
        d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
        c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
        b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
        a=AddUnsigned(a,AA);
        b=AddUnsigned(b,BB);
        c=AddUnsigned(c,CC);
        d=AddUnsigned(d,DD);
    }

    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);

    return temp.toLowerCase();
}

Event.observe(window, 'load', function() {
	$$('*[class*="autoimage"] IMG').each(function(el) {
		if (el.src.match(new RegExp('.+\/editor2\/.+')))
		{
			return;
		}

		var float = el.readAttribute('align') || el.getStyle('float');

		if ('left' == float || 'right' == float)
		{
			if (el.readAttribute('align'))
			{
				el.writeAttribute({align : ''});
			}
		}
		else
		{
			if (
				'undefined' != typeof el.parentNode
				&&
				'center' == Element.getStyle(el.parentNode, 'text-align')
			)
			{
				return;
			}

			float = 'left';
		}

		el.replace(
			Element.setStyle(
				Element.addClassName(
					document.createElement('DIV'), 'wysiwyg-img-wrapper'
				),
				{ float : float }
			).insert(Element.setStyle(el.cloneNode(true), { float : 'none' }))
		);
	});
});