var accel = 10;
var speed = 5;
var s_moving = 0;
var s_moved = 1;
var n_old = -1;

// New stuff
var sections = 4;	// number of sections
var s_height = 220;	// height of total column
var s_margin = 18;	// margin between sections
var fh = Math.floor(s_height/sections);		// Full height
var tpos = new Array();	// Target positions
var timeoutID8 = new Array();
// For NS4
var yoffset = 550;
var xoffset = 303;
var mainMenuAfterLinkColor = "#6F0104"
var subMenuAfterSelect = "#F8F7E7"

function expandSection(n,c){
	c = !c ? 0:c;	// Choose column
	if(c==0){
		ei = 0;	
		esections = sections;
		es_height = s_height;
	}else{
		ei = sections;
		esections = sections2;
		es_height = s_height2;
	}
		
	if(s_moving == 0){
		//if(s_moved!=-1) n=-1;
		
		if(n==-1){
			s_moving = sections;
			// Reset sections to average spacing
			for(i=0;i<sections;i++){
				tpos[i] = i*fh;
				sE(gE("section"+i));
				expandIt(i);
			}

			if(c==1){
				s_moving += sections2;
				for(i=ei;i<(esections+ei);i++){
					tpos[i] = (i-ei)*fh2;
					sE(gE("section"+i));
					expandIt(i);
				}
			}
			s_moved = -1;
		}else{
			s_moving = esections;
			// Expand to show section n
			yy = 0;
			
			// Set background colour
			if(n_old >=0){
				ee= gE('cel'+n_old);
				e = gE('cell'+n_old);
				e.style.backgroundColor='#F8F7E7';
				e.style.border='0px';
				ee.style.border='0px';
				ee.style.backgroundColor='#7F96AD';
				ee.style.color='white';
			}
			e = gE('cell'+n);
			ee = gE('cel'+n);
			e.style.backgroundColor=subMenuAfterSelect;
			ee.style.backgroundColor=mainMenuAfterLinkColor;

//			ee.style.border='1px solid #799427';
			e.style.border='1px solid #7DC4E2';
			e.style.borderTop='0px';
			ee.style.borderBottom='0px';
			ee.style.color='maroon';
			n_old = n;

			hn = gH(gE('section'+n))-30; 	// Get height of section n
			hn = hn<fh ? fh:hn;			// Don't want to make smaller than the average
			snh = (es_height-hn)/(esections-1);	// Heights of remaining sections
			
			for(i=ei;i<(esections+ei);i++){
				tpos[i] = yy;
				if(i == n) yy+=hn; else yy+=snh;
				expandIt(i);
			}
			s_moved = n;
		}
	}
}

// Expand a certain section
function expandIt(n){
	
	e = gE('section'+n);	
	y = gY(e);
	
	// Move to a designated position
	dy = tpos[n] - y;
	dya = dy / accel;

	if( dya < 1 && dya > 0) dya = 1;
	if( dya >-1 && dya < 0) dya =-1;
	
	y += dya;		
	
	mL(e,0,y);

	if ( Math.floor(dy) == 0) {
		mL(e,0,tpos[n]);
		s_moving--;
		if(s_moved == -1) expandSection(0);
		return;
	} else {
		timeoutID8[n] = window.setTimeout("expandIt(" + n + ")",speed);
	}
}
d=document;l=d.layers;op=navigator.userAgent.indexOf('Opera')!=-1;var ie=d.all?1:0;var w3c=d.getElementById?1:0;
function gE(e,f){if(l){f=(f)?f:self;var V=f.document.layers;if(V[e])return V[e];for(var W=0;W<V.length;)t=gE(e,V[W++]);return t;}if(d.all)return d.all[e];return d.getElementById(e);}
function sE(e){l?e.visibility='show':e.style.visibility='visible';}
function hE(e){l?e.visibility='hide':e.style.visibility='hidden';}
function gY(e){if(l){return e.top;}else if(ie){return e.style.pixelTop;}else{s=getComputedStyle(e,null);return parseInt(s.getPropertyValue('top'));}}
function gH(e){return e.offsetHeight;}

function sX(e,x){l?e.left=x:op?e.style.pixelLeft=x:e.style.left=x;}
function sY(e,y){l?e.top=y:op?e.style.pixelTop=y:e.style.top=y;}
function sW(e,w,m){if(!m)m=0;l?e.clip.width=w:op?e.style.pixelWidth=w:e.style.width=w-m;}

function mL(e,x,y){sX(e,x);sY(e,y);}	// Move layer
function bW(){if(!ie) return window.innerWidth;else return document.body.clientWidth;}


function ucalClose() {
  
   ucal_isclosing=1;
   var mye;
   if ((mye = document.getElementById("ucal_pop")) == null) reutrn ;

   ucal_cpwidth = 270;
   ucal_cpheight = 150;
   ucal_timer = setInterval("ucalAnimateClose()",10);

   ucal_isopen=0;
}
function ucalAnimateClose() {
   ucal_cpwidth -= 20;
   ucal_cpheight -= 10;

   if (ucal_cpwidth <= 0) { clearInterval(ucal_timer); ucal_timer=0; }

   if ((mye = document.getElementById("ucal_pop")) == null) return;
   if (ucal_timer==0) { 
      mye.style.visibility = "hidden";
	  mye.style.display = "none";
      mye.style.width = "auto";
      mye.style.height = "auto";
   } else {
      mye.style.width = ucal_cpwidth+"px";
      mye.style.height = ucal_cpheight+"px";
   }
   ucal_isclosing=0;
}
function ucalOpen(which) {

  
   var mye1,mye2;
   if ((mye1 = document.getElementById("ucal_pop")) == null) return ;
  

   var startx = 0;
   var starty = 0;

   for(var p = 10; p && p.tagName!='BODY'; p = p.offsetParent){
      startx += p.offsetLeft;
      starty += p.offsetTop;
   }


   mye1.style.position = "absolute";
   mye1.style.left = "500px";
   mye1.style.top = "0px";

   mye1.style.width = 0;
   mye1.style.height = 0;
   mye1.style.visibility = "";
   mye1.style.display = "";
   ucal_cpwidth = 0;
   ucal_cpheight = 0;
   ucal_timer = setInterval("ucalAnimateOpen()",20);

   
}
function ucalAnimateOpen() {
   ucal_cpwidth += 10;
   ucal_cpheight += 8;

   if (ucal_cpwidth >= 260) { clearInterval(ucal_timer); ucal_timer=0; }

   if ((mye = document.getElementById("ucal_pop")) == null) return;
   if (ucal_timer!=0){
      mye.style.width = ucal_cpwidth+"px";
      mye.style.height = ucal_cpheight+"px";
   }
}





function openW(){
	window.open("open-new.htm","","height=160,width=426,status=no,toolbar=no,menubar=no,location=no,margin=0,left=550,top=0'");
}
// done hiding -->

if (document.all || document.layers) {
        self.moveTo(0,0);
        self.resizeTo(screen.availWidth,screen.availHeight);
}  

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) 
	endstr = document.cookie.length; 
	return unescape(document.cookie.substring(offset, endstr)); 
} 

function GetCookie (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length;
		var i = 0; 
	while (i < clen) {
	var j = i + alen; 
	if (document.cookie.substring(i, j) == arg) 
	{
	return getCookieVal (j); 
	}
	i = document.cookie.indexOf(" ", i) + 1; 
	if (i == 0) 
	break; 
	} 
	return null; 
} 

function cookie_load(obj){
obj.className=GetCookie(obj.id);
}

			function checkemail(email){
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
				if ( filter.test(email) ){
					return true;
				}else{
					alert("لطفاً پست الكترونيكى خود را بررسى كنيد");
					return false;
				}
			}

			function vote(){

					var jid;
					for (i=0; i<form1.id_vote.length;i++) {
						if(form1.id_vote[i].checked) {
							jid=form1.id_vote[i].value;
							}
						}
					window.open("vote.php?id="+jid+"&catid=4", 'msgWindow', 'left=0, top=0, width=200, height=100, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0');
					 return false;
				}
				function result()
						{
							window.open("result_vote.php?catid=4", '', 'left=0, top=0, width=500, height=450, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0');
						}

var objlib="kharegi";							
							
function click_lib(type){
//alert(type);
	eval("kharegi.style.display='none';");
	eval("ashar.style.display='none';");
	eval("feqh.style.display='none';");
	eval("ejtemai.style.display='none';");
	eval("osol.style.display='none';");
	eval("akhlaq.style.display='none';");
	eval("erfan.style.display='none';");
	eval("shoroh.style.display='none';");
	eval("tarjome.style.display='none';");
  if(type != "0"){
        eval(type+".style.display='';");
  }
}						

function elementToggleHide(el) {
var obj;
var expires = new Date(); 
expires.setTime(expires.getTime() + (7*24*60*60*1000)); 
if(el.className.indexOf('search')== 0 )obj=searchcon;
if(el.className.indexOf('sound')== 0 )obj=soundcon;
if(el.className.indexOf('monasebat')== 0 )obj=monasebat_con;
if(el.className.indexOf('sher')== 0 )obj=sher_con;
if(el.className.indexOf('hadis')== 0 )obj=hadis_con;
if(el.className.indexOf('namaz')== 0 )obj=namaz_con;
if(el.className.indexOf('barg')== 0 )obj=barg_con;
if(el.className.indexOf('news')== 0 )obj=news_con;
if(el.className.indexOf('article')== 0 )obj=article_con;
if(el.className.indexOf('vote')== 0 )obj=vote_con;
if(el.className.indexOf('member')== 0 )obj=member_con;
if(el.className.indexOf('book')== 0 )obj=book_con;
if(obj.className.indexOf('hidden') == -1) {
    obj.className += ' hidden';
}
else {
    obj.className = obj.className.replace(new RegExp(' ?hidden'), '');
	}
	document.cookie = obj.id + "=" + obj.className + 	"; expires=" + expires.toGMTString();
}
if (document.all || document.layers) {
        self.moveTo(0,0);
        self.resizeTo(screen.availWidth,screen.availHeight);
}

function sun(m,d,h,lg)
{
	if(m<7)
		d= 31*(m-1)+d+h/24;
	else
		d=6+30*(m-1)+d+h/24;
	var M=74.2023+0.98560026*d;
	var L=-2.75043+0.98564735*d;
	var lst=8.3162159+0.065709824*Math.floor(d)+1.00273791*24*(d%1)+lg/15;	
	var e=0.0167065;
	var omega=4.85131-0.052954*d;
	var ep=23.4384717+0.00256*cosd(omega);
	var ed=180.0/Math.PI*e;
	var u=M;
	for(var i=1;i<5;i++)
		u=u-(u-ed*sind(u)-M)/(1-e*cosd(u));
	var v=2*atand(tand(u/2)*Math.sqrt((1+e)/(1-e)));
	var theta=L+v-M-0.00569-0.00479*sind(omega);
	var delta=asind(sind(ep)*sind(theta));
	var alpha=180.0/Math.PI*Math.atan2(cosd(ep)*sind(theta),cosd(theta));
	if(alpha>=360)
		alpha-=360;
	var ha=lst-alpha/15;
	var zr=Round(h-ha,24);
	return ([zr,delta])
}

var		lgs= [0,49.70,48.30,45.07,51.64,48.68,46.42,57.33,56.29,50.84,59.21,46.28,51.41,48.34,49.59,60.86,48.50,53.06,53.39,47.00,50.86,52.52,50.00,50.88,57.06,47.09,54.44,59.58,48.52,51.59,54.35];
		var lats=[0,34.09,38.25,37.55,32.68,31.32,33.64,37.47,27.19,28.97,32.86,38.08,35.70,33.46,37.28,29.50,36.68,36.57,35.58,35.31,32.33,29.62,36.28,34.64,30.29,34.34,36.84,36.31,34.80,30.67,31.89];

function coord()
{
	var c=document.getElementById("cities");
	var i = c.selectedIndex;
	if(i==0)
	{
		document.getElementById("longitude").value="";
		document.getElementById("latitude").value="";
	}
	else
	{
		document.getElementById("longitude").value=lgs[i].toString()
		document.getElementById("latitude").value=lats[i].toString()
	}
}
function sind(x){return(Math.sin(Math.PI/180.0*x));}
function cosd(x){return(Math.cos(Math.PI/180.0*x));}
function tand(x){return(Math.tan(Math.PI/180.0*x));}
function atand(x){return(Math.atan(x)*180.0/Math.PI);}
function asind(x){return(Math.asin(x)*180.0/Math.PI);}
function acosd(x){return(Math.acos(x)*180.0/Math.PI);}
function sqrt(x){return(Math.sqrt(x));}
function frac(x){return(x%1);}
function floor(x){return(Math.floor(x));}
function ceil(x){return(Math.ceil(x));}
function loc2hor(z,d,p){
	return(acosd((cosd(z)-sind(d)*sind(p))/cosd(d)/cosd(p))/15);
}
function Round(x,a){
	var tmp=x%a;
	if(tmp<0)
		tmp+=a;
	return(tmp)
}
