// JavaScript Document

/* FOR LIVE: CHANGE AJAX PATH- "/site/includes/" TO "/site/includes/" */



var activeTab = "tab1";
function setActiveTab(id) {
    //alert(id);
    document.getElementById(activeTab).className= "";
    document.getElementById(activeTab+"_content").style.display= "none";
    document.getElementById(id).style.backgroundPosition= "0 0";
    document.getElementById(activeTab).style.backgroundPosition="0 -32px";
    document.getElementById(id+"_content").style.display= "block";
    activeTab=id;
}
/* ACADEMY COURSES */
function getcourses(param,value){
    document.getElementById('events').innerHTML = "";
    //document.getElementById('cities').innerHTML = "";
    //document.getElementById('stores').innerHTML = "";

    var param1Val = document.getElementById('brand').value;
    var param2Val = document.getElementById('location').value;
    var param3Val = document.getElementById('section').value;

    var xmlhttp        =false;
        try {
            xmlhttp  = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                xmlhttp  = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (E) {
                xmlhttp  = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
        }
    //    xmlhttp.open('GET', '/site/includes/AJAX/getevents.php?' + param + '=' + value, true);
        xmlhttp.open('GET', '/site/includes/AJAX/getevents.php?brand=' + param1Val + '&location=' + param2Val + '&section=' + param3Val, true);


        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                var content = xmlhttp.responseText;
                if( content ){
                    document.getElementById('events').innerHTML = content;
                }
            }
        }
    xmlhttp.send(null)
    return;
    ;
}
function getevents(param,value){
    document.getElementById('events').innerHTML = "";
    //document.getElementById('cities').innerHTML = "";
    //document.getElementById('stores').innerHTML = "";

    var xmlhttp        =false;
        try {
            xmlhttp  = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                xmlhttp  = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (E) {
                xmlhttp  = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        xmlhttp.open('GET', '/site/includes/AJAX/getevents.php?catid=44&' + param + '=' + value, true);
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                var content = xmlhttp.responseText;
                if( content ){
                    document.getElementById('events').innerHTML = content;
                }
            }
        }
    xmlhttp.send(null)
    return;
    ;
}

function getlocation(param,value){
    document.getElementById('events').innerHTML = "";
    //document.getElementById('cities').innerHTML = "";
    //document.getElementById('stores').innerHTML = "";

    var xmlhttp        =false;
        try {
            xmlhttp  = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                xmlhttp  = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (E) {
                xmlhttp  = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        xmlhttp.open('GET', '/site/includes/AJAX/getevents.php?catid=45&' + param + '=' + value, true);
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                var content = xmlhttp.responseText;
                if( content ){
                    document.getElementById('events').innerHTML = content;
                }
            }
        }
    xmlhttp.send(null)
    return;
    ;
}


/* SALON LOCATOR AJAX STUFF */
function getstates(category){
    document.getElementById('states').innerHTML = "";
    document.getElementById('cities').innerHTML = "";
    document.getElementById('salon_key').style.display = "none";
    if(category == "22") {
        document.getElementById('salon_key').style.display = "block";
    }
    //document.getElementById('stores').innerHTML = "";

    var xmlhttp        =false;
        try {
            xmlhttp  = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                xmlhttp  = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (E) {
                xmlhttp  = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
        }

        if(category=='23') {
            xmlhttp.open('GET', '/site/includes/AJAX/getstates_distrib.php?category=' + category, true);
        } else if(category=='24') {
            xmlhttp.open('GET', '/site/includes/AJAX/getstates_stores.php?category=' + category, true);
        } else {
            xmlhttp.open('GET', '/site/includes/AJAX/getstates.php?category=' + category, true);
        }

        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                var content = xmlhttp.responseText;
                if( content ){
                    document.getElementById('states').innerHTML = content;
                }
            }
        }
    xmlhttp.send(null)
    return;
    ;
}

function getcities(category,state){

document.getElementById('stores').innerHTML = "";
/*
doing this in case someone changes their mind and wants to select a different state. When they do - any stores that are already listed will be cleared.
*/
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP');
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
//var file = 'getcities.php?category=state=';
if(category=='23') {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_distrib.php?category=' + category + '&state=' + state, true);
} else if(category=='24') {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_stores.php?category=' + category + '&state=' + state, true);
} else {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities.php?category=' + category + '&state=' + state, true);
}
//xmlhttp.open('GET', file + state, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var content = xmlhttp.responseText;
if( content ){
document.getElementById('cities').innerHTML = content;

}
}
}
xmlhttp.send(null)
return;
;
}

function getcities_pre(category,state){
document.getElementById('stores').innerHTML = "";
/*
doing this in case someone changes their mind and wants to select a different state. When they do - any stores that are already listed will be cleared.
*/
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP');
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
//var file = 'getcities.php?category=state=';

/*if(category=='23') {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_pre_distrib.php?category=' + category + '&state=' + state, true);
else {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_pre.php?category=' + category + '&state=' + state, true);
}*/
if(category=='23') {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_pre_distrib.php?category=' + category + '&state=' + state, true);
} else if(category=='24') {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_pre_stores.php?category=' + category + '&state=' + state, true);
} else if(category=='85') {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_pre_schools.php?category=' + category + '&state=' + state, true);
} else {
    xmlhttp.open('GET', '/site/includes/AJAX/getcities_pre.php?category=' + category + '&state=' + state, true);
}

//xmlhttp.open('GET', file + state, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var content = xmlhttp.responseText;
if( content ){
document.getElementById('cities').innerHTML = content;

}
}
}
xmlhttp.send(null)
return;
;

}


function getstores(category,state,city){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP');
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
if(category=='23') {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_distrib.php?category=' +category +'&state=' + state + '&city=' + city, true);
} else if(category=='24') {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_stores.php?category=' +category +'&state=' + state + '&city=' + city, true);
} else {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores.php?category=' +category +'&state=' + state + '&city=' + city, true);
}

xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var content = xmlhttp.responseText;
if( content ){
document.getElementById('stores').innerHTML = content;

}
}
}
xmlhttp.send(null)
return;

}

function getstores_pre(category,state){
var xmlhttp=false;
try {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
    try {
        xmlhttp = new
        ActiveXObject('Microsoft.XMLHTTP');
    } catch (E) {
        xmlhttp = false;
    }
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
}

if(category=='23') {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_pre_distrib.php?category=' +category +'&state=' + state, true);
} else if(category=='24') {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_pre_stores.php?category=' +category +'&state=' + state, true);
} else {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_pre.php?category=' +category +'&state=' + state, true);
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var content = xmlhttp.responseText;


if( content ){
var myContent = content.split("|");
    if(category=='23') {
        document.getElementById('stores').innerHTML = "<p>Please select your County.</p>";
    }
    else {
        document.getElementById('stores').innerHTML = myContent[0];
    }

/* APPEND FUNCTION FIRST - THEN FIRE */

    //loadMap(myContent[1]);
}
}
}
xmlhttp.send(null)
return;

}

function getstores_distrib(category,state,county){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
xmlhttp = new
ActiveXObject('Microsoft.XMLHTTP');
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

if(category=='23') {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_distrib.php?category=' +category +'&state=' + state + '&&county=' + county, true);
} else if(category=='24') {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores_stores.php?category=' +category +'&state=' + state + '&&county=' + county, true);
} else {
    xmlhttp.open('GET', '/site/includes/AJAX/getstores.php?category=' +category +'&state=' + state + '&&county=' + county, true);
}

xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var content = xmlhttp.responseText;
if( content ){
document.getElementById('stores').innerHTML = content;
}
}
}
xmlhttp.send(null)
return;
}




/* /SALON LOCATOR AJAX STUFF */

function toggle(el) {
    //alert(document.getElementById(el).style.display);
    document.getElementById(el).style.display = (document.getElementById(el).style.display=="none" || document.getElementById(el).style.display=="") ? "block" : "none";
}
function toggle_off(el) {
    //alert(document.getElementById(el).style.display);
    document.getElementById(el).style.display = "none";
}

function checkWidth() {
//alert(window.innerWidth);
//    var curClass = document.getElementById('model').className;
    /*if (document.getElementById('right_box_C')) {
        document.getElementById('model').className="model_squeeze_left";
    }
    else {
    */
    if(document.getElementById('model')) {
        //document.getElementById('model').className = (window.innerWidth > 1200) ? "model_right" : curClass;
        document.getElementById('model').style.display = (window.innerWidth < 850) ? "none" : "block";
        document.getElementById('container').style.width= (window.innerWidth < 850) ? "800px" : "auto";
        //alert(document.getElementById('container').style.width);
    }


}
function checkTierHeight() {
    if(document.getElementById('left_box_tier2')) {
        var divh = document.getElementById('left_box_tier2').offsetHeight;
        if(divh > 426) {
            var newHeight = (divh) - 426;
            document.getElementById('content_wrapper').style.height = (690) + (newHeight) + "px";
            document.getElementById('content_wrapper').style.backgroundColor = "#DCDCDE"
        }
    }
}
function open_height() {
    document.getElementById('nav').className="nav_tall";
    document.getElementById('nav_inner').className="nav_inner_tall";
}
function close_height() {
    document.getElementById('nav').className="nav_short";
    document.getElementById('nav_inner').className="nav_inner_short";
}

function init() {
    checkWidth();
    checkTierHeight();

}
window.onload=init;

