
function checkLinks(url, cb, i)
{
	if (url.indexOf("javascript") != -1) {
		cb({"value":null,"error":null,"msg":i});
    	return false;
	}
	var xmlReq;
    if (window.XMLHttpRequest) 
	{ // Non-IE browsers
		xmlReq = new XMLHttpRequest();
		if(cb) {
			xmlReq.onreadystatechange = function() {			
				if (xmlReq.readyState == 4) {
			    	if (xmlReq.status == 200) {
			    		if (xmlReq.responseText == "success")
						{
							cb({"value":i,"error":null,"msg":null});			
						}
						else if (xmlReq.responseText == "failed")
						{
							cb({"value":null,"error":i,"msg":null});
						}
			    	} 
				}			  
			}
		}
	    try 
	    {
	        xmlReq.open("GET", url, cb ? true:false);
	    } catch (e) 
	    {
	        alert(e);
	    }
	    xmlReq.send(null);
    } else if (window.ActiveXObject)
    { // IE
      	xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
      	if (xmlReq) 
        {	
        	if(cb) {
	        	xmlReq.onreadystatechange = function() {        		
					if (xmlReq.readyState == 4) {
				    	if (xmlReq.status == 200) {
				    		if (xmlReq.responseText == "success")
							{
								cb({"value":i,"error":null,"msg":null});			
							}
							else if (xmlReq.responseText == "failed")
							{
								cb({"value":null,"error":i,"msg":null});
							}
				    	}
					}				  
	        	}
        	}
	        xmlReq.open("GET", url, cb ? true:false);
	        xmlReq.send();        
      	}
    }
    
}

/************ 检测死链接 *************/
var alertHtml="<img alt=\"检测死链接\" src=\"/templates/default/images/ajaxloader.gif\" />正在测试链接，可能需要几分钟...";
var deadLink = 0;
function testUrl(i)
{
	document.getElementById("testlinkstatus").innerHTML = alertHtml;
	document.getElementById('submit2').disabled=true;
	var weblinks = document.getElementsByName("weblinks");
	if(weblinks != null && weblinks.length > 0) {
		if(i >= weblinks.length) {
            document.getElementById("testlinkstatus").innerHTML = "";
            document.getElementById('submit2').disabled=false;
        } else {
            checkLinks(getUrlText(weblinks[i]), callbackResult, i++);
            window.setTimeout("testUrl("+i+")",600);
        }
	}
	
}

//判断是否IE浏览器。
function isIE(){
	return document.all ? true : false;
}

function getUrlText(link)
{
   var urlValue;
   if(isIE()) {
   		urlValue = link.innerText;
   		if (urlValue.indexOf("&") != -1) {
			urlValue = urlValue.replace("&", "==");
		}
   		return "../../seoTool.do?method=checkLink&url=" + urlValue;
   } else {
   		urlValue = link.innerHTML;
   		if (urlValue.indexOf("&") != -1) {
			urlValue = urlValue.replace("&", "==");
		}
   		return "../../seoTool.do?method=checkLink&url=" + urlValue;
   }
}  		
function callbackResult (cont)
{
	if(cont)
    {
        var islinksObj = document.getElementsByName('showResult');
        var n;
        if(cont.value != null) {
        	n = cont.value;
            islinksObj[n].innerHTML = "<font color=\"green\">有效链接</font>";
        }
        if(cont.error != null) {
        	deadLink++;
        	n = cont.error;
	        islinksObj[n].innerHTML = "<font color=\"red\">死链接</font>";
        }
        if (cont.msg != null) {
        	n = cont.msg;
	        islinksObj[n].innerHTML = "JavaScript";
        }
    }
}













  
