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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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];}
}

/* This function is used to change the style class of an element */
function swapClass(obj, newStyle) {
    obj.className = newStyle;
}

function isUndefined(value) {
    var undef;
    return value == undef;
}

/* Function for showing and hiding elements that use 'display:none' to hide */
function toggleDisplay(targetId)
{
    if (document.getElementById) {
        target = document.getElementById(targetId);
      if (target.style.display == "none"){
        target.style.display = "";
      } else {
        target.style.display = "none";
      }
    }
}

// toggle visibility
function toggleVisibility(targetId) {
    if (document.getElementById) {
        target = document.getElementById(targetId);
      if (target.style.visibility == "hidden"){
        target.style.visibility = "visible";
      } else {
        target.style.visibility = "hidden";
      }
    }
}

function checkAll(theForm) { // check all the checkboxes in the list
  for (var i=0;i<theForm.elements.length;i++) {
    var e = theForm.elements[i];
    var eName = e.name;
      if (eName != 'allbox' &&
            (e.type.indexOf("checkbox") == 0)) {
          e.checked = theForm.allbox.checked;
    }
  }
}

/* Function to clear a form of all it's values */
function clearForm(frmObj) {
  for (var i = 0; i < frmObj.length; i++) {
        var element = frmObj.elements[i];
    if(element.type.indexOf("text") == 0 ||
        element.type.indexOf("password") == 0) {
          element.value="";
    } else if (element.type.indexOf("radio") == 0) {
      element.checked=false;
    } else if (element.type.indexOf("checkbox") == 0) {
      element.checked = false;
    } else if (element.type.indexOf("select") == 0) {
      for(var j = 0; j < element.length ; j++) {
        element.options[j].selected=false;
      }
            element.options[0].selected=true;
    }
  }
}

/*  This function is to select all options in a multi-valued <select> */
function selectAll(elementId) {
    var element = document.getElementById(elementId);
  len = element.length;
  if (len != 0) {
    for (i = 0; i < len; i++) {
      element.options[i].selected = true;
    }
  }
}

/* This function is used to select a checkbox by passing
 * in the checkbox id
 */
function toggleChoice(elementId) {
    var element = document.getElementById(elementId);
    if (element.checked) {
        element.checked = false;
    } else {
        element.checked = true;
    }
}

/* This function is used to select a radio button by passing
 * in the radio button id and index you want to select
 */
function toggleRadio(elementId, index) {
    var element = document.getElementsByName(elementId)[index];
    element.checked = true;
}


/* This function is used to open a pop-up window */
function openWindow(url, winTitle, winParams) {
  winName = window.open(url, winTitle, winParams);
    winName.focus();
}

function showHelp(url)
{
  var w = 800;
  var h = 600;
  var x = (screen.width - w)/2;
  var y = (screen.height - h)/2;
  var helpWin = window.open(url, "help",
    "resizable=yes,menubar=no,scrollbars=yes,status=no,width="+w+",height="+h+",top="+y+",left="+x);
  helpWin.focus();
}

function showTipsHelp(url)
{
  var w = 300;
  var h = 200;
  var x = (screen.width - w)/2;
  var y = (screen.height - h)/2;
  var helpWin = window.open(url, "help",
    "resizable=yes,menubar=no,scrollbars=yes,status=no,width="+w+",height="+h+",top="+y+",left="+x);
  helpWin.focus();
}


/* This function is to open search results in a pop-up window */
function openSearch(url, winTitle) {
    var screenWidth = parseInt(screen.availWidth);
    var screenHeight = parseInt(screen.availHeight);

    var winParams = "width=" + screenWidth + ",height=" + screenHeight;
        winParams += ",left=0,top=0,toolbar,scrollbars,resizable,status=yes";

    openWindow(url, winTitle, winParams);
}

/* This function is used to set cookies */
function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

/* This function is used to get cookies */
function getCookie(name) {
  var prefix = name + "="
  var start = document.cookie.indexOf(prefix)

  if (start==-1) {
    return null;
  }

  var end = document.cookie.indexOf(";", start+prefix.length)
  if (end==-1) {
    end=document.cookie.length;
  }

  var value=document.cookie.substring(start+prefix.length, end)
  return unescape(value);
}

/* This function is used to delete cookies */
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// This function is for stripping leading and trailing spaces
function trim(str) {
    if (str != null) {
        var i;
        for (i=0; i<str.length; i++) {
            if (str.charAt(i)!=" ") {
                str=str.substring(i,str.length);
                break;
            }
        }

        for (i=str.length-1; i>=0; i--) {
            if (str.charAt(i)!=" ") {
                str=str.substring(0,i+1);
                break;
            }
        }

        if (str.charAt(0)==" ") {
            return "";
        } else {
            return str;
        }
    }
}

function confirmDelete(obj) {
    var msg = "Are you sure to delete " + obj + "?";
    ans = confirm(msg);
    if (ans) {
        return true;
    } else {
        return false;
    }
}

function highlightTableRows(tableId) {
    var previousClass = null;
    var table = document.getElementById(tableId);
    var tbody = table.getElementsByTagName("tbody")[0];
    if (tbody == null) {
        var rows = table.getElementsByTagName("tr");
    } else {
        var rows = tbody.getElementsByTagName("tr");
    }
    // add event handlers so rows light up and are clickable
    for (i=0; i < rows.length; i++) {
        rows[i].onmouseover = function() { previousClass=this.className;this.className+=' over' };
        rows[i].onmouseout = function() { this.className=previousClass };
        rows[i].onclick = function() {
            var cell = this.getElementsByTagName("td")[0];
            var link = cell.getElementsByTagName("a")[0];
            location.href = link.getAttribute("href");
            this.style.cursor="wait";
        }
    }
}

function highlightFormElements() {
    // add input box highlighting
    //addFocusHandlers(document.getElementsByTagName("input"));
    //addFocusHandlers(document.getElementsByTagName("textarea"));
}

function addFocusHandlers(elements) {
    for (i=0; i < elements.length; i++) {
        if (elements[i].type != "button" && elements[i].type != "submit" &&
            elements[i].type != "reset" && elements[i].type != "checkbox") {
            elements[i].onfocus=function() {this.className='focus';this.select()};
            elements[i].onclick=function() {this.select()};
            elements[i].onblur=function() {this.className=''};
        }
    }
}

function radio(clicked){
    var form = clicked.form;
    var checkboxes = form.elements[clicked.name];
    if (!clicked.checked || !checkboxes.length) {
        clicked.parentNode.parentNode.className="";
        return false;
    }

    for (i=0; i<checkboxes.length; i++) {
        if (checkboxes[i] != clicked) {
            checkboxes[i].checked=false;
            checkboxes[i].parentNode.parentNode.className="";
        }
    }

    // highlight the row
    clicked.parentNode.parentNode.className="over";
}

window.onload = function() {
    highlightFormElements();
    /* Commented out b/c causes stack trace with Canoo WebTest
       http://lists.canoo.com/pipermail/webtest/2005q3/004493.html
    if ($('successMessages'))
        new Effect.Highlight('successMessages', {startcolor: '#ffff00', endcolor: '#ffffcc'});
    if ($('errorMessages'))
        new Effect.Highlight('errorMessages', {startcolor: '#ffff00', endcolor: '#ffffcc'});
    */
}

// Show the document's title on the status bar
window.defaultStatus=document.title;
String.prototype.Trim = function(){
  return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.Ltrim = function(){
  return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function(){
  return this.replace(/(\s*$)/g, "");
}
// lower case
String.prototype.trim = function(){
  return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function(){
  return this.replace(/(^\s*)/g, "");
}
String.prototype.ltrim = function(){
  return this.replace(/(\s*$)/g, "");
}

function numToDate(obj) { // convert yyyyMMdd to yyyy-MM-dd
  var ori = obj.value;
  if (ori.length != 8) return;
  obj.value = ori.substr(0, 4) + "-" + ori.substr(4, 2) + "-" + ori.substr(6, 2);
}

function setEnterAsTab() {
  if (event.keyCode != 13) return;
  var field = event.srcElement;
  if (field.type == "text") {
    event.keyCode = 9;
  }
}

// Check Chinese date input
function isDateString(sDate)
{    var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
    var iaDate = new Array(3)
    var year, month, day

    if (arguments.length != 1) return false
    iaDate = sDate.toString().split("-")
    if (iaDate.length != 3) return false
    if (iaDate[1].length > 2 || iaDate[2].length > 2) return false

    year = parseFloat(iaDate[0])
    month = parseFloat(iaDate[1])
    day=parseFloat(iaDate[2])

    if (year < 1900 || year > 2100) return false
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
    if (month < 1 || month > 12) return false
    if (day < 1 || day > iaMonthDays[month - 1]) return false
    return true
}

// 计算输入字数并提示-一个汉字算一个字符
function count(id){
  return alert("现已输入" + document.getElementById(id).value.length + "个字！")
}
// 计算输入字数并提示-一个汉字算两个字符
function count1(id){
  return alert("现已输入" + textLength1(document.getElementById(id).value) + "个字！")
}

// 过滤关键字
function filterkey(field){
	var fieldObject = eval("document.forms[0]." + field);
	if(fieldObject){
		var key = new Array();
		var val = fieldObject.value;
key[0] = "小电影";
key[1] = "法轮";
key[2] = "falun";
key[3] = "falundafa";
key[4] = "zhuanfalu";
key[5] = "六四";
key[6] = "民运";
key[7] = "dafa";
key[8] = "唐人电视台";
key[9] = "大法";
key[10] = "新唐人电视台";
key[11] = "李洪志";
key[12] = "转法轮";
key[13] = "共铲党";
key[14] = "六合彩";
key[15] = "六合采";
key[16] = "共铲党";
key[17] = "九评";
key[18] = "九评共产党";
key[19] = "人民报";
key[20] = "退党";
key[21] = "明慧";
key[22] = "明慧网";
key[23] = "大纪元";
key[24] = "大 纪元";
key[25] = "退党";
key[26] = "六四";
key[27] = "天安门事件";
key[28] = "自由亚州";
key[29] = "无界浏览";
key[30] = "极景";
key[31] = "无界";
key[32] = "无网界浏览";
key[33] = "无网界";
key[34] = "美国之音";
key[35] = "自由亚洲";
key[36] = "色情网站";
key[37] = "色情";
key[38] = "情色";
key[39] = "口交";
key[40] = "阴茎";
key[41] = "阴毛";
key[42] = "性虐待";
key[43] = "黄色网站";
key[44] = "成人网站";
key[45] = "成人小说";
key[46] = "成人文学";
key[47] = "成人电影";
key[48] = "性免费电影";
key[49] = "成人影视";
key[50] = "黄色电影";
key[51] = "黄色影视";
key[52] = "黄色小说";
key[53] = "黄色文学";
key[54] = "成人图片";
key[55] = "黄色图片";
key[56] = "黄色漫画";
key[57] = "成人漫画";
key[58] = "成人电影";
key[59] = "三级片";
key[60] = "黄色电影";
key[61] = "坐台";
key[62] = "应召";
key[63] = "应招";
key[64] = "妓女";
key[65] = "成人论坛";
key[66] = "手机铃声下载";
key[67] = "铃声下载";
key[68] = "手机铃声";
key[69] = "和弦";
key[70] = "手机游戏";

key[71] = "男性";
key[72] = "女性";
key[73] = "薪酬面议";

		for (i = 0; i < key.length; i++){
			val = val.replace(key[i],"***");
		}
		fieldObject.value = val;
	}
}

