﻿//==<SCRIPT LANGUAGE=javascript>
//Ajax
blnStopped = true;
//Banners
//Tabs
//---------------------------

$(document).ready(function() {
	$('.TopSubMenu')
		.mouseover(MenuOver)
		.mouseout(MenuOut);
});
//---------------------------

(function($) {
	$.fn.Ticker = function(options) {
		if (this.length <= 0) { return this; }
		var intItemIndex = 0,
				intCharIndex = 0,
				intStartPos = 0,
				blnStartEffect = false,
				option,
				defaultOpt = {
					speed: 100,
					color: 'Black',
					pause: false,
					nextItemWait: 1000,
					nextLineWait: 1000,
					effectSpeed: 1000
				};

		option = $.extend({}, defaultOpt, options);

		var objDiv = $(this);
		objDiv.css('white-space', 'nowrap');
		$(this).find('ul').css('margin', 0);
		this.each(function() {
			$(this).parent().unbind('mousemove', function() { option.pause = true; }).unbind('mouseout', function() { option.pause = false; });
			$(this).parent().mousemove(function() { option.pause = true; }).mouseout(function() { option.pause = false; });
			$(this).append("<div class=Thicker style='float:right;'></div>");
			var objDisplayer = $(this).find('div.Thicker');
			$(objDisplayer).css('color', option.color);
			var objLi = $(this).find('li').css({ 'list-style-type': 'none', 'float': 'right' }).hide();
			if (objLi.length > 0) {
				intItemIndex = 0;
				setTimeout(function UpdateTicker() {
					if (blnStartEffect) {
						blnStartEffect = false;
						var intDispH = $(objDisplayer).height();
						$(objDisplayer).animate({ height: 0, opacity: 0 }, option.effectSpeed, function() {
							$(objDisplayer).html('');
							$(objDisplayer).css({ height: intDispH, opacity: 1 }, 0);
							option.pause = false;
						});
					}
					if (!option.pause) {
						$(objDisplayer).html(Trim(objLi.eq(intItemIndex).text()).substring(intStartPos, intCharIndex++) + '_');
						if (objDisplayer.width() >= objDiv.parent().width()) {
							var strBigText = Trim(objLi.eq(intItemIndex).text()).substring(intStartPos, intCharIndex++);
							if (strBigText.lastIndexOf(' ') >= 0) {
								strBigText = strBigText.substring(0, strBigText.lastIndexOf(' '));
								intCharIndex = intCharIndex - ($(objDisplayer).text().length - strBigText.length) - 1;
							}
							else {
								strBigText = strBigText.substring(0, strBigText.length - 1);
								intCharIndex--;
								intCharIndex--;
							}
							intStartPos = intCharIndex;
							option.pause = true;
							setTimeout(function() { blnStartEffect = true; }, option.nextLineWait);
							$(objDisplayer).html(strBigText);
						}
						//alert(intCharIndex + ' == ' + Trim(objLi.eq(intItemIndex).text()).length);
						if (intCharIndex > Trim(objLi.eq(intItemIndex).text()).length) {
							$(objDisplayer).html($(objDisplayer).text().substring(0, $(objDisplayer).text().lastIndexOf('_')));
							intCharIndex = 0;
							intStartPos = 0;
							intItemIndex = ++intItemIndex < (objLi.length) ? intItemIndex : 0;
							option.pause = true;
							setTimeout(function() { blnStartEffect = true; }, option.nextItemWait);
						}
					}
					setTimeout(UpdateTicker, option.speed);

				}, option.speed);
			}
		});
		return this;
	};
})(jQuery);
//---------------------------

function change2Tag(pstrValue) {
	return pstrValue.replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&');
}
//---------------------------

function ShowDistance(pobjLink) {
	NewWindow(pobjLink.href, 'DistanceNewWin', 200, 200, 'location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no');
	return false;
}
//---------------------------

function UserLoginCheckdata(pstrRoot) {
	if (!CheckBadChar4UserLogin($('#txtLoginName').val())) {
		alert('.لطفا در نام کاربري از حروف " و \' و - استفاده نکنيد');
		$('#txtLoginName').focus();
		return false;
	}
	if (!CheckBadChar4UserLogin($('#txtUserPass').val())) {
		alert('.لطفا در کلمع عبور از حروف " و \' و - استفاده نکنيد');
		$('#txtUserPass').focus();
		return false;
	}

	$("#hdnEncPassword").val("");
	
	with (document.frmLeftSideUserLogin)
		hash(txtUserPass, hdnChallenge, hdnEncPassword)

	$('#spnLeftAreaLoginButton').hide();
	$('#spnLeftLoginRefresh').show();
	$.ajax({
		url: pstrRoot + 'User/UserF/RemoteLogin.asp?qsLoginName=' + $('#txtLoginName').val() + '&qsEncPassword=' + $('#hdnEncPassword').val(),
		type: 'GET',
		dataType: 'html',
		timeout: 30 * 1000,
		error: function() {
			$('#txtUserPass').attr('value', '');
			$('#spnLeftAreaLoginButton').show();
			$('#spnLeftLoginRefresh').hide();
			alert('.پاسخي از سايت دريافت نشد\n\r.لطفا مجددا سعي نماييد');
		},
		success: function(strHTML) {
			$('#spnLeftAreaLoginButton').show();
			$('#spnLeftLoginRefresh').hide();
			$('#txtUserPass').attr('value', '');
			if (strHTML.substr(0, 1) == '0') {
				if ($('#hdnNewUserPage').attr('value') == 1)
					window.location.href = window.location.href;
				else {
					$('#spnSayHi').html(strHTML.substr(1));
					$('#divB4LoginArea').animate({ height: 1, opacity: 0 }, 2000, function() { $('#divB4LoginArea').hide(); });
					$('#divAfterLoginArea').animate({ height: '70px', opacity: 1 }, 2000);
				}
			}
			else if (strHTML == '1') {
				alert('.نام كاربري نميتواند خالي باشد');
			}
			else if (strHTML == '2')
				alert('.اين نام كاربري توسط مدير تاييد نشده');
			else if (strHTML == '3')
				alert('.نام كاربري يا رمزعبور اشتباه ميباشد');
			else if (strHTML == '4')
				alert('.نام كاربري يا رمزعبور اشتباه ميباشد');
			else if (strHTML == '5')
				alert('.كلمه عبور نميتواند خالي باشد');
			else if (strHTML == '6')
				alert('.خطاي محاسباتي. لطفا مجددا سعي نماييد');
		}
	});

	return false;
}
//---------------------------

function CheckBadChar4UserLogin(pstrValue) {
	return !(pstrValue.indexOf("-") >= 0 || pstrValue.indexOf("'") >= 0 || pstrValue.indexOf('"') >= 0)
}
//---------------------------
function DoLogout(pstrRoot) {
	window.location.href = pstrRoot + 'User/UserF/Logout.asp';
}
//---------------------------

function getParameters(pstrFormId) {
	var strParameters = "";
	$.each($('#' + pstrFormId + ' :input[type!=radio][type!=checkbox]'), function(i, field) { strParameters += '&' + $(field).attr('name') + '=' + $(field).val(); });
	$.each($('#' + pstrFormId + ' :input:checked'), function(i, field) { strParameters += '&' + $(field).attr('name') + '=' + $(field).val(); });
	strParameters = strParameters.substring(1);
	return strParameters;
}
//---------------------------

(function($) {
	$.fn.Dialog = function(options) {
		if (this.length <= 0) { return this; }
		var objDiv = $(this);
		this.each(function() {
			var strButtons = '';
			for (button in options.buttons)
				strButtons += '<input onclick="DoAlertSel(' + options.buttons[button] + ')" style="width:50" value="' + button + '" type="button" class="AlertButton">&nbsp;&nbsp;';
			strButtons = strButtons.substr(0, strButtons.length - 12);
			$('#tdAlertButton').html(strButtons);
			$('#tdAlertTitle').html(objDiv.attr('title'));
			$('#tdAlertTitle').html(options.title == undefined ? objDiv.attr('title') : options.title);
			$('#tdAlertContent').html(options.body == undefined ? objDiv.html() : options.body);
			$('#divAlert').width($(document).width() - 21);
			$('#divAlert').height($(document).height() - 4);
			$('#divAlert').show();
			$('.AlertButton').unbind('click');
			$('.AlertButton').one('click', options.callback);
		});
		return this;
	};
})(jQuery);
//---------------------------

function DoAlertSel(pintRetValue) {
	intAlertRetValue = pintRetValue;
	$('#divAlert').hide(1000);
}
//---------------------------
function ResetSearch(objSearch) {
	if ($('#txtSearchKeyword').attr('value') == 'جستجو') {
		$('#txtSearchKeyword').attr('value', '');
		$('#txtSearchKeyword').css('color', 'black');
	}
}
//---------------------------
//==</SCRIPT>
