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 Search(){
  var searchWords = document.getElementById('searchBar').value;
  var url="ajax_search.php?searchWords="+searchWords;
  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;
      document.getElementById('contacts').innerHTML = returncode;
  }
}
function add_note() {
	$(document).ready(function(){

	  $("#Addnote").animate({opacity: "0.1", width: "807"}, "slow")
	  .animate({opacity: "1", height: "140"}, "slow")
	  return false;

});
};
function shrink_note() {
	$(document).ready(function(){

	  $("#Addnote").animate({opacity: "1", height: "30"}, "slow")
	  .animate({opacity: "1", width: "120"}, "slow")
	  return false;

});
};
function scrollDown() {
	for (i=0;i<window.screen.availHeight;i+=10) {window.scroll(0,i); }
}

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 gopage(id){
  if(!readCookie('arsmusicpopup')){
    showPlayer(id);
  } else {
	  var oldWin = window.open("test_pop.php?id="+id,"arsmusic");
	  oldWin.focus();
  }
}

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 get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

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

function checklogin() {
	valid = true;
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (document.getElementById('email').value.search(emailRegEx) == -1 && valid == true) {
		document.getElementById('email').focus();
        alert("Please enter a valid email address.");
		valid = false;
	}
	if(document.getElementById('password').value.length < 6 && valid == true) {
		document.getElementById('password').focus();
        alert("Please enter a valid password.");
		valid = false;
	}
	if(valid == true) {
		document.login.submit()
	}
}

function loadCompany(id) {
	var company = document.getElementById('bs_orgcompany').value;
	var url="/includes/loadcompany.php?company="+company;
	var myRandom=parseInt(Math.random()*99999999);
	http.abort();
	http.open("GET", url+'&rand='+myRandom, true);
	http.onreadystatechange=ajaxReceive;
	document.cookie = "choice=loadcompany";
	http.send(null);
	http.close;
}

function ajaxReceive(){
  if(http.readyState==4){
	  var returncode = http.responseText;

		var mode = get_cookie("choice");
	
		if(mode == 'loadcompany') {
			document.getElementById('bs_orgcontact').options.length = 0;
			var myoptions = returncode.split(',');
			
			for (var i=0; i < myoptions.length;++i){
				var cats = myoptions[i].split('#');
				if(cats[0] != '') {
					addOption(document.contact.bs_orgcontact, cats[0], cats[1]);
				}
			}
			addOption(document.contact.bs_orgcontact, 'new contact', '0');
			//document.getElementById('prod_category').value = get_cookie("current");
		}
		if(mode == 'thumbs') {
			document.getElementById('shop_display_thumbs').innerHTML = returncode;
		}
		if(mode == 'art_status') {
			var setart = returncode.split(',');
			document.getElementById('art_'+setart[0]).src = '/images/status/'+setart[1];
		}
		if(mode == 'additem') {
			GB_show('shopping cart','/spiked-store/showcart.php',520,600);
		}
		if(mode == 'bs_status') {
			var setart = returncode.split(',');
			document.getElementById('bs_'+setart[0]).src = '/images/'+setart[1];
		}
	}
}

function addOption(selectbox,text,value ) {
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
function deleteComment(commentid,babyshow) {
	var check = confirm("Are you sure you want to delete this Comment?");
	if (check == true) {
		window.location = "reception.php?deletecomment="+commentid+'&babyshow='+babyshow;
	}
}
function change_status(id) {
  var url="/includes/change_status.php?id="+id;
  var myRandom=parseInt(Math.random()*99999999);
  http.abort();
  http.open("GET", url+'&rand='+myRandom, true);
  http.onreadystatechange=ajaxReceive;
  document.cookie = "choice=bs_status";
  http.send(null);
  http.close;
}
function checkOrganiserRegister() {
	valid = true;
	if(document.getElementById('company').value == '' && valid == true) {
		document.getElementById('company').focus();
        alert("Please enter a Company or Organisation name.");
		valid = false;
	}
	if(document.getElementById('address1').value == '' && valid == true) {
		document.getElementById('address1').focus();
        alert("Please enter the first line of your address.");
		valid = false;
	}
	if(document.getElementById('town').value == '' && valid == true) {
		document.getElementById('town').focus();
        alert("Please enter the name of your town or city.");
		valid = false;
	}
	if(document.getElementById('county').value == '' && valid == true) {
		document.getElementById('county').focus();
        alert("Please enter the name of your county.");
		valid = false;
	}
	if(document.getElementById('postcode').value == '' && valid == true) {
		document.getElementById('postcode').focus();
        alert("Please enter your postcode.");
		valid = false;
	}
	if(!document.getElementById('england-east-midlands').checked == true && !document.getElementById('england-eastern').checked == true && !document.getElementById('england-north-east').checked == true && !document.getElementById('england-north-west').checked == true && !document.getElementById('england-south-east').checked == true && !document.getElementById('england-south-west').checked == true && !document.getElementById('england-eastern').checked == true && !document.getElementById('england-eastern').checked == true && !document.getElementById('england-eastern').checked == true && !document.getElementById('england-eastern').checked == true && !document.getElementById('england-west-midlands').checked == true && !document.getElementById('england-yorkshire-and-humber').checked == true && !document.getElementById('northern-ireland').checked == true && !document.getElementById('scotland-central').checked == true && !document.getElementById('scotland-north').checked == true && !document.getElementById('scotland-south').checked == true && !document.getElementById('wales-north').checked == true && ! document.getElementById('wales-south').checked == true && valid == true) {
		  alert("Please select at least one area of interest  eg. England - East Midlands.");
		valid = false;
	}	
	if(document.getElementById('name').value == '' && valid == true) {
		document.getElementById('name').focus();
        alert("Please enter your name.");
		valid = false;
	}
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (document.getElementById('sec_email').value.search(emailRegEx) == -1 && valid == true) {
		document.getElementById('sec_email').focus();
        alert("Please enter a valid email address.");
		valid = false;
	}
	if(document.getElementById('sec_password').value.length < 6 && valid == true) {
		document.getElementById('sec_password').focus();
        alert("Please enter a valid password.");
		valid = false;
	}
	if(document.getElementById('sec_password').value !== document.getElementById('sec_confirmpassword').value && valid == true) {
		document.getElementById('sec_confirmpassword').focus();
        alert("The passwords you entered do not match.");
		valid = false;
	}
	return valid;
}
function validateInfoPack() {
	valid = true;
	if(document.getElementById('name').value == '' && valid == true) {
		document.getElementById('name').focus();
        alert("Please enter your name");
		valid = false;
	}
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (document.getElementById('email').value.search(emailRegEx) == -1 && valid == true) {
		document.getElementById('email').focus();
        alert("Please enter a valid email address.");
		valid = false;
	}
	
	if(valid == true) {
		document.getElementById('request_info').disabled = true;
	}
	return valid;
}
function validateLogin() {
	valid = true;
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (document.getElementById('login_email').value.search(emailRegEx) == -1 && valid == true) {
		document.getElementById('login_email').focus();
        alert("Please enter your email address correctly.");
		valid = false;
	}
	if(document.getElementById('login_password').value.length < 1 && valid == true) {
		document.getElementById('login_password').focus();
        alert("Please enter your password.");
		valid = false;
	}
	return valid;
}
function deleteShow(babyshow) {
	var check = confirm("Are you sure you want to delete this Listing?");
	if (check == true) {
		window.location = "reception.php?deleteshow="+babyshow;
	}
}
function validateReset() {
	valid = true;
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (document.getElementById('email').value.search(emailRegEx) == -1 && valid == true) {
		document.getElementById('email').focus();
        alert("Please enter your email address correctly.");
		valid = false;
	}
	if(valid == true) {
		document.getElementById('token').value = 'alpha';
	}
	return valid;
}
function validatePassword () {
	var status = true;
		if (document.getElementById('mem_password').value.length < 6 && status == true) {
		document.getElementById('mem_password').focus();
        alert("Your password must be a minimum of 6 charachters.");
		status = false;
	}	
	if (document.getElementById('mem_password').value !== document.getElementById('mem_confirmpassword').value && status == true) {
		document.getElementById('mem_password').focus();
        alert("Password and Confirm Password do not match.");
		status = false;
	}
	return status;
}
