// JavaScript Document


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//Jump Menus
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//Pop-up windows
var win = null;
function NewWindow(mypage,myname,w,h,scroll,resize){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize;

win = window.open(mypage,myname,settings)
}

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//implementation: onClick="return areYouSure('Proceed with deletion blah blah?');"

function areYouSure(text) {
	
	
	if(!text) { 
		var text = "Are you sure you want to permanently delete this listing?"; 
	}
	
	doyou = confirm(text); //Your question.
	if (doyou == true) {
		//alert("User deleted."); //If your question is answered Yes.
		return true;
	}
	else{
		if (doyou == false) {
			//history.go(-1); //After answered No, the action. (In < this < case, it sends you back 1 page!)
			return false;
		}
	}

} 

// registration.php //

function showregforms()
{
	var reg_info = document.getElementById("reg_info");
	var reg_hours = document.getElementById("reg_hours");
	var info_h2 = document.getElementById("info_h2");
	var hours_h2 = document.getElementById("hours_h2");
	
	
	
	reg_info.style.visibility="visible";
	reg_hours.style.visibility="visible";
	info_h2.style.visibility="visible";
	hours_h2.style.visibility="visible";
}

function hideregforms()
{
	var reg_info = document.getElementById("reg_info");
	var reg_hours = document.getElementById("reg_hours");
	var info_h2 = document.getElementById("info_h2");
	var hours_h2 = document.getElementById("hours_h2");
	
	
	
	reg_info.style.visibility="hidden";
	reg_hours.style.visibility="hidden";
	info_h2.style.visibility="hidden";
	hours_h2.style.visibility="hidden";
}


// addupdate_r.php //


/*
Auto tabbing script- By JavaScriptKit.com
http://www.javascriptkit.com
*/

function autotab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	destination.focus()
}
/*
// This will add upload fields when the selectbox is used to choose a number
   args: 
      n_fields: number of fields to add, 
	  file_n_start: the labeling convention starting number
	  desination_element: the element that will contain the new file upload fields
*/
function addUploadFields(n_fields,file_n_start,destination_element) {
	
	destination_element.innerHTML = '';

	for(i = 1; i <= n_fields; i++) {
		
		n = i + file_n_start-1;
		
		destination_element.innerHTML += 'Upload File: <input type="file" name="'+n+'"  /> <br><br>';
		
	}
}

function ApplytoAll()
{
	var Mh1    = document.getElementById('M0_hour_select_1');
	var Mh2    = document.getElementById('M1_hour_select_2');
	var Mm1    = document.getElementById('M0_min_select_1');
	var Mm2    = document.getElementById('M1_min_select_2');
	var Mampm1 = document.getElementById('M0_ampm_select_1');
	var Mampm2 = document.getElementById('M1_ampm_select_2');

	for(i=2;i<13;i=i+2) {
		//document.write('selected index: ' + document.getElementById(i.'_hour_select_1').selectedIndex);
		document.getElementById(''+i+'_hour_select_1').selectedIndex = Mh1.selectedIndex;
		document.getElementById(''+i+'_min_select_1').selectedIndex	 = Mm1.selectedIndex;
		document.getElementById(''+i+'_ampm_select_1').selectedIndex= Mampm1.selectedIndex;
		
	}
	for(i=3;i<14;i=i+2) {
		document.getElementById(''+i+'_hour_select_2').selectedIndex = Mh2.selectedIndex;
		document.getElementById(''+i+'_min_select_2').selectedIndex	 = Mm2.selectedIndex;
		document.getElementById(''+i+'_ampm_select_2').selectedIndex= Mampm2.selectedIndex;
	}

  
}

function look_to_disable() {
	
	var days = Array('m','t','w','r','f','sa','s');
	
	//alert(days[6]);
			   
	for(i = 0; i < days.length; i++) {
		var closed = document.validate_me[days[i]+"_closed"];
		
		//if(closed.checked) {alert(closed.checked + ' ' + days[i]);}
		
		disable(days[i],closed.checked);	
		
	}
	
}
function disable(dayname,disableIt)
{
	if(dayname.substr(0,2) == "sa") {
		var alpha = dayname.substr(0,2);
		
	}
	else {
		var alpha = dayname.substr(0,1);
	}
	//use bracket notation (instead of dot notation) to create a variable name out of two concatenated strings
	
	var h1    = document.validate_me[alpha+"1*h"];
	var h2    = document.validate_me[alpha+"2*h"];
	var m1    = document.validate_me[alpha+"1*min"];
	var m2    = document.validate_me[alpha+"2*min"];
	var ampm1 = document.validate_me[alpha+"1*ampm"];
	var ampm2 = document.validate_me[alpha+"2*ampm"];
	
	//window.alert(alpha+"2*ampm");
	
	h1.disabled = disableIt;
	h2.disabled = disableIt;
	m1.disabled = disableIt;
	m2.disabled = disableIt;
	ampm1.disabled = disableIt;
	ampm2.disabled = disableIt;

	
}

function disableField(fieldname,disableIt) {
	
	fieldname.disabled = disableIt;
	
}

function disableAllDays(disableIt) {
	
	var days = Array('m','t','w','r','f','sa','s');
	for(i = 0; i < days.length; i++) {
		disable(days[i],disableIt);	
	}
}
/* 
This function activates the animated GIF to inform the user of upload progress.  It is placed in two places in form_validator.js : once to disable it (if any validation failures) in the function vdesc_validate() and once to enable it by default at the very END of the file.
bool = true or false.  true enables, false disables
*/
function uploadGIF(bool) {
	
	var div = document.getElementById('upload_progress');
	//var formstatus = document.validate_me;
	
	//alert('submit success');
	if(bool == true) {
		div.style.display = 'block';
	} else {
		div.style.display = 'none';
	}
}
function disableSubmitButton(bool) {
	
	var btn = document.getElementById('upload_submit');
	//var formstatus = document.validate_me;
	
	//alert('disable submit btn');
	if(bool == true) {
		btn.style.visibility = 'hidden';
		
		//alert('disable submit btn -- TRUE!');
	} else {
		btn.style.visibility = 'visible';
	}
}


// profile.php //

function switch_loc(loc_types) {
	//loc_types = array of all possible one letter loc type div ids, synched up with php and mysql entries
	
	var loc_select = document.Google_Dir['loc_type'];
	var choice = loc_select.options[loc_select.selectedIndex].value;
	
	var to_show = document.getElementById(choice);
	
	var mother = document.getElementById('map_addr_input_sub');
	
	
	for(i=0; i < loc_types.length; i++){
		//alert (loc_types[i]);
		var loc_type_div = document.getElementById(loc_types[i]);
		
		//alert('choice: '+choice);
			
		if(loc_types[i] != choice){
			
			loc_type_div.style.visibility = 'hidden';
			loc_type_div.style.display    = 'none';
			
		}
	}
	
	to_show.style.visibility = 'visible';
	to_show.style.display    = 'block';
}
function showhideChildElements(Id_or_Element,vis) {
	
	//recursive function that shows or hides ALL descendents of an element
	
	if(vis == 'show') {
		vis_in_f = 'visible';	
	} else { vis_in_f = 'hidden'; }
	
	//check to see if func argument is an Element's Id (string) or an HTML object
	var mother = document.getElementById(Id_or_Element);
	if(!mother) {
		mother = Id_or_Element;	
	}
	
	
	for (var i = 0; i<mother.childNodes.length; i++) {
		var child = mother.childNodes[i];
		if(child.nodeType == 1) {
			child.style.visibility = vis_in_f;
			
		
			showhideChildElements(child,vis);
			
		}
	}
}

// Email a Friend pop-up//
function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if ( x[i].getAttribute('maxlength') ) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML =
			'<span class="chars_typed">0</span> / <span class="chars_max">'+x[i].getAttribute('maxlength')+' chars max</span>';
			
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'error'; //edit this class in your CSS file
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

// Menu Pop-Up //
// IE Bug 12/27/07: 
// Window must be scrolled down just a hair for the TJPZoom box to be at the normal distance from the mouse pointer
function TJP_IE_Fix() {
	
	var ScrollDown = false;
	
	var currentTop  = document.documentElement.scrollTop;
	var currentLeft = document.documentElement.scrollLeft;
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		
		if( currentTop == 0 ) { 
		
			ScrollDown = true;
			//alert(document.documentElement.scrollTop);
		}
		else { ScrollDown = false; }

	}
	// other browsers use: window.pageYOffset  to measure the scroll position
	
	if (ScrollDown == true) {
		window.scrollTo(currentLeft,3);
	}

}


function Gettime() {
var now = new Date();
//var currenthour = now.getHours();
//var currenttime = now.getMinutes();
//var currentdate = now.getDate();
//var offset = now.gettimezoneOffset();
document.write(now);
}

// Purpose: to speed loading times by loading the Google Ads after the page loads
// Takes googleAds in invisible container divs from the bottom of the page and moves the ads to the previously empty display divs in the final version of the page.
// Run this in the body onload= property.

function loadGoogleAds(containerDivId,displayDivId) {
	
	
	// search through "GoogleAds_Container1","GoogleAds_Container2", ...."10"
	for(var i=1; i<10; i++){

		from = document.getElementById(containerDivId+i);
		
		// End loop if there are no more numbered ids on the page
		if(!from) {
			break;
		}
		
		to = document.getElementById(displayDivId+i);
		
		to.innerHTML = from.innerHTML;
	
	} //end for
	
	return true
	
}

///////////////////////////
// This is a live event handler
//window.onResize = toggleFooterOnResize;

////////////////////////////////

function toggleFooterOnResize() {
	
	alert('footer');
	
	var footer = document.getElementById('footer_bg');
	if(getWindowSize('height') < 400) {
		footer_bg.style.display = 'none';	
	}
	else {
		footer_bg.style.display = 'block';	
	}
}
function getWindowSize(dim) { // dim = 'height' or 'width'
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 // window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
 
  if(dim == 'height') {
   return myHeight;
  } else { return myWidth; }
}
