function setSecondNavVisible(show){
	if(show)
		vis = "visible";
	else
		vis = "hidden";	
	document.getElementById('top_nav_secondary').style.visibility = vis;
}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
			return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)
			index = i;
		else i++;
			return index;
	}
	return true;
}
function contactUs(){
        var valid = false;
        var key = document.contact;
        if(key.fname.value == ''){
                alert('First name cannot be blank.');
                key.fname.focus();
        }else if(key.lname.value == ''){
                alert('Last name cannot be blank.');
                key.lname.focus();
        }else if(key.email.value == ''){
                alert('E-Mail cannot be blank.');
                key.email.focus();
	}else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(key.email.value))){
		alert("Invalid E-mail Address! Please re-enter.")
                key.email.focus();
        }else if(key.message.value == ''){
                alert('Message cannot be blank.');
                key.message.focus();
        }else{
                key.send_message.value = "true";
                valid = true;
        }
	return valid;
}
function getFranchiseInfo(){
        var valid = false;
        var key = document.franchise;
        if(key.fname.value == ''){
                alert('First name cannot be blank.');
                key.fname.focus();
        }else if(key.lname.value == ''){
                alert('Last name cannot be blank.');
                key.lname.focus();
        }else if(key.address1.value == ''){
                alert('Address cannot be blank.');
                key.address1.focus();
        }else if(key.city.value == ''){
                alert('City cannot be blank.');
                key.city.focus();
        }else if(key.state.value == ''){
                alert('State cannot be blank.');
                key.state.focus();
        }else if(key.zip.value == ''){
                alert('Zip cannot be blank.');
                key.zip.focus();
        }else if(key.country.value == ''){
                alert('Country cannot be blank.');
                key.country.focus();
        }else if(key.email.value == ''){
                alert('E-Mail cannot be blank.');
                key.email.focus();
	}else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(key.email.value))){
		alert("Invalid E-mail Address! Please re-enter.")
                key.email.focus();
        }else if(key.phone_home.value == ''){
                alert('Home phone cannot be blank.');
                key.phone_home.focus();
        }else if(key.currentOccupation.value == ''){
                alert('Current Occupation cannot be blank.');
                key.currentOccupation.focus();
        }else if(key.everOwnedFranchise.value == ''){
                alert('"Have you ever owned a franchise?" cannot be blank.');
                key.everOwnedFranchise.focus();
        }else{
                key.send_message.value = "true";
                valid = true;
        }
	return valid;
}
function confirmDelete(appt, sec){
	if(sec == 'OnSiteCal')
	  tmp = 'appointment';
	if(sec == 'TechQueue')
	  tmp = 'work order';
	if(sec == 'UsedSysInv')
	  tmp = 'computer';
	if(confirm('Are you sure that you want to delete this '+tmp+'?')){
	  document.appointments.section.value = sec;
	  document.appointments.subsec.value = appt;
	  document.appointments.del.value = '1';
	  document.appointments.submit();
	}
}

function getMap(addr, csz){
	vars = "addr="+addr+"&csz="+csz;
	loc = "http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps?getmap=Get%Map&country=us&srchtype=a&"+vars;
	window.open(loc,'Map','toolbar=no,scrollbars=yes,location=no,width=525,height=400');
}
function chkbx(sec){
	if(sec == 'dt')
	  document.search.chkDt.checked = true;
	else if(sec == 'nm')
	  document.search.chkNm.checked = true;
	else if(sec == 'ph')
	  document.search.chkPhn.checked = true;
	else if(sec == 'wo')
	  document.search.chkWo.checked = true;
}
function submitQueue(){
  	var validDoc = false;
	if(document.queue.associate.selectedIndex == 0){
	  alert('Associate field cannot be blank');
	  document.queue.associate.focus();
	}else if(document.queue.customer.value == ""){
	  alert('Customer field cannot be blank');
	  document.queue.customer.focus();
	}else
	  validDoc= true;
	return validDoc;
}
function techCheckIn(){
  	var validDoc = false;
	if(document.queue.tech.selectedIndex == 0){
	  alert('Tech field cannot be blank');
	  document.queue.tech.focus();
	}else if(document.queue.wo.selectedIndex == 0){
	  alert('Work Order field cannot be blank');
	  document.queue.wo.focus();
	}else
	  validDoc= true;
	return validDoc;
}
function checkOut(){
  	var validDoc = false;
	var doc = document.queue; 
	if(doc.pYr.selectedIndex == 0 ||
	   doc.pMn.selectedIndex == 0 ||
	   doc.pDy.selectedIndex == 0 ||
	   doc.pHr.selectedIndex == 0 ||
 	   doc.pMin.selectedIndex == 0 ||
	   doc.pAmPm.selectedIndex == 0 ){
	  alert('Please complete the check-out date.');
	  document.queue.pMn.focus();
	}else if(document.queue.wo.value == ""){
	  alert('Work Order field cannot be blank');
	  document.queue.wo.focus();
	}else
	  validDoc= true;
	return validDoc;
}
function GetTech(tech){
	  document.navigate.section.value = "TechQueue";
	  document.navigate.tech.value = tech;
	  document.navigate.submit();
}
function Navigate(section, subsec, details){
	document.navigate.section.value = section;
	document.navigate.subsec.value = subsec;
	document.navigate.details.value = details;

	if(subsec == 'WEB'){
	  if(confirm('Are you sure that you want to synch the public web site to to the intranet?'))
	    document.navigate.submit();
	}else
	  document.navigate.submit();
}
function getReport(){
	document.appointments.CSV.value = true;
	document.appointments.section.value = 'UsedSysInv';
	document.appointments.submit();
}
function PrintPg(section){
	window.open('print.html?section='+section,null,"height=400,width=575,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");	
}
