//$(document).ready(function() {
//	$("div.panel_button").click(function(){
//		$("div#panel").animate({
//			height: "240px"
//		})
//		.animate({
//			height: "225px"
//		}, "fast");
//		$("div.panel_button").toggle();
//	
//	});	
//	
//   $("div#hide_button").click(function(){
//		$("div#panel").animate({
//			height: "0px"
//		}, "fast");
//		
//	
//   });	
//	
//    //alert("ready!");
//});

function setLoginGetObj(name) {
    if (document.getElementById) {
	    return document.getElementById(name);
    }
    else if (document.all) {
	    return document.all[name];
    }
    else if (document.layers) {
   	    return document.layers[name];
    }
}


function setLogin()
{
    var show_button = setLoginGetObj("show_button");
    var hide_button = setLoginGetObj("hide_button");
    
    if(show_button != null || hide_button != null)
    {
        //alert("div_panel_button!");
	    $("div.panel_button").click(function(){
		    $("div#panel").animate({
			    height: "240px"
		    })
		    .animate({
			    height: "225px"
		    }, "fast");
		    $("div.panel_button").toggle();
    	
	    });	
    	
       $("div#hide_button").click(function(){
		    $("div#panel").animate({
			    height: "0px"
		    }, "fast");
    		
    	
       });
   }
   else{
        setTimeout("setLogin();", 5);
   }
}

setTimeout("setLogin();", 5);


    function getHTTPObject() {
        if (typeof XMLHttpRequest != 'undefined') { 
            return new XMLHttpRequest()             ; 
        }

        try { 
            return new ActiveXObject("Msxml2.XMLHTTP") ; 
        } 
        catch (e) { 
            try { 
                return new ActiveXObject("Microsoft.XMLHTTP") ; 
            } 
            catch (e) {} 
        } 

        return false                                ; 
    }

    var Profession;
    var RealTAG;

    function setChannelVariables(channelVariables)
    {
//        var page = new PageQuery(window.location.search);
//        Profession = unescape(page.getValue("Profession"));
//        RealTAG = unescape(page.getValue("RealTAG"));
        if(channelVariables && channelVariables.length > 0)
        {
            var ProfessionField = setLoginGetObj(channelVariables[0]);
            //alert(ProfessionField.value);
            if(ProfessionField)
            {
                Profession = ProfessionField.value;
            }
        }
        
        if(channelVariables && channelVariables.length > 1)
        {
            var RealTAGField = setLoginGetObj(channelVariables[1]);
            if(RealTAGField)
            {
                RealTAG = RealTAGField.value;
            }
        }
    }

    function getChannelVariables()
    {
        var ChannelVariables = "";
//        var page = new PageQuery(window.location.search);
//        Profession = unescape(page.getValue("Profession"));
//        RealTAG = unescape(page.getValue("RealTAG"));
       if(Profession && Profession != "")
       {
           ChannelVariables += "|amp|Profession="+Profession;
       }
       if(RealTAG && RealTAG != "")
       {
           ChannelVariables += "|amp|RealTAG=" + RealTAG;
       }
       return ChannelVariables;
    }

//    function PageQuery(q) {
//        if(q.length > 1) this.q = q.substring(1, q.length);
//        else this.q = null;
//        this.keyValuePairs = new Array();
//        if(q) {
//	    for(var i=0; i < this.q.split("&").length; i++) {
//	        this.keyValuePairs[i] = this.q.split("&")[i];
//	    }
//        }
//        this.getKeyValuePairs = function() { return this.keyValuePairs; }
//        this.getValue = function(s) {
//	    for(var j=0; j < this.keyValuePairs.length; j++) {
//	        if(this.keyValuePairs[j].split("=")[0] == s)
//		        return this.keyValuePairs[j].split("=")[1];
//	    }
//	    return false;
//        }
//        this.getParameters = function() {
//	    var a = new Array(this.getLength());
//	    for(var j=0; j < this.keyValuePairs.length; j++) {
//	        a[j] = this.keyValuePairs[j].split("=")[0];
//	    }
//	    return a;
//        }
//        this.getLength = function() { return this.keyValuePairs.length; }
//    }

    function getFullAdScript(zoneId)
    {
        var adRequest = "";
        
        adRequest = getAdScriptURL(zoneId).replace("|amp|","&amp;");

        document.write ("<scr"+"ipt type='text/javascript' src='" + adRequest);
        document.write ("'><\/scr"+"ipt>");
    }
    
    function getAdScriptURL(zoneId, channelVariables)
    {
       var adRequest = "";
       
       var m3_u = (location.protocol=='https:'?'https://d1.openx.org/ajs.php':'http://d1.openx.org/ajs.php');
       var m3_r = Math.floor(Math.random()*99999999999);
       if (!document.MAX_used) document.MAX_used = ',';
//           adRequest += "<scr"+"ipt type='text/javascript' src='";
       adRequest += m3_u;
       adRequest += "?zoneid=" + zoneId;
       adRequest += '|amp|cb=' + m3_r;
       
       adRequest += getChannelVariables();

       if (document.MAX_used != ',') adRequest += "|amp|exclude=" + document.MAX_used;
       adRequest += document.charset ? '|amp|charset='+document.charset : (document.characterSet ? '|amp|charset='+document.characterSet : '');
       adRequest += "|amp|loc=" + escape(window.location);
       if (document.referrer) adRequest += "|amp|referer=" + escape(document.referrer);
       if (document.context) adRequest += "&context=" + escape(document.context);
       if (document.mmm_fo) adRequest += "|amp|mmm_fo=1";
//           adRequest += "'><\/scr"+"ipt>";
           
//           alert(adRequest);
        return adRequest;
    }

    var adDIV;
    var xmlhttp = getHTTPObject();
    var gettingAd = false;
    function refreshAd(zoneId, adDivId, ProfessionFieldId)
    {
        var async = true;
        var adRequest = "";
     
        adDIV = setLoginGetObj(adDivId);
        
        adRequest = getAdScriptURL(zoneId, ProfessionFieldId);

//        alert(xmlhttp.readyState);
        xmlhttp.open("GET", "./getAd.aspx?URL=" + adRequest, async);
//           xmlhttp.open("GET", adRequest, false);
//        alert(xmlhttp.readyState);
        xmlhttp.send(null);
//        alert(xmlhttp.readyState);
        if(async && !gettingAd)
        {
            gettingAd = true;
            setTimeout("refreshAdAsyncCheck();", 100);
        }
        else if(!gettingAd)
        {
            refreshAdCallback();
        }
    }
    
    function refreshAdAsyncCheck()
    {
//        alert(xmlhttp.readyState);
        if(xmlhttp.readyState == 4)
        {
//            alert(xmlhttp.readyState);
            refreshAdCallback();
        }
        else 
        {
            setTimeout("refreshAdAsyncCheck();", 100);
        }
    }
    
    function refreshAdCallback()
    {
        var newHTML = "";
        
        gettingAd = false;

        newHTML = xmlhttp.responseText;

        if(newHTML != "ERROR")
        {
//          alert(newHTML);
//          alert(adDIV.innerHTML);
            adDIV.innerHTML = "";
//          alert(adDIV.innerHTML);
            adDIV.innerHTML = newHTML;
//          alert(adDIV.innerHTML);
        }
        else
        {
//            alert("ERROR");
        }
    }