function showAndHide(theId){ 
	var el = document.getElementById(theId) 
	if (el.style.display=="none") { 
		el.style.display="block"; //show element 
	} 
	else { 
		el.style.display="none"; //hide element 
	} 
} 



function gotoPage(strURL){
	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){
			//document.myForm.time.value = ajaxRequest.responseText;
			document.getElementById("contentArea").innerHTML = ajaxRequest.responseText;
			initLightbox();
			myLightbox.updateImageList();
		}
	}
	ajaxRequest.open("GET", strURL, true);
	ajaxRequest.send(null);
}




function popUp(strURL,h,w){
	newwindow=window.open(strURL,'name',"menubar=no,width="+w+",height="+h+",toolbar=no,resizable=no");
	if (window.focus) {newwindow.focus()}
}
function popUp2(strURL,h,w){
	newwindow=window.open(strURL,'name',"menubar=no,width="+w+",height="+h+",toolbar=no,resizable=no,scrollbars=yes");
	if (window.focus) {newwindow.focus()}
}
function toggleEnabled(el){
	if(document.getElementById(el).value != ""){
		document.getElementById(el).disabled = false;
	}
}


function sortBlogElements(){
	//alert('Starting to Sort');
	var elements = $($('ul#all_blog_list li').remove().get().sort(sortByDate)).appendTo('#all_blog_list');		
	//alert('Finished Sorting');
}
function sortByDate(a, b){
	var a_int = parseInt(a.getAttribute('timestamp'));
	var b_int = parseInt(b.getAttribute('timestamp'));
	if(a_int>b_int){
		return -1;
	}
	if(a_int>b_int){
		return 1;
	}
	return 0; 
}

function signupValidate() {

	var nalert = "";
	var txtSignUpEmail 	= $("#txtSignupEmail").val();

	if (!isEmail(txtSignUpEmail)) {
		nalert += "\nEmail must be a valid Email Address";
	}


	if (nalert != "") {
		alert(nalert);
		return false;
	} else {
	$("#signUpForm").html('<p style="text-align:center; padding:10px;">Thanks! Please wait, we\'re validating your data!</p>');
		
	// ANDREW's DATA ENTRY BIT //

	
	$.post("signupEmail.php",
       {
		email:txtSignUpEmail
		},
       function(data)
         {
			$("#signUpForm").html(data);

		 });
	return false;

	}// end else

}


function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}




/*********************************************
* POPULATION CLOCK
**********************************************/
    var basetime 	= Date.UTC(2000, 7, 10);
	var nowtime		= <?php echo $_SESSION['clock_time']; ?>;
	nowtime = nowtime - basetime;

    function startClock() {
      redoPop(new Date());
      timerID = setTimeout("startClock()", 100);
    }

    function redoPop(timeto) {
		//deduct the basetime from the actual time
      var adjtime = timeto.getTime() - basetime;
		//alert(adjtime);
      var thepop = Math.round(Math.exp(22.528293835777973 + (4.54075867940663167699e-13*adjtime
 					- 1.1020778551110890530e-25*adjtime*adjtime) ));

	  thepop = thepop - Math.round(Math.exp(22.528293835777973 + (4.54075867940663167699e-13*nowtime
 					- 1.1020778551110890530e-25*nowtime*nowtime) ));

	  thepop = 'The World population has increased <br/>by '+addCommas(thepop)+' since you first arrived on this site';

      $("#clockTarget").html(thepop);
    }

	function addCommas(nStr){
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
