
function $(id){return document.getElementById(id);}

loader = '';
function load(show,txt)
{
  if(!loader){loader = $('loader');}

  if(show)
  {
    if(txt.length > 0){loader.innerHTML = txt;}
    else
    {loader.innerHTML = 'Please Wait...';}
    var vscroll = (document.all ? document.documentElement.scrollTop : window.pageYOffset);
    loader.style.top = vscroll + 'px';
    loader.style.display = 'block';
  }
  else
  {
    loader.style.display = 'none';
  }  
}

function isEmail(add){
  if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(add))
  {return true;}else{return false;}}			

function findX(obj){
  var curleft = 0;
  if(obj.offsetParent)
    while(1) 
    {curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;}
  else if(obj.x)
    curleft += obj.x;
  return curleft;
}

function findY(obj){
  var curtop = 0;
  if(obj.offsetParent)
    while(1)
    {curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;}
  else if(obj.y)
    curtop += obj.y;
  return curtop;
}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

String.prototype.trim = function(){
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

DDmenu = null;
DDanchor = null;
DDclassName = null;
node = null;
Dmenu = null;

document.onmousedown = checkDD;

function checkDD(ev)
{
  ev = ev || window.event;
	var target = ev.target || ev.srcElement;
	// Firefox users .target and IE uses srcElement to locate clicked item
  if(DDmenu)
  {

    if(dojo.style.getStyle(node,"display") == 'block')
    {
      try
      {
        if(DDanchor != target && DDanchor != target.parentNode.parentNode)
        {
          if(target != DDmenu && target.parentNode != DDmenu && target.parentNode.parentNode != DDmenu  && target.parentNode.parentNode.parentNode != DDmenu && target.parentNode.parentNode.parentNode.parentNode != DDmenu)
          {
			
            hideDD();
          }
        }

      }
      catch(err)
      {
        hideDD();
      }
      finally
      {
      }
    }
  }
}



function showDD(menu, anchor, offsetX, offsetxY, className, ID, ID2)
{
  pass = true;

  var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;  // Do not delete, conditional comment
  
  if(DDmenu)
  {
    if(DDmenu.style.display == 'block')
    {
      DDanchor.className = DDclassName;
      DDmenu.style.display = 'none';
      
      if(DDanchor == anchor)
      {
        pass = false;
      }
    }
  }
  
  if(pass)
  {
    DDmenu = menu;
    DDanchor = anchor;
    DDclassName = className;
    if(ID)
    {
      if(DDmenu.id != 'DDOptions' && DDmenu.id != 'DDfDel')
      {
        DDmenu = $(DDmenu.id+ "HTML");
        $('folderID').value = ID;
      }
      else
      {
        DDmenu.innerHTML = $(DDmenu.id+ "HTML").innerHTML.replace(/%ID%/g, ID);
      }

      if(ID2)
      {
        if(DDmenu.id != 'DDOptions')
        {
          $('folderTitle').value = ID2;
        }
        else
        {
            DDmenu.innerHTML = DDmenu.innerHTML.replace(/%ID2%/g, ID2);
        }
      }
    }
  
    if(DDmenu.style.display == 'block')
    {
				  
		 // alert("show time");
      DDanchor.className = DDclassName;
      DDmenu.style.display = 'none';
    }
    else
    { 
      if(IE6 == true && className == 'DD'){offsetX = offsetX + 3};  //IE bug fix
      DDmenu.style.left = (findX(DDanchor) + offsetX) + 'px';
      DDmenu.style.top = (findY(DDanchor) + offsetxY) + 'px';
      DDanchor.className = DDclassName +'on';
      DDmenu.style.display = 'block';
    }
  }
}

function showDD1(menu, anchor, offsetX, offsetxY){
	pass = true;
	var IE6 = false;
	 node = dojo.byId(menu);
	if(DDmenu){
    if(dojo.style.getStyle(node,"display") == 'block')
    {
      DDanchor.className = DDclassName;
       dojo.lfx.html.fadeHide(menu,500).play();
      
      if(DDanchor == anchor)
      {
        pass = false;
      }
    }
  }
	if(pass){
		Dmenu = menu;
		DDmenu = document.getElementById(menu);
		DDanchor = anchor;
	
		  if(dojo.style.getStyle(node,"display") == 'block')
		{
		  DDanchor.className = DDclassName;
		  dojo.lfx.html.fadeHide(menu,500).play();
	
		}
		else
		{ 
	
		    if(IE6 == true){offsetX = offsetX + 3};  //IE bug fix
		  DDmenu.style.left = (findX(DDanchor) + offsetX) + 'px';
		  DDmenu.style.top = (findY(DDanchor) + offsetxY) + 'px';
		  DDanchor.className = DDclassName +'on';
		  dojo.lfx.html.fadeShow(menu,500).play();
		 
		}	
	}
 
}

function addBookmark(title) {
		url=window.location.href;
		if (window.sidebar) { 
			window.sidebar.addPanel(title, url,""); 
		} else if( document.all ) {
			window.external.AddFavorite( url, title);
		} else if( window.opera && window.print ) {
			return true;
		}
	}

function DynamicNavBookmarkRun(C,A,D){
	var B=C+(!!A?A+"="+encodeURIComponent(window.location.href):"")+"&"+(!!D&&!!document.title?D+"="+encodeURIComponent(document.title)+"&":"");
	var xx=(window.screen.width-600)/2;
	var yy=(window.screen.height-450)/2;
	var E="status=yes,scrollbars=yes,resizable=no,width=600,height=450,top="+yy+",left="+xx;
	var B=window.open(B,"HuaweiBookmark",E);
	if(B){B.focus()}
}	

function hideDD()
{
  if(DDmenu)
  {
    if(dojo.style.getStyle(node,"display") == 'block')
    {
      temp = DDanchor.className;
      temp = temp.replace(/on/,'');
      DDanchor.className = temp;
	  dojo.lfx.html.fadeHide(Dmenu,500).play();
    }
  }
}

function clearHeadSearch(){
name = document.titleSearchForm.elements["searchString"].value;
	if(name.toLowerCase() == "搜索" ){
		document.titleSearchForm.elements["searchString"].value = "";
	}				
}

function MouseoverHighlight(element, inout, hColor) {
  if (element) {
        if (inout) {
                element.style.background=hColor;
        } else {
                element.style.background="";
        }
  }
}

function OverLv1Menu(div,name,hColor){
	if(div)
	{	
		div.style.background=hColor;
		div.style.color="#990000";
		div.className = name+' m_lv1_over';
	}
	return false;
}

function OutLv1Menu(div,name,hColor){	
	if(div)
	{
		div.className = name;
		div.style.background=hColor;
		div.style.color="#222222";
	}
	return false;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
