function getCookie(sName) {
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    return null;
}
function selectFromList(listId, val) {
    lst = document.getElementById(listId)

    for (i = 0; i < lst.length; i++) {
        if (lst[i].value == val) {
            lst.selectedIndex = i
            break;
        }
    }



}

function doOnLoad() {
    loadStr = document.getElementById("loadaddbottom").innerHTML + ""

    if (loadStr != "")
        eval(loadStr)


}

window["AJAXSocialReq"] = null;
window["socialFull"] = null;
window["isSocialVisible"] = false;
function submitAJAX(url, fData, AJAXreqId, retFunc) {
    fData = fData.replace(new RegExp(/\s/g), "%20")

    // native XMLHttpRequest object
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            window[AJAXreqId] = new XMLHttpRequest();
        } catch (e) {
            window[AJAXreqId] = false;
        }
        // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        try {
            window[AJAXreqId] = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {

            try {
                window[AJAXreqId] = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                window[AJAXreqId] = false;
            }
        }
    }
    AJAXreq = window[AJAXreqId]
    if (AJAXreq) {

        AJAXreq.onreadystatechange = retFunc;
        AJAXreq.open("POST", url, true);
        AJAXreq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        AJAXreq.send(fData);
    }
}

function getAJAXData(url, fData) {
    fData = fData.replace(new RegExp(/\s/g), "%20")
    // native XMLHttpRequest object
    var AJAXReq = false;
    if (window.XMLHttpRequest && !(window.ActiveXObject)) {
        try {
            AJAXReq = new XMLHttpRequest();
        } catch (e) {
            AJAXReq = false;
        }
        // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        try {
            AJAXReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {

            try {
                AJAXReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                AJAXReq = false;
            }
        }
    }
    if (AJAXReq) {
        AJAXReq.open("POST", url, false);
        AJAXReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        AJAXReq.send(fData);

        if (AJAXReq.status == 200) {
            return AJAXReq.responseText;
        }
        else {
            return "ERROR (" + AJAXReq.status + ")"; 
        }
        
        
    }
}

function processAJAXChange(AJAXreq) {

    if (AJAXreq.readyState == 4) {     // only if req shows "loaded"
        if (AJAXreq.status == 200) {
            return 0;
        } else {
            return 1;
        }
    }
    return -1;
}

function socialAJAXReturn() {
    req = window["AJAXSocialReq"]

    rStatus = processAJAXChange(req);  //0 good, 1 error. -1 still processing
    if (rStatus == 0 || rStatus == 1) {
        if (rStatus == 0) {
            //alert()
            //prompt("",req.responseText)
            socialFull = req.responseText
            window.setTimeout("showSocial(true)", 100)
        }
        else
        //pollError(window["pollId"])
            alert("ERROR loading Data:\n" + req.statusText);
    }
    return;
}




function showSocial(isFirst) {
    a = document.getElementById("socialLink")
    sl = document.getElementById("sociallist")

    pos = findAbsolute("socialLink")
    sl.style.left = pos[0] - 10 + "px"
    sl.style.top = pos[1] + 15 + "px"

    window["isSocialVisible"] = true
    if (socialFull == null)
        submitAJAX("/process/getsocial.asp", "t=" + escape(document.title) + "&u=" + escape(document.URL), "AJAXSocialReq", socialAJAXReturn);
    else {
        sl.style.top = pos[1] + 2 + "px"
    }
    if (isFirst && socialFull != null)
        sl.innerHTML = socialFull
    sl.style.display = "block"
}

function hideSocial() {
    if (window["isSocialVisible"]) {
        document.getElementById("sociallist").style.display = "none"
        window["isSocialVisible"] = false;
    }
}

function findAbsoluteByObject(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {

            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);

    }

    return [curleft, curtop];
}

function findAbsolute(objId) {
    obj = document.getElementById(objId)
    return findAbsoluteByObject(obj)



}
function out() {
    hideSocial()
}

function tab_show(pref, n) {

    tabs_showAll(false, pref)
    document.getElementById(pref + "_" + n).style.display = "block"
}
function tabs_showAll(sh, pref) {

    xi = 0
    while (document.getElementById(pref + "_" + ++xi)) {

        document.getElementById(pref + "_" + xi).style.display = sh ? "block" : "none"
    }



}

function changeTZ(tz) {
    alert(tz)
}

function loginPress(o) {
    document.forms['loginform'].style.display = 'inline';
    o.style.display = 'none';
    document.forms['loginform']['e'].focus()

}

function loginForm(xfrm) {

    document.forms[xfrm.name]['curl'].value = document.URL;

    return true;
}
function gt(tn) {
    window.location = "/search/?q=" + escape(tn) + "&t=TAG"
}

function getFlashStr(xurl, xw, xh) {
    flashStr = ''
    flashStr += '<OBJ' + 'ECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    flashStr += '    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'
    flashStr += '    WIDTH="' + xw + '" '
    flashStr += '    HEIGHT="' + xh + '" '
    flashStr += '    >'
    flashStr += '        <PARAM NAME=movie VALUE="' + xurl + '">'
    flashStr += '        <PARAM NAME=quality VALUE=high>'
    flashStr += '        <PARAM NAME=bgcolor VALUE=#FFFFFF>'
    flashStr += '        <PARAM NAME=wmode VALUE="transparent">'
    flashStr += '        <EM' + 'BED '
    flashStr += '            src="' + xurl + '" '
    flashStr += '            quality=high '
    flashStr += '            bgcolor=#FFFFFF '
    flashStr += '            WIDTH="' + xw + '" '
    flashStr += '            HEIGHT="' + xh + '"'
    flashStr += '            ALIGN="" '
    flashStr += '            WMODE="transparent" '
    flashStr += '            TYPE="application/x-shockwave-flash"'
    flashStr += '            PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
    flashStr += '        </EM' + 'BED>'
    flashStr += '</OB' + 'JECT>'

    return flashStr;
}


//POLL
window["AJAXPollReq"] = null;
window["pollId"] = null;
function pollVote(pollId, cType) {
    aa = pollGetSelectedOption(pollId)
    //alert(aa);
    //txt=getData()
    //document.getElementById("pollOptions"+pollId).innerHTML=submitPoll(pollId);
    pollLOAD = document.getElementById("pollLoadD" + pollId)
    pollBOX = document.getElementById("pollBx" + pollId)
    pos = findAbsolute("pollBx" + pollId)

    pollLOAD.style.left = pos[0] + 1 + "px"
    pollLOAD.style.top = pos[1] + 1 + "px"
    pollLOAD.style.width = pollBOX.offsetWidth - 2 + "px"
    pollLOAD.style.height = pollBOX.offsetHeight - 2 + "px"
    w = document.forms["pollForm" + pollId]["pollW" + pollId].value
    h = document.forms["pollForm" + pollId]["pollH" + pollId].value
    document.getElementById("pollLoad" + pollId).src = "/images/ajax-load.gif"
    pollLOAD.style.display = "block"
    window["pollId"] = pollId
    submitAJAX("/process/pollvote.asp", "id=" + pollId + "&v=" + aa + "&cid=" + cType + "&w=" + w + "&h=" + h, "AJAXPollReq", pollAJAXReturn);

}

function pollAJAXReturn() {
    req = window["AJAXPollReq"]

    rStatus = processAJAXChange(req);  //0 good, 1 error. -1 still processing
    if (rStatus == 0 || rStatus == 1) {
        if (rStatus == 0) {
            //alert()
            //prompt("",req.responseText)
            window.setTimeout("pollProcessResult('" + window["pollId"] + "','" + req.responseText + "')", 2000)
        }
        else
            pollError(window["pollId"])
        //alert("ERROR loading Data:\n" + req.statusText);
    }
    return;
}
function pollError(pid) {
    alert("An error occured while processing your vote, we apologize");
    document.getElementById("pollLoad" + pid).src = ""
    document.getElementById("pollLoadD" + pid).style.display = "none"
}
function pollProcessResult(pid, txt) {
    //alert(txt)

    a = txt.split("$$");
    if (a.length != 4) {
        pollError(pid)
        return;
    }
    piu = a[0]
    pn = a[2]
    pnA = pn.split(";")
    pc = a[1]
    pcA = pc.split(";")
    pv = a[3]
    pvA = pv.split(";")
    ltxt = ""

    h = document.forms["pollForm" + pollId]["pollH" + pollId].value
    for (i = 0; i < pnA.length; i++)
        ltxt += "<tr><td width=15><div class=colbx style='background-color:" + pcA[i] + "'>&nbsp;</div></td><td align=left>" + pnA[i] + "</td><td width=25 align=right>" + pvA[i] + "</td></tr>"
    h = "<div class=pollCh id='pollCh" + pid + "' style=\"height:" + h + "px;background-image:url('" + piu + "')\">&nbsp;</div>"
        + "<div class=pollLeg><table border=0 width=100 cellpadding=0 cellspacing=0 align=center>" + ltxt + "</table></div>"

    document.getElementById("pollLoad" + pid).src = ""
    document.getElementById("pollLoadD" + pid).style.display = "none"
    document.getElementById("pollSubmitD" + pid).innerHTML = "Thanks for voting"
    document.getElementById("pollOptions" + pid).innerHTML = h

}

function pollGetSelectedOption(pollId) {
    e = document.forms["pollForm" + pollId]["poll" + pollId];
    for (i = 0; i < e.length; i++)
        if (e[i].checked)
        return e[i].value;

    return null;
}
//END POLL

//START CAL
window["AJAXCalReq"] = null;
window["calId"] = null;
function goCal(xParams, xCalName,xCalId) {
    window["calId"] = xCalId
    submitAJAX("/process/cal/cal_"+xCalName + ".asp", xParams + (((xParams + "").length > 0) ? "&" : "") + "cid=" + xCalId + "&w=" + document.getElementById(xCalId + "_box").offsetWidth, "AJAXCalReq", calAJAXReturn);
}
function calAJAXReturn() {
    req = window["AJAXCalReq"]

    rStatus = processAJAXChange(req);  //0 good, 1 error. -1 still processing
    if (rStatus == 0 || rStatus == 1) {
        if (rStatus == 0) {
            //alert()
            //prompt("",req.responseText)
            calProcessResult(window["calId"], req.responseText)
        }
        else
            alert("ERROR loading Data:\n" + req.statusText);
    }
    return;
}
function calProcessResult(pid, txt) {
    document.getElementById(pid).innerHTML = txt
}
//END CAL


var lastSmallImg = null
var lastSmallImgHeight = 0
function img_d_small(o) {

    if (lastSmallImg != null)
        lastSmallImg.style.height = lastSmallImgHeight + "px"


    if (o.src.indexOf("_640W.gif") == -1)
        return;
    var aImg = o.src.replace("_640W.gif", "")
    var indDomain = aImg.indexOf("//" + document.domain)
    if (indDomain > -1)
        aImg = aImg.substring(indDomain + document.domain.length + 2)

    pos = findAbsoluteByObject(o)
    imgLarge = document.getElementById("img_large_view")
    imgLarge.style.left = pos[0] + 'px'
    imgLarge.style.top = pos[1] + 'px'
    imgLarge.innerHTML = "<img class='img_ver_large' src='" + aImg + "' onmousedown=\"hideLargeImg(this)\" onload=\"img_loaded(this)\"/>"
    lastSmallImgHeight = o.height
    lastSmallImg = o

}

function img_o_small(o) { }
function img_loaded(o) {
    if (lastSmallImg != null) {
        lastSmallImg.style.width = lastSmallImg.width + "px"
        lastSmallImg.style.height = o.height + "px"
    }
}
function hideLargeImg(o) {
    if (lastSmallImg != null)
        lastSmallImg.style.height = lastSmallImgHeight + "px"
    o.style.display = 'none'
}

function trackHL(mEvent, isHL, classHL) {

    if (mEvent.srcElement)
        myElement = mEvent.srcElement
    else if (mEvent.target)
        myElement = mEvent.target
    else
        return

    while (myElement && ((myElement.tagName && myElement.tagName != "TR") || !myElement.tagName)) {
        myElement = myElement.parentNode;
    }


    if (myElement) {
        if (myElement.className.indexOf("notrack") > -1)
            return;
        if (isHL && myElement.className != classHL)
            myElement.className = classHL
        else if (!isHL && myElement.className != "")
            myElement.className = ""

    }


}