$(document).ready(initAll); //*** For some reason calling initAll from here causes problems with flash to javascript communication (adding stands)
/*********************************************************************
CORE.JS | Version 1.3.51 Conference Branch
Original author: Jonathan Pritchard
Show: IPEX 2010
Last Modified by: Jonathan Pritchard
Last Modified on: 23/11/09

----------------------------------------------------------------------
NOTES:
- 1.2.01 inludes pavillion grouping in email copy.
- 1.3 Includes conference system
- 1.3.5CB This is the conference branch.
- 1.3.5CB Also implements "Allow Contact" from Springfair and Pure
- 1.3.5CB Partially implemented generic event handler as seen in springfair and pure
- 1.3.51CB Added sponsor "Add to plan" function
----------------------------------------------------------------------
----------------------------------------------------------------------
TODO:
- Convert all data transmission to JSON format for the sake of consistency and performance
----------------------------------------------------------------------
**********************************************************************/
var userID = 0;
var showID = 1;
var toggleHelp = 1;

function initAll(){
	load_flash();	
	change_loginStatus("not");
	
	//set_up_menu_boxes();
	
    var strAuth = getCookieValue("www.showplans.co.uk");
    
    if (strAuth != false)
	{
      var arrAuth = strAuth.split("##");
      userLogin(arrAuth[0], arrAuth[1], true);
    }
	
	$(".user_name").click(textBox_onClick).blur(textBox_blur);
	$(".email_copy").blur(chkEmailCopy_onBlur);
	$("#aLogout").click(function(){userLogout(); return false;});
	
	$(".save_stand").click(function(){save_stands(); return false;});
	$(".load_stand").click(function(){load_stands(); return false;});
	
	$("#menuitem_todayplanner").click(function(){load_floorplan('all');});
	$("#menuitem_siteplan").click(function(){load_siteplan(); return false;});
	
	$("#btnForward").click(function(){send_to_colleague();return false;});
	
	//set up expanding menus:
	$(".expandable").hide();

	$("#aSaveRetrieve, #aForward, #aConference, #aSaveRetrieveLower").click(function(){
		var divExpandable = ""; //holds the panel we're expanding
		var divLosinge = "#extra_features"; //holds the losinge that was clicked, default is the upper losinge.
		var arrAvailablePanels = ["#divSaveRetrieveArea", "#divForwardArea", "#divConferenceArea", "#divSaveRetrieveAreaLower"];
		var callbackFunction = null;
                switch(this.id){
			case "aSaveRetrieve":
				divExpandable = "#divSaveRetrieveArea";
				break;
			case "aForward":
				divExpandable = "#divForwardArea";
				break;
			case "aConference":
				divExpandable = "#divConferenceArea";
                                if($.browser.msie){
                                    callbackFunction = function(){fix_ie_height(1)};
                                }
                                break;
			default:
				divExpandable = "#divSaveRetrieveAreaLower";
				divLosinge = "#extra_features_lower";
		}
		
		//close any other open panels:
		for(var p=0;p<arrAvailablePanels.length;p++){
			if(arrAvailablePanels[p] != divExpandable){
				//the panel we're current at is not the one that we're expanding so check to see if its open:
				if($(arrAvailablePanels[p]).is(":visible")){
					//this panel is open so close it:
					$(arrAvailablePanels[p]).slideToggle("slow");
				}
			}
		}
		
		if($(divExpandable).is(":visible")){
			$(divLosinge).css("background","transparent url(images/menu_losinge_down.gif) no-repeat scroll left top");
		} else {
			$(divLosinge).css("background","transparent url(images/menu_losinge_up.gif) no-repeat scroll left top");
		}
                if($(divExpandable).is(":visible")){
                    $(divExpandable).slideUp("slow");
                }else{
                    $(divExpandable).slideDown("slow", callbackFunction);
                }
		
		return false;
	});


        //generic event handler (partial implementation. fully implemented in sf and pure):
        $(".event_hook").click(function(e){return event_handler(e)});
	
	//Browser Detection:
	 if(window.opera){
          var i=xUA.indexOf('opera');
          if(i!=-1){
              var v=parseInt(xUA.charAt(i+6));
              xOp7Up=v>=7;
              xOp6Dn=v<7;
          }
      } else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){
          xIE4Up=parseFloat(navigator.appVersion)>=4;
          xIE4=xUA.indexOf('msie 4')!=-1;
          xIE5=xUA.indexOf('msie 5')!=-1;
      } else if(document.layers){
          xNN4=true;
      }
      xMac=xUA.indexOf('mac')!=-1;
	  //end browser detection
	  
}

function printdayplan(){
	printtmr=setTimeout("printplan();",100);
}

function confirmExit(){
	var i = 0
	for (var tmpProp in mystands){
		i++
	}
	if(i > 0){
    	return "Are you sure you want to exit without saving your Day Plan? Click 'Cancel' to return to My IPEX, then enter your email and your itinerary will be saved for next time!";
	}
}

//**************************************load flash files********************************************
function load_flash(){
    var loadView = "siteplan";
    var loadViewArgs = "";
    //If stands numbers are found in querystring then load the floorplan directly
    if (querySt("stands") != ""){

        //stand number(s) were found in the querystring so perform the following ops on the data:
        //1) Remove all dashes from the querystring
        //2) Remove the text "Stand: " from the querystring
        //3) remove leading Zeros and Us at the beginning of each stand number

        var stands = querySt("stands").replaceAll("Stand:%20","").replaceAll("-","");
        var arrStandNumbers = stands.split(",");
        for(var i=0;i<arrStandNumbers.length;i++){
                var leadingchar = arrStandNumbers[i].substr(0,1)
                if(leadingchar == "0" || leadingchar == "U") {
                        arrStandNumbers[i] = arrStandNumbers[i].substr(1,arrStandNumbers[i].length);
                }
        }
        //set load view args:
        loadView = "floorplan";
        loadViewArgs = arrStandNumbers.toString();
    }

    if(strConfData != ""){
        //alert("conferences found")
        //process the conf data and call add_conf()...
        if(strConfData != undefined && strConfData != ""){
            var arrConfItems = strConfData.split("^^");
            for(var a = 0;a<arrConfItems.length;a++){
                //split this conference data string into individual fields:
                var arrConfFields = arrConfItems[a].split("##");
                //contains: confID,title,date,time,standnumber,standreference
                window.setTimeout('add_conference(\''+arrConfFields[0]+'\', \''+arrConfFields[1]+'\', \''+arrConfFields[2]+'\', \''+arrConfFields[3]+'\', \''+arrConfFields[4]+'\')', ((a+1)*200)+1000);
                arrConfFields = {};
            }
        }
        loadView = "floorplan";
    }

    switch(loadView){
        case "siteplan":
            makeFlash('','');
            load_siteplan();
            break;
        case "floorplan":
            makeFlash(loadViewArgs,'');
            load_floorplan();
    }

    //the siteplan
    $("#siteplan_area").flash(
        {
            swf: "FLASH/preloader.swf",
            name: "siteplan",
            height:510,
            width:857,
            params: {
                quality: 'high',
                wmode: 'transparent',
                align: 'middle',
                bgcolor: '#FFFFFF'
            }
        }
    );
}

function event_handler(e){
    var returnVal = true;
    switch(e.target.id){
        case "radioAllowContactNo":
            $("#radioAllowContactNo1").attr("checked",$("#radioAllowContactNo").attr("checked"));
            break;
        case "radioAllowContactYes":
            $("#radioAllowContactYes1").attr("checked",$("#radioAllowContactYes").attr("checked"));
            break;
        case "radioAllowContactNo1":
            $("#radioAllowContactNo").attr("checked",$("#radioAllowContactNo1").attr("checked"));
            break;
        case "radioAllowContactYes1":
            $("#radioAllowContactYes").attr("checked",$("#radioAllowContactYes1").attr("checked"));
            break;
        case "txtUsername":
            switch(e.type){
                case "blur":
                    $("#txtUsername1").val($("#txtUsername").val());
            }
            break;
        case "txtUsername1":
            switch(e.type){
                case "blur":
                    $("#txtUsername").val($("#txtUsername1").val());
            }
        case "aSponsorAddToPlan":
            returnVal = false;
            if($(".siteplan_view").is(":visible")){
                load_floorplan();
                window.setTimeout(function(){getFlashMovieObject("showplan").SetVariable("javaAdd","12AB150");},5000);
            }else{
                getFlashMovieObject("showplan").SetVariable("javaAdd","12AB150");
            }
    }
    return returnVal
}

function textBox_onClick(ob){
	if($(this).val() == "Your email address here..."){
		$(this).val("");	
	}
}

function textBox_blur(){
	if($(this).val() == ""){
		$(this).val("Your email address here...");	
	}
	
	switch(this.id){
	case "txtUsername":
		$("#txtUsername1").val($(this).val());
		break;
	case "txtUsername1":
		$("#txtUsername").val($(this).val());
	}
}

function chkEmailCopy_onBlur(ob){
	//alert(this.id + ":" + this.value);
	switch(this.id){
		case "chkEmailCopy":
			$("#chkEmailCopy1").attr("checked",$(this).attr("checked"));
			break;
		case "chkEmailCopy1":
			$("#chkEmailCopy").attr("checked",$(this).attr("checked"));
	}
}

function userLogin() {
  	var result = true;
	//var strEmail = getCookieValue("www.showplans.co.uk");
	var strEmail = $.cookie("www.showplans.co.uk");
	
	if (strEmail != null){
		//a cookie exists so enter that in the email text box and spanUserEmail <span>. Then hide the text box:
		$("#txtUsername").val(strEmail);
		$("#spanUserEmail").html(strEmail);
		$("#spanUserEmail1").html(strEmail);
		change_loginStatus("auth");
	}
	else
	{
		if($("#txtUsername").val() != "" && $("#txtUsername").val() != "Your email address here..."){
			//the text box is not empty so see if we can set a cookie with this email:
			var username = $("#txtUsername").val();
			var reValidEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(!reValidEmail.test(username)){
				//the supplied email is not valid
				response("Please enter a valid email address.", 2);
				//document.forms[0].elements[0].focus(); *** we cant shift focus here because the control doesnt exist yet. Result of callilng initAll from html (see line 1).....
				result = false;
			}else{
				//the email is valid so set a cookie and show/hide the
				// @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
				$.cookie("www.showplans.co.uk", username, {expires: 255});
				//writePersistentCookie("www.showplans.co.uk", username,"years", 255);
				$("#spanUserEmail").html(username);
				$("#spanUserEmail1").html(username);				
				change_loginStatus("auth");
			}
		} else {
			//theres no email in the email inputs and no cookie so return false
			result = false;
		}
		//a cookie does not exist so leave things as they are. Wait for the user to enter their email, then 
		//wait for them to press 'load' or 'save' before setting the cookie:
	}
	return result;
 	
}

function userLogout(){

    //remove cookie here
    userID = 0;
    change_loginStatus("not");

    $("#spanUserEmail").val("");
    $("#txtUsername").val("Your email address here...");
    //deleteCookie("www.showplans.co.uk");
    $.cookie("www.showplans.co.uk", null);
    response("You have been logged out.", 2);
    if($(".floorplan_view").is(":visible")){
        removeAllStands();
    }
}
function save_stands(){
	//set a cookie with the users validated email address:
	if(userLogin()){	
	
		//** Stand numbers from array. not exactly sure what i'm doing here.
		var arrStands = new Array();
		var stndarrpoint = 0;
		for (var tmpProp in mystands){
			//stndarr[stndarrpoint]=new Array(tmpProp,mystands[tmpProp][0],mystands[tmpProp][1],mystands[tmpProp][2],mystands[tmpProp][3],mystands[tmpProp][4],mystands[tmpProp][5]);
			if(mystands[tmpProp] != "null" || mystands[tmpProp] != "undefined"){
				arrStands.push(tmpProp);
                                //strStands += tmpProp + "##";
			}
			stndarrpoint++;
			//alert(stndarrpoint);
		}
		//** Pavillion stands
		for (var tmpPropPav in mypavstands){
			if(mypavstands[tmpPropPav[0]] != "null" || mypavstands[tmpPropPav[0]] != "undefined"){
					arrStands.push(tmpPropPav);
                                        //strStands += tmpPropPav + "##";
				}
				//stndarrpoint++;
				//alert(stndarrpoint);
		}

                

		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("post", "server_side/functions.php", true);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		oXmlHttp.onreadystatechange = function () {
			//the readyState variable has changed. See if its 4 (finished).
			if (oXmlHttp.readyState == 4) {
				//the request is finished. now check that the request was successful.
				if (oXmlHttp.status == 200) {
					//response (if any is needed. think accessibility)
					response("Your stands have been saved.", 2);
					change_loginStatus("showloadbtn");
					//alert(oXmlHttp.statusText);
					//alert("no error occurred: " + oXmlHttp.statusText)
				} else {
					response("An error occurred: " + oXmlHttp.statusText, 2);
					//alert("An error occurred: " + oXmlHttp.statusText);
				}
			}
		};
		
		var strUserEmail = document.forms[0].elements[0].value;
		
		var strEmailCopy = "";
		
		//Get the number of stands in mystands. for some reason mystands.length returns 0 everytime :(
		
		
		if($("#chkEmailCopy").attr("checked") && count_stands() > 0){
			//generate event plan grid:
			strEmailCopy = "&emailcopy=" + php_urlencode(generate_epgrid());
			//**** TO FINISH ****
		}

                //produce a true/false value for allow contact radio buttons:
                var strAllowContact = "";
                if($("#radioAllowContactYes").attr("checked")){
                    strAllowContact = "true";
                }else if($("#radioAllowContactNo").attr("checked")){
                    strAllowContact = "false";
                }

                //Generate a list of conference entries to send to the server:
                /*
                contains: confID,title,date,time,standnumber,standreference
		*/
                var arrConfTmp = [];
                for(var arrConfItem in arrConf){
                    arrConfTmp.push(arrConf[arrConfItem][0]);
                }
                var strConf = arrConfTmp.join("##");
		
		//alert("stands=" + escape(strStands) + "&uemail=" + escape(strUserEmail) + "&sid=" + escape(showID) + "&op=save" + strEmailCopy);
		oXmlHttp.send("stands=" + escape(arrStands.join("##")) + "&uemail=" + escape(strUserEmail) + "&allowcontact=" + strAllowContact + "&sid=" + escape(showID) + "&conf=" + strConf + "&op=save" + strEmailCopy);
		response("saving stands.", 3);
	}
}

function load_stands()
{
//alert("userlogin(): " + userLogin());
//set a cookie with the users validated email address:
	
	if(userLogin()){
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("post", "server_side/functions.php", true);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		oXmlHttp.onreadystatechange = function () 
		{
			//the readyState variable has changed. See if its 4 (finished).
			if (oXmlHttp.readyState == 4) 
			{
				//the request is finished. now check that the request was successful.
				if (oXmlHttp.status == 200) 
				{
                                        //request was successful. Now Parse the result:
                                        var strResult = oXmlHttp.responseText;
                                        //strResult takes the following format:
                                        //stand##stand##stand^^^conf##conf##conf##^^^option
					if(strResult != ""){
                                            //split the return string into stand and conference strings:
                                            var arrStandConfOptions = strResult.split("^^^");

                                            if(arrStandConfOptions[0] != ""){
                                                //split stand string into individual stands:
                                                var arrStands = arrStandConfOptions[0].split("##")
                                                ////deal with stands:
                                                for(var i=0; i<arrStands.length; i++){

                                                        //window.document.showplan.SetVariable("javaAdd",arrStands[i]);
                                                        getFlashMovieObject("showplan").SetVariable("javaAdd",arrStands[i]);
                                                        //alert(arrStands[i]);
                                                }
                                            }
                                            

                                            if(arrStandConfOptions[1] != ""){
                                                //split conference string into individual conference items:
                                                var arrConference = arrStandConfOptions[1].split("##")
                                                 //deal with conference entries:
                                                for(var c=0;c<arrConference.length;c++){
                                                    //split conference item string into individual data items:
                                                    var arrConfItemData = arrConference[c].split("*&*");
                                                    //arrConfItemData contains (in order): confID, title, description, standnumber, date, starttime, endtime, profileurl
                                                    add_conference(arrConfItemData[0], arrConfItemData[1], arrConfItemData[4], arrConfItemData[5] + " - " + arrConfItemData[6],  arrConfItemData[3]);
                                                }
                                            }
                                            

                                            if(arrStandConfOptions[2] != ""){
                                                //retrieve options (allow contact)
                                                var arrOptions = arrStandConfOptions[2].split("##");
                                                if(arrOptions[0] == "true"){
                                                    $("#radioAllowContactYes").attr("checked","checked");
                                                    $("#radioAllowContactNo").removeAttr('checked');
                                                    $("#radioAllowContactYes1").attr("checked","checked");
                                                    $("#radioAllowContactNo1").removeAttr('checked');

                                                }else{
                                                    $("#radioAllowContactNo").attr("checked","checked");
                                                    $("#radioAllowContactYes").removeAttr('checked');
                                                    $("#radioAllowContactNo1").attr("checked","checked");
                                                    $("#radioAllowContactYes1").removeAttr('checked');
                                                }
                                            }
                                            
                                           



                                            response("Your stands have been successfuly loaded.", 2);
                                            reListStands();
                                        }
					response("", 0);
				} else {
					response("An error occurred: " + oXmlHttp.statusText, 2);
					response("", 0);
				}
			}
		}	
		var strUserEmail = document.forms[0].elements[0].value;
		//alert("uemail=" + escape(strUserEmail) + "&sid=" + escape(showID) + "&op=load");
		response("", 1);
		//var strEmailCopy = ""
		//if($("#chkEmailCopy").attr("checked")) strEmailCopy = "&emailcopy" + $("#mystandlist").html();
		oXmlHttp.send("uemail=" + escape(strUserEmail) + "&sid=" + escape(showID) + "&op=load");
		
	
	}
}
function send_to_colleague()
{
	//send this event plan to a specified email address:
	//- check all required fields have been filled in:
	var validationResult = true
	$("#divForwardWarning").html("")
	if($("#txtForwardEmail").val() == "")
	{
		$("#divForwardWarning").html($("#divForwardWarning").html() + "<br />- Please enter a valid email address.");
		validationResult = false;
	}
	if($("#txtForwardFromName").val() == "")
	{
		$("#divForwardWarning").html($("#divForwardWarning").html() + "<br />- Please enter your name before sending.");
		validationResult = false;
	}
	if(count_stands() == 0)
	{
		$("#divForwardWarning").html($("#divForwardWarning").html() + "<br />- You have not added any stands to your event plan.");
		validationResult = false;
	}
	
	//- send information to functions.php
	if(validationResult == true)
	{
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("post", "server_side/functions.php", true);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		oXmlHttp.onreadystatechange = function () 
		{
			//the readyState variable has changed. See if its 4 (finished).
			if (oXmlHttp.readyState == 4) 
			{
				//the request is finished. now check that the request was successful.
				if (oXmlHttp.status == 200) 
				{
					//request was successful. Let the user know:
					$("#divForwardWarning").attr("class","notice");
					$("#divForwardWarning").html("<br />Your event plan was successfuly sent to " + $("#txtForwardEmail").val() + ".");
				}
				response("Your event plan has been successfuly sent.", 2);
				response("", 0);
			} else {
				response("An error occurred: " + oXmlHttp.statusText, 2);
				response("", 0);
			}
		}
		var strUserEmail = document.forms[0].elements[0].value;
		//alert("uemail=" + escape(strUserEmail) + "&sid=" + escape(showID) + "&op=load");
		response("", 1);
		//var strEmailCopy = ""
		//if($("#chkEmailCopy").attr("checked")) strEmailCopy = "&emailcopy" + $("#mystandlist").html();
		/*var strForwardEmail = $("#txtForwardEmail").val()
		var strForwardFromName = 
		var strForwardMsg = 
		var strForwardDayPlan =*/
		//alert("uemail=" + escape(strUserEmail) + "&sid=" + escape(showID) + "&op=sendplan&toemail=" + $("#txtForwardEmail").val() + "&fromname=" + $("#txtForwardFromName").val() + "&msg=" + $("#txtPersonalMsg").val() + "&dayplan=" + php_urlencode(generate_epgrid()));
		
		//generate stand list to be used in return link
		var strStands = "";
		for (var tmpProp in mystands){
			if(strStands != ""){
				strStands += ","
			}
			strStands += tmpProp;
		}
		
		oXmlHttp.send("uemail=" + escape(strUserEmail) + "&sid=" + escape(showID) + "&op=sendplan&toemail=" + $("#txtForwardEmail").val() + "&fromname=" + $("#txtForwardFromName").val() + "&msg=" + $("#txtPersonalMsg").val() + "&dayplan=" + php_urlencode(generate_epgrid()) + "&stands=" + strStands);
	}
}

function generate_epgrid(){
	
	var stndarr=new Array();
	var stndarrpoint=0;
	var quotchr=String.fromCharCode(34);
	var setnumtxt="";
	var setnumnum=0;
	var setnumbegin="";
	
	var outhtm="<table class='userstand' border='1' cellpadding='10' cellspacing='0'>\r\n";
	outhtm+="<tr><th scope='col'>&nbsp;</th><th scope='col'>Exhibitor</th><th scope='col'>Stand</th><th scope='col'>Profile</th></tr>\r\n";
	for (var tmpProp in mystands){
		stndarr[stndarrpoint]=new Array(tmpProp,mystands[tmpProp][0],mystands[tmpProp][1],mystands[tmpProp][2],mystands[tmpProp][3],mystands[tmpProp][4],mystands[tmpProp][5]);
		stndarrpoint++;
	}
	stndarr.sort(sortByColumn);
	for (var tmpRow in stndarr){
		setnumnum++;
		setnumtxt+=setnumbegin+stndarr[tmpRow][0]+","+setnumnum;
		setnumbegin=",";
		outhtm+="<tr>";
		outhtm+="<td class='userstandid'>"+setnumnum+"</td>\r\n";
		if ((stndarr[tmpRow][2]=="")||(stndarr[tmpRow][2]=="undefined")){
			outhtm+="<td class='userstandexhibitor'>&nbsp;</td>\r\n";
		}else{
			outhtm+="<td class='userstandexhibitor'>"+stndarr[tmpRow][2]+"</td>\r\n";
		}
		outhtm+="<td class='userstandstand'>"+stndarr[tmpRow][0]+"</td>\r\n";
		if ((stndarr[tmpRow][6]=="")||(stndarr[tmpRow][6]=="undefined")){
			outhtm+="<td class='userstandweb'>&nbsp;</td>\r\n";
		}else{
			outhtm += "<td class='userstandweb'><a href='http://" + stndarr[tmpRow][6] +"' >Profile</a></td>\r\n";
		}
		outhtm+="</tr>\r\n";
	}
	var startpav="<tr><th class='pavhead'><th colspan='6' class='pavhead'><h4>Pavilion Stands</h4></tr>\r\n";
	for (var tmppavRow in mypavstands){
		setnumnum++;
		setnumtxt+=setnumbegin+tmppavRow+","+setnumnum;
		setnumbegin=",";
		var tmprwspn=" rowspan='"+mypavstands[tmppavRow].length+"'";
		
		var endrow="";
		for (var tmppavExh=0; tmppavExh<mypavstands[tmppavRow].length; tmppavExh++){
			outhtm+=endrow;
			//for the first row the variable endrow is empty. We use this to determine when we're dealing with the first row:
			if (endrow==""){
				outhtm+=startpav;
				outhtm+="<tr class='pavtop'><td"+tmprwspn+" class='userstandid'>"+setnumnum+"</td>\r\n";
				if ((mypavstands[tmppavRow][tmppavExh][0]=="")||(mypavstands[tmppavRow][tmppavExh][0]=="undefined")){
					outhtm+="<td class='userstandexhibitor'>&nbsp;</td>\r\n";
				}else{
					outhtm+="<td class='userstandexhibitor'>"+mypavstands[tmppavRow][tmppavExh][0]+"</td>\r\n";
				}
				outhtm+="<td"+tmprwspn+" class='userstandstand'>"+tmppavRow+"</td>\r\n";
			}else{
				if ((mypavstands[tmppavRow][tmppavExh][0]=="")||(mypavstands[tmppavRow][tmppavExh][0]=="undefined")){
					outhtm+="<td class='userstandexhibitor'>&nbsp;</td>\r\n";
				}else{
					outhtm+="<td class='userstandexhibitor'>"+mypavstands[tmppavRow][tmppavExh][0]+"</td>\r\n";
				}
			}
			
			
			
			if ((mypavstands[tmppavRow][tmppavExh][5]=="")||(mypavstands[tmppavRow][tmppavExh][5]=="undefined")){
				outhtm+="<td class='userstandweb'>&nbsp;</td>\r\n";
			}else{
				outhtm += "<td class='userstandweb'><a href='http://" + mypavstands[tmppavRow][tmppavExh][5] +"' >Profile</a></td>\r\n";
			}
			
			endrow="</tr><tr>\r\n";
		}
		outhtm+="</tr>\r\n";
		startpav="";
	}

        if(arrConf.length > 0){
            outhtm+="<tr><th class='confhead'><th colspan='6' class='pavhead'><h4>Debates</h4></tr>";
            outhtm+="<tr><td></td><td><b>Date and time</b></td><td><b>Stand number</b></td><td><b>Debate title</b></td></tr>"
            for (var tmpConfRow in arrConf){
                //arrConf contains: confID,title,date,time,standnumber,standreference
                outhtm+="<tr>";
                outhtm+="<td class='userstandid'>"+checkForNull(arrConf[tmpConfRow][5],"error")+"</td>"; //stand reference code
                outhtm+="<td class='userstandexhibitor'>"+ checkForNull(arrConf[tmpConfRow][2],"") + " from " + checkForNull(arrConf[tmpConfRow][3],"")+"</td>"; //scheduled start time
                outhtm+="<td class='userstandstand'>"+checkForNull(arrConf[tmpConfRow][4],"")+"</td>"; //stand number
                outhtm+="<td class='userstandsection' colspan='3'>"+checkForNull(arrConf[tmpConfRow][1],"")+"</td>"; //debate details
                outhtm+="</tr>";
            }
        }

	outhtm+="</table>";
	
	return outhtm;
}

function count_stands(){
	var standcount = 0
	for (var tmpProp in mystands){
		standcount++;
	}
	return standcount;
}



var clearResponseTimer = 0;

var arrCurrentStandNumbers = [];

function addStandFromExternal(stands) {
	/*
		Im leaving this for the moment. Inconsistent and intermittent issues with multiple javaFindNum. testJavaFindNum for example works fine..............
	*/
	//remove "Stands:" from the string
	stands = stands.replaceAll("Stand:%20","")
	stands = stands.replaceAll("-","");
	//alert(stands);
	//call javaFindNum to add each stand to the floorplan selection:
	var arrStands = stands.split(",");
	
	//alert(arrStands.length);
	for(var i=0;i<arrStands.length;i++){
		
		//alert(arrStands[i]);
		if(arrCurrentStandNumbers.length != 0){
			arrCurrentStandNumbers.push("##sep##");
		}
		arrCurrentStandNumbers.push(arrStands[i]);
	}
	
	//alert("Sent to javaFindNum: " + arrCurrentStandNumbers.unique().toString().replaceAll(",",""));
	window.document.showplan.SetVariable("javaFindNum",arrCurrentStandNumbers.unique().toString().replaceAll(",",""));
	
	//alert(arrStands.length);
	/*for(var i = 1; i < arrStands.length + 1;i++){
		//alert("timer #"+i+" : " + ((i*20)*50) + " for stand: " + arrStands[i-1]);
		var standNumber = arrStands[i-1];
		var delay = ((i*20)*50);
		var functionToCall= function() { callJavaFindNum(standNumber); };
		setTimeout(functionToCall,delay);
	}*/
    
	
}

function callJavaFindNum(standNumber){
	//alert("selecting: " + standNumber);
	window.document.showplan.SetVariable("javaFindNum",standNumber);
	
}

function testJavaFindNum(){
	window.document.showplan.SetVariable("javaFindNum","20C612##sep##18E820##sep##18C840");
}
	 
	 
	 
