function Logout() {
	var logoutUrl = "templates/logout.php?user=" + document.MemberHomeForm.user.value;
	window.location.href = logoutUrl;
}
 function Popup()
 {
   mywindow = window.open("includes/SearchAirport.php", "Safety_Pilot_Club_Airport_Code","location=0,status=0,scrollbars=1, width=650,height=500");
  mywindow.moveTo(20,100);
 } 

 function ajaxFunction(uid,action,tid){
//You should pass the date field that is tobe validated as date_field, the format_field should be U, J, or W to indicate the date format and the range_field shoud be A, P, or F to indicate whether all, past or future dates are valid.
	var valid_date = true;
	if(action == "update"){
	date_field = document.EditProfile.Trip_Date.value;
	valid_date = validateDate(date_field,'U','A')
	}
	if(valid_date == true){
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(action != '0'){
				if(ajaxRequest.readyState == 4){
					var ajaxDisplay = document.getElementById('ajaxDiv');
					ajaxDisplay.innerHTML = ajaxRequest.responseText;
					ajaxDisplay.focus();
				}
			}
		}
		if(action != '0'){
		var ajaxDisplay = '';
		var TripDate = document.getElementById('Trip_Date').value;
		var TripDesc = document.getElementById('Trip_Desc').value;
		}else{
			var TripDate = 0;
			var TripDesc = 0;
		}
		var queryString = "?date=" + TripDate + "&desc=" + TripDesc + "&uid=" + uid + "&action=" + action + "&tid=" + tid;
		ajaxRequest.open("GET", "includes/ajax.php" + queryString, true);
		ajaxRequest.send(null);
	}else{
		alert('Invalid Date.Format mm/dd/yyyy');
		document.EditProfile.Trip_Date.focus();
	}
}

function ImagePopup(img,action){
	window.open( 'includes/Popup.php?img=' + img + "&action=" + action, "", "resizable=1,HEIGHT=200,WIDTH=200");
}
function ComposePopup(from_id, to_id)
{
	var Compose = window.open('templates/Mail_Compose.php?id=' + from_id + '&toid='+ to_id, 'SPC', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=650, height=400'); 
	Compose.focus();
}

function InboxPopup(id)
{
	var ReadMail = window.open('templates/Mail_Inbox.php?id=' + id, 'SPC', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=650, height=400'); 
	ReadMail.focus();
}

function ReplyPopup(from_id, to_id, Subject)
{
	var ReplyMail = window.open('Mail_Compose.php?id=' + from_id + '&toid='+ to_id + '&Subject='+ Subject, 'SPC', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=650, height=400'); 
	ReplyMail.focus();
}

function SavedPopup(from_id, to_id)
{
	var SavedMail = window.open('templates/Mail_Saved.php?id=' + from_id + '&toid='+ to_id, 'SPC', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=650, height=400'); 
	SavedMail.focus();
}

function SendPopup(id)
{
	var ReadMail = window.open('templates/Mail_Inbox.php?id=' + id+'&cat=SendItem', 'SPC', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=650, height=400'); 
	ReadMail.focus();
}

function BBPopup(){
	BB = window.open('http://www.safetypilotclub.com/phpbb/','MessageBoard','height=400,width=700,resizable,scrollbars,toolbar,location,menubar,status');
	BB.focus();
}

function DeletePic(img,stat){
	document.UploadPic.action = "index.php?action=UploadPic";
	if(stat == "delete"){
		document.UploadPic.delaction.value = "delete";
	}else if(stat == "set"){
		document.UploadPic.setaction.value = "set";
	}
	document.UploadPic.imgname.value = img;
	document.UploadPic.submit();
}

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}