var dropDownMenuShowing_id = 0;

function getCookie(c_name) {
    if (document.cookie.length>0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) { 
            c_start=c_start + c_name.length + 1; 
            c_end=document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function CheckCK() {
    ck = getCookie('ck');
    if (ck == '1') {
        re = new RegExp("Minute Menu Kids \\(also called C-K Kids\\)|Minute Menu Kids \\(and C-K Kids\\)|Minute Menu Kids", "gi");

        signup_re = new RegExp("http://www.minutemenukids.com/signup/", "gi");

        d = document.getElementById('_mm_page_content');
        var s = d.innerHTML;
        s = s.replace(signup_re, 'http://www.minutemenukids.com/signup/index.php?ck=1');
        d.innerHTML = s;

        d = document.getElementById('_mm_page_content');
        var s = d.innerHTML;
        s = s.replace(re, 'C-K Kids');
        d.innerHTML = s;

        d = document.getElementById('_mm_page_submenu');
        var s = d.innerHTML;
        s = s.replace(signup_re, 'http://www.minutemenukids.com/signup/index.php?ck=1');
        d.innerHTML = s;

        d = document.getElementById('_mm_page_submenu');
        var s = d.innerHTML;
        s = s.replace(re, 'C-K Kids');
        d.innerHTML = s;

        d = document.getElementById('_mm_page_menu');
        var s = d.innerHTML;
        s = s.replace(re, 'C-K Kids');
        d.innerHTML = s;

        d = document.getElementById('_mm_page_dropdowns');
        var s = d.innerHTML;
        s = s.replace(re, 'C-K Kids');
        d.innerHTML = s;

    }
}

function checkHideDropDown(e, id) {
    if (!e) {
    } else {
        var ddm = document.getElementById('__wsddm_' + id);
        var relTarg = e.relatedTarget || e.fromElement;
        //alert(ddm.id + " (" + ddm.nodeName + ") - " + relTarg.id + " (" + relTarg.nodeName + ")");
        if (relTarg.nodeName == 'DIV') {
            dropDownMenuShowing_id=0; 
            hideDropDown(id);
        }
    }
}

function ddmiEnter(t) {
    t.style.backgroundColor = '#7A7A7A';
    t.style.color = '#FFFFFF';
}

function ddmiLeave(t) {
    t.style.backgroundColor = '#FFFFFF';
    t.style.color = '#000000';
}

function showDropDown(id, t) {
    ddm=document.getElementById("__wsddm_" + id); 
    ddm.style.position="absolute"; 
    ddm.style.left=getX(t); 
    ddm.style.top="104px"; 
    ddm.style.display="block";
    dropDownMenuShowing_id=0;
}

function hideDropDown(id) {
    if (dropDownMenuShowing_id != id) {
        ddm=document.getElementById("__wsddm_" + id);
        ddm.style.display="none";
        dropDownMenuShowing_id=0;
    }
}

function getY(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {        
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;        
    }
    return iReturnValue;
}

function getX(oElement) {
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function xmlhttpPost(strURL, strSubmit, strResultFunc) {

    var xmlHttpReq = false;

    if (window.XMLHttpRequest) {
        // Mozilla/Safari
        xmlHttpReq = new XMLHttpRequest();
        //xmlHttpReq.overrideMimeType('text/xml');
        //alert('xmlhttpPost');
    } else if (window.ActiveXObject) {
        // IE
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            eval(strResultFunc + '(xmlHttpReq.responseText);');
        }
    }
    xmlHttpReq.send(strSubmit);
}

function xmlhttpPost_Raw(strURL, strSubmit, strResultFunc) {

    var xmlHttpReq = false;

    if (window.XMLHttpRequest) {
        // Mozilla/Safari
        xmlHttpReq = new XMLHttpRequest();
        //xmlHttpReq.overrideMimeType('text/xml');
        //alert('xmlhttpPost');
    } else if (window.ActiveXObject) {
        // IE
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            eval(strResultFunc + '(xmlHttpReq);');
        }
    }
    xmlHttpReq.send(strSubmit);
}
