window.onbeforeunload = function(){}

function BC(e,o,i,z){
	if(e){o.onclick=function(){BC2(i,o,z);}}
	else{o.onclick=function(){BC1(i,o,z);}}
	}

function BC1(e,o,z){
	document.getElementById('R'+e+'').style.display='none';o.value=0;
	document.getElementById('RL'+e+'').style.fontWeight='normal';document.getElementById('RL'+e+'').style.background='#A4A4A4';
	o.checked=false;BC(true,o,e,z);
	}

function BC2(e,o,z){
	document.getElementById('R'+e+'').style.display='block';o.value=e;
	document.getElementById('RL'+e+'').style.fontWeight='bold';document.getElementById('RL'+e+'').style.background='#CCC';
	o.checked=true;BC(false,o,e,z);
	}

/* Cal */
function popCAL(YE){
	showPage('micro_cal.php?tgt_dt='+YE,'object1');
	document.getElementById("object1").style.left=($('body').innerWidth()/2)-110+"px";
	document.getElementById("object1").style.top=y+20+"px";
	}
function refresh_value(){
	var var_D=document.getElementById('day').value;
	if(var_D < 10){var_D="0"+var_D}
	var var_M=document.getElementById('month').value;
	if(var_M < 10){var_M="0"+var_M}
	var YEAR_var=document.getElementById('year').value;
	document.getElementById('DATE').value = YEAR_var+"-"+var_M+"-"+var_D;//newDATE
	//document.getElementById('adjdate').style.visibility='visible';
	//document.getElementById('adjdate').style.backgroundColor='#ff2b49';
	hideLayer();
}
function func_two(val){
	var var_D=document.getElementById('day').value;
	var var_M=document.getElementById('month').value;
	var YEAR_var=document.getElementById('year').value;
	var tgt_dt=document.getElementById('tgt_dt').value;
	showPage('micro_cal.php?getdate='+val+'&tgt_dt='+tgt_dt,'object1');
}
function func_one(i){
	document.getElementById('day').value=i;
	document.getElementById('sday').value=i;
	refresh_value();
}
/* Cal */
var S1=0;
function sizeJ(){
	if(S1==0){S1=1;$('#NOTES').height(440);}
	else if(S1==1){S1=2;$('#NOTES').height(660);}
	else if(S1==2){S1=0;$('#NOTES').height(220);}}

function hideLayer3(){
	document.getElementById('object3').style.display='none';
	document.getElementById("object3").innerHTML="";
	}

var m_convert=0;
function s_convert(){
	hideLayer3();
	document.getElementById('object3').style.display='block';
	if(m_convert==0){showPage("location_convert.php","object3");m_convert=1;}
	else{hideLayer3();m_convert=0;}
	}

var roundto = 6;
var roundtoDMM = 3;
var roundtoDMS = 2;
function checkRanges(latd, latm, lond, lonm, lats, lons) {
	errormsg = "";
	if (latd <= -90 || latd >= 90) {
		errormsg += "* Latitude Degrees must be between 0 and 89.9999\n";
	}
	if (lond <= -180 || lond >= 180) {
		errormsg += "* Longitude Degrees must be between 0 and 179.9999\n";
	}
	if (latm < 0 || latm >= 60 || lonm < 0 || lonm >= 60) {
		errormsg += "* Minutes must be between 0 and 59.9999\n";
	}
	if (errormsg != "") {
		alert ("There are problems with your entered data:\n\n" + errormsg);
		// alert ("[function checkRanges] latd: " + latd + ", latm: " + latm + ", lond: " + lond + ", lonm: " + lonm);
		return (false);
	} else {
		return (true);
	}
}
function myParseFloat(number) {
	if (number == "-0") {
		return number;
	} else {
		return parseFloat(number);
	}
}
function myParseInt(number) {
	var newInt = parseInt(number);
	if (newInt == 0 && number < 0) {
		newInt = '-0';
	}
	return newInt;
}
function convertFromDMM(theform) {
	if (theform.dmm_lat_d.value == "") { theform.dmm_lat_d.value = 0; }
	if (theform.dmm_lat_m.value == "") { theform.dmm_lat_m.value = 0; }
	if (theform.dmm_lon_d.value == "") { theform.dmm_lon_d.value = 0; }
	if (theform.dmm_lon_m.value == "") { theform.dmm_lon_m.value = 0; }
	latd = myParseFloat(theform.dmm_lat_d.value);
	latm = myParseFloat(theform.dmm_lat_m.value);
	lond = myParseFloat(theform.dmm_lon_d.value);
	lonm = myParseFloat(theform.dmm_lon_m.value);
	if (checkRanges(latd, latm, lond, lonm)) {
		convertToDMS(theform, latd, latm, lond, lonm);
		convertToDDD(theform, latd, latm, lond, lonm);
	}
}
function convertFromDMS(theform) {
	if (theform.dms_lat_d.value == "") { theform.dms_lat_d.value = 0; }
	if (theform.dms_lat_m.value == "") { theform.dms_lat_m.value = 0; }
	if (theform.dms_lat_s.value == "") { theform.dms_lat_s.value = 0; }
	if (theform.dms_lon_d.value == "") { theform.dms_lon_d.value = 0; }
	if (theform.dms_lon_m.value == "") { theform.dms_lon_m.value = 0; }
	if (theform.dms_lon_s.value == "") { theform.dms_lon_s.value = 0; }
	latd = myParseFloat(theform.dms_lat_d.value);
	latm = myParseFloat(theform.dms_lat_m.value) + myParseFloat(theform.dms_lat_s.value)/60;
	lond = myParseFloat(theform.dms_lon_d.value);
	lonm = myParseFloat(theform.dms_lon_m.value) + myParseFloat(theform.dms_lon_s.value)/60;
	if (checkRanges(latd, latm, lond, lonm)) {
		convertToDMM(theform, latd, latm, lond, lonm);
		convertToDDD(theform, latd, latm, lond, lonm);
	}
}
function convertFromDDD(theform) {
	if (theform.ddd_lat_d.value == "") { theform.ddd_lat_d.value = 0; }
	if (theform.ddd_lon_d.value == "") { theform.ddd_lon_d.value = 0; }
	latd = myParseInt(myParseFloat(theform.ddd_lat_d.value));
	latm = Math.abs((myParseFloat(theform.ddd_lat_d.value) - parseInt(myParseFloat(theform.ddd_lat_d.value))) * 60);
	lond = myParseInt(myParseFloat(theform.ddd_lon_d.value));
	lonm = Math.abs((myParseFloat(theform.ddd_lon_d.value) - parseInt(myParseFloat(theform.ddd_lon_d.value))) * 60);
	if (checkRanges(latd, latm, lond, lonm)) {
		convertToDMM(theform, latd, latm, lond, lonm);
		convertToDMS(theform, latd, latm, lond, lonm);
	}
}
function convertToDMM(theform, latd, latm, lond, lonm) {
	// alert ("[function convertToDMM] latd: " + latd + ", latm: " + latm + ", lond: " + lond + ", lonm: " + lonm);
	document.getElementById('dmm_lat_d').value = latd;
	document.getElementById('dmm_lat_m').value = roundoff(latm, roundtoDMM);
	document.getElementById('dmm_lon_d').value = lond;
	document.getElementById('dmm_lon_m').value = roundoff(lonm, roundtoDMM);
}
function convertToDMS(theform, latd, latm, lond, lonm) {
	// alert ("[function convertToDMS] latd: " + latd + ", latm: " + latm + ", lond: " + lond + ", lonm: " + lonm);
	document.getElementById('dms_lat_d').value = latd;
	document.getElementById('dms_lat_m').value = parseInt(latm);
	document.getElementById('dms_lat_s').value = roundoff((latm - parseInt(latm)) * 60, roundtoDMS);
	document.getElementById('dms_lon_d').value = lond;
	document.getElementById('dms_lon_m').value = parseInt(lonm);
	document.getElementById('dms_lon_s').value = roundoff((lonm - parseInt(lonm)) * 60, roundtoDMS);
}
function convertToDDD(theform, latd, latm, lond, lonm) {
	if (latd < 0) {
		latm = latm * -1;
	}
	if (lond < 0) {
		lonm = lonm * -1;
	}
	document.getElementById('LAT').value = roundoff(latd + (latm / 60), roundto);
	document.getElementById('LON').value = roundoff(lond + (lonm / 60), roundto);
}
function roundoff(num,factor){
  num = myParseFloat(num);
  factor = myParseFloat(factor);
  num = Math.round(num * Math.pow(10,factor)) / Math.pow(10,factor);
  return num;
}
function initround() {
	document.latlong.ddround.value = roundto;
	document.latlong.mmround.value = roundtoDMM;
	document.latlong.ssround.value = roundtoDMS;

	updatezerofloat();
	updatefieldsizes();
}
function updatezerofloat() {
	setzerofloat(document.latlong.ddd_lat_d2,roundto);
	setzerofloat(document.latlong.ddd_lon_d3,roundto);

	setzerofloat(document.latlong.dmm_lat_m6,roundtoDMM);
	setzerofloat(document.latlong.dmm_lon_m5,roundtoDMM);

	setzerofloat(document.latlong.dms_lat_s5,roundtoDMS);
	setzerofloat(document.latlong.dms_lon_s4,roundtoDMS);
}
function setzerofloat(fieldobj,places) {
	if (! myParseFloat(fieldobj.value)) {
		fieldobj.value = '0.' + xchar('0',places);
	}
}
function updateround() {
	roundto = myParseFloat(document.latlong.ddround.value);
	roundtoDMM = myParseFloat(document.latlong.mmround.value);
	roundtoDMS = myParseFloat(document.latlong.ssround.value);

	updatezerofloat();
	updatefieldsizes();
}
function updatefieldsizes() {
	document.latlong.ddd_lat_d2.size = roundto + 2;
	document.latlong.ddd_lon_d3.size = roundto + 2;

	document.latlong.dmm_lat_m6.size = roundtoDMM + 2;
	document.latlong.dmm_lon_m5.size = roundtoDMM + 2;

	document.latlong.dms_lat_s5.size = roundtoDMS + 2;
	document.latlong.dms_lon_s4.size = roundtoDMS + 2;
}
function xchar(repeatString, repeatNum) {
    var newString = ""; 
    for (var x=1; x<=repeatNum; x++) { 
        newString = newString + repeatString; 
    } 
    return (newString); 
}



var menu_map=0;
var menu_coord=0;
var menu_smile=0;

function switch_smile(){
	if(menu_smile==0){showPage('xSMILIE.php','smile_palette');menu_smile=1;}
	else{document.getElementById('smile_palette').innerHTML='';menu_smile=0;}
	}
function loadPAN(){
	tog_close();
	document.getElementById('errorDIV').innerHTML='';
	document.getElementById('errorDIV2').innerHTML='';
	document.getElementById('saveDIV').innerHTML='<img border=0 src="../images/hazjax-loader-000.gif">';}
function tog_close(){
	menu_coord=0;
	menu_map=0;}
function tog_map(){
	if(menu_map==0){
	menu_coord=0;document.getElementById('coordDIV').style.height='0px';//Close other
	menu_map=1;document.getElementById('xmapDIV').style.height='440px';}
	else{menu_map=0;document.getElementById('xmapDIV').style.height='0px';}
}
function tog_coord(){
	if(menu_coord==0){
	//menu_map=0;document.getElementById('xmapDIV').style.height='0px';//Close other
	menu_coord=1;document.getElementById('coordDIV').style.height='100px';}
	else{menu_coord=0;document.getElementById('coordDIV').style.height='0px';}
}

function DMm(pinLAT_DD,pinLAT_MS,pinLON_DD,pinLON_MS){
	pinLAT_MS=parseFloat(pinLAT_MS/60);
	document.getElementById('LAT').value=parseFloat(pinLAT_DD)+pinLAT_MS;

	if(pinLON_DD < -1){pinLON_DD=pinLON_DD.substring(1,pinLON_DD.length);}
	pinLON_MS=parseFloat(pinLON_MS/60);
	document.getElementById('LON').value=parseFloat(pinLON_DD)+pinLON_MS;
	}

function DMS(pinLAT_DD,pinLAT_MM,pinLAT_SS,pinLON_DD,pinLON_MM,pinLON_SS){
	pinLAT_MM=parseFloat(pinLAT_MM/60);
	pinLAT_SS=parseFloat(pinLAT_SS/3600);
	document.getElementById('LAT').value=parseFloat(pinLAT_DD)+(pinLAT_MM)+(pinLAT_SS);

	if(pinLON_DD < -1){pinLON_DD=pinLON_DD.substring(1,pinLON_DD.length);}
	pinLON_MM=parseFloat(pinLON_MM/60);
	pinLON_SS=parseFloat(pinLON_SS/3600);
	document.getElementById('LON').value=parseFloat(pinLON_DD)+(pinLON_MM)+(pinLON_SS);
	}
function switch_menu(PRI,L,D,S)
{
	var menu = document.getElementById('HIKEdiv');
	var current_display;
	if(menu.style.display!="block"){current_display="none";}else{current_display="block";};
	switch (current_display)
	{
		case 'block':
			menu.style.display = 'none';
			//document.getElementById('llDIV').style.display='block';
		break;

		case 'none':
			menu.style.display = 'block';
			showPage('../dex2/TLOGS_SELECT_TRIP.php?SHOW=2&PRIDY='+PRI+'&LOG_ID='+L+'&DRAFT='+D+'&STu='+S,'HIKEdiv');
			document.getElementById('llDIV').style.display='none';
			document.getElementById('llSUB').style.display='none';
			setCheckedValue(document.forms['postform'].elements['TripSelect'], 'DEX');
		break;
	}
}
function checkForm()
	{
		if (document.getElementById('DISTANCE').value.length < 1)
		{
				alert('You must enter a distance');
				return false;
		}
		else
		{
			return true;
		}
	}
function ll()
{
popopen=window.open("","popopen","resizable=no,top=20,left=100,height=400,width=450,scrollbars=yes")
popopen.document.write("<TITLE>Latitude / Longitude</TITLE><BODY BGCOLOR='ffffff'><u><font size='4'>Latitude / Longitude</font></u><BR><BR><b>Optional</b><BR><BR>When a Generic Trip is being logged you have the option to enter lat/lon.  It is not necessary unless you wish to see your trip pinpointed on various maps throughout the site.<BR><BR>Only <b>decimal</b> coordinates are valid.  If you have odd characters, spaces or double decimals you must convert first.  Simply click on the <i>Convert</i> button.  You may also attain coordinates via map by clicking on <i>Map</i>.<BR><center><form><p><input TYPE='BUTTON' VALUE='Close' onCLick='self.close()'></p></center></BODY>")
popopen.document.close()
}
var current_type;
    function cmbChanged(cbx,dexT)
    { 

	 if(cbx.value=='1'){//1 Hiking
		document.getElementById('TIMEd').disabled = true;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='2'){//2 Run/Jog
		document.getElementById('TIMEd').disabled = true;
		document.getElementById('TIMEs').disabled = false;}
	 if(cbx.value=='3'){//3 Biking
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = false;}
	 if(cbx.value=='4'){//4 Horseback
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='5'){//5 Backpack
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='6'){//6 4x4
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='7'){//7 Climbing
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = false;}
	 if(cbx.value=='8'){//8 Kayak
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='9'){//9 Fishing
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='10'){//10 Skiing
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = false;}
	 if(cbx.value=='11'){//11 Dive
		document.getElementById('TIMEd').disabled = true;
		document.getElementById('TIMEs').disabled = false;}
	 if(cbx.value=='12'){//12 Canyoneering
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='13'){//8 Caving
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}
	 if(cbx.value=='14'){//8 Snowshoeing
		document.getElementById('TIMEd').disabled = false;
		document.getElementById('TIMEs').disabled = true;}

	 var goCLIMB = "http://hikearizona.com/trip-X-CLIMB.php?SHOW=2&dexTRIP=" + dexT;
	 var goCANYON = "http://hikearizona.com/trip-X-CANYON.php?SHOW=2&dexTRIP=" + dexT;
         if(cbx.value=='7')
         {
		showPage(goCLIMB,'CLIMBdiv');
         }
         else if(cbx.value=='12')
         {
		showPage(goCANYON,'CLIMBdiv');
         }
	 else{
		showPage('http://hikearizona.com/trip-X-CLIMB.php?SHOW=1','CLIMBdiv');
		sendRequest('http://hikearizona.com/trip-X-CANYON.php?SHOW=1','CLIMBdiv');
	 }
    }
function gChanged(cbx)
    { 

	 if(cbx.value<3){
		document.getElementById('cynRISK').value = '';
		document.getElementById('cynRISK').disabled = true;}
	 if(cbx.value>2){
		document.getElementById('cynRISK').disabled = false;}
    }
function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}

	var form_name = 'postform';
	var text_name = 'NOTES';

	// Define the bbCode tags
	var bbcode = new Array();
	var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]');
	var imageTag = false;

	// Helpline messages
	var help_line = {
		b: 'Bold text: [b]text[/b]',
		i: 'Italic text: [i]text[/i]',
		u: 'Underline text: [u]text[/u]',
		q: 'Quote text: [quote]text[/quote]',
		c: 'Code display: [code]code[/code]',
		l: 'List: [list]text[/list]',
		o: 'Ordered list: [list=]text[/list]',
		p: 'Insert image: [img]http://image_url[/img]',
		w: 'Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]',
		a: 'Inline uploaded attachment: [attachment=]filename.ext[/attachment]',
		s: 'Font color: [color=red]text[/color]  Tip: you can also use color=#FF0000',
		f: 'Font size: [size=x-small]small text[/size]',
		e: 'List: Add list element',
		d: 'Flash: [flash=width,height]http://url[/flash]'
			}

	var panels = new Array('options-panel', 'attach-panel', 'poll-panel');
	var show_panel = 'options-panel';

var menu_color = 'hidden';
function switch_color()
{
	switch (menu_color)
	{
		// hide
		case 'shown':
			menu_color = 'hidden';
			showPage('color2.php?SHOW=1','colour_palette');
			document.getElementById('colour_palette').style.display='none';
		break;

		// show
		case 'hidden':
			menu_color = 'shown';
			showPage('color2.php?SHOW=2','colour_palette');
			document.getElementById('colour_palette').style.display='block';
		break;
	}
}
function celltest(){
	if(document.postform.SB1.style.visibility=='hidden'){
	document.postform.SB1.style.visibility='visible';
	}
}
