/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function showPic()
{
    if(document.getElementById('validatorPic').innerHTML=="")
    {
        document.getElementById('validatorPic').innerHTML = "<img src=\"/logic/ValidatorPicMaker\" />不区分大小写";
    }
}

function getHttpRequest()
{
    var httpRequest;

    if (window.ActiveXObject)
    { // IE
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            //alert("IE!");
            return httpRequest;
        }
        catch (e) {}
    }
    else if (window.XMLHttpRequest)
    { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType)
        {
            httpRequest.overrideMimeType('text/xml');
        }
        //alert("firefox!");
        return httpRequest;
    }
    return false;
}

function makeRequest(url,para,tagName,waitStr,methodName,resultType)
{
    if(url=="")
    {
        return false;
    }
    var httpRequest = getHttpRequest();
    if (!httpRequest) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    httpRequest.onreadystatechange = function() { 
        requestResult(httpRequest,methodName,resultType);
    };
    httpRequest.open('POST',url,true);
    httpRequest.setRequestHeader("Content-Length",para.length);
    httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    httpRequest.send(para);
    if(tagName!='')
    {
        document.getElementById(tagName).innerHTML = waitStr;
    }
    return true;
}

function requestResult(httpRequest,methodName,resultType)
{
    if (httpRequest.readyState == 4)
    {
        var result;
        if (httpRequest.status == 200)
        {
            //alert(httpRequest.responseText.replace(/(^\s*)|(\s*$)/g, ""));
            if(resultType=='xml')
            {
                eval(methodName+'(httpRequest.responseXML)');
            }
            else if(resultType=='text')
            {
                eval(methodName+'(httpRequest.responseText)');
            }
        }
        else
        {
            alert('操作失败…');
        }
    }
}

//读取Cookie的函数
function readCookie(name)
{
    //alert(document.cookie);
    /*var cookieValue = "";
    var search = name + "=";
    if(document.cookie.length > 0)
    {
        offset = document.cookie.indexOf(search);
        if (offset != -1)
        {
            offset += search.length;
            end = document.cookie.indexOf(";",offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end));
        }
    }
    return cookieValue;*/
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null)
    {
        var cookieValue = unescape(arr[2]);
        if(cookieValue.indexOf("\"")!=-1) return cookieValue.substring(1,cookieValue.length-1);
        return cookieValue;
    }
    return "";
}

//这个很简单，直接使用document.cookie等于（COOKIE名等于对应的值）就OK
//写入Cookie的函数
function writeCookie(name, value, hours)
{
    var expire = "";
    if(hours != null)
    {
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = "; expires=" + expire.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + expire;
    return cookieValue;
}

var slowDisappear_div;
function slowDisappear(height)
{
    //alert(height);
    var interval = 5;
    if(height < interval)
    {
        slowDisappear_div.style.display = 'none';
        return;
    }
    else
    {
        height -= interval;
        slowDisappear_div.style.height=height;
        setTimeout('slowDisappear('+height+')',10);
    }
}

function getUrlParaValue(name)
{
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&^#]*)(\\s|&|#|$)", "i");
    if (reg.test(location.href)) return RegExp.$2;
    return "";
}

function favOK(responseXML)
{
    var result = getResult(responseXML,'Favorite');
    if(result=='DONE')
    {
        window.external.addFavorite('http://www.hedaren.com','和达人 - 创造和谐人际关系')
    }
    else
    {
        alert('请重试！');
    }
}

