// JavaScript Document



// Function to allow one JavaScript file to be included by another.
function IncludeJavaScript(jsFile)
{
	newJS = document.createElement('script');
	newJS.type='text/javascript';
	newJS.src=jsFile;
	// Add the element to the end of the head, body, or any other tag HERE:
	document.getElementsByTagName('body')[0].appendChild(newJS);
}

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,scrollb,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='+scrollb+',resizable='+resize;

win = window.open(mypage,myname,settings)
}
//Run this from a link around the entire wrapper div of a pop-up
function closethis() {
	if(opener){
		self.close();
		opener.focus();
	}
}
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; }
}

function areYouSure(item_name) {
	
	if(!item_name) { var item_name = "this listing"; }
	else {
		item_name = "the listing for \""+item_name+"\"";	
	}
	doyou = confirm("Are you sure you want to permanently delete "+item_name+" from Menuscan.com?"); //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()
}


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';
	}
}

// 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;
	
	
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		
		if(document.documentElement.scrollTop == 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(0,3);
	}
	
	//Every half-second, check to see if user is at top of page.  If so, bring user down 3px;
	//Unfortunately this looping property degrades performance, so it is disabled
	//setTimeout('TJP_IE_Fix();',4000);

}

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);
}


