
var lastcolselected='?'
var isIE=/*@cc_on!@*/false;//IE detector

function tabclick(el) {
    var tabname
    var thisel
    var i, k
    tabname = "tbrps" + el.id //eg. tbrpstab1
    el.className = "tabon"
    //deselect all other tabs
    myarr = document.getElementById('tbtabs').getElementsByTagName('div')
    for (i = 0; i < myarr.length; i++) {
        thisel = myarr[i]
        if (thisel != el) {
            thisel.className = "taboff"
        }
    }
    //rebuild selresids from just those selected on selected tab. Note we do NOT deselect the checkboxes onscreen
    myarr = document.getElementById(tabname).getElementsByTagName('input')
    document.getElementById('selresids').value = ''
    for (i = 0; i < myarr.length; i++) {
        thisel = myarr[i]
        if (thisel.id.substring(0, 8).toLowerCase() == "resource" && thisel.type == "checkbox") {
            if (thisel.checked) {
                document.getElementById('selresids').value += '|' + thisel.getAttribute("mytag") + '|'
            }
        }
    }
    //reset selection of BF based on user-selection on selected tab.
    document.getElementById('selbfid').value = ''
    myarr = document.getElementById(tabname).getElementsByTagName('*')
    for (i = 0; i < myarr.length; i++) {
        thisel = myarr[i]
        if (thisel.id.substring(0, 2) == "BF") {
            if (thisel.type == "checkbox" && thisel.checked) {
                document.getElementById('selbfid').value = thisel.getAttribute("mytag") + "|" + thisel.getAttribute("nn")
            }
            if (thisel.type == "select-one" && thisel.selectedIndex != 0) {
                document.getElementById('selbfid').value = String(thisel.value) + "|" + thisel.options[thisel.selectedIndex].text //flagid 
            }
        }
    }
    setbuttons()
    showiframe(false)

    //clear all resource CBs
    //           	myarr=document.getElementById('tbrps').getElementsByTagName('input')
    //           	for (i = 0; i < myarr.length; i++) {
    //           	    thisel = myarr[i]
    //           	    if (thisel.id.substring(0,8).toLowerCase() == "resource") {
    //           	        thisel.checked = false
    //           	    }
    //           	}
    //Hide all other 'tabs'
    myarr = document.getElementById('tbrps').getElementsByTagName('table')
    for (i = 0; i < myarr.length; i++) {
        thisel = myarr[i]
        if (thisel.id.substring(0, 8).toLowerCase() == "tbrpstab" && el.id != tabname) {
            thisel.style.display = "none"
        }
    }
    document.getElementById(tabname).style.display = ""

    //unselect all bookable-flags - set to "(None)" if cbo
    //            myarr = document.getElementById('tbrps').getElementsByTagName('*')
    //            for (i = 0; i < myarr.length; i++) {
    //                thisel = myarr[i]
    //                if (thisel.id.substring(0,2).toLowerCase() == "bf") {
    //                    switch (thisel.type) {
    //                        case "select-one":
    //                         for (var k = 0; k < thisel.options.length; k++) {
    //                              if (thisel.options[k].value == '(None)') {
    //                                  thisel.selectedIndex = k;
    //                                  break;
    //                              }                              
    //                         }
    //                        case "checkbox":
    //                            thisel.checked = false
    //                    }//end switch
    //                }
    //            }
} //end tabclick

function hideRPS() { //called from DefaultSub
return vHideRPs 
}
function myResize() {
if(document.getElementById("EventList")) {
    sizeToFillAvailableVertSpace(document.getElementById("EventList"),28)
}
if (GSScroll == 1) { //if we are wanting GS to show its own scrollbars
    //following will trigger onresize for the page that is shown in the Iframe (e.g. GridSub.aspx)
    var mgf = document.getElementById('mygridframe')
    sizeToFillAvailableVertSpace(mgf, 32)//containing cell has padding:7
    //this not needed in IE8, but is in 7
    sizeToFillAvailableHorizSpace(mgf, 22) //note HORIZONTAL
  //Next line ONLY for 'player site content' NOT for Gridsub (not needed)
   if (typeof (window.frames['mygridframe'].myResize) == "function") { window.frames['mygridframe'].myResize() }
}    
}

function myResizeIFrameForNoScroll() {
    //document.getElementById('mygridframe').style.width = (window.frames['mygridframe'].document.getElementById('scrollregion').clientWidth + 5) + "px"
    var o,f
    f=window.frames['mygridframe'].document
    if (f.getElementById('RHS')) {
        o = f.getElementById('RHS')
    } else {
        o = f.getElementById('scrollregion')
    }
    document.getElementById('mygridframe').style.width = (findPosX(o)+o.clientWidth + 5) + "px"
    document.getElementById('mygridframe').style.height = (findPosY(o)+o.clientHeight + 5) + "px"
}

function refreshGridsub() {  //This is called from Confirmed.aspx (which,in Admin module, is in a pop-up window OR in IFrame)
    //we could do self.location.href="gridsub.aspx?ReQuery=1", but we don't
    showiframe(true)
    //if (changeMade) {document.frames[0].location.reload(true)} this works ok but causes 'flash'
}
function reOpen() { //called from GS
    var s = 'Default.aspx?open=1' //this wont work cos of use of redirect to get here...location.href.replace(location.search, "") //strip querystring
    location.href=s
}
function goE(id) {
    location.href='ViewEvents.aspx?id=' + id
}
function mymouseover(evt) {

evt=(evt) ? evt : ((window.event) ? window.event : null) //W3C pass the event
var el = (evt.target) ? evt.target : evt.srcElement //W3c uses target, IE used srcElement
if (el.tagName == 'TD') {
    //if (el.id==undefined && el.parentNode.id.charAt(0)=="d") {el=el.parentNode}// fudge for Safari only
    if (el.className == 'calendarunsel') { el.className = 'calendart' }
    if (el.className == 'calendarunselom') { el.className = 'calendartom' }
}
}	
function mymouseout(evt) {
evt=(evt) ? evt : ((window.event) ? window.event : null) //W3C pass the event
var el= (evt.target) ? evt.target :evt.srcElement //W3c uses target, IE used srcElement
if (el.tagName == 'TD') {
    //if (el.id==undefined && el.parentNode.id.charAt(0)=="d") {el=el.parentNode}// fudge for Safari only
    if (el.className == 'calendart') { el.className = 'calendarunsel' }
    if (el.className == 'calendartom') { el.className = 'calendarunselom' }
}
}	
function mycalclick(evt){
evt=(evt) ? evt : ((window.event) ? window.event : null) //W3C pass the event
var el = (evt.target) ? evt.target : evt.srcElement //W3c uses target, IE used srcElement
if (el.tagName == 'TD') {
    //if (el.id==undefined && el.parentNode.id.charAt(0)=="d") {el=el.parentNode}// fudge for Safari only
    if (el.className == 'calendart' || el.className == 'calendartom' || el.className == 'calendarseldate' || el.className == 'calendarseldateom') {
        sd(el.id)
    }
}
}

//THis may get called from "bootCode" JS which is generated by Default.aspx.vb... directly from the header fields in GridSub to switch to Detail view. Optionally specifies which RP if we are currently showing >1
//bootcode is called from myInit()
function fSSD(d,rp,force) 
//d should be "dnnn",rp should be "4" or "4|66"
{
cleardates()
 document.getElementById('seldates').value="|"+d+"|"
//In MEMBER app. we should never hide RPs here (in case RP checkboxes are not displayed to user - he'll never get them back!). So passed 'rp' should always be blank in MEMBER app.
if (rp!="") {
	clearRPs()
	document.getElementById('selresids').value= "|"+rp +"|"
} 
if (force) {showiframe()} 
}
function getselresids() {
	var locselresids;
	var strresources
	//follow the same sequence of the splitting of array
	locselresids = document.getElementById('selresids').value.replace(/\|\|/g, "|");
	if (locselresids == "") { return null }
	strresources = locselresids.substring(1, locselresids.length - 1).split('|');
	return strresources
}
function getseldates() {
//returns integers WITHOUT "d" prefix
    var locseldates
    var strseldates
    locseldates = document.getElementById('seldates').value.replace(/\|\|/g, "|");
    if (locseldates == "") { return null }
    locseldates = locseldates.replace(/d/g, "")
    strseldates = locseldates.substring(1, locseldates.length - 1).split('|');
    return strseldates
}
function clearRPs() {
	var inti;
	//follow the same sequence of the splitting of array
	var theform = GetFormObject();
	strresources = getselresids()
	if (strresources != null) {
	    for (inti = 0; inti < strresources.length; inti++) {
	        document.getElementById("Resource" + strresources[inti]).checked = false
	    }
	    theform.selresids.value = ""
	    setbuttons()
	}
}

function disablebutt(id,mode) {
var el=document.getElementById (id)
	if (mode=='on'){
	    el.className="mybtndis"
		}			
	else {
	    el.className="mybtn"
	}
}

function ci(el,mode) {
	if (mode=='on'){
		el.src=el.src.replace ('_off.','_on.')}
	else {
		el.src=el.src.replace ('_on.','_off.')
	}		
}
function GetFormObject()
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.Form1;
	}
	else 
	{
		theform = document.forms["Form1"];
	}	
	return theform;
}           

function showiframe(keepScroll)
{ 
    var theform = GetFormObject();
	if ((theform.seldates.value.length ==0) || (theform.selresids.value.length ==0)) { return false}
	if (allowsuperpooling == 'no') {
		if ((theform.seldates.value.indexOf('||') != -1)  && (theform.selresids.value.indexOf('||') != -1)) { 
		alert ('You have selected more than 1 Date AND more than 1 Resource. This is not a valid combination to display. Please select a single Date OR a single Resource.')
		return false
		}
	}
	if ((theform.seldates.value.indexOf('||') != -1)  && (theform.selbfid.value!='')) { 
		alert ('To see the availability of ' + theform.selbfid.value.substring(theform.selbfid.value.indexOf("|")+1) + ', please select only a SINGLE date.')
		return false
	}
if (!fudgeCode()) {return false} //see dyamic JS in Default.aspx

if (!keepScroll==true) { 
	document.getElementById('gsX').value=0
	document.getElementById('gsY').value=0
} 
    //this removed 9/6/6 to allow user to resubmit same request (to refresh screen if looking for walk-on etc.)    disablebutt('btngo','on')
    disablebutt('btnnext','on')
    document.getElementById('btnnext').title="You must first select desired time-slots"

var sss        

  var ht
  /////////sizeToFillAvailableVertSpace(document.getElementById('mygridframe'))
  ht=document.getElementById('mygridframe').offsetHeight
 
     sss= encodeURI("gridsub.aspx?reqresourceIDs=" + theform.selresids.value + "&reqdates=" + theform.seldates.value  + "&gsy=" + ht + "&gsx=" + (document.getElementById('mygridframe').offsetWidth) + "&fid=" + document.getElementById ('selbfid').value )
     if (GSScroll != 1) { sss += "&GSNS=1" }
    document.getElementById("mygridframe").src = sss ;    

    //5/29/9document.getElementById("fstuff").style.display="none";  
    document.getElementById("tinstructs").style.display="block"; //THIS AFFECTS HEIGHT OF LEFTPANEL, AND THEREFORE TD3
    //document.getElementById("mygridframe").style.display="block" 
 
    //we have just shown tinstructs, so in FF re-calculate reqd. height of EventList to take up space (or whole form grow below window!)
    if(document.getElementById("EventList")) {
        sizeToFillAvailableVertSpace(document.getElementById("EventList"),28) 
    }
} 

function setDefaultForGridsub() {
    //call when display a gridsub in IFrame. This gets invoked from onload of Gridsub.aspx
    if (GSScroll != 1) { myResizeIFrameForNoScroll() } 

       document.getElementById('btngo').className="mybtn"
       showmess()
}


function selectRP(el) { //add or remove passed RP to list of 'selecteds'
var theform = GetFormObject();
//to add when selected the id of the check box
if (el.checked) {
    theform.selresids.value = '|' + el.getAttribute("mytag") + '|' 
	 if (!checkBFsandRPs(false)) {
	    el.checked = false
	    theform.selresids.value = ''
        return	   	    
    }
    
} else {
    theform.selresids.value=''
}
showiframe()
}
function selectRPmulti(el) {
//adds or removes the passed RP checkbox to the list of 'selecteds'
var theform = GetFormObject();	
//	This logic will avoid ever duplicating the code
theform.selresids.value=theform.selresids.value.replace('|' + el.getAttribute("mytag") + '|','')	
if (el.checked) 
{    theform.selresids.value+='|' + el.getAttribute("mytag") + '|'
	 if (!checkBFsandRPs(false)) {
	    el.checked = false
	    theform.selresids.value = theform.selresids.value.replace('|' + el.getAttribute("mytag") + '|', '')
        return	   	    
    }
	
}
//Changed 1/18/10 so that it now auto-refreshes Gridsub whenever court-type selection is changed (same as selectRP above)
//out 1/18/10 setbuttons();
showiframe()	
}	
function selectBF(el) { //add or remove passed BookableFlag
   	var i,o
   	var v, bfid
   	var myarr
   	var chkRP

   	var theform = GetFormObject();
   	//If already got a BF selected, we will blindly deselect it
   	if (theform.selbfid.value != "") {
   	    bfid = theform.selbfid.value.substring(0,theform.selbfid.value.indexOf("|"))
   	    if (document.getElementById('BF' + bfid)) {//its a checkbox
   	        document.getElementById('BF' + bfid).checked = false
   	    } else { //must be an option in a Select. Set parent Select to option 0, hoping this is "(None)"
   	        myarr = document.getElementById('tbrps').getElementsByTagName('option')
   	        for (i = 0; i < myarr.length; i++) {
   	            o = myarr[i]
   	            if (o.value == bfid  && el!=o.parentNode) {//DONT clear it out if the user just selected ANOTHER option in this combo!
   	                o.parentNode.selectedIndex = 0
   	                break
   	            }
   	        }
   	    }
        theform.selbfid.value=""
   	}
   	if (el.type=="checkbox") {
   	    if (el.checked) {
   	        v=el.getAttribute("mytag")
   	        theform.selbfid.value = v + "|" + el.getAttribute("nn")
   	        if (!checkBFsandRPs(true)) {   	    
   	        }	        
	    } 
	} else { //combo
	if (el.value!="") {
	    v=String(el.value) //flagid
	    theform.selbfid.value= v + "|" + el.options[el.selectedIndex].text
   	        if (!checkBFsandRPs(true)) {
   	        }	        
	    } 
	}
	showiframe()
}

function checkBFsandRPs( deselectBadRPs) {
var bfid, chkBF, chkRP,o
   	//check combinations of selected RPs and bookable flags. OUter loop is for each BF (checkbox or combo), then inner loop for each RP
//set deselectBadRPs to true to have this forcibly clear any conflicting RPS. Otherwise, just gives message.
////   	myBFarr=document.getElementById('tbrps').getElementsByTagName('*')
////   	for (i=0;i<myBFarr.length;i++) {
////        chkBF=myBFarr[i]
////        if (chkBF.id.substring(0,2)=="BF" && ((chkBF.type=="checkbox" && chkBF.checked)||(chkBF.type=="select-one" && chkBF.selectedIndex!=0))) {
//Now taken care of in SelectBF
//            if ((chkBF!=el)  && (el.id.substring(0,2)=="BF" && ((el.type=="checkbox" && el.checked)||(el.type=="select-one" && el.selectedIndex!=0)))){ //clear all other selections
//   	            alert('Sorry, only one "extra" (pro, ball-machine, etc.) can be selected.')                
//                if (chkBF.type=="checkbox") {
//                    chkBF.checked=false
//                } else {
//                    chkBF.selectedIndex=0
//                }           
//            }

    if (document.getElementById('selbfid').value != "") { //if already got a BF selected
        bfid = document.getElementById('selbfid').value.substring(0, document.getElementById('selbfid').value.indexOf("|"))
        if (document.getElementById('BF' + bfid)) {//its a checkbox
            chkBF = document.getElementById('BF' + bfid)
        } else { //must be an option in a Select, get parent Select
            myarr = document.getElementById('tbrps').getElementsByTagName('option')
            for (i = 0; i < myarr.length; i++) {
                o = myarr[i]
                if (o.value == bfid) {
                    chkBF = o.parentNode
                    break
                }
            }
        }
    }

    if (chkBF) { //if got a BF selected 
        lst = chkBF.getAttribute("allow") //eg. |4|66|
        //this changed to handle tabbed RP-selection box
        myrparr = getselresids()
        if (myrparr != null) {
            for (j = 0; j < myrparr.length; j++) {
                chkRP = document.getElementById('Resource' + myrparr[j])
                if (lst.indexOf("|" + String(chkRP.getAttribute("mytag")) + "|") == -1) {
                    if (!deselectBadRPs) {
                        alert("\'" + chkRP.getAttribute("nn") + "\' cannot be selected in combination with \'" + chkBF.getAttribute("nn") + "\'. please de-select one of the incompatible options.")
                        return false
                    } else {
                        chkRP.click()//this will actually deselect it, then invoke handler
                    }
                }
            }
        }



        //            myrparr=document.getelementbyid('tbrps').getelementsbytagname('input')
        //            for (j=0;j<myrparr.length;j++) {
        //                chkRP=myrparr[j]
        //                if (chkRP.id.substring(0,8)=="resource" && chkRP.checked) {
        //                    if (lst.indexof("|"+string(chkRP.getAttribute("mytag"))+"|")==-1)	 {
        //                        if (!deselectbadrps) {
        //                            alert ("\'" + chkRP.getAttribute("nn") + "\' cannot be selected in combination with \'" + chkbf.getAttribute("nn") + "\'. please de-select one of the incompatible options.")
        //                            return false
        //                        } else {
        //                            chkRP.click()//this will actually deselect it, then invoke handler
        //                        }
        //                    }  	       	    
        //                }  	
        //            }

    }
   	return true
}

function setbuttons(dontbotherhidingiframe) 	{
//call this after user clicks a date or a RP
	var theform = GetFormObject();
	if ((theform.seldates.value.length >1) && (theform.selresids.value.length >1))
	{
		//theform.btngo.disabled=false
			    disablebutt('btngo','off')
	}
	else 
	{
		//theform.btngo.disabled=true
			    disablebutt('btngo','on')
	}
	//as selection changed... disable the next button as will reflect in change of the 
	//court timings and dates.
	
	if (theform.seldates.value.indexOf("||")!=-1) 
	{ //display this only if >1 date selected (which most users will never do)
		document.getElementById('btncleardates').style.visibility="visible"
		//disablebutt('btncleardates','on')
	}
	else
	{
	    document.getElementById('btncleardates').style.visibility="hidden"
	    //disablebutt('btncleardates','off')
	}
	
	disablebutt('btnnext','on')
	document.getElementById('btnnext').title="You must first view a schedule"
	EnableDisableNavigation()
}
function EnableDisableNavigation()
{
	var theform = GetFormObject();
	var strseldates
	var arrseldates
	var inti
	var dayint
	
	if (theform.seldates.value.length > 0) 
	{
		disablebutt('btnMoveNext','off')
	    disablebutt('btnMovePrev','off')
	    disablebutt('btnPrevWeek','off')
	    disablebutt('btnNextWeek','off')
		//Smart disabling of buttons. This is not only nice, it prevents a mess if they jump onto a "X" date

	    arrseldates = getseldates()
	    for (inti=0;inti < arrseldates.length;inti++)
	    {
		dayint=parseInt(arrseldates[inti])
		if (document.getElementById('x'+(dayint-7))) { disablebutt('btnPrevWeek','on')}//if this is shown as an 'X'ed date,
		if (document.getElementById('x'+(dayint-1))) { disablebutt('btnMovePrev','on')}
		if (document.getElementById('x'+(dayint+1))) { disablebutt('btnMoveNext','on')}
		if (document.getElementById('x'+(dayint+7))) { disablebutt('btnNextWeek','on')}
		}			
	} else {
		disablebutt('btnMoveNext','on')
	    disablebutt('btnMovePrev','on')
	    disablebutt('btnPrevWeek','on')
	    disablebutt('btnNextWeek','on')	
	}
}
function setselecteddates() { //sets styles in calendar
    var locarr = getseldates()
    if (locarr != null) {
        document.getElementById('seldates').value = "" //clear out
        for (inti = 0; inti < locarr.length; inti++) {
            sd('d' + locarr[inti])
        }
    }
}
function setselectedRPs() { //set RP checkboxes according to selresids
    var strresources;
    var inti;
    strresources = getselresids();
    if (strresources != null) {
        for (inti = 0; inti < strresources.length; inti++) {
            if (strresources[inti] != '') {
                if (document.getElementById("Resource" + strresources[inti])) { document.getElementById("Resource" + strresources[inti]).checked = true }
            }
        }
    }
}


function sd(elid,dontbotherhidingiframe) 
{
	//to select or unselect the date in the calendar control
   	var theform=GetFormObject();
	var el=document.getElementById(elid)
	var n=elid

	//tempting to use if (el.className=="calendarunsel") but this fails if date is not in currently-displayed month!
	if (theform.seldates.value.indexOf('|' + n + '|') == -1)
	{
		//we have just selected a new date
		if (!CheckDateCount())
		{
			return;
		}
		else 
		{ if (el) 
			{	if (allowmultidays=="N") {cleardates(true)}
			    if (el.className=='calendart' ||el.className=='calendarunsel') {
					el.className="calendarseldate"
				}
				if (el.className=='calendartom' ||el.className=='calendarunselom' ) {
					el.className="calendarseldateom"
				}
				el.title="Click again to unselect"
			}
			//to change the color on select	
			theform.seldates.value+='|' + n + '|'
			//disablebutt('btncleardates','off')
			//if (allowmultidays=="N") {showiframe(true);setbuttons(true);return false}
			showiframe(true); setbuttons(true); return false 
		}
	}
	else
	{
		//we are UNselecting it
		//the element may not be visible if this called from cleardates()
		if (el)
		{
			//we set this attribute in the code behing in day render event
			if (el.className=="calendarseldate")
			{
				el.className ="calendarunsel";
			}
			else
			{
				el.className ="calendarunselom";
			}
			el.title="";				
		}
		theform.seldates.value=theform.seldates.value.replace('|' + n + '|','')		
	}
	setbuttons(dontbotherhidingiframe)
}


function myInit() 
{
    //if (vpWidth() < 800) {
    if (screen.availWidth<800){
        GSScroll = 0 //don't want GS to have own scrollbars
        document.getElementById('iBlock').style.width=""
        document.getElementById('iBlock').style.minWidth = "800px"
       // document.body.removeAttribute("onresize")        
    }
 	myResize() //this will NOT invoke showiframe

 	
	//to reflect the status of the resource pools
	if (document.getElementById('selresids').value != '')
	{
        setselectedRPs()
	}
	if (allowmultidays=="N") {
        document.getElementById('btncleardates').style.display="none"
	} else {//allow row and col-selection in calendar
	for (var c=1;c<8;c++) 
	{	var mycell = document.getElementById('Calendar1').rows[1].cells[c];	
		mycell.innerHTML = "<a style='color:White' title='Select all days in column' href='javascript:selectweekday(" + c  +");'>" + mycell.innerHTML + "</a></font>";
	}
	var wkb
	var wkbid
	var dayint
	var startd=0
	for (var r=2;r<8;r++) 
	{	
		//find first selectable cell in this row, if any
		startd=0
		for (var c=1;c<8;c++) 
		{ 			
			var mycell= document.getElementById('Calendar1').rows[r].cells[c];
			if (mycell.className!="calendarna" && mycell.className!="calendarnaom") {startd=mycell; break}			
		}
		mycell=document.getElementById('Calendar1').rows[r].cells[0];
		if (startd!=0) {
			dayint=parseInt(startd.id.substring(1))
			mycell.innerHTML = "<font size='3'><a style='color:white' title='Select whole week' href='javascript:selectweek(" + dayint + ")'>&gt;</a></font>"
			} 
		else {
			mycell.innerHTML = "<font size='3'><Div style='color:DimGray'>&gt;</Div></font>"
		}
	}	
	}	
		
		
	if(autoshowtoday){
	    SelectSingleDate(0) //same as clicking 'Today'
	}else {	
	    setselecteddates()	
	   //out 2/9/10 showiframe()
	}
	setbuttons()
	
	var c
//highlight today if shown in calendar
	dayint= GetTodaysDayNum()

	c=document.getElementById('d'+dayint)
//	document.getElementById('d2064').onmouseover=function() {alert("mouseover")} //mymouseover(event)} //onclick=function() {alert("Hello 15")}
//	document.getElementById('d2064').onmouseout=function() {alert("mouseout")} //{mymouseout(event)} //onclick=function() {alert("Hello 15")}
//document.getElementById('d2070').className="calendarseldate"
//document.getElementById('d2070').onclick=function() {mycalclick(event)}
	if (!c && document.getElementById('x'+dayint)) {
	c=document.getElementById('x'+dayint)
	}
	if(c) {c.style.color="red";c.style.fontWeight="bold"}
		 	 
	 if (document.images)
    {
	var image1=new Image
	image1.src="Static/I/bgball.bmp"
	var image2=new Image
	image2.src="Static/I/bgball2.bmp"	
    }

    //If any start-up code generated by VB, execute it
    //if (typeof (bootCode) == "function") { bootCode() } 		
}
function showmess() {
//called from GS - used to display mess AFTER iframe is refreshed
if (displaymess!='') {alert(displaymess); displaymess=""}
}
function selectweekday(ColNum)
	{
		for (var r=1 ;r<8 ;r++) 
		{
			var mycell=document.getElementById('Calendar1').rows[r].cells[ColNum]

			if ((mycell.className =="calendarunsel")  || (mycell.className ==  "calendarunselom"))
			{
				if (!CheckDateCount())
				{
					return;
				}
				//alert('Came for SD');
				sd(mycell.id)			 //This will re-display GS on each calling!! Not good. Should have a mode that tells sd NOT to re-display.
			}
		} //endFor
	}
function selectweek(el) 
{
	var d=el
	//switch basis from 1/1/2000 to 1/1/2005
	var cstr
	for (var n=0; n<=6;n++) 
	{
		cstr="d"		
		dd=d+n
		cstr=cstr+dd //eg dn34
		
		if (document.getElementById(cstr)) 
		{	
			//will not exist if this is an 'unavailable' (past) date
			//also will be when the date is selected
			if ((document.getElementById(cstr).className =="calendarunsel")  || (document.getElementById(cstr).className == "calendarunselom"))
			{
				if (!CheckDateCount())
				{
					return;
				}
				sd(cstr)					
			}
		}
	}		
}
//
function cleardates(dontbotherhidingiframe) 
{
	//to clear all the selected dates
   	var theform=GetFormObject();
	var valarr
	//clear selections of dates in calendar

	valarr = getseldates()
	if (valarr != null) {
	    for (var n = 0; n < valarr.length; n++) {
	        sd('d' + valarr[n], dontbotherhidingiframe)
	        //this will unselect in calendar and remove them from seldates (also disables btngo and btncleardates)
	    }
	}
}
function  CheckDateCount()
{
	//limit how many can be selected
	var theform = GetFormObject();
	//
	var numd=0
	for (var m=0; m<=(theform.seldates.value.length)-1;m++) 
	{
		if (theform.seldates.value.charAt(m)=="|") 
		{
			numd+=1
		}
	}
	if (numd>(6*2)) 
	{
		//to check if other dates are remaing then only display else no dispaly
		alert('A maximum of 7 dates can be selected for display.');
		return false;			
	}
	else
	{
		return true;
	}
}

	function GetTodaysDayNum()
	//returns days since 1/1/5
{
    var dtDate1 =new Date();
    var dstr=(dtDate1.getMonth()+1) + "/" + dtDate1.getDate() + "/" + dtDate1.getFullYear() //assumes m/d/y
    return DateDiff("1/1/2005",dstr,"D",true)
}
function DateDiff( start, end, interval, rounding ) {
    var iOut = 0;    
    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;    		   
    var number = bufferB-bufferA ;    
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'w': case 'W': 
            iOut = parseInt(number / 604800000) ;
            if(rounding) iOut += parseInt((number % 604800000)/302400001) ;
            break ;
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
    }   
    
    return iOut ;
}
function SelectSingleDate(para)
{
	//para will be 0 if called from today
	//para will be 1 if called from >
	//para will be -1 if called from <
	//para will be 'dnn' if called from fssd
	var theform = GetFormObject();	
	var daynum
	var dayint=0
	if (para==0) {//select today
		dayint= GetTodaysDayNum()	
		daynum="d" + dayint
		if (document.getElementById('x'+dayint))  {alert ("Sorry! Closed today."); return}//if closed
	}
	
	if (para!=0) {
		daynum=para //will be 'dnn'
		dayint=parseInt(para.substring(1))
	}
		cleardates(true) //true is new 9/20/8 for FF
	
	if (document.getElementById(daynum)) 
	{ //this date is currently displayed in calendar		
		sd(daynum)	
	}
	else 
	{	
		theform.seldates.value='|' + daynum + '|'; 	//Note, this date may end up being closed when we display the correct month
		document.getElementById('calendarjump').value=dayint
		mysubmitform()
	}	
}
function moveweek(delta){
		var inti;
		var arrseldates
		var strdates
		var daynum
		var gotone
		gotone=false
		var datetoskipto
		datetoskipto=0

		arrseldates = getseldates()
		if (arrseldates != null) {
		    cleardates(true)//tell it not to bother hiding iframe (and help panel) cos we are going to redisplay immediately (this avoids tiny flicker)
		    for (inti = 0; inti < arrseldates.length; inti++) {
		        dayint = parseInt(arrseldates[inti])
		        dayint = dayint + delta
		        daynum = "d" + dayint
		        if (!document.getElementById('x' + dayint)) { //if this is shown as an 'X'ed date, do nothing
		            if (document.getElementById(daynum)) //this date is currently displayed in calendar	
		            {
		                gotone = true
		                sd(daynum, true)	//tell it not to bother hiding iframe (and help panel) cos we are going to redisplay immediately (this avoids tiny flicker)
		            } else //manually add it
		            {
		                document.getElementById('seldates').value += '|' + daynum + '|'
		                if (datetoskipto == 0) { datetoskipto = dayint }
		            }
		        } else {
		            alert('That date is not available for booking')
		        }
		    }
		    if (!gotone && datetoskipto != 0) {
		        document.getElementById('calendarjump').value = datetoskipto //delta
		        mysubmitform()
		    }
		}
}
function mysubmitform() {
var theForm = document.forms['Form1'];
if (!theForm) {theForm = document.Form1};
theForm.submit();
}