/*------------------ global js (Front End) ----------------------------*/

/*--------------- Change style css ----------------------*/
function celOver(obj) {
  var s = obj.className;
  s = s.replace(/-over/g, "");
  obj.className = s+"-over";
}

function celOut(obj) {
  var s = obj.className;
  s = s.replace(/-over/g, "");
  obj.className = s;
}


/*------------- Search field ----------------*/
function searchinfo() {
  var errors = '';
  var form = document.SearchFrm
  if (form.searchfield.value == "SEARCH" || form.searchfield.value == "") {
    errors = "True";
  }
  if (errors) {
    alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}

function searchfocus(val) {
  if (val.value == "SEARCH") {
    val.value = "";
  }
}

function searchblur(val) {
  if (val.value == "") {
    val.value = "SEARCH";
  }
}

/*------------------User Login------------------*/

function userfocus(val) {
  if (val.value == "Username") {
    val.value = "";
  }
}

function userblur(val) {
  if (val.value == "") {
    val.value = "Username";
  }
}

function passfocus(val) {
  if (val.value == "Password") {
    val.value = "";
  }
}

function passblur(val) {
  if (val.value == "") {
    val.value = "Password";
  }
}

function valform() {
  var errors = '';
  var form = document.Form1

  if (form.Username.value == "Username" || form.Username.value == "") {
    errors += " - Username is reqired.\n";
  }

  if (form.Password.value == "Password" || form.Password.value == "") {
    errors += " - Password is reqired.\n";
  }

  if (errors) {
    alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}


/*-------gallery system (item)----------*/
function popup(idimg,width,height) { 
  xp = (screen.width-width)/2;
  if (xp <= 0) {
    xp = 0;
  }
  yp = 0;

  fen = window.open(idimg,'','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,top='+yp+',left='+xp+',width=' + width + ',height=' + height);
  fen.focus(); 
}

/*-------gallery system (itempopup)----------*/
function checksize() {
 if (document.images[0].complete) {
  window.resizeTo(document.images[0].width+12,document.images[0].height+30);
  window.focus();
 }
}

/*-----------------Booking Form Validation-----------------*/
 
   
function verifyEmail(val) {
  var msg = true;
  regex = new RegExp("^[a-z0-9_]([.-]?[a-z0-9_]+)+@[a-z0-9_]([.-]?[a-z0-9_]+)+\.([a-z]{2,4}|[a-z]{6})$", "gi");
  if (!regex.exec(val)) {
    msg = false;
  }
				
  return msg;
}


function validate_booking() {
  var errors = '';
  var form = document.form1

  if (form.SurName.value == "") {
    errors += " - Family Name is required.\n";
  }
  
  if (form.FirstName.value == "") {
    errors += " - First Name is required.\n";
  }
  
  
  if ((!form.Gender[0].checked) && (!form.Gender[1].checked)) {
    errors += " - Gender is required.\n";
  }
  
  if (form.DOB.value == "") {
    errors += " - Date of birth is required.\n";
  }
  
  if (form.Address.value == "") {
    errors += " - Address is required.\n";
  }
  
  if (form.City.value == "") {
    errors += " - City is required.\n";
  }
  
  if (form.Country.value == "") {
    errors += " - Country is required.\n";
  }
  
  if (form.Mobile3.value == "" || form.Mobile3.value == "Phone Number") {
    errors += " - Phone Number is required.\n";
  }
  
  if (form.elements["E-Mail"].value == "") {
    errors += " - Email is required.\n";
  }
  
  if (form.confirmemail.value == "") {
    errors += " - Confirmation email is required.\n";
  }
  
  if (form.confirmemail.value != form.elements["E-Mail"].value) {
    errors += " - Email addresses must match.\n";
  }
  
  
  if (!verifyEmail(form.elements["E-Mail"].value))  {
    errors += " - Email must contain an e-mail address.\n";
  }
  
  
  if (form.Nationality.value == "") {
    errors += " - Nationality is required.\n";
  }
  
  if (form.terms.checked = false) {
    errors += " - Have you read the terms and conditions?\n";
  }
  if (form.NativeLanguage.value == "") {
    errors += " - Native Language is required.\n";
  }
  if (form.infocorrect.checked = false) {
    errors += " - Is your information correct.\n";
  }

  if (errors) {
    alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
	
}
/*------------------end global js----------------------------*/