﻿String.prototype.trim = function()  
{  
	return this.replace(/(^\s*)|(\s*$)/g, "");  
}
function J(val)
{
    return document.getElementById(val);
}
function WinOpen(url,n,w,h)
{
        var left = (screen.width-w)/2;
        var top = (screen.height-h)/2;
        var f = "width="+w+",height="+h+",top="+top+",left="+left;
        var c = window.open(url,n,f);
        return c; 
}
function WinOpenDialog(url,w,h)
{
    var feature = "dialogWidth:"+w+"px;dialogHeight:"+h+"px;center:yes;status:no;help:no";
    showModalDialog(url,window,feature);
}
function showlist(path,chId,fieldName,fieldValue,_target)
{
    var encodeValue = escape(fieldValue);
    if(_target.toLowerCase()=='blank') 
    window.open(path+'/list.aspx?chid='+chId+'&fieldname='+fieldName+'&keyword='+encodeValue);
    else
    location.href(path+'/list.aspx?chid='+chId+'&fieldname='+fieldName+'&keyword='+encodeValue);  
}
function ReviewPadding(appPath,modelType,id,pageSize,pageIndex)
{
    var data = XmlHttpGetMethodText(appPath + "/sys_template/MoreReviewList.aspx?ModelType=" + modelType + "&Id=" + id + "&PageSize=" + pageSize + "&P=" + pageIndex);
    document.getElementById('review_morelist_' + modelType + '_' + id).innerHTML=data
}

function SetSearchField(appPath,val)
{
    if(val.value!=0)
   { 
        document.getElementById("src_field_list").src=appPath+"/common/getsearchform.aspx?id="+val.value+"&flag=1"
   }
   else
   {
         document.getElementById("src_field_list").src=appPath+"/common/getsearchform.aspx?id="+val.value+"&flag=0"
   } 
}
function GoSearch(appPath)
{
   var chid = document.getElementById("search_channel_list").value;
   //var fieldName =  document.getElementById("search_field_list").value;
   var keyword = document.getElementById("search_txt_keyword").value.trim();
   if(keyword.length==0)
   {
        alert('搜索内容必须填写');
        return;
   }
//   if(chid!=0&&fieldName!=0)
//   {
//        window.open(appPath+"/List.aspx?chid="+chid+"&fieldname="+fieldName+"&keyword="+escape(keyword)+"&Search=1");
    //   }
    if (chid != 0) {
        window.open(appPath + "/search.aspx?chid=" + chid + "&keyword=" + escape(keyword) + "&Search=1");
    }
   else
   {
        alert("请选择频道");
   }
}
function CheckNumber(val)
{
   var patt=/^\d+$/;
   return patt.test(val) ;
}
function go(f_url,pc,colid)
{
    var pi = J("txtPageNav"+colid).value;
    if(!CheckNumber(pi)) 
    {
        alert('页索引只能是数字'); 
        return; 
    }  
    if(pi<1||pi>pc)
    { 
        alert("页索引超出范围") ;
        return; 
     } 
     if(pi==1) 
    { 
        location.href(f_url) ;
        return; 
     } 
     var charindex = f_url.lastIndexOf(".")
     var preStr = f_url.substr(0,charindex);
     var ext = f_url.substr(charindex,f_url.length-charindex);
     var patt = /.*(\..*?)\?.*/i
     if(f_url.replace(patt,"$1").toLowerCase()!=".aspx") 
     {     
            location.href(preStr+"_"+pi+ext);
     } 
     else
     {
            location.href(f_url.setQuery("p",pi));
     }   
}
 String.prototype.setQuery   =   function(name,   value)   
  {   
      var   reg   =   new   RegExp("(^|&|\\?)("+   name   +"=)([^&]*)(&|$)");   
      var   r   =   this.substr(this.indexOf("?")+1).match(reg);   
      if   (r!=null)   return   this.replace(reg,   "$1$2"+   value   +"$4");   
      else   return   this   +   (this.indexOf("?")>-1   ?   "&"   :   "?")+   name   +"="+   value   
  }   
function SetDig(appPath,modelid,id)
{

    if( J("dig_"+modelid+"_"+id)!=null&&J("click_dig_"+modelid+"_"+id)!=null)
    { 
   var loadstr =   '<img src="'+appPath+'/images/dig_loading.gif">' 

        J("click_dig_"+modelid+"_"+id).innerHTML = loadstr;

    var data = XmlHttpGetMethodText(appPath+"/common/dig.aspx?type=set&modelid="+modelid+"&id="+id); 
         if(data!="-1") 
           { 
                J("dig_"+modelid+"_"+id).innerHTML=data;
           } 
       J("click_dig_"+modelid+"_"+id).innerHTML="成&nbsp;&nbsp;功";
        J("click_dig_"+modelid+"_"+id).style.removeAttribute("cursor");
        J("click_dig_"+modelid+"_"+id).removeAttribute("onclick"); 
     } 
    return false; 
}



function SuperLabelPage(PagePath,CaseId)
{
    var data = XmlHttpGetMethodText(PagePath);
    document.getElementById(CaseId).innerHTML=data;
}

function GetAjaxLabel(url,paramStr,currId,type)
{
    
     var data = XmlHttpPostMethodText(url,"paramStr="+paramStr+"&currId="+currId+"&type="+type)
     document.write(data) ;
}

function GetHiddenContent(url,paramStr,infoId,pageIndex,pageCount,tableName)
{
    var data = XmlHttpPostMethodText(url,"paramstr="+paramStr+"&id="+infoId+"&pageindex="+pageIndex+"&pagecount="+pageCount+"&tablename="+tableName);
     document.write(data) ;
}


function setTab(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
}

function changeTab(index) {
    for (var i = 1; i <= 3; i++) {
        document.getElementById("li_" + i).className = "normal";
        document.getElementById("li_" + index).className = "selected";
        document.getElementById("div" + i).style.display = "none";
    }
    document.getElementById("div" + index).style.display = "block";
}


//==========================设为首页加入收藏JS函数开始===============================
//调用加入收藏addBookmark(document.title)
function addBookmark(title) {
    var url = parent.location.href;
    try {
        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;
        }
    } catch (e) {
        alert("加入收藏失败！请手动Ctrl+D添加。");
    }
}
//调用设为首页SetHome(this,window.location)
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    catch (e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("抱歉！您的浏览器不支持直接设为首页。请手动设置");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}
//==========================设为首页加入收藏JS函数结束===============================

window.onload = function(){ 
    document.body.oncopy= function(){return false;}  
}
function  Click(){ window.event.returnValue=false; } 
    document.oncontextmenu=Click;
