﻿// JavaScript Document
var xmlHttp;
var valtype;
var elem;
function changeSearchcriteria() {
    if (document.frmSearch.AreaOfInterest.value == "" || document.frmSearch.AreaOfInterest.value == "Corporate" || document.frmSearch.AreaOfInterest.value == "Area of Interest") {
        document.frmSearch.category.style.display = "block";
        document.frmSearch.location.style.display = "block";
        document.frmSearch.keywords.style.display = "block";
        document.frmSearch.category.value = "";
        document.frmSearch.location.value = -1;
        var location = document.frmSearch.location;
        var category = document.frmSearch.category;
        removeOption(location);
        removeOption(category);
        GetDropDownValue(document.frmSearch.AreaOfInterest.value,"c");
        
    }
    if (document.frmSearch.AreaOfInterest.value == "Store Managers/District Managers" || document.frmSearch.AreaOfInterest.value == "Hourly Associates/Co-Managers" ) {
        document.frmSearch.category.style.display = "none";
        document.frmSearch.location.style.display = "block";
        if (document.frmSearch.AreaOfInterest.value == "Store Managers/District Managers" )
        {
        document.frmSearch.keywords.style.display = "block";
        }
        document.frmSearch.category.value = "";
        document.frmSearch.location.value = -1;
        var location = document.frmSearch.location;
        var category = document.frmSearch.category;
        removeOption(location);
        removeOption(category);
        GetDropDownValue(document.frmSearch.AreaOfInterest.value, "l");
    }
    
    //Condition split into two by Ramanathan for validating the hourly and NY Design - 27-05-2011
    if (document.frmSearch.AreaOfInterest.value == "Hourly Associates/Co-Managers" ) {
        document.frmSearch.category.style.display = "none";
        document.frmSearch.keywords.style.display = "none";
        document.frmSearch.location.style.display = "block";
        document.frmSearch.category.value = "";
        document.frmSearch.location.value = -1;
        var location = document.frmSearch.location;
        var category = document.frmSearch.category;
        removeOption(location);
        removeOption(category);
    }
    if (document.frmSearch.AreaOfInterest.value == "NY Design Studio And Office") {
        document.frmSearch.category.style.display = "none";
        document.frmSearch.location.style.display = "none";
        document.frmSearch.keywords.style.display = "block";
        document.frmSearch.category.value = "";
        document.frmSearch.location.value = -1;
        var location = document.frmSearch.location;
        var category = document.frmSearch.category;
        removeOption(location);
        removeOption(category);
    }
}
function GetDropDownValueforhourly(val, type) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        //alert ("Your browser does not support AJAX!");
        document.form.submit();
        return;
    }
    var url = "getlocation.asp?val=";
    url = url + val + "&type=" + type + "&cval=" + document.frmSearch.AreaOfInterest.value;
    valtype = type;
    xmlHttp.onreadystatechange = showlocresult;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function GetDropDownValue(val, type) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        //alert ("Your browser does not support AJAX!");
        document.form.submit();
        return;
    }
    var url = "getlocation.asp?val=";
    url = url + val + "&type=" + type;
    valtype = type;
    xmlHttp.onreadystatechange = showlocresult;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

}


function showlocresult(type) {
    if (xmlHttp.readyState == 4) {
        var result = xmlHttp.responseText;
        if (result != "") {
            if (valtype == "l") {
                var location = document.frmSearch.location;
                if (result.indexOf("$$") == -1) { result = result + "$$"; }
                var ArrData = result.split("$$")
                var temp;
                for (var i = 0; i < ArrData.length; i++) {
                    temp = ArrData[i];
                    if (temp.indexOf("%%") != -1) {
                        var ArrTemp = temp.split("%%");
                        var Opt = document.createElement('option');
                        location.options.add(Opt);
                        Opt.text = ArrTemp[1];
                        Opt.value = ArrTemp[0];
                    }
                }
            }
            else {
                var category = document.frmSearch.category;
                if (result.indexOf("$$") == -1) { result = result + "$$"; }
                var ArrData = result.split("$$")
                var temp;
                for (var i = 0; i < ArrData.length; i++) {
                    temp = ArrData[i];
                    if (temp.indexOf("%%") != -1) {
                        var ArrTemp = temp.split("%%");
                        var Opt = document.createElement('option');
                        category.options.add(Opt);
                        Opt.text = ArrTemp[1];
                        Opt.value = ArrTemp[0];
                    }
                }
            
             }


         }
         if ((document.frmSearch.AreaOfInterest.value == "Corporate" || document.frmSearch.AreaOfInterest.value == "Area of Interest" || document.frmSearch.AreaOfInterest.value == "") && valtype == "c") { GetDropDownValue(document.frmSearch.AreaOfInterest.value, "l"); }
    }

}
function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function removeOption(listelem) {
    if (listelem) {
        var len = listelem.options.length;
        for (var j = 1; j < len; j++) {
            listelem.remove(1);
        }
    }
}    

