function $(id)
{
return document.getElementById(id);
}

function getposOffset(what, offsettype)
{ 
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop; 
    var parentEl=what.offsetParent; 
    while (parentEl!=null)
    { 
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; 
         parentEl=parentEl.offsetParent; 
    } 
    return totaloffset; 
}

function GetTop(obj)
{
 return getposOffset(obj,'top');
}
function GetLeft (obj)
{
 return getposOffset(obj,'left');
}


function getposOffset_top(what, offsettype)
{ 
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop; 
    var parentEl=what.offsetParent; 
    while (parentEl!=null)
    { 
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; 
         parentEl=parentEl.offsetParent; 
    } 
    return totaloffset; 
}

function showwindowKSW(obj,objdiv,addx,addy){
	var x=getposOffset_top(obj,'left');
    var y=getposOffset_top(obj,'top');
    var div_obj=$(objdiv);
		div_obj.style.left=(addx)+'px';
		div_obj.style.top=(addy)+'px';
		div_obj.style.display="inline";
	}
	
function Hidewindow(objdiv){
    var div_obj=$(objdiv);
		if(div_obj){
			div_obj.style.display="none";
		}
	}	


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


/*灰色背景 开始*/
function highlightRows() {
  if(!document.getElementById) return false;
  if(!document.getElementsByTagName) return false;
  
  var change_bg=document.getElementById("bg_gray");
  var rows = change_bg.getElementsByTagName("tr");
  
  for (var i=0; i<rows.length; i++) {
  	 
    rows[i].onmouseover = function() {
	  this.style.background = "#fafafa";
    }
    rows[i].onmouseout = function() {
	  this.style.background = "#fff";
    }

  }
}
addLoadEvent(highlightRows);



/*灰色背景 结束*/

/*白色背景 开始*/
function highlightwhite() {
  if(!document.getElementById) return false;
  if(!document.getElementsByTagName) return false;
  
  var change_bg=document.getElementById("bg_white");
  var rows = change_bg.getElementsByTagName("tr");
  
  for (var i=0; i<rows.length; i++) {
  	 
    rows[i].onmouseover = function() {
	  this.style.background = "#fff";
    }
    rows[i].onmouseout = function() {
	  this.style.background = "#fefbf6";
    }

  }
}
addLoadEvent(highlightwhite);



function highlightwhites() {
  if(!document.getElementById) return false;
  if(!document.getElementsByTagName) return false;
  
  var change_bg=document.getElementById("bg_whites");
  var rows = change_bg.getElementsByTagName("tr");
  
  for (var i=0; i<rows.length; i++) {
  	 
    rows[i].onmouseover = function() {
	  this.style.background = "#fff";
    }
    rows[i].onmouseout = function() {
	  this.style.background = "#f7fff4";
    }

  }
}
addLoadEvent(highlightwhites);


/*白色背景 结束*/






  
//research.js

function $(id)
{
    return document.getElementById(id);
};


function g(id)
{
     return $(id);
};
function getCookie(name) {
  var search;
  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}




function replaceHTML(data){
    return data.replace(/\</g,"");
}

function checkResearchContent(){
    if($("research_content")!=null){
        if($("research_content").value=="") return false;
        var contlen = $("research_content").value.length;
        if(contlen>500){
            $("research_result").innerHTML = "限制为500字！目前字数为"+contlen+"字";
            return false;
        }
        return true;
    }
}

var http=null;
var POST_URL="http://doc.dangdang.com/Research/PostResearch.ashx";
function postResearch(agentHandler){
    if(checkResearchContent()==false) return;

    var type = $("research_type").value;
    var content = replaceHTML($("research_content").value);
    var custId = getCookie("custid");
    var postUrl = window.location.href;	
    $("research_result").innerHTML = "提交中...";

    if(window.XMLHttpRequest) // Mozilla
    { 
        http=new XMLHttpRequest();
        if(http.overrideMimeType)
            http.overrideMimeType("text/html;");
    }
    else if(window.ActiveXObject) // IE
    {
        try
        {
            http=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                http=new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e)
            {
            }
        }
    }

	if(http==null) return;
	
    http.onreadystatechange = postResearchProcessResponse;
    http.open("POST", agentHandler, true);
    //HttpRequest.setRequestHeader("if-Modified-Since","0");
    http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); 
    try
    {
         http.send("request_url="+POST_URL+"&type="+type+"&content="+content+"&custId="+custId+"&postUrl="+postUrl);
    } catch (e)
    {
    }
}

function postResearchProcessResponse(){
    if(http!=null){
        if(http.readyState == 4){
            if(http.status != 200)
                return;

            var result = http.responseText;
            if(result == "false"){
                $("research_result").innerHTML ="提交有误！";
            }
            else{
                $("research_content").value="";
                $("research_result").innerHTML = "感谢您的反馈！";
            }
        }
    }
}

