/*--- Designed by Babak Arjmandnia (babakarj@gmail.com) ---*/
/*--- http://www.rahian.com ---*/

// -------------------------------------------------------------------
// -------------------------------------------------------------------
function OpenWin(FileName,W,H)
{
 window.open( FileName, "displayWindow", 'width='+W+', height='+H+', resizable=1, scrollbars=yes');
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------

function createAjaxObj()
{
 var httprequest=false;
 
 if(window.XMLHttpRequest)
   { // if Mozilla, Safari etc
    httprequest=new XMLHttpRequest();
    if (httprequest.overrideMimeType) httprequest.overrideMimeType('text/xml');
   }
  else
   if(window.ActiveXObject)
   { // if IE
    try { httprequest=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e)
     {
      try{ httprequest=new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e){}
     }
   }
   
 return httprequest;
}

// -------------------------------------------------------------------
function ajax_fn(fileStr, divId, divClass, delay, fadeornot, language)
{
 this.fileStr=fileStr;
 this.idOfDiv=divId;
 this.delay=delay;
 this.opacitystring=(typeof fadeornot!="undefined")? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : "";
 if (this.opacitystring!="") this.delay+=500;
 this.opacitysetting=0.2; 
 this.ajaxobj=createAjaxObj();
 this.lang=language;

 if(this.lang=="Fa")
   document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'" dir="rtl">&#1583;&#1585; &#1581;&#1575;&#1604; &#1570;&#1605;&#1575;&#1583;&#1607; &#1587;&#1575;&#1586;&#1740;...</div></div>');

 if(this.lang=="En")
   document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'">Initializing...</div></div>');
   
 this.getXMLfile();
}

// -------------------------------------------------------------------
ajax_fn.prototype.getXMLfile=function()
{
 if(this.ajaxobj)
   {
    var instance=this;
    var url=this.fileStr+"?bustcache="+new Date().getTime();
    this.ajaxobj.onreadystatechange=function(){instance.initialize();}
    this.ajaxobj.open('GET', url, true);
    this.ajaxobj.send(null);
   }
}

// -------------------------------------------------------------------
ajax_fn.prototype.initialize=function()
{ 
 if(this.ajaxobj.readyState == 4)
   { 
     if(this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1)
       {
        this.contentdiv=document.getElementById(this.idOfDiv).firstChild;
        var strData=this.ajaxobj.responseText;
        this.contentdiv.style.display="none";
        this.contentdiv.innerHTML=strData;
        if(strData.length==0)
          {
           this.contentdiv.innerHTML="<b>Error</b> fetching remote ticker file!";
           return;
          }
          
        var instance=this;
        if(window.attachEvent)
          window.attachEvent("onunload", function(){instance.contentdiv=instance.ajaxobj=null;});
        
        
        this.contentdiv.innerHTML="";
        this.contentdiv.style.display="block";
               
        this.fadetransition("reset");
        this.contentdiv.innerHTML=strData;
        this.fadetimer1=setInterval(function(){instance.fadetransition('up', 'fadetimer1')}, 100);
       }
   }      
}

// -------------------------------------------------------------------

ajax_fn.prototype.fadetransition=function(fadetype, timerid)
{
 var contentdiv=this.contentdiv
 if(fadetype=="reset") this.opacitysetting=0.2
 if(contentdiv.filters && contentdiv.filters[0])
   {
    if(typeof contentdiv.filters[0].opacity=="number") //IE6+
      contentdiv.filters[0].opacity=this.opacitysetting*100
     else //IE 5.5
      contentdiv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
   }
  else
   if(typeof contentdiv.style.MozOpacity!="undefined" && this.opacitystring!="")
    { contentdiv.style.MozOpacity=this.opacitysetting }
   else
    this.opacitysetting=1
 
 if (fadetype=="up") this.opacitysetting+=0.1
 if (fadetype=="up" && this.opacitysetting>=1) clearInterval(this[timerid])
}

// -------------------------------------------------------------------
// -------------------------------------------------------------------

//Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 1st, 06'

//Changed for Farsi Menu: Babak Arjmadnia (babakarj@gmail.com)

var cssdropdown={
disappeardelay: 250, 
dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all,
getposOffset:function(what, offsettype) {
   var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
   var parentEl=what.offsetParent;
   while (parentEl!=null)
    {
     totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
     parentEl=parentEl.offsetParent;
    }
   return totaloffset;  },
 showhide:function(obj, e, visible, hidden) {
   if (this.ie || this.firefox)
     this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px";
   if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
     obj.visibility=visible;
    else if (e.type=="click") obj.visibility=hidden; },
iecompattest:function() { return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body; },
clearbrowseredge:function(obj, whichedge) {
   var edgeoffset=0;
   if (whichedge=="rightedge"){
     var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
     this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth;
     if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)
       edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth; }
    else {
     var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset;
     var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
     this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight;
     if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure)
      { 
       edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight;
       if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) 
         edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge;
      } } return edgeoffset;  },
 dropit:function(obj, e, dropmenuID, lang)  {
   if (this.dropmenuobj!=null) 
    this.dropmenuobj.style.visibility="hidden"
   this.clearhidemenu()
   if (this.ie||this.firefox) {
     obj.onmouseout=function(){cssdropdown.delayhidemenu()}
     this.dropmenuobj=document.getElementById(dropmenuID)
     this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
     this.dropmenuobj.onmouseout=function(){cssdropdown.dynamichide(e)}
     this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
     this.showhide(this.dropmenuobj.style, e, "visible", "hidden")
     if(lang=="Fa")
        this.dropmenuobj.x=this.getposOffset(obj, "left")-100 
       else
        this.dropmenuobj.x=this.getposOffset(obj, "left")      
     this.dropmenuobj.y=this.getposOffset(obj, "top")
     this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
     this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
    }  },
 contains_firefox:function(a, b)
  { while (b.parentNode) if ((b = b.parentNode) == a) return true;   return false;  },
 dynamichide:function(e)  {
   var evtobj=window.event? window.event : e
   if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement)) this.delayhidemenu()
     else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
   this.delayhidemenu()  },
delayhidemenu:function() {  this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'",this.disappeardelay) },
clearhidemenu:function() {  if (this.delayhide!="undefined") clearTimeout(this.delayhide) }
}
