﻿String.prototype.trim = function()  
{  
	return this.replace(/(^\s*)|(\s*$)/g, "");  
}
function $(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");
   }
   else
   {
        alert("频道和字段必须选择");
   }
}
function CheckNumber(val)
{
   var patt=/^\d+$/;
   return patt.test(val) ;
}
function go(f_url,pc,colid)
{
    var pi = $("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( $("dig_"+modelid+"_"+id)!=null&&$("click_dig_"+modelid+"_"+id)!=null)
    { 
   var loadstr =   '<img src="'+appPath+'/images/dig_loading.gif">' 

        $("click_dig_"+modelid+"_"+id).innerHTML = loadstr;

    var data = XmlHttpGetMethodText(appPath+"/common/dig.aspx?type=set&modelid="+modelid+"&id="+id); 
         if(data!="-1") 
           { 
                $("dig_"+modelid+"_"+id).innerHTML=data;
           } 
       $("click_dig_"+modelid+"_"+id).innerHTML="成&nbsp;&nbsp;功";
        $("click_dig_"+modelid+"_"+id).style.removeAttribute("cursor");
        $("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 GetOffsetTop (el, p) {
    var _t = el.offsetTop;
    var _p = el.offsetParent;

    while (_p) {
        if (_p == p) break;
        _t += _p.offsetTop;
        _p = _p.offsetParent;
    }

    return _t;
};
function GetOffsetLeft (el, p) {
    var _l = el.offsetLeft;
    var _p = el.offsetParent;

    while (_p) {
        if (_p == p) break;
        _l += _p.offsetLeft;
        _p = _p.offsetParent;
    }

    return _l;
};

function fod(obj,name)
		{
			var p = obj.parentNode.getElementsByTagName("div");
			var p1 = document.getElementById(name).getElementsByTagName("div");
			for(i=0;i<p1.length;i++)
			{
				if(obj==p[i])
				{
					p[i].className = "s1";
					p1[i].className = "up";
				}
				else
				{
					p[i].className = "d1";
					p1[i].className = "block";
				}
			}
		}

var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddmenu(id,d){
  var h = document.getElementById('idstr'+ id);
  var c = document.getElementById(id + '-ddcontent');
  var l;
  l = GetOffsetLeft(h);
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
	  c.style.left = l +'px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
	  
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById('idstr'+ id);
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
	  c.style.display = 'block'
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
	  c.style.display = 'none'
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

function request(paras){ 
var url = location.href;   
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");   
var paraObj = {}   
for (i=0; j=paraString[i]; i++){   
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf 
("=")+1,j.length);   
}   
var returnValue = paraObj[paras.toLowerCase()];   
if(typeof(returnValue)=="undefined"){   
return "";   
}else{   
return returnValue;   
}   
} 
var theurl 
theurl=request("url"); 
if (theurl!=''){ 
location=theurl 
} 
