function SimpleAjax(url, method, postData, callbackMethod, name) {
	if(typeof(name) == 'undefined')
		name = 'xmlRequest';
	var xmlRequest,e;
    try {
    	xmlRequest = new XMLHttpRequest();
    }
    catch(e) {
    	try {
            xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
		catch(e) {
    		return false;
        }
    }
	xmlRequest.open(method, url, true);
	eval('document.' + name + ' = xmlRequest');
	xmlRequest.onreadystatechange = callbackMethod;
	if (postData != null && method == "POST") {
		xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlRequest.setRequestHeader("Content-length", postData.length);
	    xmlRequest.send(postData);
	}
	else {
		xmlRequest.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	    xmlRequest.send(null);
	}
	return true;
}
pathTemp = window.location.pathname;
pathArray = pathTemp.split( '/index.php' );
pathTemp = pathArray[0];
pathArray = pathTemp.split( '/user.php' );
pathTemp = pathArray[0];
pathArray = pathTemp.split( '/admin.php' );
pathTemp = pathArray[0];
pathArray = pathTemp.split( '/modules.php' );
pathTemp = pathArray[0];
if (pathTemp.substr(pathTemp.length-1,1) == '/')
	pathTemp = pathTemp.substr(0,pathTemp.length-1);
var host = window.location.protocol + '//' + window.location.host;
if (window.location.port > '' && window.location.host.indexOf(":") < 0)
	host += ':' + window.location.port;

function loadCatNews(obj,id,min,max,expand){
	links = document.getElementsByName('topicName');
	for(i=0;i<links.length;i++)
		links[i].className = '';
	obj.className = 'topicSelected';
    $(document.getElementById("news")).fadeTo(0, 0.3);
	SimpleAjax(host + '/index.php?name=news&op=getCatNews&standalone=1&topic_id=' + id+'&min='+min+'&max='+max+'&expand='+expand, 'GET', null, catNews_CallBack);
}
function catNews_CallBack() {
	if (document.xmlRequest.readyState == 4) {
		document.getElementById('news').innerHTML = document.xmlRequest.responseText;
		evalAJAXJavaScripts(document.xmlRequest.responseText);
		document.xmlRequest = null;
		$(document.getElementById("news")).fadeTo(0, 1);
	}
}
function showHideNews(obj,id) {
	var divobj = document.getElementById(id);
	if (divobj.style.display == 'none'){
		divobj.style.display = '';
		obj.src = themePath + 'images/collapse.gif'
	}
	else{
		divobj.style.display = 'none';
		obj.src =  themePath + 'images/expand.gif'
	}
}
var isLogin=0;
function loginProcess(){
	isLogin = 1;
	document.getElementById('loginInfo').style.display='none';
	document.getElementById('loginProcess').style.display='';
}
var isHide = false;
function showUserMenu(obj,userName,uid,lang){
	if(obj.children)
		var userIcon = obj.children[0];
	else
		var userIcon = obj.childNodes[1];
	var region = $(userIcon).offset();
	var objMenu = document.getElementById("__OnlineUserMenu__");
	objMenu.style.display = '';
	var regionMenu =  $(objMenu).offset();
	menuHeight = $(objMenu).outerHeight();
	if (lang == 'far')
		region.left = region.left - 250;
	objMenu.style.top = (region.top-menuHeight+15)  + 'px';
	objMenu.style.left = (region.left) + 'px';
	var objInfo = document.getElementById("userInfo_" + uid);
	document.getElementById("userMenuInfo").innerHTML = objInfo.innerHTML;
	isHide = false;
}
function isHideUserMenu(){
	if (isHide==true){
		var objMenu = document.getElementById("__OnlineUserMenu__");
		objMenu.style.display = 'none';
	}else
		window.setTimeout(isHideUserMenu,1000);
}
function loadAgent(){
	try {
		SimpleAjaxTest(host + '/index.php?name=alert&func=getAlerts', 'GET', null, agent_CallBack);	
	}
	catch (ex) {}
}
var __alertContent;
function agent_CallBack() {
	try {
		if (document.xmlRequest.readyState == 4) {
			var events;
		eval("events = " + document.xmlRequest.responseText + ";");

		if (__alertContent != events.alerts && events.alerts != '')
				playSound('images/alerts/notify.wav');
			document.getElementById('alertMenuContent').innerHTML = events.alerts;
			if (document.getElementById('alertMenuContent').innerHTML != '')
				document.getElementById('alertMenu').style.display = '';
			else
				document.getElementById('alertMenu').style.display = 'none';
			__alertContent = events.alerts;
			if (events.messages != '') {
				var pms = events.messages.split(",");
				for(idx=0; idx<pms.length;idx++) {
					if (pms[idx] != '') {
						startQuickChat(pms[idx]);
					}
				}
			}
			document.xmlRequest = null;
		}
	}
	catch (ex) {}
}
function deleteAlert(alert_id){
	try {
		SimpleAjax(host + '/index.php?name=alert&func=setReadAlert&alert_id='+alert_id, 'GET', null, deleteAlert_CallBack);
	}
	catch (ex) {}
}
function deleteAlert_CallBack(){
	try {
		if (document.xmlRequest1.readyState == 4) {
			document.xmlRequest1 = null;
			loadAgent();
		}
	}
	catch (ex) {}
}
function showHideDesc(alert_desc_id){
	if (document.getElementById(alert_desc_id).style.display	== '')
		document.getElementById(alert_desc_id).style.display = 'none';
	else
		document.getElementById(alert_desc_id).style.display = '';
}
function showDeleteIcon(obj){
	obj.childNodes[2].style.display = '';
	obj.style.backgroundColor = '#F0F0F0';
}
function hideDeleteIcon(obj){
	obj.childNodes[2].style.display = 'none';
	obj.style.backgroundColor = '';
}
ver=parseInt(navigator.appVersion)
ie4=(ver>3  && navigator.appName!="Netscape")?1:0

function playSound(soundFile) {
	if (ie4) document.all['alert_sound'].src=soundFile;
}
function stopSound() {
	if (ie4) document.all['alert_sound'].src='';
}
var hex_chr = "0123456789abcdef";
function rhex(num){
	str = "";
	for(j = 0; j <= 3; j++)
			str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
 				hex_chr.charAt((num >> (j * 8)) & 0x0F);
	return str;
}
function str2blks_MD5(str){
	nblk = ((str.length + 8) >> 6) + 1;
	blks = new Array(nblk * 16);
	for(i = 0; i < nblk * 16; i++)
		blks[i] = 0;
	for(i = 0; i < str.length; i++)
			blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
	blks[i >> 2] |= 0x80 << ((i % 4) * 8);
	blks[nblk * 16 - 2] = str.length * 8;
	return blks;
}
function add(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
	return (msw << 16) | (lsw & 0xFFFF);
}
function rol(num, cnt) {
	return (num << cnt) | (num >>> (32 - cnt));
}
function cmn(q, a, b, x, s, t) {
	return add(rol(add(add(a, q), add(x, t)), s), b);
}
function ff(a, b, c, d, x, s, t) {
	return cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function gg(a, b, c, d, x, s, t){
		return cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function hh(a, b, c, d, x, s, t){
		return cmn(b ^ c ^ d, a, b, x, s, t);
}
function ii(a, b, c, d, x, s, t){
		return cmn(c ^ (b | (~d)), a, b, x, s, t);
}
function MD5(str){
var a =  1732584193;
var b = -271733879;
var c = -1732584194;
var d =  271733878;
	x = str2blks_MD5(str);
	for(i = 0; i < x.length; i += 16) {
	var olda = a;
	var oldb = b;
	var oldc = c;
	var oldd = d;
		a = ff(a, b, c, d, x[i+ 0], 7 , -680876936);
		d = ff(d, a, b, c, x[i+ 1], 12, -389564586);
		c = ff(c, d, a, b, x[i+ 2], 17,  606105819);
		b = ff(b, c, d, a, x[i+ 3], 22, -1044525330);
		a = ff(a, b, c, d, x[i+ 4], 7 , -176418897);
		d = ff(d, a, b, c, x[i+ 5], 12,  1200080426);
		c = ff(c, d, a, b, x[i+ 6], 17, -1473231341);
		b = ff(b, c, d, a, x[i+ 7], 22, -45705983);
		a = ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
		d = ff(d, a, b, c, x[i+ 9], 12, -1958414417);
		c = ff(c, d, a, b, x[i+10], 17, -42063);
		b = ff(b, c, d, a, x[i+11], 22, -1990404162);
		a = ff(a, b, c, d, x[i+12], 7 ,  1804603682);
		d = ff(d, a, b, c, x[i+13], 12, -40341101);
		c = ff(c, d, a, b, x[i+14], 17, -1502002290);
		b = ff(b, c, d, a, x[i+15], 22,  1236535329);

		a = gg(a, b, c, d, x[i+ 1], 5 , -165796510);
		d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
		c = gg(c, d, a, b, x[i+11], 14,  643717713);
		b = gg(b, c, d, a, x[i+ 0], 20, -373897302);
		a = gg(a, b, c, d, x[i+ 5], 5 , -701558691);
		d = gg(d, a, b, c, x[i+10], 9 ,  38016083);
		c = gg(c, d, a, b, x[i+15], 14, -660478335);
		b = gg(b, c, d, a, x[i+ 4], 20, -405537848);
		a = gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
		d = gg(d, a, b, c, x[i+14], 9 , -1019803690);
		c = gg(c, d, a, b, x[i+ 3], 14, -187363961);
		b = gg(b, c, d, a, x[i+ 8], 20,  1163531501);
		a = gg(a, b, c, d, x[i+13], 5 , -1444681467);
		d = gg(d, a, b, c, x[i+ 2], 9 , -51403784);
		c = gg(c, d, a, b, x[i+ 7], 14,  1735328473);
		b = gg(b, c, d, a, x[i+12], 20, -1926607734);

		a = hh(a, b, c, d, x[i+ 5], 4 , -378558);
		d = hh(d, a, b, c, x[i+ 8], 11, -2022574463);
		c = hh(c, d, a, b, x[i+11], 16,  1839030562);
		b = hh(b, c, d, a, x[i+14], 23, -35309556);
		a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
		d = hh(d, a, b, c, x[i+ 4], 11,  1272893353);
		c = hh(c, d, a, b, x[i+ 7], 16, -155497632);
		b = hh(b, c, d, a, x[i+10], 23, -1094730640);
		a = hh(a, b, c, d, x[i+13], 4 ,  681279174);
		d = hh(d, a, b, c, x[i+ 0], 11, -358537222);
		c = hh(c, d, a, b, x[i+ 3], 16, -722521979);
		b = hh(b, c, d, a, x[i+ 6], 23,  76029189);
		a = hh(a, b, c, d, x[i+ 9], 4 , -640364487);
		d = hh(d, a, b, c, x[i+12], 11, -421815835);
		c = hh(c, d, a, b, x[i+15], 16,  530742520);
		b = hh(b, c, d, a, x[i+ 2], 23, -995338651);

		a = ii(a, b, c, d, x[i+ 0], 6 , -198630844);
		d = ii(d, a, b, c, x[i+ 7], 10,  1126891415);
		c = ii(c, d, a, b, x[i+14], 15, -1416354905);
		b = ii(b, c, d, a, x[i+ 5], 21, -57434055);
		a = ii(a, b, c, d, x[i+12], 6 ,  1700485571);
		d = ii(d, a, b, c, x[i+ 3], 10, -1894986606);
		c = ii(c, d, a, b, x[i+10], 15, -1051523);
		b = ii(b, c, d, a, x[i+ 1], 21, -2054922799);
		a = ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
		d = ii(d, a, b, c, x[i+15], 10, -30611744);
		c = ii(c, d, a, b, x[i+ 6], 15, -1560198380);
		b = ii(b, c, d, a, x[i+13], 21,  1309151649);
		a = ii(a, b, c, d, x[i+ 4], 6 , -145523070);
		d = ii(d, a, b, c, x[i+11], 10, -1120210379);
		c = ii(c, d, a, b, x[i+ 2], 15,  718787259);
		b = ii(b, c, d, a, x[i+ 9], 21, -343485551);

		a = add(a, olda);
		b = add(b, oldb);
		c = add(c, oldc);
		d = add(d, oldd);
	}
		return rhex(a) + rhex(b) + rhex(c) + rhex(d);
}
function SHA1 (msg) {
	function rotate_left(n,s) {
		var t4 = ( n<<s ) | (n>>>(32-s));
		return t4;
	};
	function lsb_hex(val) {
		var str="";
		var i;
		var vh;
		var vl;
		for( i=0; i<=6; i+=2 ) {
			vh = (val>>>(i*4+4))&0x0f;
			vl = (val>>>(i*4))&0x0f;
			str += vh.toString(16) + vl.toString(16);
		}
		return str;
	};
	function cvt_hex(val) {
		var str="";
		var i;
		var v;
		for( i=7; i>=0; i-- ) {
			v = (val>>>(i*4))&0x0f;
			str += v.toString(16);
		}
		return str;
	}; 
	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 blockstart;
	var i, j;
	var W = new Array(80);
	var H0 = 0x67452301;
	var H1 = 0xEFCDAB89;
	var H2 = 0x98BADCFE;
	var H3 = 0x10325476;
	var H4 = 0xC3D2E1F0;
	var A, B, C, D, E;
	var temp;
	msg = Utf8Encode(msg);
	var msg_len = msg.length;
	var word_array = new Array();
	for( i=0; i<msg_len-3; i+=4 ) {
		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
		word_array.push( j );
	}
	switch( msg_len % 4 ) {
		case 0:
			i = 0x080000000;
		break;
		case 1:
			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
		break;
		case 2:
			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
		break;
		case 3:
			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
		break;
	}
	word_array.push( i );
	while( (word_array.length % 16) != 14 ) word_array.push( 0 );
	word_array.push( msg_len>>>29 );
	word_array.push( (msg_len<<3)&0x0ffffffff );
	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
		for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
		A = H0;
		B = H1;
		C = H2;
		D = H3;
		E = H4;
		for( i= 0; i<=19; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
		for( i=20; i<=39; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
		for( i=40; i<=59; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
		for( i=60; i<=79; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
		H0 = (H0 + A) & 0x0ffffffff;
		H1 = (H1 + B) & 0x0ffffffff;
		H2 = (H2 + C) & 0x0ffffffff;
		H3 = (H3 + D) & 0x0ffffffff;
		H4 = (H4 + E) & 0x0ffffffff;
	}
	var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
	return temp.toLowerCase();
}
function dummyPassword(passName){
	document.getElementById(passName).value = document.getElementById('org_' + passName).value;
	return true;
}
function encryptPassword(passName) {
	var uname_salt = document.getElementById('uname').value;
	document.getElementById(passName).value = MD5(SHA1(MD5(document.getElementById('org_' + passName).value) + uname_salt.toString()));
	document.getElementById('org_' + passName).value='';
	return true;
}
function encryptChangePassword() {
	if (!checkStrongPass(document.getElementById('org_pass')))
		return false;
	var uname_salt = document.getElementById('uname').value;
	document.getElementById('pass').value = MD5(SHA1(MD5(document.getElementById('org_pass').value) + uname_salt.toString()));
	document.getElementById('org_pass').value='';
	document.getElementById('old_pass').value = MD5(SHA1(MD5(document.getElementById('org_old_pass').value) + uname_salt.toString()));
	document.getElementById('org_old_pass').value='';
	document.getElementById('vpass').value = MD5(SHA1(MD5(document.getElementById('org_vpass').value) + uname_salt.toString()));
	document.getElementById('org_vpass').value='';
	return true;
}
function encryptNewUserPassword() {
	if (!checkStrongPass(document.getElementById('org_pass')))
		return false;
	var uname_salt = document.getElementById('uname').value;
	document.getElementById('pass').value = MD5(SHA1(MD5(document.getElementById('org_pass').value) + uname_salt.toString()));
	document.getElementById('org_pass').value='';
	document.getElementById('rpass').value = MD5(SHA1(MD5(document.getElementById('org_rpass').value) + uname_salt.toString()));
	document.getElementById('org_rpass').value='';
	return true;
}
var passLength = 6;
function checkStrongPass(passObj){
	passValue = passObj.value;
	if (passValue.replace(/^\s+|\s+$/,'')==''){
		alert('کلمه عبور نبايد خالي باشد.');
		return false;
	}
	if(passLength != 0 && passLength=="")
		passLength=6;
	if(passValue.length < passLength) {
		alert('کلمه عبور بايد بيشتر از '+ passLength+' حرف باشد');
		return  false;
	}
	if(passValue.length < passLength+2||checkPassStrong) {
		reLetter=/[a-zA-Z]/g;
		if (passValue.replace(reLetter,'')==''){
			alert('کلمه عبور بايد ترکيبي از حروف انگليسي، ارقام و علائم باشد.');
			return  false;
		}
		reDigit = /[0-9]/g;
		if (passValue.replace(reDigit,'')==''){
			alert('کلمه عبور بايد ترکيبي از حروف انگليسي، ارقام و علائم باشد.');
			return  false;
		}
	}
	reFinal=/^[a-zA-Z0-9~!@#$%^&*()_+|}{:;?><.,=\-\[\]]+$/;
	if (passValue.replace(reFinal,'')!=''){
		alert('کلمه عبور بايد ترکيبي از حروف انگليسي، ارقام و علائم باشد.');
		return  false;
	}
	return true;
}
var opendPMWindows = new Array();
function startQuickChat(uid, userOpened){
	var extra = '';
	if (!userOpened)
		extra = ',top=0,left=0';
	opendPMWindows[uid] = window.open("", "chat", "resizable=no,height=400,width=300,status=no,toolbar=no,menubar=no,location=no" + extra);
	if (opendPMWindows[uid].location.toString().indexOf("index.php") == -1) {
		opendPMWindows[uid].location = basePath + "index.php?module=quick_chat&standalone=1&uid=" + uid;
		opendPMWindows[uid].focus();
	}
	return false;
}
function evalAJAXJavaScripts(content){	
	var parts = content.split(new RegExp("</script>", "i" ));
	if (parts.length <= 1)
		return;
	for(var idx=0; idx<parts.length; idx++) {
		var indexOfScript = parts[idx].search(new RegExp("<script", "i" ));
		if (indexOfScript > -1) {
			var script = parts[idx].substr(indexOfScript);
			script = script.substr(script.indexOf(">") + 1);
			try {
				eval(script);
			}
			catch (ex) {}
		}
	}
	return;
	var reg = new RegExp('(<script[^>]*?>.*\S*\s*<\/script>)');
	r  = reg.exec(content);
	alert(content);
	if (r != null) {
		var lastScript = '';
    	for(idx=0; idx<r.length;idx++) {
    		var re = new RegExp('<script.*?>');
    		m = r[idx].match(re);
    		if (m != null) {
        		r[idx] = r[idx].replace(m[0], '').replace('<\/script>', '');
        		if (r[idx] != lastScript) {
        			alert(r[idx]);
        			eval(r[idx]);
        		}
				lastScript = r[idx];
    		}
    	}
	}
}
function dateEditAutoComplete(dateObj, type) {
	if(type == null ) type = 'JALALIDATE';
	if( dateObj.value == '' ) return false;
	var dateAry = dateObj.value.split('/');
	var day = dateAry[0];
	var month = dateAry[1];
	var year = dateAry[2];
	if( day && month && year && 1<=day && day<=31 && 1<=month && month<=12) {
		if (year.length == 1)
			preYear = (type == 'JALALIDATE') ? '130' : '200';
		else
			preYear = (type == 'JALALIDATE') ? '13' : '20';
		if ( day.length < 2 )
			day = '0' + day;
		if ( month.length < 2 )
			month = '0' + month;
		if ( year.length < 3 )
			year = preYear + year;
		else if(year.length < 4)
			year = preYear.charAt(0) + year;
		dateObj.value = day + '/' + month + '/' + year;
	}
	else
		dateObj.value = '';
}
function timeEditAutoComplete(timeObj) {
	if (timeObj.value == '') return false;
	var timeAry = timeObj.value.split(':');
	switch (timeAry.length) {
		case 1:
				hour = timeAry[0];
				minute = '0';
				second = '0';
				break;
		case 2:
				second = '0';
				hour = timeAry[0];
				minute= timeAry[1];
				break;
		case 3:
				hour = timeAry[0];
				minute = timeAry[1];
				second = timeAry[2];
				break;				
	}
	if (second > 59 || minute > 59 || hour > 23) {
		timeObj.value = '';
		return false;
	}
	if (second && minute && hour) {
		if ( second.length < 2 )
			second = '0' + second;
		if ( minute.length < 2 )
			minute = '0' + minute;
		if ( hour.length < 2 )
			hour = '0' + hour;
		timeObj.value = hour + ':' + minute + ':' + second;	
	}
	else
		timeObj.value = '';
}
function checkNullValue(value) {
	if (value.length ==0 || value.replace(/^\s+|\s+$/,'') == '')
    	return true;
	return false;
}
var newsNum;
var newsNumMax;
var newsNumMin;
function setImgNewsBlock(){
	if (newsNum <= 0)
		return ;
	if(newsNum>=newsNumMax)
		document.getElementById('addNewsBlockImg').style.display = 'none';
	else
		document.getElementById('addNewsBlockImg').style.display = '';
	if(newsNum<=newsNumMin)
		document.getElementById('removeNewsBlockImg').style.display = 'none';
	else
		document.getElementById('removeNewsBlockImg').style.display = '';
}
function addNewsToBlock(){
	if(newsNum>newsNumMax)
		return;
	newsNum++;
	document.getElementById('news'+newsNum).style.display = '';
	setImgNewsBlock();
}
function removeNewsFromBlock(){
	if(newsNum<=newsNumMin)
		return;
	document.getElementById('news'+newsNum).style.display = 'none';
	newsNum--;
	setImgNewsBlock();
}
var galleriesBlockAlbum;
var galleriesBlockimageInterval;
var galleriesBlockImgWidth;
var galleriesBlockImgHeight;
var galleriesBlockPlay = 0;
function loadAlbumImages(obj,albumId){
	if (galleriesBlockAlbum)
		document.getElementById('galleriesBlock_album'+galleriesBlockAlbum).className = 'galleriesBlock_album';
	if (galleriesBlockPlay == 1){
		galleriesBlockPlay = 0;
		tmpSrc = document.getElementById('playImg').src;
		document.getElementById('playImg').src = document.getElementById('pauseImg').src;
		document.getElementById('pauseImg').src = tmpSrc;
	}
	galleriesBlockAlbum = albumId;
	obj.className = 'galleriesBlock_selectedAlbum';
	getGalleriesBlockImage(albumId,'first');
}
function getGalleriesBlockImage(id,param){
	clearInterval(galleriesBlockimageInterval);
	SimpleAjax(host + '/index.php?name=photo_gallery&func=getGalleriesBlockImage&folderId=' + id+'&imgwidth='+galleriesBlockImgWidth+'&imgheight='+galleriesBlockImgHeight+'&param='+param, 'GET', null, getGalleriesBlockImage_CallBack, 'xmlRequestGalleriesBlock');
}
function getGalleriesBlockImage_CallBack() {
	if (document.xmlRequestGalleriesBlock.readyState == 4) {
		tmpresponse = document.xmlRequestGalleriesBlock.responseText;
		var params = new Array(3);
		params = tmpresponse.split(",");
		document.getElementById('trnsimg').src = params[0];
		document.getElementById('album_anchor').href=params[1];
		document.getElementById('imgdesc_gallery').innerText = params[2];
		document.xmlRequestGalleriesBlock = null;
		if (galleriesBlockPlay == 1)
			galleriesBlockimageInterval = setInterval('getGalleriesBlockImage(galleriesBlockAlbum,"next")',5000);
	}
}
function galleriesBlockNextImage(obj){
	if (galleriesBlockPlay == 1){
		tmpSrc = document.getElementById('playImg').src;
		document.getElementById('playImg').src = document.getElementById('pauseImg').src;
		document.getElementById('pauseImg').src = tmpSrc;
	}
	galleriesBlockPlay = 0;
	getGalleriesBlockImage(galleriesBlockAlbum,'next');
}
function galleriesBlockPlayImage(obj,resttime){
	clearInterval(galleriesBlockimageInterval);
	tmpSrc = document.getElementById('playImg').src;
	document.getElementById('playImg').src = document.getElementById('pauseImg').src;
	document.getElementById('pauseImg').src = tmpSrc;
	if (galleriesBlockPlay == 1){
		galleriesBlockPlay = 0;
	}else{
		galleriesBlockPlay = 1;
		galleriesBlockimageInterval = setInterval('getGalleriesBlockImage(galleriesBlockAlbum,"next")',resttime);
	}
}
function galleriesBlockPevImage(obj){
	if (galleriesBlockPlay == 1){
		tmpSrc = document.getElementById('playImg').src;
		document.getElementById('playImg').src = document.getElementById('pauseImg').src;
		document.getElementById('pauseImg').src = tmpSrc;
	}
	galleriesBlockPlay = 0;
	getGalleriesBlockImage(galleriesBlockAlbum,'prv');
}
var catNewsLimitLeft = 0;
var catNewsSign;
var catNewsCount;
function moveCatNews(){
	tmpCatNewsLeft = document.getElementById('tblMotion').style.left.replace("px", "");
	tmpCatNewsLeft = tmpCatNewsLeft.replace("pt", "");
    var catNewsLeft = Number(tmpCatNewsLeft) + catNewsSign * 3;
    if (catNewsSign == -1) {
        if (catNewsLeft < catNewsLimitLeft)
            catNewsLeft = catNewsLimitLeft;
    }
    else {
        if (catNewsLeft > catNewsLimitLeft)
            catNewsLeft = catNewsLimitLeft;
    }
    document.getElementById('tblMotion').style.left = catNewsLeft + "px";
    if (catNewsLeft == catNewsLimitLeft) {
        document.getElementById('nextCatNews').disabled = false;
        document.getElementById('previousCatNews').disabled = false;
    }
    else {
        window.setTimeout(moveCatNews, 1);
    }
}
function initMoveCatNews() {
	tmpCatNewsLimitLeft = document.getElementById('tblMotion').style.left.replace("px", "");
	tmpCatNewsLimitLeft = tmpCatNewsLimitLeft.replace("pt", "");
    catNewsLimitLeft = Number(tmpCatNewsLimitLeft) + catNewsSign * 79;
	if(lang=='far'){
	    if(catNewsLimitLeft<0)
	    	return;
	    if(catNewsLimitLeft > (catNewsCount-5)*79 )
	    	return;
	}else{
	    if(catNewsLimitLeft>0)
	    	return;
	    if(catNewsLimitLeft < (catNewsCount-5)*-79 )
	    	return;
	}
    document.getElementById('nextCatNews').disabled = true;
    document.getElementById('previousCatNews').disabled = true;
    window.setTimeout(moveCatNews, 1);
}
function showHoverHint(obj, url, cWidth, cHeight, cTop, cLeft){	
	obj.onmouseout = function() {hideHoverHint(obj);};
	allowHideHoverHint = false;
	divHint = document.getElementById('__divHoverHint__');
	if (divHint == null) {
		divHint = document.createElement('div');
		divHint.onmouseover = function() {allowHideHoverHint = false;};
		divHint.onmouseout = function() {allowHideHoverHint = true;};
		divHint.id = '__divHoverHint__';
		divHint.className = 'hoverHint';
		divHint.style.width = cWidth + "px";
		divHint.style.height = cHeight + "px";
		if (typeof(cTop) == 'undefined' && typeof(cLeft) == 'undefined')
			var region =  $(obj).offset();
		if (typeof(cTop) == 'undefined' && typeof(cLeft) == 'undefined') {
			divHint.style.top = region.top + "px";
			divHint.style.left = (region.left - (Number(cWidth) + 9)) + "px";
		}
		else {
			divHint.style.top = (Number(cTop) + Number(document.body.scrollTop)) + "px";
			divHint.style.left = (Number(cLeft) + Number(document.body.scrollLeft)) + "px";
		}
		divHint.innerHTML = '<div id="__frmHoverHint__" style="width:'+cWidth+'px;height:'+cHeight+'px;overflow:hidden;display:none;background-color:#fff" ></div>';
		document.body.appendChild(divHint);
	}
	divHint.setAttribute("linkText", obj.innerHTML);
	window.setTimeout(function() {
				var hint = document.getElementById('__divHoverHint__');
				if (hint.getAttribute('linkText') != obj.innerHTML)
					return;
				if (typeof(cTop) == 'undefined' && typeof(cLeft) == 'undefined')
					var region = $(obj).offset();
				var hintFrame = document.getElementById('__frmHoverHint__');
				if (typeof(cTop) == 'undefined' && typeof(cLeft) == 'undefined') {
					hint.style.top = region.top + "px";
					hint.style.left = (region.left - (Number(cWidth) + 9)) + "px";
				}
				else {
					hint.style.top = (Number(cTop) + Number(document.body.scrollTop)) + "px";
					hint.style.left = (Number(cLeft) + Number(document.body.scrollLeft)) + "px";
				}
				hintFrame.style.display = "none";
				hint.style.display = "";
				SimpleAjax(url, 'GET', null, showHoverHintThumbnail_CallBack, 'hoverHint');
			}, 300);
}
function showHoverHintThumbnail_CallBack() {
	try {
		if (document.hoverHint.readyState == 4) {
			var hintFrame = document.getElementById('__frmHoverHint__');
			hintFrame.innerHTML = document.hoverHint.responseText;
			hintFrame.style.display = "";
			document.hoverHint = null;
		}
	}
	catch (ex) {}
}
function hideHoverHint(obj){
	allowHideHoverHint = true;
	if (!hiddingHoverHintProgress)
		window.setTimeout(function() {
				hiddingHoverHintProgress = true;
				hideHoverHint2(obj);
			}, 500);
}
var allowHideHoverHint = true;
var hiddingHoverHintProgress = false;
function hideHoverHint2(obj){
	var hint = document.getElementById('__divHoverHint__');
	if (!allowHideHoverHint) {
		window.setTimeout(function() { hideHoverHint2(obj) }, 500);
		return;
	}
	hint.style.display = "none";
	hiddingHoverHintProgress = false;
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
/*Styleswitcher.js*/
function setActiveStyleSheet(title){
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  currentThenme = title;
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
function createCookie(name,value,days) {
	var pref=window.location.host;
	pref=pref.replace("www","");
	pref=pref.replace(/[.]/g,'');
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+pref+"="+value+expires+"; path=/";
}
function readCookie(name){
	var pref=window.location.host;
	pref=pref.replace("www","");
	pref=pref.replace(/[.]/g,'');
	var nameEQ = name +pref+ "=";
	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;
}
window.onunload = function(e){
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
var currentThenme;
var originalThenme;
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null')
	title = 'bluestyle';
originalThenme = title;
setActiveStyleSheet(title);
/*end style switcher.js*/
function sisRegsiterEvent(obj, eventName, funcObj){
	if (window.attachEvent)
		obj.attachEvent("on"+eventName, funcObj);
	else
		obj.addEventListener(eventName, funcObj, false);
}

function removeCRLF(str, replaceWith) {
	if (!str)
		return "";
	if (!replaceWith)
		replaceWith = "";
	return str.replace( /\r\n/g, replaceWith);
}
