	
	/**/
	var unique = 0;
	var progresscount = 0;
	var initCallBackList = new Array();
	
	/**/
	var handleSuccess = function(o){
		try{
			
			if(o.responseText !== undefined)
			{		
				if(isValue(o.argument.prgbarstage))
					setIHtml(o.argument.prgbarstage, '');
					
				if(isValue(o.argument.doFirst))
					eval(o.argument.doFirst);
				
				if(isValue(o.argument.stage))
					 $(o.argument.stage)
					 		.hide()
							.html(o.responseText)
							.fadeIn(500);
				
				if(isValue(o.argument.doAfter))
					eval(o.argument.doAfter);
					
			}
			
			}catch(e)
			{
				if(isValue(o.argument.stage))
					setIHtml(o.argument.stage,'عمليات با مشكل مواجه شد');
			}
		}
	var handleFailure = function(o) {
		
		try{
			
			if(isValue(o.argument.doFailed))
			{
				eval(o.argument.doFailed);
			}
			
			}catch(e)
			{
				if(isValue(o.argument.stage))
					setIHtml(o.argument.stage,'عمليات با مشكل مواجه شد');
			}
		}
	var handleProgress = function(eventArg) {
		try{	
			if(isValue(eventArg.prgbarstage))
			{
				if(isValue(eventArg.prgbar))
				{
					setIHtml(eventArg.prgbarstage, eventArg.prgbar);
				}
			}
			
			}catch(e)
			{
			}
		}
	
	/**/
	function showProgressBar()
	{
		return true;
		$('#loaderprg').show();	
		progresscount++;
		
		setTimeout("hideProgressBar();", 300000);
	}
	
	function hideProgressBar()
	{
		return true;
		progresscount--;
		
		if(progresscount <= 0)
		{
			progresscount = 0;
			$('#loaderprg').hide();	
		}
	}
	
	
	/**/
	function htmlspecialchars (string, quote_style, charset, double_encode) {
	
		var optTemp = 0, i = 0, noquotes= false;
		if (typeof quote_style === 'undefined' || quote_style === null) {
			quote_style = 2;
		}
		string = string.toString();
		if (double_encode !== false) { // Put this first to avoid double-encoding
			string = string.replace(/&/g, '&amp;');
		}
		string = string.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	
		var OPTS = {
			'ENT_NOQUOTES': 0,
			'ENT_HTML_QUOTE_SINGLE' : 1,
			'ENT_HTML_QUOTE_DOUBLE' : 2,
			'ENT_COMPAT': 2,
			'ENT_QUOTES': 3,
			'ENT_IGNORE' : 4
		};
		if (quote_style === 0) {
			noquotes = true;
		}
		if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
			quote_style = [].concat(quote_style);
			for (i=0; i < quote_style.length; i++) {
				// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
				if (OPTS[quote_style[i]] === 0) {
					noquotes = true;
				}
				else if (OPTS[quote_style[i]]) {
					optTemp = optTemp | OPTS[quote_style[i]];
				}
			}
			quote_style = optTemp;
		}
		if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
			string = string.replace(/'/g, '&#039;');
		}
		if (!noquotes) {
			string = string.replace(/"/g, '&quot;');
		}
	
		return string;
	}


	function getUnique() {
			return unique++;
		}
	function isValue(value) {
			return ((value != '') && (value != undefined) && (value != null))?true:false;
		}
	function getObject(obj) {
			return document.getElementById(obj);
		}
	function getConfirm(msg) {
			return confirm(msg);
		}
	function goTo(url) {window.location.href = url;}
	function chngView(object, display) { 

			var obj = getObject(object);
			if(display == undefined)
			{
				if(obj.style.display == 'none')
					obj.style.display = '';
				else
					obj.style.display = 'none';
			}
			else
				obj.style.display = display;
				
		}
	function show(object) { 

			var obj = getObject(object);
			obj.style.display = 'block';
	
	}
	function hide(object) { 

			var obj = getObject(object);
			obj.style.display = 'none';
				
		}
	function chngClass(object, classA, classB) {
		
		var obj = getObject(object);
		obj.className = (obj.className == classA)? classB : classA ;
		
	}
	function myClass(object, setClass) {
		
		object.className = setClass ;
		
	}
	function setClass(object, className) {
		
		var obj = getObject(object);
		obj.className = className ;
		
	}
	function getValue(object) {
		return $(object).val();	
	}
	function setValue(object, value) {		
		$(object).val(value);	
	}
	function setIHtml(object, value) {
		$(object).html(value);		
	}
	function getIHtml(object) {
		
		var obj = getObject(object);
		 return obj.innerHTML;
		
	}
	function addIHtml(object, value) {
		
		var obj = getObject(object);
		obj.innerHTML += value ;
		
	}
	function antispam(){document.write(unescape('%3Cinput%20name%3D%22post%22%20type%3D%22hidden%22%20id%3D%22post%22%20value%3D%221%22%20%2F%3E'));}
	function etop(entry) {
		var str = "" + entry;
		str = str.replace(/1/g, "۱");
		str = str.replace(/2/g, "۲");
		str = str.replace(/3/g, "۳");
		str = str.replace(/4/g, "۴");
		str = str.replace(/5/g, "۵");
		str = str.replace(/6/g, "۶");
		str = str.replace(/7/g, "۷");
		str = str.replace(/8/g, "۸");
		str = str.replace(/9/g, "۹");
		str = str.replace(/0/g, "۰");
		return str;
	}
	
	/**/
	function fixImgs() {
			var pix=document.getElementsByTagName('img');
			var maxW = 550;
			var setW = 350;
			for (i=0; i<pix.length; i++) 
			{
				if(pix[i].id != 'unfix')	
				{
					w=pix[i].width;
					h=pix[i].height;
					if (w > maxW) 
					{
						f=1-((w - setW) / w);
						pix[i].width=w * f;
						pix[i].height=h * f;
						
						/*****/
						pix[i].style.cursor = 'pointer';
						pix[i].onclick = function(){window.open(this.src);}
					}
				
				}
			}
			
			setTimeout('fixImgs()', 5000);
		}
	function textCounter(object, maxlimit, cfield) {
		
		try{
			
			if ($(object).val().length > maxlimit)
				$(object).val($(object).val().substring(0, maxlimit));
			
			$(cfield).html(etop(maxlimit - object.value.length));			
		
		}catch(e){}		
	}
	
	/**/
	function submitEditorContent(object, editor){
			getObject(object).value = editor.getHTMLBody();
		}
	
	/**/
	function jLoad(method, url, callback, data){
		try{
				if(callback == undefined || callback == null)
					callback = {};
					
				if(callback.success == undefined)
					callback.success = handleSuccess;
				
				if(callback.failure == undefined)
					callback.failure = handleFailure;
				
				if(callback.Progress == undefined)
					callback.Progress = handleProgress;

				if(callback.argument == undefined)
					callback.argument = {stage:'#null'};

				XLoader.asyncRequest(method, url, callback, data);
			
			}catch(e)
			{
				alert('عمليات با خطا مواجه شد');
			}
		}
	function jSubmit(form, url, callback){
		try{
				XLoader.setForm(form);
				jLoad('POST', url, callback, 'callback=1');
			
			}catch(e)
			{
				alert(e);
			}
			
		return false;
	}
	function jRender(callback){
		$('a').live('click', function(){
			if($(this).attr("href").toLowerCase().indexOf('javascript:') != 0)
			{
				jLoad('POST', $(this).attr("href"), callback, 'callback=1');
				return false;
			}
		});
		
		$('form').live('submit', function(){
										  
			var action = 
				($(this).attr("action").toLowerCase().indexOf('/') == 0)?
					$(this).attr("action"):
					(
					 	($(this).attr("action")=='')?
							$(document).attr('URL'):''
					 );

			if(action.length > 0)
			{
				XLoader.setForm(this)
				jLoad($(this).attr("method"), action, callback, 'callback=1');
				return false;
			}
		});
	}
	
	function captcha(object){
			jLoad('POST', '/pages/ajax-captcha/', {argument:{stage:object}}, 'callback=1');
		}
		
	/**/
	function initCallBack(func) {
		initCallBackList.push(func)
	}
	
	function init() {
		
		fixImgs();

		while(func = initCallBackList.pop())
			eval(func);
			
	}
	

