/******** some global vars *********/
/***********************************/

// var to remember if 'Continue' was clicked
cont_click = false;
function reset_cont_click (num) {
	cont_click = false;
		
	document.getElementById("share_missing_input_" + num + "_arrow").innerHTML = '';
	document.getElementById("share_missing_input_" + num + "_txt").innerHTML = '';
		
}

// global var to tell if there were returned no related activities
no_related = true;


// Function to reset coordinates and radius:
function clear_coords () {
	document.getElementById("clat").value = '';
	document.getElementById("clon").value = '';
	document.getElementById("cradius").value = '';
}




/******** check username *********/
/*********************************/

var ajaxObject = false;
// this is our object which gives us access
// to Ajax functionality
 
function doAjaxQuery(url) {
 
        ajaxObject = false;
 
    if (window.XMLHttpRequest) { // if we're on Gecko (Firefox etc.), KHTML/WebKit (Safari/Konqueror) and IE7
       
        ajaxObject = new XMLHttpRequest(); // create our new Ajax object
 
        if (ajaxObject.overrideMimeType) { // older Mozilla-based browsers need some extra help
            ajaxObject.overrideMimeType('text/xml');
        }
   
       
    } else if (window.ActiveXObject) { // and now for IE6
            try {// IE6 has two methods of calling the object, typical!
 
            ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");
            // create the ActiveX control
 
 
        } catch (e) { // catch the error if creation fails
 
            try { // try something else
 
            ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
            // create the ActiveX control (using older XML library)
 
 
            } catch (e) {} // catch the error if creation fails
        }
    }
 
        if (!ajaxObject) { // if the object doesn't work
 
            // for some reason it hasn't worked, so show an error
 
        alert('Sorry, your browser seems to not support this functionality.');
 
        return false; // exit out of this function
        }
 
   
        ajaxObject.onreadystatechange = ajaxResponse; // when the ready state changes, run this function
 
    // DO NOT ADD THE () AT THE END, NO PARAMETERS ALLOWED!
 
    ajaxObject.open('GET', url, true); // open the query to the server
 
        ajaxObject.send(null); // close the query
 
    // and now we wait until the readystate changes, at which point
    // ajaxResponse(); is executed
 
    return true;
 
    } // end function doAjaxQuery
 
function ajaxResponse() { // this function will handle the processing
 
    // N.B. - in making your own functions like this, please note
    // that you cannot have ANY PARAMETERS for this type of function!!
   
    if (ajaxObject.readyState == 4) { // if ready state is 4 (the page is finished loading)
 
        if (ajaxObject.status == 200) { // if the status code is 200 (everything's OK)
 
            // here is where we will do the processing
 
           if (ajaxObject.responseText == '1') { // if the result is 1
                document.getElementById('un_msg').innerHTML = "";
				document.getElementById('un_ok').innerHTML = "<div style=\"float: left; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/green_man_small.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>Available</small></div>";
            }
 
            else if (ajaxObject.responseText == '0') { // otherwise
 				document.getElementById('un_msg').innerHTML = "";
				document.getElementById('un_ok').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div>";
            }
			else {
				document.getElementById('un_msg').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>Please enter a username!</small></div>";
				document.getElementById('un_ok').innerHTML = "";
			}
 
        } // end if
 
        else { // if the status code is anything else (bad news)
 
            alert('There was an error. HTTP error code ' + ajaxObject.status.toString() + '.');
            return; // exit
 
        }
 
    } // end if
 
    // if the ready state isn't 4, we don't do anything, just
    // wait until it is...
 
 
} // end function ajaxResponse





function confirm_pass (txt1, txt2) {
	var stat;
	if (txt1.value.length !== 0 && txt2.value.length == 0) {
		document.getElementById('stat_pass').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>Please confirm the password!</small></div>";
	} else if (txt1.value.length !== 0 ) {
		if (txt1.value == txt2.value) {
			document.getElementById('stat_pass').innerHTML = "<div style=\"float: left; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/green_man_small.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>OK</small></div>";
		} else if (txt2.value !== txt1.value) {
			document.getElementById('stat_pass').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div>";
		}
	} else if (txt1.value.length == 0 && txt2.value.length == 0) {
		document.getElementById('stat_pass').innerHTML = "";
	}
}


function check_pass_length (pw) {
	if (pw.value.length < 1 ) {
		document.getElementById('pass_length').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>Please enter a password!</small></div>";
	} else	if (pw.value.length < 8 ) {
		document.getElementById('pass_length').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>Must be at least 8 characters!</small></div>";
	} else {
		document.getElementById('pass_length').innerHTML = "<div style=\"float: left; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/green_man_small.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>OK</small></div>";
	}
}


function empty_email (em) {
	if (em.value.length < 1 ) {
		document.getElementById('em_err').innerHTML = "<div style=\"float: left; padding-top: 3px; padding-left: 5px; padding-right: 10px;\"><img src=\"styles/icons/red_small_button.png\" /></div> <div style=\"float: left; padding-top: 3px;\"><small>Please enter an email address!</small></div>";
	} else {
		document.getElementById('em_err').innerHTML = "";
	}
}


/******************** define global vars *******************/
/***********************************************************/




/******************** GetXmlHttpObject *********************/
/***********************************************************/


function GetXmlHttpObject() {
	var xmlHttp = null;
	try {	// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		
	} catch (e) {	// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


/*************** Functions to call edit form ***************/
/***********************************************************/

function get_form (type, loc, ex1) {
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	ty = type;
	lo = loc;
	x1 = ex1;
	
	var url = "include/ajax_get_form.php";
	url = url + "?t=" + type;
	url = url + "&l=" + loc;
	url = url + "&x1=" + ex1;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChanged1;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function stateChanged1() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("le_edit_" + ty).innerHTML = xmlHttp.responseText;
		document.getElementById("le_edit_" + ty + "_green").innerHTML = "";
		
		document.getElementById("le_edit_" + ty).style.height = ' 100%';
	}
}


function get_form_prof (type, uid, ex1, ex2) {
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	ty = type;
	ui = uid;
	x1 = ex1;
	x2 = ex2;
	
	var url = "include/ajax_get_form.php";
	url = url + "?t=" + type;
	url = url + "&u=" + uid;
	url = url + "&x1=" + ex1;
	url = url + "&x2=" + ex2;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedProf;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function stateChangedProf() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("pc_edit_" + ty).innerHTML = xmlHttp.responseText;
		document.getElementById("pc_edit_" + ty + "_green").innerHTML = "";
		
		document.getElementById("pc_edit_" + ty).style.height = ' 100%';
		
		if (x1 == "visit") {
			document.getElementById("pcr_left_middle_vis").style.display = 'none';
		}
		if (x1 == "favorit") {
			document.getElementById("pcr_middle_fav").style.display = 'none';
		}
	}
}



function get_form_vids (type, vid, ex1, ex2) {
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	ty = type;
	vi = vid;
	x1 = ex1;
	x2 = ex2;
	
	var url = "include/ajax_get_form.php";
	url = url + "?t=" + type;
	url = url + "&v=" + vid;
	url = url + "&x1=" + ex1;
	url = url + "&x2=" + ex2;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedVids;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function stateChangedVids() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("vc_edit_" + ty + vi).innerHTML = xmlHttp.responseText;
		document.getElementById("vc_edit_" + ty + vi + "_green").innerHTML = "";
		document.getElementById("vc_edit_" + ty + vi).style.height = ' 100%';
	}
}


/************* Functions to call subcategories *************/
/***********************************************************/

function show_sub_cat (CatId) {
	xmlHttp = GetXmlHttpObject();
		
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = "include/ajax_get_sub_category.php";
	url = url + "?q=" + CatId;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChanged3;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function stateChanged3() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("scat_select").innerHTML = xmlHttp.responseText;
	}
}


function show_sub_cat_share (CatId) {
	xmlHttp = GetXmlHttpObject();
		
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = "include/ajax_get_sub_category_share.php";
	url = url + "?q=" + CatId;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedSubCatShare;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function stateChangedSubCatShare() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("scat_select").innerHTML = xmlHttp.responseText;
	}
}


/************* Functions to remove visited countries *************/
/******************************** NOT USED *********************************/

function remove_visit_country (nr) {
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = "include/ajax_get_sub_category.php";
	url = url + "?q=" + CatId;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = remove_visit_state_changed;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function remove_visit_state_changed() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("").innerHTML = xmlHttp.responseText;
	}
}



/*************** Functions to cancel edit form ***************/
/***********************************************************/


function cancel_edit (type) {
	if (!ty) {ty = '';}
	if (!lo) {lo = '';}
	if (!x1) {x1 = '';}
	document.getElementById("le_edit_" + type + "_green").innerHTML = "<div class=\"green_button\" style=\"float: right;\"><p><a href=\"#\" onclick=\"get_form ('"+ty+"', '"+lo+"', '"+x1+"'); return false;\">Edit&nbsp;<img src=\"styles/graphics/button_arrow_down.png\" /></a></p></div>";
	document.getElementById("le_edit_" + type).innerHTML = "";
	document.getElementById("le_edit_" + type).style.height = ' 0';
}

function cancel_edit2 (type) {
	if (!ty) {ty = '';}
	if (!ui) {ui = '';}
	if (!x1) {x1 = '';}
	if (!x2) {x2 = '';}
	document.getElementById("pc_edit_" + type + "_green").innerHTML = "<div class=\"green_button\" style=\"float: right;\"><p><a href=\"#\" onclick=\"get_form_prof ('"+ty+"', '"+ui+"', '"+x1+"', '"+x2+"'); return false;\">Edit&nbsp;<img src=\"styles/graphics/button_arrow_down.png\" /></a></p></div>";
	document.getElementById("pc_edit_" + type).innerHTML = "";
	document.getElementById("pc_edit_" + type).style.height = ' 0px';
}

function cancel_edit3 (type) {
	if (!ty) {ty = '';}
	if (!ui) {ui = '';}
	if (!x2) {x2 = '';}
	document.getElementById("pc_edit_" + type + "_green").innerHTML = "<div class=\"green_button\" style=\"float: right;\"><p><a href=\"#\" onclick=\"get_form_prof ('"+ty+"', '"+ui+"', 'visit', '"+x2+"'); return false;\">Edit&nbsp;<img src=\"styles/graphics/button_arrow_down.png\" /></a></p></div>";
	document.getElementById("pc_edit_" + type).innerHTML = "";
	document.getElementById("pcr_left_middle_vis").style.display = 'block';
	document.getElementById("pc_edit_" + type).style.height = ' 0px';
}

function cancel_edit4 (type) {
	if (!ty) {ty = '';}
	if (!ui) {ui = '';}
	if (!x2) {x2 = '';}
	document.getElementById("pc_edit_" + type + "_green").innerHTML = "<div class=\"green_button\" style=\"float: right;\"><p><a href=\"#\" onclick=\"get_form_prof ('"+ty+"', '"+ui+"', 'favorit', '"+x2+"'); return false;\">Edit&nbsp;<img src=\"styles/graphics/button_arrow_down.png\" /></a></p></div>";
	document.getElementById("pc_edit_" + type).innerHTML = "";
	document.getElementById("pcr_middle_fav").style.display = 'block';
	document.getElementById("pc_edit_" + type).style.height = ' 0px';
}


function cancel_edit_video (type, vid) {
	if (!ty) {ty = '';}
	if (!vi) {vi = '';}
	if (!x1) {x1 = '';}
	if (!x2) {x2 = '';}
	document.getElementById("vc_edit_" + type + vid + "_green").innerHTML = "<div class=\"green_button\" style=\"float: right;\"><p><a href=\"#\" onclick=\"get_form_vids ('"+ty+"', '"+vi+"', '"+x1+"', '"+x2+"'); return false;\">Edit&nbsp;<img src=\"styles/graphics/button_arrow_down.png\" /></a></p></div>";
	document.getElementById("vc_edit_" + type + vid).innerHTML = "";
	document.getElementById("vc_edit_" + type + vid).style.height = ' 0px';
}




function limit_text (textField, max_length) {
	if (textField.value.length > max_length) {
		textField.value = textField.value.substring(0, max_length);
	}
}














function rel_search () {
	cont_click = true;
	var mcat = document.getElementById("srl_cat").value;
	var scat = document.getElementById("srl_scat").value;
	var lat = document.getElementById("clat").value;
	var lng = document.getElementById("clon").value;
	var rad = document.getElementById("cradius").value;
	
	if (scat != "") {
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		var url = "include/ajax_get_related_locs.php";
		url = url + "?mc=" + mcat;
		url = url + "&sc=" + scat;
		url = url + "&la=" + lat;
		url = url + "&lo=" + lng;
		url = url + "&ra=" + rad;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = stateChangedRelSearch;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}

function stateChangedRelSearch() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		if (xmlHttp.responseText != 'none') { // Some related locations were found
			no_related = false;
			document.getElementById("rel_placeholder").innerHTML = '<div id="share_related"><p>3&nbsp;&nbsp;&nbsp;&nbsp;New location or already a TogFrog location?</p><div id="share_focus_5"><div id="share_rel_list_wrap"><div id="srl_result">' + xmlHttp.responseText + '</div></div></div><div id="share_focus_5_arrow"></div></div>';
			
			Shadowbox.setup();
			share_focus(5, 5);
		} else { // there are no related locations
			document.getElementById("rel_placeholder").innerHTML = '';
		}
	}
}






function side_guide () {
	document.getElementById("srl_result").innerHTML = "Hello World";	
}




/* Var to remember last focus */
if (getURLVar('step') == 'plot') {
	last_focus = 3;
} else if (getURLVar('step') == 'location') {
	last_focus = 6;
} else if (getURLVar('step') == 'video') {
	last_focus = 12;
}

function share_focus(place, stat_bar) {
	if (place != last_focus) {
		var a = last_focus-place;
		document.getElementById("share_focus_" + (place+a)).style.backgroundColor = '#FFFFFF';
		document.getElementById("share_focus_"+(place+a)+"_arrow").innerHTML = "";
		document.getElementById("share_guide_head_" + (place+a)).style.color = '#575757';
		document.getElementById("share_guide_text_" + (place+a)).style.display = 'none';
	}
	document.getElementById("share_focus_" + place).style.backgroundColor = '#F2FAE9';
	document.getElementById("share_guide_head_" + place).style.color = '#000000';
	document.getElementById("share_guide_text_" + place).style.display = 'block';
	if (place == 3) {
		document.getElementById("share_right").style.marginTop = '0px';
	} else if (place == 4) {
		document.getElementById("share_right").style.marginTop = '0px';
	} else if (place == 5) {
		document.getElementById("share_right").style.marginTop = '450px';
	} else if (place == 9) {
		document.getElementById("share_right").style.marginTop = '100px';
	} else if (place == 10) {
		document.getElementById("share_right").style.marginTop = '180px';
	} else if (place == 11) {
		document.getElementById("share_right").style.marginTop = '270px';
	} else if (place == 14) {
		document.getElementById("share_right").style.marginTop = '100px';
	} else if (place == 15) {
		document.getElementById("share_right").style.marginTop = '170px';
	} else if (place == 16) {
		document.getElementById("share_right").style.marginTop = '300px';
	} else {
		document.getElementById("share_right").style.marginTop = '0px';
	}
	
	var j=0;
	for (j=0;j<16;j++) {
		document.getElementById("prog_bar_dash_" + j).style.backgroundColor = '#000000';
	}
	var k=0;
	for (k=0;k<stat_bar;k++) {
		document.getElementById("prog_bar_dash_" + k).style.backgroundColor = '#639127';
	}
	
	if (place == 3) {
		document.getElementById("share_focus_" + place + "_arrow").innerHTML = '<img src="styles/graphics/share_focus_arrow_down.png" />';
	} else {
		document.getElementById("share_focus_" + place + "_arrow").innerHTML = '<img src="styles/graphics/share_focus_arrow_up.png" />';
	}
	
	last_focus = place;
}



function getURLVar(urlVarName) {
	//divide the URL in half at the '?' 
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array 
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable 
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
			//load the name/value pair into an array 
			var urlVarPair = urlVars[i].split('=');
			if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
				//I found a variable that matches, load it's value into the return variable 
				urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}



function pass_cat (type, id) {
	if (type == 'm') {
		document.getElementById("form2_mcat").value = id;
	} else if (type == 's') {
		document.getElementById("form2_scat").value = id;
	} else if (type == 'lid') {
		document.getElementById("form2_lid").value = id;
	} else if (type == 'check') {
		document.getElementById("form2_lid").value = id;
		document.getElementById("form2_check").value = 'checked';
	}
}



/*** makes sure that only one checkbox is checked ***/
function one_checkbox (box, total) {
	var i=0;
	for (i=0; i<total; i++) {
		if (i != box) {	
			document.getElementById("sha_check" + i).checked = '';
		}
	}
	
	if (document.getElementById("sha_check" + box).checked == '') {	
		document.getElementById("form2_lid").value = '';
		document.getElementById("form2_check").value = '';
	}
}






/** get list of states **/
function get_state_list (sta) {
	
	if (sta == 'all') { // Get all countries
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		var url = "include/ajax_get_countries.php";
		url = url + "?sid=" + Math.random();
		xmlHttp.onreadystatechange = stateChangedCountryList;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	} else if (sta != "" && sta != 'all') { // Get all relevant states or regions
		xmlHttp = GetXmlHttpObject();
		
		if (xmlHttp == null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		var url = "include/ajax_get_states.php";
		url = url + "?st=" + sta;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = stateChangedStateList;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}

function stateChangedStateList() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("share_state_input").innerHTML = xmlHttp.responseText;
	}
}

function stateChangedCountryList() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("share_country_input").innerHTML = xmlHttp.responseText;
	}
}



function share_form_submit () {
	if (document.getElementById("form2_lid").value != '' && document.getElementById("form2_check").value == 'checked') {
		document.forms['form2'].submit();
	} else {
		document.forms['form1'].submit();
	}
}






function convert_currency (rate) {	
	var us = document.getElementById("us_rate").value;
	var input = document.getElementById("input").value;
	var conv = input * (us / rate);
	var result = conv.toFixed(2);
	
	if (result > 999999.99) {
		document.getElementById("output").innerHTML = ' - the price can not be more than $US 999999.99';
	} else if (result >= 0 || result == false) {
		document.getElementById("curr_output").value = result;
	} else {
		document.getElementById("curr_output").value = '';
	}
	if (input == '') {
		document.getElementById("curr_output").value = '';
	}
}




function get_comments (lid) {
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = "include/ajax_get_comments.php";
	url = url + "?l=" + lid;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedVComms;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}


function stateChangedVComms() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		parent.document.getElementById("comm_wrap").innerHTML = xmlHttp.responseText;
		Shadowbox.setup();
	}
}





function share_plot_check (inp1, inp2) {
	if (inp1.value.length !== 0 && inp2.value.length !== 0) { // check that required fields are filled out
		// document.getElementById("hover_mess").style.display = 'none';
		if (!cont_click) { // cont_click is false by default
			rel_search();
			setTimeout("if (no_related) {share_form_submit();}", 1000);
		} else {
			cont_click = false;
			share_form_submit();
		}
	} else { // missing input
		// return a message on which fields that need attention
		// document.getElementById("hover_mess").style.display = 'block';
		if (inp1.value.length == 0) {
			document.getElementById("share_missing_input_3_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_3_txt").innerHTML = '<em> - you need to choose a main category and a sub category</em>';
		}
		if (inp2.value.length == 0) {
			document.getElementById("share_missing_input_4_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_4_txt").innerHTML = '<em> - you need to plot the location on the map</em>';
		}
	}
}


function share_loc_check (inp1, inp2) {
	// check that required fields are filled out
	if (inp1.value.length !== 0 && inp2.value.length !== 0) { 
		// document.getElementById("hover_mess").style.display = 'none';
		document.forms['form_loc_input'].submit();

	// missing input
	} else { 
		// return a message on which fields that need attention
		// document.getElementById("hover_mess").style.display = 'block';
		if (inp1.value.length == 0) {
			document.getElementById("share_missing_input_6_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_6_txt").innerHTML = '<br /> <em> - missing country</em>';
		}
		if (inp2.value.length == 0) {
			document.getElementById("share_missing_input_8_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_8_txt").innerHTML = '<br /> <em> - missing city</em>';
		}
	}
}

function share_vid_check (inp1, inp2, inp3, inp4) {
	// check that required fields are filled out
	if (inp1.value.length !== 0 && inp2.value.length !== 0 && inp3.value.length !== 0 && inp4.value.length !== 0) { 
		// document.getElementById("hover_mess").style.display = 'none';
		document.forms['form_vid_input'].submit();

	// missing input
	} else { 
		// return a message on which fields that need attention
		// document.getElementById("hover_mess").style.display = 'block';
		if (inp1.value.length == 0) {
			document.getElementById("share_missing_input_12_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_12_txt").innerHTML = ' <em> - missing embedding code</em>';
		}
		if (inp2.value.length == 0) {
			document.getElementById("share_missing_input_13_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_13_txt").innerHTML = ' <em> - missing video title</em>';
		}
		if (inp3.value.length == 0) {
			document.getElementById("share_missing_input_14_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_14_txt").innerHTML = ' <em> - missing description</em>';
		}
		if (inp4.value.length == 0) {
			document.getElementById("share_missing_input_16_arrow").innerHTML = '-> ';
			document.getElementById("share_missing_input_16_txt").innerHTML = ' <em> - missing price</em>';
		}
	}
}


// Front page show/hide
more_counter = 0;
function fp_suggest_show (where) {
	more_counter = more_counter+1;
	if (more_counter % 2 == 1) {
		document.getElementById(where).style.display = 'block';
		document.getElementById("fp_suggest_butt_txt").innerHTML = 'Less <img src="styles/graphics/button_arrow_up.png" />';
	} else {	
		document.getElementById(where).style.display = 'none';
		document.getElementById("fp_suggest_butt_txt").innerHTML = 'More <img src="styles/graphics/button_arrow_down.png" />';
	}
}

// function used to set focus in a form field
function form_focus (form, field) {
	//alert(field);
	document.forms[form].elements[field].focus();
}




// select / deselect:
function select_deselect (prefix, total, sel) { 
	if (sel == true) { 
		for (j=0;j<total;j++) {
			document.getElementById(prefix + j).checked = 'checked'; 
		}
	} else {
		for (i=0; i<total; i++) {
			document.getElementById(prefix + i).checked = '';
		}
	}
}



function clear_div (id) {
	document.getElementById(id).innerHTML = '';
}

function rate_this_message (act_id, user) {
	
	if (user == false) {
		document.getElementById('rate_message').innerHTML = '<p><a href="login.php?last=location.php%3Factivity%3D'+act_id+'" class="red">Login</a> is required</p>';
		setTimeout("clear_div ('rate_message')", 10000);
	} else {
		document.getElementById('rate_message').innerHTML = '<img src="styles/graphics/ajax-loader.gif" class="ajax_gif_wait">';
		
		xmlHttp = GetXmlHttpObject();
			
		if (xmlHttp == null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		var url = "ajax/ajax_rate_check.php";
		url = url + "?l=" + act_id;
		url = url + "&u=" + user;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = stateChangedRateCheck;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
	}
}

function stateChangedRateCheck() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("rate_message").innerHTML = xmlHttp.responseText;
		if (xmlHttp.responseText == "<p>You've already rated this one</p>") {
			setTimeout("clear_div ('rate_message')", 10000);
		} else {
			setTimeout("clear_div ('rate_message')", 20000);	
		}
	}
}

function new_rate (act_id, user, rate) {
	document.getElementById('rate_message').innerHTML = '<img src="styles/graphics/ajax-loader.gif" class="ajax_gif_wait">';
	
	xmlHttp = GetXmlHttpObject();
	
	rate_new = rate;
	
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = "ajax/ajax_rate.php";
	url = url + "?l=" + act_id;
	url = url + "&u=" + user;
	url = url + "&r=" + rate;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedRate;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);	
	
}

function stateChangedRate() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("rate_message").innerHTML = xmlHttp.responseText;
		if (xmlHttp.responseText == "<p>Thanks for rating</p>") {
			if (rate_new == 1) {	
				document.getElementById("rating_act").innerHTML = parseInt(document.getElementById("rating_act").innerHTML) + 1;
			} else if (rate_new == 2) {
				var old_rate = parseInt(document.getElementById("rating_act").innerHTML);
				document.getElementById("rating_act").innerHTML = old_rate + 1;
				if ((old_rate-1)<0) {
					document.getElementById("rate_icon").innerHTML = '<img src="styles/icons/thumbs_down_icon.png" />';
				}
			}
		}
		setTimeout("clear_div ('rate_message')", 20000);
	}
}

/** tried this check and message **/
function tried_this_message (act_id, user) {
	
	if (user == false) {
		document.getElementById('tried_message').innerHTML = '<p><a href="login.php?last=location.php%3Factivity%3D'+act_id+'" class="red">Login</a> is required</p>';
		setTimeout("clear_div ('tried_message')", 10000);
	} else {
		document.getElementById('tried_message').innerHTML = '<img src="styles/graphics/ajax-loader.gif" class="ajax_gif_wait">';
		
		xmlHttp = GetXmlHttpObject();
			
		if (xmlHttp == null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		var url = "ajax/ajax_tried_check.php";
		url = url + "?l=" + act_id;
		url = url + "&u=" + user;
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = stateChangedTriedCheck;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
		
		setTimeout("clear_div ('tried_message')", 30000);
	}
}

function stateChangedTriedCheck() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("tried_message").innerHTML = xmlHttp.responseText;
		if (xmlHttp.responseText == "<p>You've already marked this as one you've tried</p>") {
			setTimeout("clear_div ('tried_message')", 30000);
		}
	}
}

/** Add as a location you've tried **/
function new_tried (act_id) {
	document.getElementById('tried_message').innerHTML = '<img src="styles/graphics/ajax-loader.gif" class="ajax_gif_wait">';
	
	xmlHttp = GetXmlHttpObject();
		
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = "ajax/ajax_tried.php";
	url = url + "?l=" + act_id;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedTried;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);	
}

function stateChangedTried() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("tried_message").innerHTML = xmlHttp.responseText;
		
		if (xmlHttp.responseText == "<p>Thanks for adding this location!</p>") {
			document.getElementById("tried_act").innerHTML = parseInt(document.getElementById("tried_act").innerHTML) + 1;
		}
		
		setTimeout("clear_div ('tried_message')", 15000);
	}
}


// Login message when trying to "POST A COMMENT"
function comment_login (act_id) {
	document.getElementById('comm_message').innerHTML = '<p><a href="login.php?last=location.php%3Factivity%3D'+act_id+'" class="red">Login</a> is required</p>';	
}


