﻿var isinit;
var initView;
var initTree;
var initList;
var initSrch;
var initModir;
var initMarkaz;
var isSrchRsltVsbl;
var initSubj;
var activeTab;
var activeTabFrame;
var xhistory;
var findTxt;
var printPrev;
var viewDescVisble=false;
var themePath;
var webSiteTitle="قوانین و مقررات فروش برق";

function initControls(){
	webSiteTitle=document.title;
  var waitDlg=document.getElementById("waitDlg");
  if(waitDlg==null)return;
  waitDlg.style.display="none";
  var butBack=document.getElementById("butBack");
  var butForward=document.getElementById("butForward");
  if(butBack==null || butForward==null)return;
  xhistory=new c_history(butBack,butForward);
  findTxt=new c_findTxt();
  printPrev=new c_printPrev();
		var feedTree=document.getElementById("feedTree");
		var feedView=document.getElementById("feedView");
		initTree=true;
		viewTab("Tree");
		initView=true;
		themePath=document.getElementById("themePath").value;
		if(themePath.charAt(themePath.length-1)!="/")themePath+="/";
		addStyleSheet(themePath+"view.css");
		addStyleSheet(themePath+"tables.css");
  winResize();
  xhistory.add("mmHome","","feedView",feedView.innerHTML)
  viewChanged(new c_Action("","",""));
  isinit=true;
}
function goHome(){
	ajaxViewData("mmHome","","feedView");
}
function gotoID(id){
  openLink(id);
  viewList(id);
}
function winResize(){
  splitterInit("splitterBox");
	var mainPanelBox=document.getElementById("mainPanelBox");
  var contentRPnl=document.getElementById("contentRPnl");
  var contentLPnl=document.getElementById("contentLPnl");
  var x;
  if(document.body.clientHeight<300 || document.body.offsetWidth<600){
    document.body.style.overflow="auto";
  }else{
    if(mainPanelBox.style.display=="none")document.body.style.overflow="auto";
    else{
			if(navigator.appName.toLowerCase()=="netscape")document.body.style.overflow="-moz-scrollbars-none";
			else document.body.style.overflow="visible";
			var p=absolutePosition(contentRPnl);
			var h=document.body.clientHeight-p.top-2;
			contentRPnl.style.height=h+"px";
			p=absolutePosition(contentLPnl);
			h=document.body.clientHeight-p.top-2;
			contentLPnl.style.height=h+"px";
    }
  }
}
function absolutePosition(obj) {
  var p=null;
  if(obj!=null){
    p=new Object();
    p.top=obj.offsetTop;
    p.left=obj.offsetLeft;
    p.width=obj.offsetWidth;
    p.height=obj.offsetHeight;
    obj=obj.offsetParent;
    while(obj!=null){
      p.top+=obj.offsetTop;
      p.left+=obj.offsetLeft;
      obj=obj.offsetParent;
    }
  }
  return(p);
}
function viewView(html,a,p,f){
  if(!initView)initView=true;
  document.getElementById("feedView").style.filter="";
  document.getElementById("feedView").innerHTML=html;
  if(p.length>=1){
    if(a=="mmView" && (p.substr(0,1)=="c" || p.substr(0,1)=="d" || p.substr(0,1)=="e")){
      if(actvCDEtab==null)actvCDEtab=0;
      var tbl=getChildElementByTag(document.getElementById("feedView"),"TABLE");
      if(tbl!=null)xTab(tbl.rows[0].cells[actvCDEtab]);
      setLinksList();
    }else{actvCDEtab=null;}
		if(a.startsWith("markaz_")){
			actvCDEtab=3;
			var tbl=getChildElementByTag(document.getElementById("feedView"),"TABLE");
			if(tbl!=null && tbl.rows[0].cells[actvCDEtab]!=null)xTab(tbl.rows[0].cells[actvCDEtab]);
			setLinksList();
		}
  }
  html=document.getElementById("feedView").innerHTML;
  viewChanged(new c_Action(a,p,f));
  xhistory.add(a,p,f,html);
//  window.location.hash="id="+p;
	if(document.getElementById("ctrlToolbar1_xxxxxx")!=null){
		
	}
}
function viewChanged(action){
	var butViewDesc=document.getElementById("butViewDesc");
  var v=document.getElementById("viewDesc");
  if(v!=null){
    butViewDesc.style.display="";
    if(viewDescVisble)viewDesc.style.display=""; else viewDesc.style.display="none";
  }else{
    butViewDesc.style.display="none";
  }
}
function viewList(id){
	var feedList=document.getElementById("feedList");
  if(!initList){
    initList=true;
    addStyleSheet(themePath+"list.css");
  }
  if(feedList.innerHTML=="")feedList.innerHTML="لیست";
  viewTab("List");
  ajaxViewData("mmList",id,"feedList");
}
function viewSubj(id){
  if(!initSubj){
    initSubj=true;
    addStyleSheet(themePath+"subj.css");
  }
  if(feedSubj.innerHTML=="")feedSubj.innerHTML="موضوعات";
  viewTab("Subj");
  ajaxViewData("mmSubj",id,"feedSubj");
}
function viewTab(tab){
	var feedTree=document.getElementById("feedTree");
	var feedList=document.getElementById("feedList");
	var feedSrch=document.getElementById("feedSrch");
	var feedSrchRslt=document.getElementById("feedSrchRslt");
	var feedSubj=document.getElementById("feedSubj");
	var feedModir=document.getElementById("feedModir");
	var feedMarkaz=document.getElementById("feedMarkaz");
  if(activeTab!=null)activeTab.parentNode.className="tabButton";
  activeTab=document.getElementById("tab"+tab);
  activeTab.parentNode.className="tabButtonActv";
  feedTree.style.display="none";
  feedList.style.display="none";
  feedSrch.style.display="none";
  feedSrchRslt.style.display="none";
  feedSubj.style.display="none";
  feedModir.style.display="none";
  feedMarkaz.style.display="none";
  switch(tab){
  case 'Tree':
    activeTabFrame=feedTree;
    feedTree.style.display="";
    if(!initTree){
      initTree=true;
      addStyleSheet(themePath+"tree.css");
      ajaxViewData("mmTree", "", "feedTree");
    }else if(feedTree.innerHTML=="")ajaxViewData("mmTree", "", "feedTree");
    break;
  case 'List':
    activeTabFrame=feedList;
    feedList.style.display="";
    if(!initList){
      initList=true;
      addStyleSheet(themePath+"list.css");
      ajaxViewData("mmList", "", "feedList");
    }else if(feedList.innerHTML=="")ajaxViewData("mmList", "", "feedList");
    break;
  case 'Srch':
    if(isSrchRsltVsbl){
      activeTabFrame=feedSrchRslt;
      feedSrchRslt.style.display="";
    }else{
      activeTabFrame=feedSrch;
      feedSrch.style.display="";
    }
    if(!initSrch){
      initSrch=true;
      addStyleSheet(themePath+"srch.css");
      goSearch("getSrchDlg");
    }else if(feedSrch.innerHTML=="")goSearch("getSrchDlg");
    break;
  case 'Subj':
    activeTabFrame=feedSubj;
    feedSubj.style.display="";
    if(!initSubj){
      initSubj=true;
      addStyleSheet(themePath+"subj.css");
      ajaxViewData("mmSubj", "", "feedSubj");
    }else if(feedSubj.innerHTML=="")ajaxViewData("mmSubj", "", "feedSubj");
    break;
  case 'Modir':
    activeTabFrame=feedModir;
    feedModir.style.display="";
    if(!initModir){
      initModir=true;
      ajaxViewData("modir_menu", "", "feedModir");
    }else if(feedModir.innerHTML=="")ajaxViewData("modir_menu", "", "feedModir");
    break;
  case 'Markaz':
    activeTabFrame=feedMarkaz;
    feedMarkaz.style.display="";
    if(!initMarkaz){
      initMarkaz=true;
      ajaxViewData("markaz_menu", "", "feedMarkaz");
    }else if(feedMarkaz.innerHTML=="")ajaxViewData("markaz_menu", "", "feedMarkaz");
    break;
  }
}
function treeCollapseExpand(node,mode){
  node=document.getElementById(node);
  if(node!=null){
    if(getChildElementByTag(node,"img").src.search("minus")>-1){
			getChildElementByTag(node,"img").src="images/plus"+mode+".gif";
	    var subNodes=getChildElement(getChildElement(node,0),1);
	    subNodes.style.display="none";
    }else{
			getChildElementByTag(node,"img").src="images/minus"+mode+".gif";
	    var subNodes=getChildElement(getChildElement(node,0),1);
      subNodes.style.display="";
    }
  }
}
var SelectedItem;
function SlctItem(id){
  if(SelectedItem!=null){SelectedItem.className="cmnList";SelectedItem.setAttribute("ActiveClass","cmnList");}
  SelectedItem=document.getElementById(id);
  if(SelectedItem!=null){SelectedItem.className="cmnListSlcted";SelectedItem.setAttribute("ActiveClass","cmnListSlcted");}
}
function listSlctItem(elem,clsName){
	var tbl=getparentElementByTag(elem,"TABLE");
	if(tbl!=null){
		for(var i=0;i<tbl.rows.length;i++){
			tbl.rows[i].className=clsName;
		}
		elem.className+="Actv";
	}
}
function showPicture(){
  var pfn=document.getElementById("picFileName");
  if(pfn!=null)open("Pictures.aspx?pic="+pfn.value);
}
function collapseRPanel(){
  if(butclpsRPanel.src.indexOf("leftp.gif")>-1){
    butclpsRPanel.src="images/rightp.gif";
    butclpsRPanel.alt="بستن پانل سمت راست";
    contentRPanelBox.style.display="";
  }else{
    butclpsRPanel.src="images/leftp.gif";
    butclpsRPanel.alt="باز کردن پانل سمت راست";
    contentRPanelBox.style.display="none";
  }
  winResize();
}
function expandViewDesc(state){
  if(state){
    butViewDesc.children(1).src="images/upp.gif";
    butViewDesc.children(1).alt="بستن پانل توضیحات";
    viewDesc.style.display="";
    viewDescVisble=true;
  }else{
    butViewDesc.children(1).src="images/downp.gif";
    butViewDesc.children(1).alt="باز کردن پانل توضیحات";
    viewDesc.style.display="none";
    viewDescVisble=false;
  }
}
//////////// Search
var srchIsAdv = false;
function srchShowAdvanced(){
	if(srchIsAdv){
		srchIsAdv = false;
		textSmpl.style.display="";
		textAdv.style.display="none";
		srchSlctAdv.style.display="none";
		lableAdv.innerText="جستجوى پيشرفته";
		imgAdv.src="images/down.gif";
		imgAdv.alt="جستجوى پيشرفته";
		imgAdv.name="Simple";
	}else{
		srchIsAdv = true;
		textSmpl.style.display="none";
		textAdv.style.display="";
		srchSlctAdv.style.display="";
		lableAdv.innerText="جستجوى ساده";
		imgAdv.src="images/up.gif";
		imgAdv.alt="جستجوى ساده";
		imgAdv.name="Advanced";
	}
}
function goSearch(srchAction){
    var param="srchAction="+srchAction+";";
    var feed;
    switch(srchAction){
    case "getSrchDlg":
        feed="feedSrch";
        break;
    case "srch":
        isSrchRsltVsbl=true;
        viewTab("Srch");
        document.getElementById("srchRsltMsg").style.display="";
        param+="withCnt="+document.getElementById("srchWithCnt").checked+";";
        feed="feedSrchRslt";
        if(!srchIsAdv){
            param+="isAdv=false;";
            param+="Section=c;";
            param+="cntInPage=10;";
            param+="srchTxt="+document.getElementById("srchTxt").value+";";
        }else{
            param+="isAdv=true;";
            param+="Section="+document.getElementById("srchSlctSections").value+";";
            param+="cntInPage="+document.getElementById("srchSlctCntInPage").value+";";
            param+="advTxtAnd="+document.getElementById("srchAdvTxtAnd").value+";";
            param+="advTxtExact="+document.getElementById("srchAdvTxtExact").value+";";
            param+="advTxtOr="+document.getElementById("srchAdvTxtOr").value+";";
            param+="advTxtNot="+document.getElementById("srchAdvTxtNot").value+";";
            param+="dateFrom="+document.getElementById("srchDateFrom").value+";";
            param+="dateTo="+document.getElementById("srchDateTo").value+";";
            param+="slctRecs="+document.getElementById("srchSlctRecs").value+";";
            param+="slctStates="+document.getElementById("srchSlctStates").value+";";
            var x=document.getElementsByName("srchRdoTitleDesc");
            for(var i=0;i<x.length;i++){
                if(x[i].checked)param+="titleDesc="+x[i].value+";";
            }
        }
        break;
    case "srchNo":
        isSrchRsltVsbl=true;
        viewTab("Srch");
        document.getElementById("srchRsltMsg").style.display="";
        param+="withCnt="+document.getElementById("srchWithCnt").checked+";";
        feed="feedSrchRslt";
        param+="srchTxt="+document.getElementById("srchNo").value+";";
        param+="Section=c;";
        param+="cntInPage=10;";
        break;
    case "srchPrev":
        feed="feedSrchRslt";
        param+="from="+document.getElementById("srchFirst").innerText+";";
        break;
    case "srchNext":
        feed="feedSrchRslt";
        param+="from="+document.getElementById("srchLast").innerText+";";
        break;
    case "chngSection":
        feed="feedSrchRslt";
        param+="Section="+document.getElementById("srchRsltSlctSect").value+";";
        break;
    }
    ajaxViewData("mmSearch", param, feed);
}
function srchSectionChng(){
    var rec=document.getElementById("srchSlctRecs");
    var state=document.getElementById("srchSlctStates");
    var slctSect=document.getElementById("srchSlctSections").value;
    rec.disabled=true;
    state.disabled=true;
    if(slctSect=="a"){rec.disabled=false;state.disabled=false;}
    if(slctSect=="d"){rec.disabled=false;}
}
//////////// History
function c_Action(a,p,f){
    this.action=a;
    this.param=p;
    this.feed=f;
}
function c_history(butB,butF){
    this.histArray=new Array();
    this.arActions=new Array();
    this.current=0;
    this.butBack=butB;
    this.butForward=butF;
    this.add=function(action,param,feed,html){
        this.histArray.splice(this.current,this.histArray.length-this.current);
        this.arActions.splice(this.current,this.arActions.length-this.current);
        var a=new c_Action(action,param,feed);
        this.arActions.push(a);
        this.current=this.histArray.push(html);
        if(this.current>1)this.enableBackBut(true);else this.enableBackBut(false);
        this.enableForwardBut(false);
    }
    this.Refresh=function(){
        var a=this.arActions[this.current-1];
        this.histArray.splice(this.current-1,1);
        this.arActions.splice(this.current-1,1);
        ajaxViewData(a.action,a.param,a.feed);
    }
    this.goBack=function(){
        this.current--;
        if(this.current<=1)this.enableBackBut(false);
        var html=this.histArray[this.current-1];
        document.getElementById("feedView").innerHTML=html;
        document.title=webSiteTitle;
        viewChanged(this.arActions[this.current-1]);
        this.enableForwardBut(true);
    }
    this.goForward=function(){
        this.current++;
        if(this.current>=this.histArray.length)this.enableForwardBut(false);
        var html=this.histArray[this.current-1];
        document.getElementById("feedView").innerHTML=html;
        document.title=webSiteTitle;
        viewChanged(this.arActions[this.current-1]);
        this.enableBackBut(true);
    }
    this.enableBackBut=function(e){
        if(e){
            this.butBack.src="images/back.gif";
            this.butBack.style.cursor="pointer";
            this.butBack.onclick=function(){xhistory.goBack()};
        }else{
            this.butBack.src="images/backDsbl.gif";
            this.butBack.style.cursor="";
            this.butBack.onclick="";
        }
    }
    this.enableForwardBut=function(e){
        if(e){
            this.butForward.src="images/forward.gif";
            this.butForward.style.cursor="pointer";
            this.butForward.onclick=function(){xhistory.goForward()};
        }else{
            this.butForward.src="images/forwardDsbl.gif";
            this.butForward.style.cursor="";
            this.butForward.onclick="";
        }
    }
}
//////////// Contact Us
var contactUsPreviusPage;
function showContactUs(){
	if(!contactUsPreviusPage)contactUsPreviusPage=document.getElementById("feedView").innerHTML;
	ajaxViewData("mmViewHtml","xHtml/contactus.htm","feedView");
}
function hideContactUs(frmId){
	document.getElementById("feedView").innerHTML=contactUsPreviusPage;
	contactUsPreviusPage=null;
}
function sendContactData(frmId){
  var param="";
  var frm=document.forms[frmId];
  if(frm["subj"].value=="" || frm["message"].value=="")alert("لطفاً موضوع و متن پیام را مشخص نمایید");
  else{
		param+="<feedback>";
		for(var i=0;i<frm.length;i++){//frm.length
			if(frm[i].type.toLowerCase()=="text"||frm[i].type.toLowerCase()=="hidden"){
				param+="<"+frm[i].name+">"+frm[i].value+"</"+frm[i].name+">";
			}
			if(frm[i].type.toLowerCase()=="textarea"){
				param+="<"+frm[i].name+"><![CDATA["+frm[i].value+"]]></"+frm[i].name+">";
			}
		}
		param+="</feedback>";
		ajaxViewData("mmContactUs",param,frmId);
  }
}
function feedbackDelMsgs(elem){
  var frm=document.forms[elem];
  if(frm==null){alert("خطا: امکان حذف وجود ندارد");return;}
  var param="";
  for(var i=0;i<frm.length;i++){
    if(frm[i].type.toLowerCase()=="checkbox" && frm[i].checked && frm[i].name.substr(0,12)=="feedback_msg")param+=frm[i].name.substr(12)+";";
  }
  if(param=="")alert("هیچ گزینه ای انتخاب نشده است");
  else ajaxViewData("modir_feedback_del",param,"feedView");
}
//////////// Find Text
function c_findTxt(){
    this.Rng;
    this.dlgShow=function(){
        if(findTxtDlg.style.display=="none"){
            if(this.Rng==null)this.Rng=document.body.createTextRange();
            this.Rng.moveToElementText(feedView);
            findTxtDlg.style.display=""
            findTxtText.focus();
        }else findTxtDlg.style.display="none";
    }
    this.TextChng=function(){
        findTxtButB.style.display="";
        findTxtButP.style.display="none";
        findTxtButN.style.display="none";
        if(event.keyCode==13)this.Begin();
    }
    this.Begin=function(){
        if(findTxtText.value!=""){
            if(this.Rng.findText(this.ConvertChars(findTxtText.value))){
                this.ExpandAllParent(this.Rng);
                try{this.Rng.select();}catch(e){}
                this.Rng.scrollIntoView();
                findTxtButB.style.display="none";
                findTxtButP.style.display="";
                findTxtButN.style.display="";
           }
       }
    }
    this.Prev=function(){
        if(findTxtText.value!=""){
            this.Rng.collapse(true);
            if(this.Rng.findText(this.ConvertChars(findTxtText.value),-1073741824,1)){
                this.ExpandAllParent(this.Rng);
                try{this.Rng.select();}catch(e){}
                this.Rng.scrollIntoView();
            }
        }
    }
    this.Next=function(){
        if(findTxtText.value!=""){
            this.Rng.collapse(false);
            if(this.Rng.findText(this.ConvertChars(findTxtText.value))){
                this.ExpandAllParent(this.Rng);
                try{this.Rng.select();}catch(e){}
                this.Rng.scrollIntoView();
            }
        }
    }
    this.All=function(){
        if(findTxtText.value!=""){
            this.Rng=document.body.createTextRange();
            this.Rng.moveToElementText(feedView);
            while(this.Rng.findText(this.ConvertChars(findTxtText.value))){
                this.ExpandAllParent(this.Rng);
                this.Rng.pasteHTML("<a name='highLight' style='color:#000000;background-color:#FFFF00'>" + this.Rng.text + "</a>");
            }
            this.Rng.moveToElementText(feedView);
        }
    }
    this.ConvertChars=function(inTxt){
        var outTxt=inTxt;
        outTxt=outTxt.replace("ى","ي");
        outTxt=outTxt.replace("ی","ي");
        outTxt=outTxt.replace("ک","ك");
        outTxt=outTxt.replace("أ","ا");
        outTxt=outTxt.replace("ؤ","و");
        return outTxt;
    }
    this.ExpandAllParent=function(Rng){
        var p = Rng.parentElement();
        while(p!=null){
            if(p.style.display=="none" && p.id!="activeViewSubjs")p.style.display="";
            p=p.parentElement;
        }
    }
}
//////////// Print Preview
function c_printPrev(){
    this.elem;
    this.elemParent;
    this.go=function(elem){
        this.elem=elem;
        this.elemParent=this.elem.parentNode;
        mainPanelBox.style.display="none";
        printPanelBox.style.display="";
        printPanel.appendChild(this.elem);
        document.body.style.overflow="auto";
        printToolbar.style.display="";
    }
    this.end=function(){
        mainPanelBox.style.display="";
        printPanelBox.style.display="none";
        this.elemParent.appendChild(this.elem);
        winResize();
    }
    this.print=function(){
        printToolbar.style.display="none";
        print();
        this.end();
    }
}
///{ Splitter }
var splitterFlag;
var splitterGap=200;
function splitterInit(splitterId){
  var splitterBox=document.getElementById(splitterId);
  splitterFlag=splitterBox.childNodes[0];
  splitterFlag.style.width="1px";
  splitterFlag.style.height=splitterFlag.parentNode.offsetHeight+"px";
  if(splitterBox!=null)splitterBox.onmousedown=splitterStart;
  splitterPanelWidth(getCookie("RPanelWidth"));
}
function splitterStart(e){
  e=(e==null)?window.event:e;
  splitterFlag.style.left=e.clientX;
  splitterFlag.style.height=splitterFlag.parentNode.offsetHeight+"px";
  splitterFlag.style.display="";
  document.onmousemove=splitterMove;
  document.onmouseup=splitterEnd;
  if(splitterFlag.setCapture)splitterFlag.setCapture();
  if(document.body.style.MozUserSelect!=null)document.body.style.MozUserSelect="none";
}
function splitterMove(e){
  e=(e==null)?window.event:e;
  var splitterX=e.clientX;
  if(splitterX<splitterGap)splitterX=splitterGap;
  if(splitterX>document.body.clientWidth-splitterGap)splitterX=document.body.clientWidth-splitterGap;
  splitterFlag.style.left=splitterX+"px";
}
function splitterEnd(e){
  e=(e==null)?window.event:e;
  splitterFlag.style.display="none";
  var x=splitterFlag.parentNode.parentNode.offsetWidth;
  var w=x-parseInt(splitterFlag.style.left);
  splitterPanelWidth(w);
  setCookie("RPanelWidth",w,true);
  document.onmousemove=null;
  document.onmouseup=null;
  document.onclick=splitterAfter;
  if(splitterFlag.releaseCapture)splitterFlag.releaseCapture();
}
function splitterPanelWidth(w){
  var contentRPnl=document.getElementById("contentRPnl");
  var contentLPnl=document.getElementById("contentLPnl");
  var p=getPreviousSibling(splitterFlag.parentNode);
  if(w==null)w=300;
  if(p){
    p.style.width=w+"px";
    contentRPnl.style.width=p.style.width;
    contentRPnl.style.width=p.clientWidth+"px";
    p=getNextSibling(splitterFlag.parentNode);
    contentLPnl.style.display="none";
    contentLPnl.style.width=p.style.width;
    contentLPnl.style.width=p.clientWidth+"px";
    contentLPnl.style.display="";
  }
}
function splitterAfter(e){
  if(document.body.style.MozUserSelect!=null){
    document.body.style.MozUserSelect="";
    document.onclick=null;
  }
}
///{ End Splitter }
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}
String.prototype.startsWith=function(s){
  if (this.length<s.length)return false;
  else return this.substring(0, s.length)===s;
}
////////////////////////
var actvCDEtab;
function getChildElement(elem,no){
  var x=null;
  if(elem!=null)
    if(elem.hasChildNodes()){
      var j=-1;
      for(var i=0;i<elem.childNodes.length;i++){
        if(elem.childNodes[i].nodeType==1)j++;
        if(j==no){x=elem.childNodes[i];break;}
      }
    }
  return x;
}
function getChildElementByTag(elem,tag){
  var x=null;
  if(elem!=null){
		var tags=elem.getElementsByTagName(tag);
		if(tags.length>0){
			x=tags[0];
		}
  }
  return x;
}
function getparentElementByTag(elem,tag){
  var x=null;
  if(elem!=null){
    x=elem.parentNode;
    while(x.tagName.toLowerCase()!=tag.toLowerCase())x=x.parentNode;
  }
  return x;
}
function getPreviousSibling(elem){
  var p=elem;
  do p=p.previousSibling;
  while(p&&p.nodeType!=1);
  return p;
}
function getNextSibling(elem){
  var n=elem;
  do n=n.nextSibling;
  while(n&&n.nodeType!=1);
  return n;
}
function xTab(elem){
  actvCDEtab=elem.cellIndex;
  var tbl=getparentElementByTag(elem,"TABLE");
  for(var i=0;i<tbl.rows[0].cells.length-1;i++)tbl.rows[0].cells[i].className="tabBut";
  tbl.rows[0].cells[actvCDEtab].className="tabButActv";
  tbl=getNextSibling(tbl);
  for(var i=0;i<tbl.rows[0].cells.length;i++)tbl.rows[0].cells[i].style.display="none";
  tbl.rows[0].cells[actvCDEtab].style.display="";
}
function setLinksList(){
	var doc_referralsTo=document.getElementById("doc_referralsTo");
	if(doc_referralsTo==null)return;
	var doc_Text=document.getElementById("doc_Text");
  var links=doc_Text.getElementsByTagName("a");
  var html="";
  for(var i=0;i<links.length;i++){
    html+="<a href=\""+links[i].href+"\">";
    html+=links[i].innerHTML;
    html+="</a><br/>";
  }
	doc_referralsTo.innerHTML=html;
}
function addStyleSheet(cssFile){
  if(document.createStyleSheet){
    var flag=false;
    for(var i=0;i<document.styleSheets.length;i++){
      if(document.styleSheets[i].href.toLowerCase()==cssFile.toLowerCase())flag=true;
    }
    if(!flag)document.createStyleSheet(cssFile);
  }else{
    var newSS=document.createElement('link');
    newSS.rel='stylesheet';
    newSS.type='text/css';
    newSS.href=escape(cssFile);
    document.getElementsByTagName("head")[0].appendChild(newSS);
  }
}
function logoutKarbar(category){
	var d=new Date();
	d.setFullYear(d.getFullYear()-1);
  document.cookie = "Tariff_"+category+"UserName=; expires="+d.toString()+";";
  document.cookie = "Tariff_"+category+"Password=; expires="+d.toString()+";";
  location=document.location;
}
function themeSelect(elemId){
	var frm=document.forms[elemId];
	var rslt="";
	for(var i=0;i<frm.length;i++){
		if(frm[i].type=="radio" && frm[i].checked){rslt=frm[i].value;break;}
	}
	if(rslt!="")ajaxViewData("modir_themeChanged",rslt,"feedView");
	else alert("خطا: امکان تغییر نما وجود ندارد");
}
function menuListSelect(elem){
	var tbl=getparentElementByTag(elem,"TABLE");
	var aTags=tbl.getElementsByTagName("a");
	for(var i=0;i<aTags.length;i++)aTags[i].className="";
	elem.className="menuActv";
}
function chkAllChkboxs(elem){
	if(elem!=null)if(elem.tagName.toLowerCase()=="input")if(elem.type.toLowerCase()=="checkbox"){
		var tbl=elem;
		while(tbl.tagName.toLowerCase()!="table")tbl=tbl.parentNode;
		if(tbl!=null){
			var chks=tbl.getElementsByTagName("INPUT");
			for(var i=0;i<chks.length;i++){
				if(chks[i].tagName.toLowerCase()=="input")if(chks[i].type.toLowerCase()=="checkbox")chks[i].checked=elem.checked;
			}
		}
	}
}
function newsDelMsgs(elem){
  var frm=document.forms[elem];
  if(frm==null){alert("خطا: امکان حذف وجود ندارد");return;}
  var param="";
  for(var i=0;i<frm.length;i++){
    if(frm[i].type.toLowerCase()=="checkbox" && frm[i].checked && frm[i].name.substr(0,8)=="news_msg")param+=frm[i].name.substr(8)+";";
  }
  if(param=="")alert("هیچ گزینه ای انتخاب نشده است");
  else{
		param=param.substr(0,param.length-1);
		if(confirm("آیا برای حذف اخبار "+param+" اطمینان دارید؟"))ajaxViewData("modir_news_del",param,"feedView");
	}
}
function saveForm(formId,cmnd){
	var frm=document.forms[formId];
	var param="<root>";
	var xid=null;
	for(var i=0;i<frm.length;i++){
		if(frm[i].name=="id")xid=frm[i].value;
		if(frm[i].name.toLowerCase()=="fulldate"){
			var d=getShortDate(frm[i].value);
			if(d==""){alert("تاریخ صحیح نیست");frm[i].focus();return;}
			param+="<date><![CDATA["
			param+=d;
			param+="]]></date>"
		}else{
			if(frm[i].name.toLowerCase()=="title" && frm[i].value==""){alert("عنوان نمیتواند خالی باشد");frm[i].focus();return;}
			param+="<"+frm[i].name+"><![CDATA["
			param+=frm[i].value;
			param+="]]></"+frm[i].name+">"
		}
	}
	param+="</root>";
	if(xid!=null)param="id="+xid+";"+param;
	ajaxViewData(cmnd,param,"feedView");
}
function getShortDate(fullDate){
	var rslt="";
	var s=fullDate.split("/");
	if(s.length==3){
		var day=s[0];
		var month=s[1];
		var year=s[2];
		var isValid=true;
		if(isNaN(Math.ceil(year)))isValid=false;
		if(isNaN(Math.ceil(month)))isValid=false;
		if(isNaN(Math.ceil(day)))isValid=false;
		if(year.length==4){
			if(year.substr(0,2)!="13")isValid=false;
			year=year.substr(2);
		}
		if(Math.ceil(year)<70 || Math.ceil(year)>99)isValid=false;
		if(Math.ceil(month)<1 || Math.ceil(month)>12)isValid=false;
		if(Math.ceil(day)<1 || Math.ceil(day)>31)isValid=false;
		if(isValid){
			rslt+=year;
			if(Math.ceil(month)<10)rslt+="0"+Math.ceil(month); else rslt+=Math.ceil(month);
			if(Math.ceil(day)<10)rslt+="0"+Math.ceil(day); else rslt+=Math.ceil(day);
		}
	}
	return rslt;
}
function togglePnlState(elem){
	var imgs=elem.getElementsByTagName("img");
	if(imgs.length>0)var imgUD=imgs[imgs.length-1];
  var pnlBody=getparentElementByTag(elem,"TABLE");
  if(pnlBody!=null)pnlBody=pnlBody.rows[1];
  if(pnlBody!=null)pnlBody=pnlBody.cells[0];
  if(pnlBody==null)return;
  if(pnlBody.style.display=="none"){
    pnlBody.style.display="";
    var re=/down/ig;
    if(imgUD!=null)imgUD.src=imgUD.src.replace(re,"up");
  }else{
    pnlBody.style.display="none";
    var re=/up/ig;
    if(imgUD!=null)imgUD.src=imgUD.src.replace(re,"down");
  }
}
function getCookie(sName){
  var aCookie=document.cookie.split(";");
  for(var i=0;i<aCookie.length;i++){
    var aCrumb=aCookie[i].split("=");
    if("Tariff_"+sName==aCrumb[0].trim())return unescape(aCrumb[1]);
  }
  return null;
}
function setCookie(sName,sData,save){
  if(save){
    var d=new Date();
    d.setFullYear(d.getFullYear()+1);
    document.cookie="Tariff_"+sName+"="+sData+"; expires="+d.toGMTString();
  }else{
    document.cookie="Tariff_"+sName+"="+sData;
  }
}
function treeOutlCollapseExpand(node){
  var feed=document.getElementById("xt"+node);
  if(feed!=null){
    if(feed.style.display=="none"){
      feed.style.display="";
      if(feed.innerHTML.trim()=="")ajaxViewData("mpTree",node,"xt"+node);
    }else{
      feed.style.display="none";
    }
  }
}
var dropDownMenuActive;
var dropDownMenuCloseTimer=0;
function dropDownMenuOpen(elem){
	dropDownMenuCancel();
	if(dropDownMenuActive)dropDownMenuActive.style.display="none";
	var menu=getNextSibling(elem);
	if(menu==null)return;
	dropDownMenuActive=menu;
	var pos=absolutePosition(elem);
	menu.style.display="";
	menu.style.top=pos.top+pos.height;
	menu.style.left=pos.left+pos.width-menu.offsetWidth+4;
}
function dropDownMenuClose(){
	if(dropDownMenuActive)dropDownMenuActive.style.display="none";
}
function dropDownMenuCloseTime(){
	dropDownMenuCloseTimer=setTimeout(dropDownMenuClose,1000);
}
function dropDownMenuCancel(){
	if(dropDownMenuCloseTimer){
		clearTimeout(dropDownMenuCloseTimer);
		dropDownMenuCloseTimer=null;
	}
}
function add_need_docs(){
	if(active_doc_id==null)return;
	var feedView=document.getElementById("feedView");
	var r=document.selection.createRange();
	if(r.text!=""){
		var x="";
		x+="<needDoc>";
		x+="<docId>"+active_doc_id+"</docId>";
		x+="<slctTxt>"+r.text+"</slctTxt>";
		x+="</needDoc>";
		var mb=new msgBox();
		mb.bodyId="werewrewer";
		mb.title="اطلاعات زیر ذخیره شد";
		mb.message=x;
		mb.xslPath="xHtml/needDoc.xsl";
		mb.show();
		ajaxViewData("markaz_add_need_docs",x,"feedview");
	}
}
//////////// msgBox
function msgBox(){
	this.bodyId;
	this.title;
	this.message;
	this.xslPath;
	this.width;
	this.height;
	var box;
	this.show=function(){
		box=document.body.appendChild(document.createElement("table"));
		box.className="msgboxPnl";
		if(this.width==null)box.style.width=300;else box.style.width=this.width;
		var tr=document.createElement("tr");
		var td=document.createElement("td");
		td.appendChild(this.getTitlePnl());
		tr.appendChild(td);
		box.appendChild(tr);
		tr=document.createElement("tr");
		td=document.createElement("td");
		td.appendChild(this.getMessagePnl());
		tr.appendChild(td);
		box.appendChild(tr);
		box.style.top=this.getTopPos();
		box.style.left=this.getLeftPos();
	}
	this.getTitlePnl=function(){
		var tbl=document.createElement("table");
		tbl.width="100%";
		tbl.cellPadding="0";
		tbl.cellSpacing="0";
		tbl.onmousedown=function(e){
			e=(e==null)?window.event:e;
			var mouseX=e.clientX;
			var mouseY=e.clientY;
			document.onmousemove=function(e){
				e=(e==null)?window.event:e;
				var offsetX=e.clientX-mouseX;
				var offsetY=e.clientY-mouseY;
				box.style.top=parseInt(box.style.top.split("px")[0])+offsetY;
				box.style.left=parseInt(box.style.left.split("px")[0])+offsetX;
				mouseX=e.clientX;
				mouseY=e.clientY;
			}
			document.onmouseup=function(e){
				document.onmousemove=null;
				return false;
			}
		}
		var tBody=document.createElement("tbody");
		tbl.appendChild(tBody);
		tbl.className="msgboxHead";
		var tr=document.createElement("tr");
		var td=document.createElement("td");
		td.style.width="16px";
		td.verticalAlign="middle";
		td.appendChild(this.getExitBut());
		tr.appendChild(td);
		td=document.createElement("td");
		td.appendChild(document.createTextNode(this.title));
		tr.appendChild(td);
		td=document.createElement("td");
		td.style.width="16px";
		tr.appendChild(td);
		tBody.appendChild(tr);
		return tbl;
	}
	this.getMessagePnl=function(){
		var div=document.createElement("div");
		if(this.bodyId!=null)div.id=this.bodyId;
		div.className="msgboxBody";
		if(this.height==null)div.style.height="180";else div.style.height=this.height;
		if(this.xslPath==null)div.innerHTML=this.message;
		else div.innerHTML=getHtmlFromXml(getXMLfromText(this.message),getXslDoc(this.xslPath))
		return div;
	}
	this.getExitBut=function(){
		var img=document.createElement("img");
		img.src="images/close.gif";
		img.title="خروج";
		img.style.styleFloat="right";
		img.style.cursor="pointer";
		img.style.verticalAlign="middle";
		img.style.border="1px solid transparent";
		img.onmouseover=function(){this.style.border="1px solid #FFAA88";}
		img.onmouseout=function(){this.style.border="1px solid transparent";}
		img.onclick=function(){box.removeNode(true);}
		return img;
	}
	this.getTopPos=function(){
		var t=0;
		t=document.body.clientHeight/2;
		t-=box.offsetHeight/2;
		return t;
	}
	this.getLeftPos=function(){
		var t=0;
		t=document.body.clientWidth/2;
		t-=box.offsetWidth/2;
		return t;
	}
}
