var baseurl = "http://"+location.hostname+((location.port.length>0&&location.port!=80&&location.port!=443)?":"+location.port:""); 
var baseurlsec = "https://"+location.hostname+((location.port.length>0&&location.port!=80&&location.port!=443)?":"+location.port:"");
var aDate = new Date();
//aDate.setMinutes(0,0);  //get rid of minutes and seconds
var javaMilli = Math.floor(aDate.getTime()/1000)*1000; // 3600000 adds 1 hr to time to move the slider forward, and get rid of millsecond numbers

function selectIcon(iconObj,editMode){
	var pinType = $(iconObj).attr('title');
	$('#icontype').val(pinType);

	$(iconObj).siblings().attr('class','icon');
	$(iconObj).siblings().children().attr('height','30');
	$(iconObj).siblings().children().attr('width','30');

	$(iconObj).attr('class','iconselected');
	$(iconObj).children().attr('height','40');
	$(iconObj).children().attr('width','40');
	
	if(editMode==1){
		$('.icon').css('display','block');
	}
	
}

function selectInitialIcon(iconid){
	var pinType = $('#' + iconid).attr('title');
	$('#icontype').val(pinType);

	$('#' + iconid).attr('class','iconselected');
	$('#' + iconid).children().attr('height','40');
	$('#' + iconid).children().attr('width','40');		
	
}

function fetchLiveUsers(){
	var usersTimer = setInterval("getLiveUsers()",60000);	//run repeatedly (every 60 seconds)
}

function getLiveUsers(){	
	
	var url = baseurl + '/includes/getLiveUsers.php';
	var params = 'ran=' + new Date().getTime();
	
	try{
		// Opera 8.0+, Firefox, Safari
		request = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			} 
		}
	}

	request.open("POST", url, true);
	//Send the proper header information along with the request
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");

	request.onreadystatechange = function()
	{
		if (request.readyState == 4 && request.status == 200)
		{		
			if(request.responseText!=''){
				$('#fr_liveusers').css('display','block');
				$('#fr_anim').css('display','none');
				$('#fr_liveitems').html(request.responseText);
			} else {				
				$('#fr_liveusers').css('display','none');
				$('#fr_anim').css('display','block');
			}			
		
		}
	};
	
	request.send(params);
	
}

function hoverButton(imgid,hoverimgname){
	document.getElementById(imgid).setAttribute("src", "images/" + hoverimgname);
}

function setInitialVals(editfrom,editto){ 
	editfrom = editfrom || 0;
	editto = editto || 0;
	
	var from = document.getElementById("from"); 
	var to = document.getElementById("to"); 	
	
	if(editfrom>0){  //editing existing flight
		from.value = editfrom;
		to.value = editto;	
	} else {
		from.value = getClockSec(javaMilli,24);
		to.value = getClockSec(javaMilli,0);
	}

	updateTimes(from.value, to.value);
}

function reportPost(num){
	$('.reportbox').hide(400);
	var reason = $('#reportreason'+num).val();
	var flight = $('#fname').val();
	var user = $('#name').val();
	
	var url = baseurl + '/includes/reportComment.php';
	var params = 'id=' + num + '&reason=' + reason + '&u=' + user + '&f=' + flight;
	
	try{
		// Opera 8.0+, Firefox, Safari
		request = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			} 
		}
	}

	request.open("POST", url, true);
	//Send the proper header information along with the request
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");

	request.onreadystatechange = function()
	{

		if (request.readyState == 4 && request.status == 200)
		{
			if (request.responseText)
			{			
				$('#reportreason'+num).val('reason...');				
			}
		}
	};
	
	request.send(params);
	
}


function submitComment(topbot){
	$('#' + topbot + '-commentbox').hide(400);
	var fid = $('#fid').val();
	var ctxt = $('#commenttxt' + topbot).val(); 
	
	var url = baseurl + '/includes/addComment.php';
	var params = 'f=' + fid + '&c=' + ctxt;
	
	try{
		// Opera 8.0+, Firefox, Safari
		request = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			} 
		}
	}

	request.open("POST", url, true);
	//Send the proper header information along with the request
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");

	request.onreadystatechange = function()
	{

		if (request.readyState == 4 && request.status == 200)
		{
			if (request.responseText)
			{													
				if((request.responseText)!='0'){
					if((request.responseText)!=='-1'){
						//update display
						$('#allcomments').prepend(request.responseText);
						$('#commenttxt' + topbot).val('');
					}
				} else {
					$('#allcomments').prepend("<div class='dcomments'><div><span class='dname'>There was a problem adding your comment.</span></div></div>");
				}
			}
		}
	};
	
	request.send(params);
	
}

function getClockSec(curmilli,int1)
{   
   var newSec = (curmilli/1000) - Math.floor(int1)*60*60;     //minus 1hr to counterbalance
   //console.log(newSec);
   return newSec;
} 
/*function createMenuShimmer(){
	var shimmer = document.createElement('iframe');
	shimmer.id='menushimmer';
	shimmer.style.position='absolute';
	shimmer.style.width='170px';
	shimmer.style.height='96px';
	shimmer.style.top='0px';
	shimmer.style.left='81px';
	shimmer.style.zIndex='999';
	shimmer.style.backgroundColor='#ed8787';
	shimmer.setAttribute('frameborder','0');
	shimmer.setAttribute('src','http://www.fonesentinel.com/template/blank.html');
	document.getElementById('content').appendChild(shimmer);
	alert('asdfasd');
}*/
function menuShimmerIn() {     
	if(document.getElementById('menushimmer')){
		document.getElementById('menushimmer').style.display='block';        
	}
}
function menuShimmerOut() {
	if(document.getElementById('menushimmer')){
		document.getElementById('menushimmer').style.display='none';
	}
}
	  
function updatePointsCounter(){
	var points = document.getElementById("epoints");
	var persec = document.getElementById("persec");
	var out = document.getElementById("fr_point");
	
	var newVal = Number(points.value) + Number(5*(persec.value));
	
	out.innerHTML = newVal;
	points.value = newVal;
	
	setTimeout(updatePointsCounter,5000);	
}

function checkFlightName(flightname,bname,original){	
		
	var url = baseurlsec + '/includes/checkFlightTitle.php';	
	var params = 'f=' + encodeURIComponent(flightname) + '&n=' + bname + '&orig=' + original + '&ran=' + new Date().getTime();
	
	try{
		// Opera 8.0+, Firefox, Safari
		request = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			} 
		}
	}

	request.open("POST", url, true);
	//Send the proper header information along with the request
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");

	request.onreadystatechange = function()
	{
		if (request.readyState == 4 && request.status == 200)
		{
			if (request.responseText)
			{				
				var theTitle = document.getElementById('title');
				var btSave = document.getElementById('btSave');			
				var output = request.responseText;
				if(output == '1'){
					btSave.style.display = 'none';
					theTitle.style.background = '#ffa798';
				} else { 
					btSave.style.display = 'inline';
					theTitle.style.background = '#ffffff';
				}	
			} 
		}
	};
	
	request.send(params);		
	
}

function loginFocus(){
	document.getElementById('username').focus();
}
function loadAnim(col){
	var bsurr = document.getElementById('butSurrounds');
	bsurr.innerHTML = '<div style="color:#ffffff" /><img src="images/' + col + 'Anim.gif" /> Please Wait </div>';
}
function unloadAnim(){
	var bsurr = document.getElementById('butSurrounds');
	bsurr.innerHTML = '<a href="#" onclick="tb_remove()"><img src="../images/mcancel.gif"></a><span id="submitimg2"><input id="submitimg2" style="padding-left:100px;" type="image" src="../images/msave.gif" /></span>';
}
function showAnim(){
	var bsurr = document.getElementById('butSurrounds');
	var animimg = document.getElementById('animimg');
	bsurr.innerHTML = '';
	animimg.style.display = 'block';
}
function showLegend(){
	var leg = document.getElementById("legend_ph");
	leg.innerHTML = '<a href="#" onclick="hideLegend();"><img src="images/legend_ph_minus.png" /></a><br /><img src="images/legend_ph.png" />';
}
function hideLegend(){
	var leg = document.getElementById("legend_ph");
	leg.innerHTML = '<a href="#" onclick="showLegend();"><img src="images/legend_ph_plus.png" /></a>';
}

function selectPh(pnum,price){  //used to select a radio button when a div is clicked
	var nput = document.getElementById('accType'+pnum);
	
	var img0 = document.getElementById('acctype_i0');
	var img1 = document.getElementById('acctype_i1');
	var img2 = document.getElementById('acctype_i2');
	var img3 = document.getElementById('acctype_i3');

	if(pnum=='0'){ img0.style.border = "4px solid #f8f648"; img1.style.border = "none"; img2.style.border = "none"; img3.style.border = "none"}
	else if(pnum=='1'){ img1.style.border = "4px solid #f8f648"; img0.style.border = "none"; img2.style.border = "none"; img3.style.border = "none"}
	else if(pnum=='2'){ img2.style.border = "4px solid #f8f648"; img1.style.border = "none"; img0.style.border = "none"; img3.style.border = "none"}
	else if(pnum=='3'){ img3.style.border = "4px solid #f8f648"; img1.style.border = "none"; img2.style.border = "none"; img0.style.border = "none"}
	
	//set price for updatePhAmount
	var cprice = document.getElementById('cprice');
	cprice.value = price;
	
	nput.checked = true;
}

function daysInMonth() {
	var d = new Date();
	var month = d.getMonth()+1;
	var year = d.getFullYear();
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
} 

function updatePhAmount(){
	var myspan = document.getElementById('prorata');
	var days = document.getElementById('days');
	var price = document.getElementById('cprice');	
	var prorata = 1;//
	prorata = (price.value / daysInMonth()) * days.value; //assume 31 days so that pro-rata amount is least (could work out exact days, but not necessary)
	myspan.innerHTML = '$' + prorata.toFixed(2);
}

function changePW(){  // used to enable / disable the change password field in settings_phacc.php
	var pass = document.getElementById('phPass');
	if(pass.style.visibility == 'hidden'){
		pass.style.visibility = 'visible';
	} else {
		pass.style.visibility = 'hidden';
		pass.value = '';  //clear value
	}	
}

function checkGPSmode(uFreqChange){  //used to disable/enable gps mode drop down in phone config

	uFreqChange = uFreqChange || false;  //sets default if not passed
	
	var freq = document.getElementById('uFreq');
	var gpsmode = document.getElementById('fTime');
	var battlife = document.getElementById('battlife');	
	var battlifetxt = document.getElementById('battlifetxt');		
	
	if(freq.value>=600){
		gpsmode.disabled = false;
		if(uFreqChange) gpsmode.value = 0;
	} else {
		gpsmode.value = 1;
		gpsmode.disabled = true;				
	}
			
	if(gpsmode.value == 1){		
		battlife.innerHTML = '<img src="images/batt21.png" height="34px" width="15px">';
		battlifetxt.innerHTML = '<img src="images/conf_b1.png" height="10px" width="44px">';		
	} else {
		if(freq.value>=600){
			if(freq.value>=2700){
				if(freq.value>=5400){
					battlife.innerHTML = '<img src="images/batt81.png" height="34px" width="15px">';
					battlifetxt.innerHTML = '<img src="images/conf_b4.png" height="10px" width="44px">';		
				} else { 
					battlife.innerHTML = '<img src="images/batt61.png" height="34px" width="15px">'; 
					battlifetxt.innerHTML = '<img src="images/conf_b3.png" height="10px" width="44px">';		
				}
			} else {
				battlife.innerHTML = '<img src="images/batt41.png" height="34px" width="15px">';
				battlifetxt.innerHTML = '<img src="images/conf_b2.png" height="10px" width="44px">';						
			}
		} else { 
			battlife.innerHTML = '<img src="images/batt21.png" height="34px" width="15px">'; 
			battlifetxt.innerHTML = '<img src="images/conf_b1.png" height="10px" width="44px">';		
		}			
	}
}

function pollC(id, load){  // needed to run an onload event withing a moodalbox
	if (!load&&document.getElementById(id)){
			document.getElementById(id).id='';
		return;
	}
	else if (load&&document.getElementById(id)){
		if (id=='unique_1')  //optional
			checkGPSmode();  //required
		return;
	}
	else if (load&&!document.getElementById(id))
		setTimeout("pollC('"+id+"', 'load')", 60);
}

/***************************************** VALIDATION ********************************************/

function validateContactus(aForm) {  //new registration account details validation
  var reason = "";

  reason += validateEmail(aForm.emailFrom);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}


function validateCC(aForm) {  //phone settings form validation
var reason = "";

  reason += validateCCard(aForm.card_number);
  reason += validateCVV(aForm.card_cvv);
  reason += validateCCExp(aForm.card_expiry_month);
  reason += validateCCExp(aForm.card_expiry_year);
  reason += validateNameSp(aForm.card_holder);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validatePhSettings(aForm,accHold) {  //phone settings form validation
var reason = "";
//alert('-'+aForm.fname.value+'-'+aForm.phPass.value+'-'+aForm.budname.value+'-'+aForm.codeword.value)

  if(accHold>=1){ reason += validateUsernameSp(aForm.fname); }
  //reason += validateUsernameSp(aForm.budname);  deprecated
  reason += validatePassword(aForm.codeword);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateNewAcc(aForm) {  //new account registration validation
  var reason = "";

  reason += validateUsername(aForm.acclogin);
  reason += validatePassword(aForm.passw);
  

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateNewAccDet(aForm) {  //new registration account details validation
  var reason = "";

  reason += validateNameSp(aForm.fname);
  reason += validateNameSp(aForm.lname);
  reason += validateCountry(aForm.continentList);
  /*reason += validateEmpty(aForm.address);*/
  reason += validateEmail(aForm.email);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function submitAddPhoneAcc(){
	
}

function validateNewPhone(aForm) {  //new phone validation during registration
  var reason = "";

  loadAnim('red'); 
	
  reason += validatePhone(aForm.phNo);
  reason += validateUsernameSp(aForm.fname);
  reason += validateUsernameSp(aForm.budname);
  reason += validateCodeword(aForm.codeword);
  reason += validatePassword(aForm.passw);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
	
	unloadAnim();
	
    return false;
  }

  return true;
}

function validateNewPhoneAcc(aForm) {  //new phone validation during registration
  var reason = "";
  
  loadAnim('red'); 
  
  reason += validatePhone(aForm.phNo);
  reason += validateUsernameSp(aForm.fname);
  reason += validateUsernameSp(aForm.budname);
  reason += validateCodeword(aForm.codeword);
  reason += validatePassword(aForm.passw);
  reason += validateIsChecked(aForm.payagree);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
	
	unloadAnim();
	
    return false;
  }
  
  return true;
}

function validateBudAdd(aForm) {  //phone settings form validation
var reason = "";
//alert('-'+aForm.phone.value

  reason += validateUsername(aForm.phNo);  //bc can have ph no, or buddy name
  reason += validatePassword(aForm.codeword);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateIsChecked(fld) {

	var error = "";
	
    if (fld.checked != true) {
        fld.style.background = '#f9bfbf'; 
        error = "You need to agree to our payment terms.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 15)) {
        fld.style.background = '#f9bfbf'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#f9bfbf'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateUsernameSp(fld) {  //allows spaces as well
    var error = "";
    var illegalChars = /[^A-Za-z0-9\x20]/; // allow letters, numbers, and space
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 15)) {
        fld.style.background = '#f9bfbf'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#f9bfbf'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateNameSp(fld) {  //allows spaces as well
    var error = "";
    var illegalChars = /[^A-Za-z0-9\x20]/; // allow letters, numbers, and space
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf'; 
        error = "You didn't enter a name.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 25)) {
        fld.style.background = '#f9bfbf'; 
        error = "The name is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#f9bfbf'; 
        error = "The name contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCountry(fld) {  //allows spaces as well
    var error = "";
    var illegalChars = /[^A-Za-z0-9\(\)\x20]/; // allow letters, numbers, and space, and brackets
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf'; 
        error = "You didn't select a Country.\n";    
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#f9bfbf'; 
        error = "You didn't select a Country.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEmail(fld) { // checks for min of a@b.com
    var error = "";    
	if(!((fld.value.indexOf(".") > 2) && (fld.value.indexOf("@") > 0))){ 
		fld.style.background = '#f9bfbf'; 
		error = "The email address is not valid. \n"; 
	} else {
		fld.style.background = 'White';
	}
 
    return error;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /\W/; // allow only letters and numbers  and underscores
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 22)) {
        error = "The password should be 5 to 22 characters. \n";
        fld.style.background = '#f9bfbf';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = '#f9bfbf';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = '#f9bfbf';
    } else {
        fld.style.background = 'White';
    }
   return error;
}

function validateCodeword(fld) {
    var error = "";
    var illegalChars = /\W/; // allow only letters and numbers  and underscores
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf';
        error = "You didn't enter a codeword.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 22)) {
        error = "The codeword should be 4 to 22 characters. \n";
        fld.style.background = '#f9bfbf';
    } else if (illegalChars.test(fld.value)) {
        error = "The codeword contains illegal characters.\n";
        fld.style.background = '#f9bfbf';    
    } else {
        fld.style.background = 'White';
    }
   return error;
}

function validateCodeword(fld) {
    var error = "";
    var illegalChars = /\W/; // allow only letters and numbers  and underscores
 
    if (fld.value == "") {
        fld.style.background = '#f9bfbf';
        error = "You didn't enter a codeword.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 22)) {
        error = "The codeword should be 5 to 22 characters. \n";
        fld.style.background = '#f9bfbf';
    } else if (illegalChars.test(fld.value)) {
        error = "The codeword contains illegal characters.\n";
        fld.style.background = '#f9bfbf';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The codeword must contain at least one numeral.\n";
        fld.style.background = '#f9bfbf';
    } else {
        fld.style.background = 'White';
    }
   return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = '#f9bfbf';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = '#f9bfbf';
    } else if (!((stripped.length >= 9)&&(stripped.length <= 12))) {
        error = "The phone number is the wrong length.\n";
        fld.style.background = '#f9bfbf';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCVV(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a CVV number.\n";
        fld.style.background = '#f9bfbf';
    } else if (isNaN(parseInt(stripped))) {
        error = "The CVV number contains illegal characters.\n";
        fld.style.background = '#f9bfbf';
    } else if ((stripped.length < 3)||(stripped.length > 6)) {
        error = "The CVV number is the wrong length.\n";
        fld.style.background = '#f9bfbf';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCCard(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a Credit Card number.\n";
        fld.style.background = '#f9bfbf';
    } else if (isNaN(parseInt(stripped))) {
        error = "The Credit Card number contains illegal characters.\n";
        fld.style.background = '#f9bfbf';
    } else if (!(stripped.length == 16)) {
        error = "The Credit Card number is the wrong length.\n";
        fld.style.background = '#f9bfbf';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCCExp(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter an Expiry number.\n";
        fld.style.background = '#f9bfbf';
    } else if (isNaN(parseInt(stripped))) {
        error = "The Expiry number contains illegal characters.\n";
        fld.style.background = '#f9bfbf';
    } else if (!(stripped.length == 2)) {
        error = "The Expiry number is the wrong length.\n";
        fld.style.background = '#f9bfbf';
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#f9bfbf'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

/***************************************** end VALIDATION ********************************************/

function showCodeBox(){  // used to display codeword request box
	var codeword = document.getElementById('codeword');
	for (var i=0; i < document.pend.option.length; i++){
		if (document.pend.option[i].checked){
			var rad_val = document.pend.option[i].value;
		}
	}
	if(rad_val=='allow'){  //show div
		codeword.className = 'showme';		
	} else {
		codeword.className = 'hideme';
	}
}


function checkPass(){
	var passw1 = $('#password').val();
	var passw2 = $('#password2').val();
	if((passw1 == passw2)&&(passw2!='')){
		$('#submit').css('display','inline');
		$('#password2').css('border','solid 2px #236a2f'); 
		$('#password2').css('background-color','#e0fce5');
	} else{
		$('#submit').css('display','none');
		$('#password2').css('border','solid 2px #a62315'); 
		$('#password2').css('background-color','#fce6e1');
	}
}

function checkUsername(){  // used to check username when changing names
	var path = baseurlsec + '/includes/';
	var ajaxRequest;  // The variable that makes Ajax possible!
	var txtBox = document.getElementById('bname');
	var submitImg = document.getElementById('submit');
	var errtxt = document.getElementById('aForm_errorloc');
	
	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(ajaxRequest.readyState == 4){
			var budFound = ajaxRequest.responseText;
//			alert(ajaxRequest.responseText);
			if(budFound == '1'){ //Bud FOUND		
				txtBox.style.border = 'solid 2px #a62315'; 
				txtBox.style.backgroundColor = '#fce6e1'; 
				submitImg.style.visibility = 'hidden';
				errtxt.style.visibility = 'visible';
			} else {   // NO Bud FOUND
				txtBox.style.border = 'solid 2px #236a2f'; 
				txtBox.style.backgroundColor = '#e0fce5'; 
				submitImg.style.visibility = 'visible';					
				errtxt.style.visibility = 'hidden';
			} 
		}
	}
	var queryString = "?bud=" + txtBox.value;
//	alert(queryString);
	ajaxRequest.open("GET", path+"checkAcc.php" + queryString + "&ran=" + new Date().getTime(), true);
	ajaxRequest.send(null); 	
}

function resetLogin(){  // used to reset faiiled login attempts so user doesn't have to wait 24hrs
	var path = baseurlsec + '/includes/';
	var ajaxRequest;  // The variable that makes Ajax possible!
	var resetBut = document.getElementById('resetbut');	
	var txtBox = document.getElementById('bnamehid');
	
	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(ajaxRequest.readyState == 4){
			var resetDone = ajaxRequest.responseText;
			if(resetDone == '1'){ //done ok				
				resetBut.innerHTML = '<img src="../images/reset_done.png" />'; 
			} 
		}
	}
	var queryString = "?i=" + txtBox.value;	
	ajaxRequest.open("GET", path+"resetLoginAttempts.php" + queryString + "&r=" + new Date().getTime(), true);
	ajaxRequest.send(null); 	
}

function addSignUpContact(){  // used to add a contact to the database for mailouts
	var path = baseurlsec + '/includes/';
	var ajaxRequest;  // The variable that makes Ajax possible!
	var txtName = document.getElementById('myname');
	var txtEmail = document.getElementById('myemail');
	var contactBox = document.getElementById('contact_box');
	var errtxt = document.getElementById('aForm_errorloc');
//	var savegr = document.getElementById('savegr');
	
	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(ajaxRequest.readyState == 4){
			var respText = ajaxRequest.responseText;
			if(respText == 'successful'){ 
				contactBox.innerHTML = '<br /><br /><span style="font-size:14px;font-weight:bold; color:#317e35">Thankyou!</span><br /><br /><span style="font-weight:bold;">We will send you an email when we are ready to accept registrations.</span>';				
			} else {   //not successful
				alert('There was a problem with the email address you entered.  Please try again.');
				txtEmail.focus();
				txtEmail.select();
			} 
		}
	}
	var queryString = "?name=" + txtName.value + "&email=" + txtEmail.value;
	ajaxRequest.open("GET", path+"addContact.php" + queryString + "&ran=" + new Date().getTime(), true);
	ajaxRequest.send(null); 	
}


function showAddUser(){  // used to display different divs for diff radio but seleted.
	var myacc = document.getElementById('myacc');
	var othacc = document.getElementById('othacc');
	for (var i=0; i < document.budtypeform.budtype.length; i++){
		if (document.budtypeform.budtype[i].checked){
			var rad_val = document.budtypeform.budtype[i].value;
		}
	}
	if(rad_val=='0'){  //show add my account buddy div
		myacc.className = 'showme';
		othacc.className = 'hideme';			
	} else {
		myacc.className = 'hideme';
		othacc.className = 'showme';
	}
}

function getStatus(phones,updateFreq,sess,ph,type){  //  xx,15000,1,0,0
	updateStatus(phones,ph,type);  //run initially
	if(sess==1){	//make sure the user is logged in
		var timer = setInterval("updateStatus('"+phones+"','"+ph+"','"+type+"')",updateFreq);	//run repeatedly
	}
}

function updateStatus(phonelist,ph,type){

	var path = baseurlsec + '/includes/';
	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(ajaxRequest.readyState == 4){
//		alert(ajaxRequest.responseText);
			var statusArr = ajaxRequest.responseText.split(",");
//			alert(statusArr.length);
			for(k=0;k<statusArr.length;k++){
				var iconDiv = 'status_'+k;
				var ajaxDisplay = document.getElementById(iconDiv);				
				ajaxDisplay.style.backgroundImage = "url("+statusArr[k]+")";					
			}			
		}
	}

	var queryString = "?phs=" + phonelist + "&ph=" + ph + "&stat=" + type;
	//alert(path+"updatestatus.php" + queryString);
	ajaxRequest.open("GET", path+"updatestatus.php" + queryString + "&ran=" + new Date().getTime(), true);
	ajaxRequest.send(null); 	
	//alert(queryString); 

}

function updateImage(img, text) {
  var image = document.getElementById(img);
  image.src = text;
}

function showAdvLink(phid){  // used to hide / unhide advanced setting link on phone settings page

	var adv = document.getElementById(phid);
//	alert(phid);
//	alert(adv.value);
	
	var advlnk = document.getElementById('lnk'+phid);
	
	if(adv.value==2){
		advlnk.style.visibility = 'visible';
	} else {
		advlnk.style.visibility = 'hidden';
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


// tooltips
// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety =  8;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
			zIndex = '2000';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}
function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}