function Querystring(qs) { 
	this.params = new Object()
	this.get=Querystring_get
	if (qs == null)
		qs=location.search.substring(1,location.search.length)
	if (qs.length == 0) return
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])
		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		this.params[name] = value
	}
}
function Querystring_get(key, default_) {
	if (default_ == null) default_ = null;
	var value=this.params[key]
	if (value==null) value=default_;
	return value
}

var qs = new Querystring();
var DefEduLvl;
var DefCategory;
var DefSubject;
var ExecuteNextStep=false;
SetQSValues();

function SetQSValues()
{
    DefEduLvl=qs.get("edulvl","0");
    DefCategory=qs.get("category","0");   
    DefSubject=qs.get("subject","0");        
}

function IsAsyncEduLvlCall()
{
    return DefEduLvl=="0";
}
function IsAsyncCategoryCall()

{
    return DefCategory=="0";
}


var xmlhttp=null;
var xml;
var doc;
var str;

function SetXMLHttp()
{
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	    try {
		    xmlhttp = new XMLHttpRequest();
	    } catch (e) {
		    xmlhttp=false;
	    }
    }
    if (!xmlhttp && window.ActiveXObject) {
	    try {
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {
		    xmlhttp=false;
	    }
    }
}



function PopulateCategory(result)
{
    if (xmlhttp.readyState==4) 
    {
        ExecuteNextStep=false;
        xml = result;
        var nodes = xml.split("<Category>");
        var i=0;
        var index=1;
        for(i=0;i<nodes.length;i++)
        {
            if(nodes[i].indexOf("<Value>") > -1)
            {
                var nodeval = nodes[i].substr(nodes[i].indexOf("<Value>")+7, nodes[i].indexOf("</Value>")-nodes[i].indexOf("<Value>")-7);
                var nodetext = nodes[i].substr(nodes[i].indexOf("<DisplayName>")+13, nodes[i].indexOf("</DisplayName>")-13);
               	
                if(nodetext.indexOf("&amp;") > -1) 
                {
                    nodetext = nodetext.substr(0, nodetext.indexOf("&amp;")) + "&" + nodetext.substr(nodetext.indexOf("&amp;")+5)
                }
                document.myform.optone[index] = new Option(nodetext, nodeval);
                if (nodeval.toUpperCase()==DefCategory.toUpperCase())
                { 
                    document.myform.optone.selectedIndex = index;
                    ExecuteNextStep=true;
                }
                index++;
            }
        }
        if (ExecuteNextStep) CategoryChanged();
    }
}

function PopulateSubjects(result)
{
    if (xmlhttp.readyState==4) 
    {
        xml = result;
        var nodes = xml.split("<Subject>");
        var i=0;
        var index=1;

        for(i=0;i<nodes.length;i++)
        {
            if(nodes[i].indexOf("<Value>") > -1)
            {
                var nodeval = nodes[i].substr(nodes[i].indexOf("<Value>")+7, nodes[i].indexOf("</Value>")-nodes[i].indexOf("<Value>")-7);	
                var nodetext = nodes[i].substr(nodes[i].indexOf("<DisplayName>")+13, nodes[i].indexOf("</DisplayName>")-13);
                document.myform.industry[index] = new Option(nodetext, nodeval);
                if (nodeval.toUpperCase()==DefSubject.toUpperCase())
                { 
                    document.myform.industry.selectedIndex = index;                
                }                
                index++;
            }
        }
    }
}

function LoadDegrees() 
{
    SetQSValues();
    SetXMLHttp();
    xmlhttp.open("POST", "/WebServices/external/ELearnersWebService.asmx",IsAsyncEduLvlCall());
    xmlhttp.setRequestHeader("SOAPAction", "http://elearners.com/GetEDULevel_ByCampaign");
    xmlhttp.setRequestHeader("Content-Type", "text/xml");
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4) 
        {
            PopulateDegreeLevel(xmlhttp.responseText);
        }
    }

    str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
		    "<soap12:Envelope " +
		    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
		    "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
		    "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
		    "<soap12:Body>" +
		    "<GetEDULevel_ByCampaign xmlns=\"http://elearners.com/\">" +
		    "<RPCamp_GUID>" + document.myform.cid.value + "</RPCamp_GUID>" +
		    "</GetEDULevel_ByCampaign>" +
		    "</soap12:Body>" +
		    "</soap12:Envelope>";
     xmlhttp.send(str);
}
function DegreeChanged() {
    SetQSValues();
    SetXMLHttp();
    document.myform.optone.disabled=false;
    document.myform.industry.disabled=true;
    document.myform.industry.selectedIndex=0;
    var x;
    for(x=document.myform.optone.length-1;x>0;x--)
    {
	    document.myform.optone[x] = null;
    }
    xmlhttp.open("POST", "/WebServices/external/ELearnersWebService.asmx",IsAsyncCategoryCall());
    xmlhttp.setRequestHeader("SOAPAction", "http://elearners.com/GetCategories_SSOProfile");
    xmlhttp.setRequestHeader("Content-Type", "text/xml");
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4) 
        {
            PopulateCategory(xmlhttp.responseText);
        }
    }
    str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
		    "<soap12:Envelope " +
		    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
		    "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
		    "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
		    "<soap12:Body>" +
		    "<GetCategories_SSOProfile xmlns=\"http://elearners.com/\">" +
		    "<Degree>" + document.myform.eduLvl[document.myform.eduLvl.selectedIndex].value + "</Degree>" +
		    "<RPCamp_GUID>" + document.myform.cid.value + "</RPCamp_GUID>" +
		    "</GetCategories_SSOProfile>" +
		    "</soap12:Body>" +
		    "</soap12:Envelope>";
    xmlhttp.send(str);
}

function CategoryChanged() {
    SetQSValues();
    SetXMLHttp();
    document.myform.industry.disabled=false;
    document.myform.industry.selectedIndex=0;
    var x;
    for(x=document.myform.industry.length-1;x>0;x--)
    {
	    document.myform.industry[x] = null;
    }
    xmlhttp.open("POST", "/WebServices/external/ELearnersWebService.asmx",IsAsyncCategoryCall());
    xmlhttp.setRequestHeader("SOAPAction", "http://elearners.com/GetSubjects_SSOProfile");
    xmlhttp.setRequestHeader("Content-Type", "text/xml");
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4) 
        {
            PopulateSubjects(xmlhttp.responseText);
        }
    }
    str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
		    "<soap12:Envelope " +
		    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
		    "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
		    "xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
		    "<soap12:Body>" +
		    "<GetSubjects_SSOProfile xmlns=\"http://elearners.com/\">" +
		    "<Degree>" + document.myform.eduLvl[document.myform.eduLvl.selectedIndex].value + "</Degree>" +
		    "<Category>"  + document.myform.optone[document.myform.optone.selectedIndex].value + "</Category>" + 
		    "<RPCamp_GUID>" + document.myform.cid.value + "</RPCamp_GUID>" +
		    "</GetSubjects_SSOProfile>" +
		    "</soap12:Body>" +
		    "</soap12:Envelope>";
    xmlhttp.send(str);
}

function IndustryChanged()
{
    if (document.myform.industry[document.myform.industry.selectedIndex].value != "-1")
    {
        doSubmit();
    }
}
function doSubmit()
{
    var optOne = document.myform.optone.options[document.myform.optone.selectedIndex].value;
    var industry = document.myform.industry.options[document.myform.industry.selectedIndex].value;
    var eduLvl = document.myform.eduLvl.options[document.myform.eduLvl.selectedIndex].value;
    var CID = document.myform.cid.value;
    var PostUrl = document.myform.PostUrl.value;
    document.myform.action=PostUrl;
    document.myform.submit();
}