var floatad = floatad || {}
floatad.automove = function automove(id) {
 var xPos = 300;
 var yPos = 200;
 var step = 1;
 var delay = 30;
 var width = document.body.clientWidth;
 var height = document.body.clientHeight;
 var Hoffset = 0;
 var Woffset = 0;
 var yon = 0;
 var xon = 0;
 var pause = true;
 var interval;
 var img1=document.getElementById(id);
 img1.style.top = yPos;

 function changePos()
 {
  Hoffset = img1.offsetHeight;
  Woffset = img1.offsetWidth;
  img1.style.left = xPos + document.body.scrollLeft;
  img1.style.top = yPos + document.body.scrollTop;
  if (yon)
  {
   yPos = yPos + step;
  }
  else
  {
   yPos = yPos - step;
  }
  if (yPos < 0)
  {
   yon = 1;yPos = 0;
  }
  if (yPos >= (height - Hoffset))
  {
   yon = 0;yPos = (height - Hoffset);
  }
  if (xon)
  {
   xPos = xPos + step;
  }
  else
  {
   xPos = xPos - step;
  }
  if (xPos < 0)
  {
   xon = 1;xPos = 0;
  }
  if (xPos >= (width - Woffset))
  {
   xon = 0;xPos = (width - Woffset);
  }
 }

 function start()
 {
  if(interval == null) {
   img1.visibility = "visible";
   interval = setInterval(changePos, delay);
  }
 }
 function pauseit()
 {
  if(pause)
  {
   clearInterval(interval);
   pause = false;
  }
 }
 function resumeit()
 {
  if(!pause)
  {
   interval = setInterval(changePos,delay);
   pause = true;
  }
 }
 function pause_resume()
 {
  if(pause)
  {
   clearInterval(interval);
   pause = false;
  }
  else
  {
   interval = setInterval(changePos,delay);
   pause = true;
  }
 }
 start();
 img1.onmouseover = function() {pauseit();}
 img1.onmouseout = function() {resumeit();}
}
function hide(id) {
	var e = document.getElementById(id);
    e.style.display = 'none';
}
function setMenuListSize(menubarId,width) {
 var menubar=document.getElementById(menubarId);
 var menulist = menubar.getElementsByTagName("ul")[0];
 var style = "width:" + menulist.children.length * width + "px;";
 menulist.setAttribute('style', style);
 menulist.style.width = menulist.children.length * width;
}
function autoSizeImg(id, maxWidth, maxHeight) {
 var abc=document.getElementById(id);
 var imgs=abc.getElementsByTagName("img");
 for (var i=0,g;g=imgs[i];i++)
  g.onload=function(){
   if (this.width>maxWidth){
    this.width=maxWidth
   }else{
    if (this.height>maxHeight)
     this.height=maxHeight
   }
  }
}
function enableDropDownMenu(id) {
 var handler = attachDropDownMenuHandler(id);
 //if (window.attachEvent) window.attachEvent("onload", handler);
}
function attachDropDownMenuHandler(id) {
   var sfEls = document.getElementById(id).getElementsByTagName("LI");
   for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
     this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
     this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
   }
}
function switchTab(id,num,count)
{
  ClearTabClass(id,count);
  document.getElementById("tabname_" + id + num).className = "tabf";
  var box = document.getElementById(id + num);
  if(typeof box !== "undefined") {
    box.style.display = "";
  }
}
function swicthTab(id,num,count)
{
  ClearTabClass(id,count);
  document.getElementById("tabname_" + id + num).className = "tabf";
  var box = document.getElementById(id + num);
  if(typeof box !== "undefined") {
    box.style.display = "";
  }
}
function ClearTabClass(id,count)
{
  for(i=1;i<=count;i++)
  {
    document.getElementById("tabname_" + id + i).className = "tabn";
    var box = document.getElementById(""+id + i);
    if(typeof box !== "undefined") {
      box.style.display = "none";
     }
  }
}
var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
    
}
/**
 * util
 */
var util = util || {}
util.applySelectOptionColor = function applySelectOptionColor(id) {
  var select = document.getElementById(id);
  var nodes = select.children;
  var color;
  var option;
  var i;
  for(i=1; i<nodes.length; i++) {
    option = nodes[i];
    color = option.value;
    style = 'background:'+color+'; color:'+color+';';
    option.setAttribute('style', style);
    option.style.cssText = style;
  }
}
util.applySelectOptionFont = function applySelectOptionFont(id) {
  var select = document.getElementById(id);
  var nodes = select.children;
  var fontFamily;
  var option;
  var i;
  for(i=1; i<nodes.length; i++) {
    option = nodes[i];
    fontFamily = option.value;
    style = 'font-family:'+fontFamily;
    option.setAttribute('style', style);
    option.style.cssText = style;
  }
}
util.changeStyle = function changeStyle(id, colorSelectId, fontSelectId) {
  var colorSelect = document.getElementById(colorSelectId);
  var fontSelect = document.getElementById(fontSelectId);
  var color = colorSelect.options[colorSelect.selectedIndex].value;
  var fontFamily = fontSelect.options[fontSelect.selectedIndex].value;
  var style = 'color:'+color + '; font-family:'+fontFamily;
  var element = document.getElementById(id);
  element.setAttribute('style', style);
  element.style.cssText = style;
}
/**
 * focus photo
 */
var focusPhoto = focusPhoto || {};
focusPhoto.n=0;
focusPhoto.autoStart;

focusPhoto.setBg = function setBg(value){
  for(var i=0;i<5;i++)
    document.getElementById("t"+i+"").className="bbg0";
  document.getElementById("t"+value+"").className="bbg1";
};
focusPhoto.plays = function plays(value){
  try
  {
    with (au){
      filters[0].Apply();
      for(i=0;i<5;i++)i==value?children[i].style.display="block":children[i].style.display="none";
      filters[0].play();
      }
  }
  catch(e)
  {
    var d = document.getElementById("au").getElementsByTagName("div");
    for(i=0;i<5;i++)i==value?d[i].style.display="block":d[i].style.display="none";
  }
};
focusPhoto.conaus = function conaus(value){
  try
  {
    with (conau){

      for(i=0;i<5;i++)i==value?children[i].style.display="block":children[i].style.display="none";

      }
  }
  catch(e)
  {
    var d = document.getElementById("conau").getElementsByTagName("div");
    for(i=0;i<5;i++)i==value?d[i].style.display="block":d[i].style.display="none";
  }
};
focusPhoto.Mea = function Mea(value){
  focusPhoto.n=value;
  focusPhoto.setBg(value);
  focusPhoto.plays(value);
  focusPhoto.conaus(value);
};
focusPhoto.clearAuto = function clearAuto(){
  clearInterval(focusPhoto.autoStart)
};
focusPhoto.setAuto = function setAuto(){
  focusPhoto.autoStart=setInterval("focusPhoto.auto()", 3000)
};
focusPhoto.auto = function auto(){
  var n = focusPhoto.n;
  n++;
  if(n>4)n=0;
  focusPhoto.Mea(n);
  focusPhoto.conaus(n);
  focusPhoto.n = n;
};

/**
 * marquee
 * 速度数值越大速度越慢
 */
var marquee = marquee || {};
marquee.startHorizontal= function startHorizontal(boxId, box1Id, box2Id, speed) {
  if(speed === null || typeof speed === "undefined") {
    speed = 25;
  }
  var box = document.getElementById(boxId);
  var box1 = document.getElementById(box1Id);
  var box2 = document.getElementById(box2Id);
  box2.innerHTML=box1.innerHTML;
  function Marquee(){
    if(box2.offsetWidth-box.scrollLeft<=0)
      box.scrollLeft-=box1.offsetWidth;
    else{
      box.scrollLeft++;
    }
  }
  var MyMar=setInterval(Marquee,speed);
  box.onmouseover=function() {
    clearInterval(MyMar);
  }
  box.onmouseout=function() {
    MyMar=setInterval(Marquee,speed);
  }
}
marquee.startVertical = function startVertical(boxId, box1Id, box2Id, speed) {
  if(speed === null || typeof speed === "undefined") {
    speed = 100;
  }
  var box = document.getElementById(boxId);
  var box1 = document.getElementById(box1Id);
  var box2 = document.getElementById(box2Id);
  box2.innerHTML=box1.innerHTML;
  function Marquee(){
    if(box2.offsetTop-box.scrollTop<=0)
      box.scrollTop-=box1.offsetHeight;
    else{
      box.scrollTop++;
    }
  }
  var MyMar=setInterval(Marquee,speed);
  box.onmouseover=function() {
    clearInterval(MyMar);
  }
  box.onmouseout=function() {
    MyMar=setInterval(Marquee,speed);
  }
}
/**
 * theme
 */
var theme = theme || {};
theme.cookieName = 'theme';
theme.linkId = 'link';
theme.selectId = 'select';
theme.resetTheme = function resetTheme() {
  var select = document.getElementById(theme.selectId);
  select.selectedIndex = 0;
  theme.selectTheme();
};
theme.applyTheme = function applyTheme() {
  var t = cookie.readCookie(theme.cookieName);
  if(t === null || typeof t === "undefined") {
    return;
  }
  var link = document.getElementById(theme.linkId);
  link.href='../'+t+'/style.css';
};
theme.adjustSelect = function adjustSelect() {
  var t = cookie.readCookie(theme.cookieName);
  if(t === null || typeof t === "undefined") {
    return;
  }
  var select = document.getElementById(theme.selectId);
  for(var i =0; i<select.length; i++) {
    var option = select.options[i];
    if(option.value == t) {
      option.selected = true;
    }
  }
}
theme.selectTheme = function selectTheme() {
  var select = document.getElementById(theme.selectId);
  var t = select.options[select.selectedIndex].value;
  cookie.createCookie(theme.cookieName, t, 365);
  theme.applyTheme();
}
/**
 * cookie function
 * http://www.quirksmode.org/js/cookies.html
 */
var cookie = cookie || {};
cookie.createCookie = function createCookie(name,value,days) {
  var expires;
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    expires = "; expires="+date.toGMTString();
  }
  else  {
    expires = "";
  }
  document.cookie = name+"="+value+expires+"; path=/";
}

cookie.readCookie = function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

cookie.eraseCookie = function eraseCookie(name) {
  cookie.createCookie(name,"",-1);
}

/**
 * plain, simple, advance
 * editor
 */
function initEditor(t,id,lan) {
 initEditor2(t,id,lan,"TINYMCE");
}
function initEditor2(t,id,lan,editorType) {
 if(t === null || typeof t === "undefined" || t == "plain") {
  return;
 }
 if(editorType == "TINYMCE") {
  if(t == "simple") {
   tinyMCE.init({
    //mode : "textareas",
    mode : "exact",
    elements : id,
    theme : "simple",
    language : lan,
    debug : false
   });
   return;
  }
  if(t == "simple2") {
   tinyMCE.init({
    //mode : "textareas",
    mode : "exact",
    elements : id,
    theme : "advanced",
    language : lan,
    plugins : "paste",
    theme_advanced_buttons1_add_before : "fontselect,fontsizeselect,separator,forecolor,backcolor",
    theme_advanced_buttons2_add_before : "pastetext,pasteword,selectall",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_disable: "styleselect",
    paste_auto_cleanup_on_paste : true,
    paste_retain_style_properties: "text-indent,font-size,color",
    debug : false
   });
  }
  if(t == "advance") {
   tinyMCE.init({
    //mode : "textareas",
    mode : "exact",
    elements : id,
    theme : "advanced",
    language : lan,
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    extended_valid_elements : "a[href|target|name]",
    plugins : "table,media,paste",
    theme_advanced_buttons1_add_before : "fontselect,fontsizeselect,separator,forecolor,backcolor",
    theme_advanced_buttons2_add_before : "pastetext,pasteword,selectall",
    theme_advanced_buttons3_add_before : "tablecontrols,separator",
    theme_advanced_buttons3_add : "media",
    paste_auto_cleanup_on_paste : true,
   paste_retain_style_properties: "text-indent,font-size,color",
   //invalid_elements : "a",
   //theme_advanced_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1", // Theme specific setting CSS classes
   theme_advanced_disable: "styleselect",
   debug : false,
   media_wmp6_compatible : true
  });
  return;
 }
 } else if(editorType == "CKEDITOR") {
  CKEDITOR.replace(id,
   {language : lan}
   );
 }
}

function jmpURLonSelect(select) {
 var jmpURL=select.options[select.selectedIndex].value;
 if(jmpURL === null || typeof jmpURL === "undefined") {
  return;
 } else {
  window.open(jmpURL);
  select.selectedIndex=0;
 }
}
function changeImgOnSelectById(selectid,imgid) {
  var select = document.getElementById(selectid);
  changeImgOnSelect(select,imgid);
}
function changeImgOnSelect(select,imgid) {
  var imgUrl = select.options[select.selectedIndex].value;
  if(imgUrl === null || typeof imgUrl === "undefined") {
    return;
  } else {
    var box = document.getElementById(imgid);
    box.src = imgUrl;
  }
}
function navImgOfSelect(selectid,imgid,next) {
  var select = document.getElementById(selectid);
  var index = 0;
  for(var i =0; i<select.length; i++) {
    var option = select.options[i];
    if(option.selected) {
      index = i;
      option.selected = false;
    }
  }
  if(next) {
    index++;
    if(index >= select.length) {
      index = 0;
    }
  } else {
    index--;
    if(index < 0) {
      index = select.length-1;
    }
  }
  select.options[index].selected = true;
  changeImgOnSelect(select, imgid);
}
// common JavaScript functions
/* ---------------- Common basic type operations/ --------------- */
// serial of functions to trim string
var whitespace = " \t\n\r";

function charInString (c, s)
{
  for (i = 0; i < s.length; i++)

  {
    if (s.charAt(i) == c) return true;
  }
  return false
}

function stripInitialWhitespace (s)
{
  var i = 0;

  while ((i < s.length) && charInString (s.charAt(i), whitespace))
    i++;

  return s.substring (i, s.length);
}

function stripEndingWhitespace (s)
{
  var i = s.length - 1;

  while ((i > 0) && charInString (s.charAt(i), whitespace))
    i--;

  return s.substring (0, i+1);
}

function trimString (s)
{
  return stripEndingWhitespace ( stripInitialWhitespace (s) );

}

// function to check E-mail address like string
function isEmail (s)
{
  // there must be >= 1 character before @, so we
  // start looking at character position 1
  // (i.e. second character)
  var i = 1;
  var sLength = s.length;

  if ( sLength <= 1 ) return false ;

  // look for @
  while ((i < sLength) && (s.charAt(i) != "@"))
  {
    i++
  }

  if ((i >= sLength) || (s.charAt(i) != "@")) return false;
  else i += 2;

  // look for .
  while ((i < sLength) && (s.charAt(i) != "."))
  {
    i++
  }

  // there must be at least one character after the .
  if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
  else return true;
}

// function to check IP Address like string
function isIPAddress ( strIPAddress )
{
  regExp = new RegExp ( "([0-9]{1,3})[\.]{1,}([0-9]{1,3})[\.]{1,}([0-9]{1,3})[\.]{1,}([0-9]{1,3})" ) ;
  aParts = regExp.exec ( strIPAddress ) ;
  if ( aParts == null )
  {
    return false ;
  }

  if ( aParts.length != 5 )
  {
    return false ;
  }

  for ( nLoopCnt = 1 ; nLoopCnt < 5 ; nLoopCnt ++ )
  {
    if ( aParts [ nLoopCnt ] < 0 || aParts [ nLoopCnt ] > 255 )
    {
      return false ;
    }
  }

  return true ;
}

// function to check login name like string
function fn_CheckLoginName ( strLogin )
{
  strLogin = trimString( strLogin ) ;

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._";
  var checkStr = strLogin ;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if ( ! allValid )
  {
    return (false);
  }

  if ( checkStr.charAt(0) == '-' || checkStr.charAt(0) == '.' || checkStr.charAt(0) == '_' )
  {
    return (false);
  }

  return (true);
}

// function to check Domain name like string
function fn_CheckDomainName ( strDomainName )
{
  strDomainName = trimString ( strDomainName ) ;

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
  var checkStr = strDomainName;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }

  if ( checkStr.charAt(0) == '-' || checkStr.charAt(0) == '.' )
  {
    return (false);
  }

  return (true);
}

// function to check year, month, day numbers
function fn_ValidateDate ( nYear , nMonth , nDay )
{
  if ( nMonth < 1 || nMonth > 12 ) return false ;
  if ( nDay < 1 || nDay > 31 ) return false ;
  if ( nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11 )
  {
    if ( nDay > 30 ) return false ;
  }
  if ( nMonth == 2 )
  {
    if ( nYear % 4 == 0 )
    {
      if ( nYear % 100 == 0 )
      {
        if ( nYear % 400 == 0 )
        {
          if ( nDay > 29 ) return false ;
        }
        else
        {
          if ( nDay > 28 ) return false ;
        }
      }
      else
      {
        if ( nDay > 29 ) return false ;
      }
    }
    else
    {
      if ( nDay > 28 ) return false ;
    }
  }

  return true ;
}

/* ---------------- /Common basic type operations --------------- */
var ad = ad || {}
ad.autohide = function autohide(id,height) {
  var time = 600;
    var h = 0;
	if(typeof height === "undefined") {
		height = 500;
	}
	var element = document.getElementById(id);
    function addCount()
    {
        if(time>0)
        {
            time--;
            h = h+5;
        }
        else
        {
            return;
        }
        if(h>height)  //高度
        {
            return;
        }
        element.style.display = "";
        element.style.height = h+"px";
        setTimeout(addCount,30); 
    }
    
    window.onload = function showAds()
    {
        addCount();
        setTimeout(noneAds,7000); //停留时间自己适当调整
    }

	
    var T = 600;
    var N = height; //高度
    function noneAds()
    {
        if(T>0)
        {
            T--;
            N = N-5;
        }
        else
        {
            return;
        }
        if(N<0)
        {
            element.style.display = "none";
            return;
        }
        
        element.style.height = N+"px";
        setTimeout(noneAds,30); 
    }
	}
