function hover(box) {
	document.getElementById('box'+box).className = 'menuHover';
}
function hoverOut(box) {
	document.getElementById('box'+box).className = 'menuOption';
}
function pagehover(box) {
	document.getElementById('page'+box).className = 'textLinkHvr';
}
function pagehoverOut(box) {
	document.getElementById('page'+box).className = 'textLink';
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function enter() {
	var check = alert("You entered an incorrect username / password.");
}
function myAlert(message) {
	alert(message);
}

var http = getHTTPObject();
function getHTTPObject(){
  var xmlHttp=null;
  try{ xmlHttp=new XMLHttpRequest(); }
  catch(err){
    try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(err){
    }
  } return xmlHttp;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function removeSession(session){
  var url="/includes/removeSession.php?var="+session;
  var myRandom=parseInt(Math.random()*99999999);
  http.abort();
  http.open("GET", url+'&rand='+myRandom, true);
  http.onreadystatechange=ajaxReceive;
  http.send(null);
  http.close;
}

function setPic(image) {
	document.getElementById('mainpic').src = '/images/elite/' + image;
}
 
function send_newsletter(){
	var flag = 0;
	var name = document.getElementById("n_name").value;
	if(name == 'your name') {
		alert("You must enter your name");
		flag = 1;
	}
	var email = document.getElementById("n_email").value;
	if(email == 'email address' && flag == 0) {
		alert("You must enter an email address");
		flag = 1;
		
	}
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.getElementById("n_email").value.search(emailRegEx) == -1 && flag == 0) {
    alert("Please enter a valid email address.");
		flag = 1;
    }
	
	if (flag == 0) {
	url="/includes/send_newsletter.php?name="+name+"&email="+email;
	var myRandom=parseInt(Math.random()*99999999);
	http.abort();
	http.open("GET", url+'&rand='+myRandom, true);
	http.onreadystatechange=ajaxReceive;
	document.cookie = "choice=newsletter";
	http.send(null);
	http.close;
	}
}

function send_press(){
	var flag = 0;
	var name = document.getElementById("p_name").value;
	if(name == 'your name') {
		alert("You must enter your name");
		flag = 1;
	}
	var email = document.getElementById("p_email").value;
	if(email == 'email address' && flag == 0) {
		alert("You must enter an email address");
		flag = 1;
		
	}
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.getElementById("p_email").value.search(emailRegEx) == -1 && flag == 0) {
    alert("Please enter a valid email address.");
		flag = 1;
    }
	var tel = document.getElementById("p_tel").value ;
	if(tel == 'your tel/mob' && flag == 0) {
		alert("You must enter a contact telephone or mobile no");
		flag = 1;
	}
	var pub = document.getElementById("p_pub").value;
	if(pub == 'the publication you write for' && flag == 0) {
		alert("You must enter who you write for");
		flag = 1;
	}
	
	if (flag == 0) {
	url="/includes/send_press.php?name="+name+"&email="+email+"&tel="+tel+"&pub="+pub;
	var myRandom=parseInt(Math.random()*99999999);
	http.abort();
	http.open("GET", url+'&rand='+myRandom, true);
	http.onreadystatechange=ajaxReceive;
	document.cookie = "choice=press";
	http.send(null);
	http.close;
	}
}

function myAlert(message) {
	alert(message);
}

function removeSession(session){
  var url="../includes/removeSession.php?var="+session;
  var myRandom=parseInt(Math.random()*99999999);
  http.abort();
  http.open("GET", url+'&rand='+myRandom, true);
  http.onreadystatechange=ajaxReceive;
  http.send(null);
  http.close;
}

function ajaxReceive(){
if(http.readyState==4){
  	var returncode = http.responseText;
	var mode = get_cookie("choice");
	if(mode == 'opt') {
		  document.getElementById('cats_main').innerHTML = returncode;
	}
	if(mode == 'cat') {
		  document.getElementById('cats_sub').innerHTML = returncode;
	}
	if(mode == 'newsletter') {
	  var returnsplit = returncode.split(',');
		alert(returnsplit[1]);
		window.location = '/';	
	}
	if(mode == 'press') {
	  var returnsplit = returncode.split(',');
		alert(returnsplit[1]);
		window.location = '/';	
	}
  	}
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function validateSearch() {
    valid = true;
	if ( document.getElementById('searchsite').value == 'search website...' || document.getElementById('searchsite').value.length < 3) {
		document.getElementById('searchsite').focus();
		alert("Your search must be for a word of at least 3 charchters");
		valid = false;
	}
	return valid;
}

function checkScroll() {
	valid = true;
	if ( document.getElementById('scrollpic').value.length < 1) {
		alert("Your must pick a picture to upload");
		valid = false;
	}
	return valid;
}

function disable(id) {
	document.getElementById(id).disabled = true;
}
function deleteHeader(id) {
		var answer = confirm('Do you want to delete this Header?')
	if(answer) {
		window.location = 'reception.php?deleteheader='+id;
	}
}
function deleteGallery(id, name) {
		var answer = confirm('Are you sure you want to Delete the Album: '+name+'?')
	if(answer) {
		window.location = 'reception.php?delete_gallery='+id;
	}
}
function delete_galpic(id) {
		var answer = confirm('Are you sure you want to remove this photo?')
	if(answer) {
		window.location = 'reception.php?delete_galpic='+id;
	}
}
function delete_spc(id, name) {
		var answer = confirm('Are you sure you want to delete: '+name+'?')
	if(answer) {
		window.location = 'reception.php?delete_spc='+id;
	}
}
