// JavaScript Document
function check_chars() { 
	var str = window.document.contact_form.msg.value;
	
	if (str.length > 500) {
		window.document.contact_form.msg.value = str.substring(0,500);
	} else {		
		//document.getElementById("counter").innerHTML = 500 - window.document.contact_form.msg.value.length + " characters remaining.";
		document.getElementById("counter").value = 500 - window.document.contact_form.msg.value.length;
	}
}

	function trim(txt) {		
		tmp = (txt.replace(/^\W+/,'')).replace(/\W+$/,'');
		return tmp;
	}
	
	function doit() {
		var myname = window.document.contact_form.name.value;
		var myemail = window.document.contact_form.email.value;
		var msg = window.document.contact_form.msg.value;
		myname  = trim(myname);
		myemail = trim(myemail);
		msg = trim(msg);

		if ((myname.length > 0) && (msg.length > 0) && (myemail.length > 0)) {
			return true;
		} else {
			alert("Please enter all your details.");
			return false;
		}

		return false;
	}
	

function showPic(mypic)
{
	document.getElementById("bigpic").src = "images/gallery/" + mypic.id;
	
}


var xmlHttp;

function getPic(str)
{ 
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
  {
	  alert ("Your browser does not support AJAX!");
	  return;
  } 

//show loading gif
document.getElementById("picholder").innerHTML = "<div style='background: url(images/loading.gif) center no-repeat; width:400px; height:300px;' ></div>";
var url = "pages/ajax_getpic.php?fn=" + str.id;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

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

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

function show(id) 
{
	document.getElementById(id).style.display = "block";
}

function hide(id) 
{
	document.getElementById(id).style.display = "none";
}