///
///
///  Elka Content Management v4.0
///  Copyright© 2004 ElkaGroup. All right reserved.
///  Site General Scripts By Yosef Dehghani (afshind@gmail.com)
///  Last update 14 December, 2005 - 12:17
///
///

	function changeWeather(city)
	{
		document.body.focus();
		document.cookie = "cm_weather="+city;
		_g_send("weather", "_waether="+city);
	}
	
	// First release of "showFaqPage" by Ali Sharifi
	function showFaqPage(bUrl)
	{
		windowheight = screen.availHeight;
		rightwidth=240;
		leftwidth=screen.availWidth-rightwidth-11;	
			
		faqWindo = window.open(bUrl+'/faq.php','faqWindow','width='+rightwidth+',height='+(windowheight-51)+',screenX='+leftwidth+',screenY=0,top=0,left=' +leftwidth+',toolbar=0,location=0,status=1,menubar=0,resizable=1,scrollbars=1');
		faqWindo.focus();
		
		window.moveTo(0,0);
		window.resizeTo(leftwidth,screen.availHeight);	
	}

	function showPrintFriendly()
	{
		var url;
		if(_isPostBack)
		{
			if(document.forms.length==0)
				return false;
			var f = document.forms[document.forms.length-1];
			var oa = f.action;
			var ot = f.target;
			f.action = oa+(oa.indexOf("?")==-1? "?":"")+"&_c=p";
			f.target = "PrintPreview";
			f.submit();
			f.action = oa;
			f.target = ot;
		}		
		else
		{
			/*if((new String(_cryptedId_)).indexOf("=")==-1)
				url = "?i="+_cryptedId_;
			else
				url = "?"+_cryptedId_;*/
			url = document.location.href;
			if(url.indexOf("?")==-1)
				url += "?";
			window.open(url+"&_c=p", "PrintPreview");
		}
	}
	
	function GSearchBox(f, m)
	{
		var method = "get";
		var action = "?";
		var qfname = "q";
		m = parseInt(m);
		switch(m)
		{
			case 3:
				action = "?p=nd";
				method = "post";
				qfname = "nq";
				break;
			case 4:
				action = "?p=sd";
				method = "post";
				qfname = "sq";
				break;
		}
		f.action  = action;
		f.method  = method;
		f[0].name = qfname;
	}

	function SearchBox(o, m, ln)
	{
		var defText = new Array("جستجو", "Search");
		if(m==1)
		{
			if(o.value == defText[ln])
				o.value = "";
		}
		else if(m==2)
		{
			if(o.value == "")
				o.value = defText[ln];
		}
	}

	function ValidateForm(frm, ln)
	{
		var validator = new Array();
		validator[1] = "";
		validator[2] = new RegExp("^([0-9])+$");
		validator[3] = new RegExp("^([a-zA-Z0-9_\.\-])+@([a-zA-Z0-9\-])+\.([a-zA-Z0-9])+");
		
		var retVal = true;
		for(i=0;i<frm.length;i++)
		{
			if(frm[i].getAttribute("warn") && frm[i].value=="")
			{
					alert(frm[i].getAttribute("warn"));
					retVal = false;
					break;
			}
			if(frm[i].req && frm[i].req=="1" && frm[i].value=="")
			{
				alStr = "";
				switch(ln)
				{
					case "fa":	alStr = "فيلد های ستاره دار اجباری هستند"; break;
					case "en":	alStr = "Stared Fields Are Required"; break;
				}
				alert(alStr);
				retVal = false;
				break;
			}
			if(frm[i].val && frm[i].val!="1" && frm[i].value!="")
				if(!validator[parseInt(frm[i].val)].test(frm[i].value))
				{
					alStr = "";
					switch(ln)
					{
						case "fa":	alStr = 'لطفا اطلاعات "'+frm[i].name.replace(/_/g," ")+'" را به طور صحيح وارد کنيد'; break;
						case "en":	alStr = 'Please Enter "'+frm[i].name.replace(/_/g," ")+'" Correct'; break;
					}
					alert(alStr);
					retVal = false;
					break;
				}
		}
		return retVal;
	}
	
	/* Generakl Float Pan */
	function pan_attach(e)
	{
		id = e? e.target.id:event.srcElement.id;
		o = document.getElementById(id.replace("db_pant_", "db_pan_"));
		if(!o)
			return;
		o.style.zIndex = ++document._db_panOrder;
		window._fPan = o;
		window._fPanX = e? e.layerX:event.offsetX;
		window._fPanY = e? e.layerY:event.offsetY;
		document.body.onmousemove = pan_move;
		document.body.onmouseup = pan_release;
		document.ondrugstart = function(){return false};
		document.onselectstart = function(){return false};
	}
	
	function pan_release()
	{
		document.onmousemove = null;
		document.ondrugstart = null;
		document.onselectstart = null;
		document.onmouseup = null;
		window._fPan = null;
		window._fPanX = 0;
		window._fPanY = 0;
	}
	
	function pan_move(e)
	{
		if(window._fPan)
		{
			window._fPan.style.left = (e? e.pageX:event.x) - window._fPanX;
			window._fPan.style.top  = (e? e.pageY:event.y-5 + document.body.scrollTop) - window._fPanY;
		}
	}
	
	function pan_front(id)
	{
		o = document.getElementById(id);
		if(o)
			o.style.zIndex = ++document._db_panOrder;
	}
	
	/* Ak Functions */
	function _g_ak(lParam, wParam, module)
	{
		ctrlId = "_c_"+module;
		o = document.getElementById(ctrlId);
		if(!o) return;
		if(lParam == 1)
		{
			if(!wParam)
				eval("o.innerHTML = document._c_"+ctrlId+"_c");
			else
			{
				eval("document._c_"+ctrlId+"_c = o.innerHTML");
				setTimeout(function(){o.innerHTML = _g_wait();}, 200);
			}
		}
		else if(lParam == 2)
			o.innerHTML = wParam;
	}
	
	/* Data Provider Scripts */
	var _gi = 1;
	var _gu = "";
	function _g_init()
	{
		name = "_g_frame" + _gi;
		if(document.all)
		{
			str = "<iframe name=\""+name+"\" id=\""+name+"\"></iframe>";
			document.body.insertAdjacentHTML("beforeEnd", str);
		}
		else
		{
			o = document.createElement("IFRAME");
			o.name = name;
			o.id = name;
			document.body.appendChild(o);			
		}
		_gi++;
		return _gi - 1;
	}
	
	function _g_send_form(f, g, module)
	{
		if(!f)
			return false;
	
		if(!g)
			return false;

		f.target = g;
		if(f.method.toUpperCase()=="POST")
		{
			str = f.action;
			if(str.indexOf("?")==-1)
				str += "?";
			str += "&_gh=" + module + "&_gi=" + g;
			f.action = str;
		}
		else
		{
			i = document.createElement("INPUT");
			i.type = "hidden";
			i.name = "_gh";
			i.value = handler;
			f.appendChild(i);
			
			i = document.createElement("INPUT");
			i.type = "hidden";
			i.name = "_gi";
			i.value = g;
			f.appendChild(i);
		}
		_g_ak(1, true, module);
	}
	
	function _g_send(module, params)
	{
		gi = _g_init();
		url = "?i=" + _cryptedId_ + "&" + params + "&_gh=" + module + "&_gi=" + gi;
		o = document.getElementById("_g_frame"+gi)
		if(o)
		{
			o.style.display = 'none';
			document.body.appendChild(o);
			o.src = url;
			_g_ak(1, true, module);
		}
	}
	
	function _g_recieve(i, module, str)
	{
		if(module)
			_g_ak(2, str, module);
		if(!isNaN(parseInt(i)))
		{
			o = document.getElementById("_g_frame"+i);
			if(o)
				o.removeNode();
		}
	}
	
	function _g_wait()
	{
		str = "<table width=\"100%\" height=\"100%\"><tr><td align=\"center\">";
		str += "<img src=\"templates/StandardTemplate/general/i/loading.gif\" vspace=\"10\"><br>در حال بازيابی اطلاعات"
		str += "</td></tr></table>";
		return str;
	}
	
	/* Database Module Scripts */
	
	function db_gf(id, key)
	{
		document.location = "?i="+_cryptedId_+"&_params=4;"+id+";"+key;
		return false;
	}
	
	function db_sd(id, key, prin)
	{
		key = key? key:"";
		fr = document.getElementById("db_fr");
		fr.setAttribute("did", id);
		fr.setAttribute("dkey", key);
		if(prin)
			window.open("?i="+_cryptedId_+"&_params=1;"+id+";"+key+"&_c=p", "PrintPreview");
		else
		{
			if(fr && window.showInline)
			{
				fr.src = "?i="+_cryptedId_+"&_params=2;"+id+";"+key;
				db_waStart();
			}
			else
				location = "?i="+_cryptedId_+"&_params=1;"+id+";"+key;
		}
		
		return false;
	}
	
	function db_init()
	{
		document.write("<iframe id=\"db_fr\" style=\"display:none\"></iframe>");
		document._db_panStr = "<DIV onclick=\"pan_front('db_pan_#ID#')\" dir=\"rtl\" style=\"width:100%;background-color:white;border:solid 1px gray;filter:progid:DXImageTransform.Microsoft.Shadow(color='#999999',Direction=120, Strength=3);padding:2px;\"><table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr bgcolor=\"#F6C46C\"><td height=\"1\" width=\"1\"><img src=\"templates/StandardTemplate/general/i/dcl.gif\" width=\"15\" height=\"15\" onclick=\"db_close('db_pan_#ID#')\"></td><td width=\"100%\" id=\"db_pant_#ID#\" align=\"left\" style=\"padding-left:4px;\"><a style=\"color:black;text-decoration:none\" href=\"#\" onclick=\"return prinData('#did#', '#dkey#')\"; style=\"font-size:10px\">چاپ داده</a></td></tr><tr><td colspan=\"2\" id=\"db_dpan_#ID#\" valign=\"top\"></td></tr></td></table></DIV>";
		document.write("<div id=\"db_wa\" style=\"width:130px;display:none;position:absolute;top:0px;left:0px;color:red;z-index:1000\">&#8226; در حال بازيابی اطلاعات &#8226; </div>");
		document._db_panId = 0;
		document._db_opens = 0;
		document._db_panOrder = 0;
	}
	
	/* Wait Pan */
	function db_waStart()
	{
		if(!document._db_wa)
		{
			document.body.onmousemove = db_wa;
			document.getElementById("db_wa").style.display = "block";
			document._db_wa = 1;
		}
		/*else
			document._db_wa++;*/
		db_wa();
	}
	
	function db_waEnd()
	{
		document._db_wa--;
		if(!document._db_wa)
		{
			document.getElementById("db_wa").style.display = "none";
			document.body.onmousemove = null;	
		}
	}

	function db_wa(e)
	{
		if(!document.all && !e) return true;
		wa = document.getElementById("db_wa");
		wa.style.top = (e? e.pageY:event.y+document.body.scrollTop)+20;
		wa.style.left = (e? e.pageX:event.x)-65;
	}
	
	function db_close(id)
	{
		o = document.getElementById(id)
		if(o)
		{
			o.parentNode.removeChild(o);
			document._db_opens--;
			if(document._db_opens==0 && document.all)
			{
				s = document.getElementById("searchPan");
				if(s)
					s.style.visibility = 'visible';
			}
		}
	}
	
	function db_tini(html)
	{
		dPan = document.createElement("DIV");
		dPan.id = "db_pan_" + document._db_panId;
		dPan.style.position = "absolute";
		dPan.style.zIndex = document._db_panOrder++;
		dPan.style.width = "460px";

		var fr = document.getElementById("db_fr");
		tStr = document._db_panStr.replace(/#did#/g, fr.getAttribute("did"));
		tStr = tStr.replace(/#dkey#/g, fr.getAttribute("dkey"));
		dPan.innerHTML = tStr.replace(/#ID#/g, document._db_panId);
		document.body.appendChild(dPan);
		document.getElementById("db_pant_"+document._db_panId).onmousedown = pan_attach;
		daPan = document.getElementById("db_dpan_"+document._db_panId);
		daPan.innerHTML = html
		document._db_panId++;
		
		dPan.style.top = document.body.scrollTop + 120;
		dPan.style.left = (screen.availWidth-430)/2;
		if(dPan.offsetHeight<250)
			dPan.childNodes[0].style.height = "250px";
		
		document._db_opens++;
		if(document.all)
		{
			s = document.getElementById("searchPan");
			if(s)
				s.style.visibility = 'hidden';
		}
		db_waEnd();
	}
	
	function prinData(did, dkey)
	{
		db_sd(did, dkey, true);
		return false;
	}
	
	function checkField(name, val)
	{
		if(name.indexOf("[]")==-1)
		{
			o = eval("f."+name);
			if(o.tagName.toUpperCase()=="SELECT")
				o.value = val;
			else
			{
				if(o.length)
				{
					for(i=0;i<o.length;i++)
						if(o[i].value == val)
						{
							o[i].checked = true;
							break;
						}	
				}
				else if(o.value == val)
					o.checked = true;
			}
		}
		else
		{
			val = "," + val + ",";
			for(i=0;i<f.length;i++)
				if(f[i].name == name && val.indexOf(","+f[i].value+",")>-1)
					f[i].checked = true;
		}
	}
	