function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function pop(h, w, p, n, s, r){
	var theHeight=h;
	var theWidth=w;
	var theTop=(screen.height/2)-(theHeight/2)
	var theLeft=(screen.width/2)-(theWidth/2)
	var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	var winPop = window.open(p,n,"scrollbars="+s+","+features+",resizable="+r+"");
	winPop.focus();
}


function popTools(h, w, p, n, s, r){
	var theHeight=h;
	var theWidth=w;
	var theTop=(screen.height/2)-(theHeight/2)
	var theLeft=(screen.width/2)-(theWidth/2)
	var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	var winPop = window.open(p,n,"toolbar=yes,scrollbars="+s+","+features+",resizable="+r+"");
	winPop.focus();
}


function zero_empty_field(f,V){
	if(V.value == "" || isNaN(V.value)){
		 V.value = "0";
		 if(add_up) add_up(f);
	}
}

function processKey(f) {
    var keyvalue = window.event.keyCode;
    if (keyvalue==13) f.submit();
}



function phone_dash(t,v){
	if(v.length > 3 && v.indexOf("-") == -1){
		t.value = v.substring(0,3) + "-" + v.substring(3);
	}
}


function next_field(f,fld){
	if(fld.value.length >= fld.maxLength){
		for(i=0;i<f.elements.length;i++){
			if(f.elements[i].name == fld.name){
				f.elements[i+1].focus(0);
			}
		}
	} //this call from the form field: onkeyup="next_field(this.form,this)
}



function cal(f){
	pop(200, 250, "/activity/Intranet/pop_calendar.asp?f="+f+"&d="+eval("document."+f+".value"), "popCalendar", "no", "no");
}

function cal_limit(f,lower, upper){
	pop(200, 250, "/activity/Intranet/pop_calendar_limit_range.asp?f="+f+"&d="+eval("document."+f+".value")+"&start_date="+lower+"&lower_limit="+lower+"&upper_limit="+upper, "popCalendar", "no", "no");
}

function calM(f){
	pop(208, 250, "/activity/Intranet/pop_calendar_multiple.asp?f="+f+"&d="+eval("document."+f+".value")+"&start_date="+eval("document."+f+".value"), "popCalendar", "no", "no");
}

function calWarning(){
	alert("Please use the pop up calendar to select days!");
}

function calHome(f){
	pop(200, 250, "pop_calendar_home.asp?a=opener.document.GridForm.submit()&f="+f+"&d="+eval("document."+f+".value"), "popCalendar", "no", "no");
}

function CheckAll(Frm, Total, ElementName, Checked){
	if(Total > 0)
		for(var x=1;x<=Total;x++)
			eval("Frm."+ElementName+"[x].checked = Checked");
			
}


function facility(idno, sale_idno){
	pop(550, 750, "/activity/Intranet/facility.asp?idno="+idno + "&sale_idno="+sale_idno, "Edit",1,1);
}



function CamperSelect(user_idno){
	opener.document.GridForm.user_idno.value = user_idno;
	opener.validator(opener.document.GridForm, "SetCamper"); 
	opener.focus();
	window.close();
}

function ShowParkMap(i){
	pop(600, 650, '/activity/Intranet/pop_map.asp?park_idno='+i, 'WinMap', 'yes', 'yes');
}


function openFull(URL, WindowName) {
   var w = screen.availWidth - 10;
   var h = screen.availHeight - 45;
   var objWin = open(URL,"","toolbar=no,location=no,manubar=no,scrollbars=yes,resizable=yes,"+
               ",status=yes,width="+w+",height="+h+",left=0,top=0");
   objWin.focus();
}





function POSAddItems(idno, sale_idno, park_idno, PostPage){
	openFull('/activity/Intranet/POS/Products.asp?idno='+idno+'&sale_idno='+sale_idno+'&PostPage='+PostPage+'&park_idno='+park_idno, 'WinPosItems');
	//pop(600, 720, '/activity/Intranet/POS/Products.asp?idno='+idno+'&sale_idno='+sale_idno+'&PostPage='+PostPage+'&park_idno='+park_idno, 'WinPosItems', 'yes', 'yes');
}



function CheckIn(idno){
	//openFull("/activity/Intranet/CheckIn/CheckIn.asp?idno="+idno, "WinCheckIn");
	document.location.href = "/activity/Intranet/CheckIn/CheckIn.asp?idno="+idno;
}



function ParkingPermit(Vars){
	var theHeight=400;
	var theWidth=620;
	var theTop=10
	var theLeft=10
	var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	var winPop = window.open("ParkingPermit.asp?"+Vars,"WinParkingPermit","toolbar=yes,scrollbars=yes,"+features+",resizable=yes");
	winPop.focus();
}

function ParkingPermitNew(Vars){
	var theHeight=400;
	var theWidth=620;
	var theTop=10
	var theLeft=10
	var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	var winPop = window.open("ParkingPermit_new.asp?"+Vars,"WinParkingPermit","toolbar=yes,scrollbars=yes,"+features+",resizable=yes");
	winPop.focus();
}

function DoCancel(){
	if(window.opener){
		if(confirm("No changes will be saved, are you sure you want to cancel?")){
			window.close();
			opener.focus();
		}
	}else{
		document.location.href="/activity/intranet/";
	}
}

function DiscountCardAdmin(UserID){
	var theHeight=300;
	var theWidth=530;
	var theTop=10
	var theLeft=10
	var	features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	var winPop = window.open("DiscountAdmin.asp?UserID="+UserID,"DiscountCardAdmin","toolbar=no,scrollbars=yes,"+features+",resizable=yes");
	winPop.focus();
}

function CurrencyFormatted(amount)
	{
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s;
	}
	
// Prompt Alternative code here ---------------
// This is variable for storing callback function
var ae_cb = null;
 
// this is a simple function-shortcut
// to avoid using lengthy document.getElementById
function ae$(a) { return document.getElementById(a); }
 
// This is a main ae_prompt function
// it saves function callback 
// and sets up dialog
function ae_prompt(cb, q, a) {
	ae_cb = cb;
	ae$('aep_t').innerHTML = 'Set Time';
	ae$('aep_prompt').innerHTML = q;
	ae$('aep_text').value = a;
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = '';
	ae$('aep_text').focus();
	ae$('aep_text').select();
}
 
// This function is called when user presses OK(m=0) or Cancel(m=1) button
// in the dialog. You should not call this function directly.
function ae_clk(m) {
	// hide dialog layers 
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = 'none';
	if (!m) {
		ae_cb(null);  // user pressed cancel, call callback with null
		remove_entire_block(temp_site,temp_block,0);
	}else{
		ae_cb(ae$('aep_text').value); // user pressed OK 
	}
}
// END prompt alternative code --------------------------


//custom alt/alert box code below -------------------------

var pin_open = false;
	

function ShowBox(evt,box_name)
	{
		if(!pin_open){
		/*simple browser detection in order to choose between using pageX (does not work in IE) and clientX*/
			var IE=false;
			if(navigator.appName == "Microsoft Internet Explorer")
			IE = true;
		
			if(IE){
				x = evt.clientX + document.body.scrollLeft;
				y = evt.clientY + document.body.scrollTop;
			}else{
				x = evt.pageX;
				y = evt.pageY;
			}
		
			obj = document.getElementById(box_name);
			obj.style.left = (x + 15) + 'px';
			obj.style.top = (y + 2) + 'px';
			obj.style.visibility = 'visible';
			//obj.innerHTML = "<a href=\"#\" onclick=\"javascript:pin_open=false;closeBox('" + box_name + "');return false;\" class=\"close\" title=\"Close the box\"><B>X close</b></a><br>" + obj.innerHTML;
		}
	}
	function ShowBox_text(evt,box_name,display_text)
	{
		if(!pin_open){
		/*simple browser detection in order to choose between using pageX (does not work in IE) and clientX*/
			var IE=false;
			if(navigator.appName == "Microsoft Internet Explorer")
			IE = true;
		
			if(IE){
				x = evt.clientX + document.body.scrollLeft;
				y = evt.clientY + document.body.scrollTop;
			}else{
				x = evt.pageX;
				y = evt.pageY;
			}
		
			obj = document.getElementById(box_name);
			obj.style.left = (x + 15) + 'px';
			obj.style.top = (y + 2) + 'px';
			obj.style.visibility = 'visible';
			if(document.getElementById("alert_box_text")){
				obj = document.getElementById("alert_box_text");
				obj.style.visibility = 'visible';
				obj.innerHTML = display_text;
			}else{
				obj.innerHTML = display_text;
			}
			
		}
	}
	
	
	
	function closeBox(box_name)
	{
		if(!pin_open){
			obj = document.getElementById(box_name);
			obj.style.visibility = 'hidden';
		}
	}
// END custom alt/alert box code below -------------------------


function open_roster(V){
	pop(700,600,"program_roster.asp?program_session_idno=" + V,"Edit",1,1);
}



// Autocomplete! ----------------------------------------------


var customarray=new Array('apple','alligator','elephant','elegant', 'orange', 'pear','kingbird','kingbolt','kingcraft','kingcup','kingdom','kingfisher','kingpin');

/* ---- Variables ---- */
var actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
var actb_lim = 4;    // Number of elements autocomplete can show (-1: no limit)
var actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
/* ---- Variables ---- */

/* --- Styles --- */
var actb_bgColor = '#888888';
var actb_textColor = '#FFFFFF';
var actb_hColor = '#000000';
var actb_fFamily = 'Verdana';
var actb_fSize = '11px';
var actb_hStyle = 'text-decoration:underline;font-weight="bold"';
/* --- Styles --- */

/* ---- Constants ---- */
var actb_keywords = new Array();
var actb_display = false;
var actb_pos = 0;
var actb_total = 0;
var actb_curr = null;
var actb_rangeu = 0;
var actb_ranged = 0;
var actb_bool = new Array();
var actb_pre = 0;
var actb_toid;
var actb_tomake = false;
/* ---- Constants ---- */

function actb_parse(n){
    var t = escape(actb_curr.value);
    var tobuild = '';
    var i;
    
    if (actb_firstText){
        var re = new RegExp("^" + t, "i");
    }else{
        var re = new RegExp(t, "i");
    }
    var p = n.search(re);
    
    for (i=0;i<p;i++){
        tobuild += n.substr(i,1);
    }
    tobuild += ""
    for (i=p;i<t.length+p;i++){
        tobuild += n.substr(i,1);
    }
    tobuild += "";
    for (i=t.length+p;i<n.length;i++){
        tobuild += n.substr(i,1);
    }
    return tobuild;
}

function actb_generate(){
    if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
    a = document.createElement('table');
    a.cellSpacing='1px';
    a.cellPadding='2px';
    a.style.position='absolute';
    a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
    a.style.left = curLeft() + "px";
    a.style.backgroundColor=actb_bgColor;
    a.id = 'tat_table';
    document.body.appendChild(a);
    var i;
    var first = true;
    var j = 1;

    var counter = 0;
    for (i=0;i<actb_keywords.length;i++){
        if (actb_bool[i]){
            counter++;
            r = a.insertRow(-1);
            if (first && !actb_tomake){
                r.style.backgroundColor = actb_hColor;
                first = false;
                actb_pos = counter;
            }else if(actb_pre == i){
                r.style.backgroundColor = actb_hColor;
                first = false;
                actb_pos = counter;
            }else{
                r.style.backgroundColor = actb_bgColor;
            }
            r.id = 'tat_tr'+(j);
            c = r.insertCell(-1);
            c.style.color = actb_textColor;
            c.style.fontFamily = actb_fFamily;
            c.style.fontSize = actb_fSize;
            c.innerHTML = actb_parse(actb_keywords[i]);
            c.id = 'tat_td'+(j);
            j++;
        }
        if (j - 1 == actb_lim && j < actb_total){
            r = a.insertRow(-1);
            r.style.backgroundColor = actb_bgColor;
            c = r.insertCell(-1);
            c.style.color = actb_textColor;
            c.style.fontFamily = 'arial narrow';
            c.style.fontSize = actb_fSize;
            c.align='center';
            c.innerHTML = '\\/';
            break;
        }
    }
    actb_rangeu = 1;
    actb_ranged = j-1;
    actb_display = true;
    if (actb_pos <= 0) actb_pos = 1;
}

function curTop(){
    actb_toreturn = 0;
    obj = actb_curr;
    while(obj){
        actb_toreturn += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return actb_toreturn;
}

function curLeft(){
    actb_toreturn = 0;
    obj = actb_curr;
    while(obj){
        actb_toreturn += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return actb_toreturn;
}

function actb_remake(){
    document.body.removeChild(document.getElementById('tat_table'));
    a = document.createElement('table');
    a.cellSpacing='1px';
    a.cellPadding='2px';
    a.style.position='absolute';
    a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
    a.style.left = curLeft() + "px";
    a.style.backgroundColor=actb_bgColor;
    a.id = 'tat_table';
    document.body.appendChild(a);
    var i;
    var first = true;
    var j = 1;
    if (actb_rangeu > 1){
        r = a.insertRow(-1);
        r.style.backgroundColor = actb_bgColor;
        c = r.insertCell(-1);
        c.style.color = actb_textColor;
        c.style.fontFamily = 'arial narrow';
        c.style.fontSize = actb_fSize;
        c.align='center';
        c.innerHTML = '/\\';
    }
    for (i=0;i<actb_keywords.length;i++){
        if (actb_bool[i]){
            if (j >= actb_rangeu && j <= actb_ranged){
                r = a.insertRow(-1);
                r.style.backgroundColor = actb_bgColor;
                r.id = 'tat_tr'+(j);
                c = r.insertCell(-1);
                c.style.color = actb_textColor;
                c.style.fontFamily = actb_fFamily;
                c.style.fontSize = actb_fSize;
                c.innerHTML = actb_parse(actb_keywords[i]);
                c.id = 'tat_td'+(j);
                j++;
            }else{
                j++;
            }
        }
        if (j > actb_ranged) break;
    }
    if (j-1 < actb_total){
        r = a.insertRow(-1);
        r.style.backgroundColor = actb_bgColor;
        c = r.insertCell(-1);
        c.style.color = actb_textColor;
        c.style.fontFamily = 'arial narrow';
        c.style.fontSize = actb_fSize;
        c.align='center';
        c.innerHTML = '\\/';
    }
}
function actb_goup(){
    if (!actb_display) return;
    if (actb_pos == 1) return;
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
    actb_pos--;
    if (actb_pos < actb_rangeu) actb_moveup();
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
    if (actb_toid) clearTimeout(actb_toid);
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
}
function actb_godown(){
    if (!actb_display) return;
    if (actb_pos == actb_total) return;
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
    actb_pos++;
    if (actb_pos > actb_ranged) actb_movedown();
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
    if (actb_toid) clearTimeout(actb_toid);
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
}
function actb_movedown(){
    actb_rangeu++;
    actb_ranged++;
    actb_remake();
}
function actb_moveup(){
    actb_rangeu--;
    actb_ranged--;
    actb_remake();
}
function actb_penter(){
    if (!actb_display) return;
    actb_display = 0;
    var word = '';
    var c = 0;
    for (var i=0;i<=actb_keywords.length;i++){
        if (actb_bool[i]) c++;
        if (c == actb_pos){
            word = actb_keywords[i];
            break;
        }
    }
    a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
    actb_curr.value = a;
    actb_removedisp();
}
function actb_removedisp(){
    actb_display = 0;
    if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
    if (actb_toid) clearTimeout(actb_toid);
}
function actb_checkkey(evt){
    a = evt.keyCode;
    if (a == 38){ // up key
        actb_goup();
    }else if(a == 40){ // down key
        actb_godown();
    }else if(a == 13){
        actb_penter();
    }
}
function actb_tocomplete(sndr,evt,arr){
    if (arr) actb_keywords = arr;
    if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;
    var i;
    if (actb_display){ 
        var word = 0;
        var c = 0;
        for (var i=0;i<=actb_keywords.length;i++){
            if (actb_bool[i]) c++;
            if (c == actb_pos){
                word = i;
                break;
            }
        }
        actb_pre = word;//actb_pos;
    }else{ actb_pre = -1};
    
    if (!sndr) var sndr = evt.srcElement;
    actb_curr = sndr;

    if (sndr.value == ''){
        actb_removedisp();
        return;
    }
    var t = sndr.value;
    if (actb_firstText){
        var re = new RegExp("^" + t, "i");
    }else{
        var re = new RegExp(t, "i");
    }
    
    actb_total = 0;
    actb_tomake = false;
    for (i=0;i<actb_keywords.length;i++){
        actb_bool[i] = false;
        if (re.test(actb_keywords[i])){
            actb_total++;
            actb_bool[i] = true;
            if (actb_pre == i) actb_tomake = true;
        }
    }
    if (actb_toid) clearTimeout(actb_toid);
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
    actb_generate(actb_bool);
}




// end Autocomplete ---------------------------------------------------


