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 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));
}


function revealContactForm(){

	if($('#contact_form').is(':hidden')){

		$("#contact_form").slideToggle(1000);

		$("#footer").animate({ 
			height: "390px",
			marginTop: "-390px"
		 }, 1000 );

		$("#content").animate({ 
			paddingBottom: "390px"
		 }, 1000 );

	} else {

		$("#contact_form").slideToggle(1000);

		$("#footer").animate({ 
			height: "90px",
			marginTop: "-90px"
		 }, 1000 );

		$("#content").animate({ 
			paddingBottom: "90px"
		 }, 1000 );

	}

	var wait = setInterval(function() {
		if( !$("#contact_form, #footer, #content").is(":animated") ) {
			clearInterval(wait);
			// run this code after the elements above have finished their animation	
			$('html').scrollTo("#contact_form", 1000);
		}
	}, 200);

}



function validateContactForm(){
	var nalert 			= "";
	var email_email		= $("#email_email").val();
	var email_name		= $("#email_name").val();
	var email_message	= $("#email_message").val();


	if(!isEmail(email_email)){
		nalert += "<li>Email must be a valid email address.</li>";
	}
	if(email_name == ""){
		nalert += "<li>Your name is a required Field.</li>";
	}
	if(email_message == ""){
		nalert += "<li>Please write a short message and let us know what your enquiry is regarding.</li>";
	}


	if(nalert == ""){
		return true;
	} else {
		nalert = '<div id="form_alert"><p>We\'re sorry but there\'s been a few problems with your enquiry. There\'s a few fields that we need to process your enquiry correctly:</p><ul>'+nalert+'</ul></div>';
		$("#contact_alert_target").html(nalert);
		return false;
	}
	

}



