
// 隐藏左边分类目录
function ctg_hidden(navname) {	    
	document.all(navname).style.display = "none";		
	document.all("ctg_show").style.display = "";
}
// 显示左边分类
function ctg_show(navname) {			
	document.all(navname).style.display = "";		
	document.all("ctg_show").style.display = "none";
}

// 搜索
function do_search(keyword) { 
    if (keyword == undefined || keyword == null)
        keyword = document.all("keyword").value;
     
    if (keyword == "") {
        alert("请输入网站域名或关键词后再进行查询");
        document.all("keyword").focus();
        return false;
    }  
  
    document.location.href = "../../cn_web/site/search_site.aspx?keyword=" + keyword;
    return false;
}

//在查询之前检查窗体数据
function check_search_form() {
    var keyword = document.all("keyword").value;     
    if (keyword == null || keyword == "") {
        alert("请输入网站域名或关键词后再进行查询");
        document.all("keyword").focus();
        return false;
    }
    return false;
}

// more page
function go_page(page) {
    var url = document.location.href;
    var spos = 0;
    var epos = 0;   
    //document.all.form1.curPage.value = page;     
    //document.all.form1.submit();
    
    if ((spos=url.indexOf("curPage=")) > 0) { 
      if ((epos = url.indexOf("&",spos)) < 0)
        epos = url.length;
      url = url.substr(0,spos+8) + page + url.substr(epos);
    }
    else if (url.indexOf("?") > 0)
      url = url + "&curPage=" + page;
    else
      url = url + "?curPage=" + page;
    document.location.href = url;
}

// 异步请求url
function req_url_async(url) {				
	var xmlhttp = null;			
	try	{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");	}
	catch(e) {
		try {	xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");}catch(e2){}
	}
	xmlhttp.open("GET",url,true);	
	xmlhttp.onreadystatechange=function() {
        //if (xmlhttp.readyState==4) { xmlhttp.responseText; }
        //if (xmlhttp.readyState==3) {  }
    }
    xmlhttp.send(null);
}

function checkweb(obj) {
	IPvalidate = true;
	if(/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(obj)) {
		return true;
	} else {
		IPvalidate=false;
	}

	if(/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(tw)|(hk))$/.test(obj)) {	
		return true;
	} else {
		IPvalidate=false;
	}
	
	if (IPvalidate==false) {
		return false;
	}
	
	return true;
}

//search_website()
function search_website(keyword)
{
    var searchtype = "SITE";
    if(keyword == "")
    {
        alert("请输入网站域名或关键词后再进行查询");
        return;
    }
    //alert(keyword);
    // modified by harold 2007-01-08
    //var isSite = 0;
    //if(checkweb(keyword)) isSite = 1;
    
    if (document.all("searchType")[0].checked)
        searchtype = document.all("searchType")[0].value;
    else if (document.all("searchType")[1].checked)
        searchtype = document.all("searchType")[1].value;
        
    if (searchtype == "CTG")
        document.location.href = "../../cn_web/rank/ctg_search.aspx?searchType=" + searchtype + "&keyword=" + keyword;
    else
        //document.location.href = "../../cn_web/site/search_site.aspx?isSite=" + isSite + "&keyword=" + keyword;
        document.location.href = "../../cn_web/site/search_site.aspx?searchType=" + searchtype + "&keyword=" + keyword;
    
    //return true;
}

//search_website()
function search_website1(keycode,keyword)
{
    //alert(keycode);
    if(keycode == 13)
        search_website(keyword);
    else
        return false;
}

// 切换不同的统计图表
// 完整路径: ../../chart_cache/publishcode/g/google_com_rank_6m.png
// picurl:../../chart_cache/publishcode/g/google_com
// charttype: rank reach view
// timetype: 1d 3m 1q
// 实际图片路径为: ../../chart_cache/
function switch_chart(picurl, charttype,timetype,isStatSite)  {
	var chart = document.getElementById("imgChart");
	var impurl = picurl + "_" + charttype + "_" + timetype + ".png";
	
	if (isStatSite != "1" && charttype == "rank")	{
	    impurl = "../images/website_no_rank.png";	    
	}
	chart.src = impurl;
	
	document.all("btnChart_rank").className = "clsChartBtnNoSel";
	document.all("btnChart_reach").className = "clsChartBtnNoSel";
	document.all("btnChart_view").className = "clsChartBtnNoSel";
	document.all("btnChart_" + charttype).className = "clsChartBtnSel";	
}




//cross platform function for getting the scroll width of the page
function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

//cross platform function for getting the scroll height of the page
function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

function HideComponentBySpanID(spnID)
{
	
	// if the spnID display is 'none' it will be null and we dont need to do any work here
	if (document.all[spnID] != null)
	{
		
		var eventX = window.event.x+getScrollWidth();
		var eventY = window.event.y+getScrollHeight();
	
		var pos = GetElementPosition(spnID);
		
		pos.top+=2;//the mouseout even fires too soon and we aren't really out yet so add some padding
		pos.left+=2;//the mouseout even fires too soon and we aren't really out yet so add some padding
	
		var right = pos.left + document.all[spnID].offsetWidth;
		var bottom = pos.top + document.all[spnID].offsetHeight;
		
		
		// If the mouse is out of the actions (the span) we hide it
		if (!(( eventX > pos.left && eventX < right ) && ( eventY > pos.top && eventY < bottom )))
		{				
			document.all[spnID].style.display	= "none";
			//document.getElementById("tdDelete").onclick = "";
		}
	}	
}


function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
	return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
	return "";
	}
	else{
	return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
	return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
	if(VALUE.charAt(iTemp) == w_space){
	}
	else{
	strTemp = VALUE.substring(0,iTemp +1);
	break;
	}
	iTemp = iTemp-1;

	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
	return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
	if(VALUE.charAt(iTemp) == w_space){
	}
	else{
	strTemp = VALUE.substring(iTemp,v_length);
	break;
	}
	iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function



function GetElementBySubID(objParent, id)
{	
	var retVal = null;
	
	for (var i=0; i<objParent.all.length; i++)
	{
		if (objParent.all[i].id.indexOf(id) >= 0)
		{
			retVal = objParent.all[i];
			break;
		}
	}
	return retVal;
}

function GetElementPosition(elemID) 
{    
	var counter = 0;
	
	var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) 
    {
	
		offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
        counter ++;
    }
   
    return {left:offsetLeft, top:offsetTop};
}

/*-- 进度条 --*/
function ShowMakerProgress()
{
	try
	{   
		whichbar=1;
		var i;					
		var uploadGif	= document.all("UploadProgress");
			
		uploadGif.style.display = "";			
		uploadGif.style.display		= "inline";				
		setTimeout("doPrg()", 250);		
	}
	catch(er)
	{		
	}	
}

/*-- 进度条 --*/
function ShowUploadProgressWithID(id)
{
	if (typeof id == 'undefined')	
		var id=-1;
	try
	{
		var isOK = true;//Page_ClientValidate();
		//isOK = Page_ClientValidate();
	
		var btnSave = document.all("btnNext");	
		var btnBack = document.all("btnPreviod");
		if (btnSave	==	null)
		{			
			btnSave =	document.all("btnFinish");
			btnBack	=	document.all("btnPreviod");
			if (btnSave	!=	null)
			{			
				btnBack.style.display ="none";
			}
		}
		
		var i;
		if (isOK)
		{			
			var uploadGif	= document.all("UploadProgress");	
			var pos			= GetElementPosition(event.srcElement.id);
			
			uploadGif.style.display = "";
			btnSave.style.display ="none";
			if (btnBack != null && btnBack != undefined)	
				btnBack.style.display ="none";
			
			if (id.indexOf("btnNext") != -1)
			{
				uploadGif.style.left		= pos.left - 100;
			}
			else
			{
				uploadGif.style.left		= pos.left - 150;
			}
			alert(pos.top);
			uploadGif.style.top			= pos.top - 20;
			uploadGif.style.display		= "inline";			
			
			setTimeout("doPrg()", 250);
		}
	}
	catch(er)
	{		
	}	
}

var whichbar=1;
function doPrg()
{		
	if(whichbar >= 0 && whichbar < 15 ) {
		var imgid = "prog" + whichbar;
		if (document.all["prog1"].length > 1)
		{		
			return;
		}
		if (whichbar == 1)
		{
			document.all["prog14" ].style.display = 'none';
			document.all["prog1"].style.display = 'inline';
		}
		else
		{
			document.all[imgid].style.display = 'inline'
			document.all["prog" +(whichbar -1 )].style.display = 'none'
		}		
		setTimeout("doPrg()", 250)
		whichbar ++;		
	}
	else if (whichbar != -1)
	{
	  	whichbar =1
	  	for (var i =1 ; i < 15 ; i++ ){
	  		document.all["prog"+i].style.display = 'none'
	  	}
	  	setTimeout("doPrg()", 250)
	}	
}

function StopProgress() {
	whichbar = -1;
}
