// JavaScript Document

$(document).ready(function() {

		$("input, select, textarea").focus(function () {         
			$(this).addClass('fieldFocus');    
		});
		
		$("input, select, textarea").focusout(function () {         
			$(this).removeClass('fieldFocus');			    
		});
	
			// image checkboxs
		$(".img_check").click(function() {
			var chk = $(this).attr("id")
			var str = chk.substr(7, chk.length)
			var e = $("#"+str)
			
			if (e.val()=='1') {	
				e.val("0")
				e.removeAttr("checked");
				$(this).removeClass("img_checked")
			} else {
				e.val("1")
				e.attr("checked", "checked");
				$(this).addClass("img_checked")
			}
		});
	
		$("#tour_menu li").hover(function() {
		   var tiptxt = "Click to take a Tour of our "
		   switch ($(this).attr("id")) {
		   	case 'lobby': 
				tiptxt = tiptxt + "Lobby"
				break;
		   	case 'estimates': 
				tiptxt = tiptxt + "Indoor Estimating"
				break;
		   	case 'metal': 
				tiptxt = tiptxt + "Body Shop"
				break;
		   	case 'wheels': 
				tiptxt = tiptxt + "Wheel Repair Dept."
				break;
		   	case 'dents': 
				tiptxt = tiptxt + "Paintless Dent Repair Examples"
				break;
		   	case 'paint': 
				tiptxt = tiptxt + "Paint Refinishing Dept."
				break;
		   	case 'detailing': 
				tiptxt = tiptxt + "Detailing Dept."
				break;
			}	
				
			$(this).attr("title",tiptxt)
		});
	 
		$("#tour_menu li").click(function() {
			var id = $(this).attr("id")
			var url = "../tour_the_shop.asp?dept=" + id
			window.location = url
		});
});


function validate_list_items() {
	url = "check_lists_items.asp?id=" + page_ID 
	$.get(url, function(data){
		if (data=="1") {
			window.location = "../database/lists.asp?id=" + page_ID + "&pg_name=" + pagename
		} else {
			alert($("#page_name").val() + ", Does not have any lists items!")
		}
	});
}

function validate_text_regions() {
	url = "check_text_regions.asp?id=" + page_ID
	$.get(url, function(data){
		if (data=="1") {
			window.location = "../database/text_regions.asp?id=" + page_ID + "&pg_name=" + pagename
		} else {
			alert($("#page_name").val() + ", Does not have any text regions!")
		}
	});
}

function update_check_buttons() {

   $(':checkbox').each(function () { 
	   var but = "#button_" + $(this).attr("id")
	   
	   if (this.value=="1") {
		  $(but).addClass("img_checked")		  
	   } else {
		  $(but).removeClass("img_checked")
	   }		   
	});
}

function slideDown()  {
	// colored flash effect
	$("#drawer").css("backgroundColor", "#229");
	$("#drawer").slideToggle("slow");
	setTimeout(function() { $("#drawer").css("backgroundColor", "#fff"); }, 1000);
	setTimeout(function() { slideUp(); }, 5000);
};

function slideUp()  {
	$("#drawer").slideToggle("slow");
};

function hide_errors() {
   $('#errors').css("display","none")
}

function showhelp() {
	alert("Remember Me Information:\n\nThis functionality provides you with the convienience of not having to re-enter your personal data each time you return to schedule a new appointment and will save you time, a small file called a cookie stores your info on your own computer, so for this to work your browser must have cookies enabled for this site.\n\nThis is safe because all the information is stored on your own computer.")	
}

function title_txt(id) {
   var tiptxt = "Click to take a Tour of our "
   switch (id) {
	case 'lobby': 
		tiptxt = tiptxt + "Lobby"
		break;
	case 'estimates': 
		tiptxt = tiptxt + "Indoor Estimating"
		break;
	case 'metal': 
		tiptxt = tiptxt + "Body Shop"
		break;
	case 'wheels': 
		tiptxt = tiptxt + "Wheel Repair Dept."
		break;
	case 'lounge': 
		tiptxt = tiptxt + "Lounge Room"
		break;
	case 'dents': 
		tiptxt = tiptxt + "Paintless Dent Repair Examples"
		break;
	case 'paint': 
		tiptxt = tiptxt + "Paint Refinishing Dept."
		break;
	case 'detailing': 
		tiptxt = tiptxt + "Detailing Dept."
		break;
	}	
		
	$("#" + id).attr("title",tiptxt)
};

// JavaScript Document

function open_page(PageAction, target) {
    window.open(PageAction,target);
}

function nav(id) {
   window.location = id	
}

function SessionInit() {
   // we only need to change this variable to reconfigure the timeout
	var nMins = 20
	var nTimeout = (60000 * nMins)
	//alert("Session Maximum: " + nMins + nTimeout + " Session Warning: " + (nMins-2)*60000)
	setTimeout('sessionTimeout('+nMins+')', nTimeout);
	setTimeout('sessionTimeoutNotify()',((nMins-2)*60000));
}

function sessionTimeoutNotify()  {
	var url= "/get_status.asp"		
	$.get(url, function(data){
		var AccessLevel = data.AccessLevel
	   // Ignor if they are just a visitor
	   if (AccessLevel == '0' | AccessLevel == '1') {
		   return;
		}
		alert("Your Session will end in 2 Minutes."
		+ "\n" + "due to inactivity.");
	},"json")
}

function sessionTimeout(nMins)  {
	alert("Your Session has timed out."	
	+ "\n" + "As a Security measure, your Session ends after " + nMins 
	+ " minutes of inactivity."+ "\n" 
	+ "you will need to Login again to continue with elevated tasks.");
	window.location ="/logout.asp?mode=h";
}

function logout() {
	var url= "logout.asp"	
	$.get(url, function(data){
	$("#LogInOut").html("<a href='login.asp'>User Login</a>")
	});
	
	disp_status ()
}		


function disp_status(){

	url= "get_visitors.asp"
	$.get(url, function(data){
	   if (data != '0') {		
		  var str = "Visitors: " + data;	          
		  $("#visitors").html(str)	   
	   }
	});		

	url= "greeting.asp"
	$.get(url, function(data){
	   if (data != '0') {		
		  var str = data;	          
		  $("#user").html(str)	
	   }
	});		

	url= "user.asp"
	$.get(url, function(data){
		// See what the UserID Session Status is
	   if (data != '') {		
	      //alert("User is Logged In")
		  $("#LogInOut").html("<a href='javascript:; logout()'>User Logout</a>")
	   } else {
		   //alert("User is Logged Out")
		  $("#LogInOut").html("<a href='login.asp'>User Login</a>")
	   }
	});
}


function NewWindow(mypage,myname,w,h,scroll){
	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=no,'
	win = window.open(mypage,myname,settings)
}

function previous_page() {
	window.history.back();
}	


function showValues(form){
   var values = '';
   var frm = $("#" + form)

   $(' :input').each(function () {
	   if ( $(this).attr("type") != 'button') {
		   values += $(this).attr("id")
		   values += ': \t';
		   values += $(this).val()
		   values += '\n';
	   }
	});
	alert(values);
}

function str_replace(haystack, needle, replacement) {
	//var str=haystack;
	//str.replace(needle, replacement) 
	var temp = haystack.split(needle);
	return temp.join(replacement);
	//return str;
}

//onkeyup="input_phone(this,this.value)"	   
function key_hit(key, fld) {
		
	if (key.keyCode==9) {
	   return false;
	}
	
	if (key.keyCode==13) {
	   prepare_Query_Fields()
	   return false;
	} else {
    
		// move to the next field if the require length has been reached
		if (fld.value.length==fld.maxLength) {
			 switch(fld.name) {
				case 'TireWidth': {
					document.getElementById('TireHeight').focus();
					document.getElementById('TireHeight').select();
				    //thefrm.TireHeight.focus();
				    //thefrm.TireHeight.select();
				   break;
				}   
				case 'TireHeight': {
					document.getElementById('Rim').focus();
					document.getElementById('Rim').select();
					//thefrm.Rim.focus();					
					//thefrm.Rim.select();
					break;
				}	     
				case 'Rim': { 
					document.getElementById('but_display').focus();
					break;
				}	     
			}	
		}
	}
}

function whichButton(event)
{
alert(event.keyCode);
}


function clear_form(frm) {
    document.getElementById(frm).reset();
}

function submit_form(frm) {
    document.getElementById(frm).submit();
}

function hide_div(id) {
	var e = document.getElementById(id);
		e.style.display = 'none';
}

function show_div(id) {
	var e = document.getElementById(id);
		e.style.display = 'block';
}

function toggle_layer(id) {
	var e = document.getElementById(id);
	if (e.style.visibility == 'hidden') {
	   e.style.visibilty = 'visible'
	} else {	
	   e.style.visibility = 'hidden'
	}
}


function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
  tempX = event.clientX + document.body.scrollLeft;
  tempY = event.clientY + document.body.scrollTop;
} else {  // grab the x-y pos.s if browser is NS
  tempX = e.pageX;
  tempY = e.pageY;
}  

if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  

//document.Show.MouseX.value = tempX;
//document.Show.MouseY.value = tempY;

return true;

}


// Session Monitoring Functions


function BrowserInfo()

{
  this.name = navigator.appName;
  this.codename = navigator.appCodeName;
  this.version = navigator.appVersion.substring(0,4);
  this.platform = navigator.platform;
  this.javaEnabled = navigator.javaEnabled();
  this.screenWidth = screen.width;
  this.screenHeight = screen.height;
  this.userAgent = navigator.userAgent;
  this.cookieEnabled = navigator.cookieEnabled;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

