var sPath = window.location.pathname;
var re_checkoutpage = new RegExp('/basket.zi/');
var re_product = new RegExp('/Events/[A-Z,a-z,0-9,\-]+.html');

window.onload=initAll;

function initAll(){

  //display noda for newcastle only
  if (readCookie('cookie_location')=='newcastle') { 
    setDisplayOn('navCatBlock7');
  }

  if (sPath.match(re_product)) {
    // if this is a product page
    setTheProductPageWidth();
    setTheShoppingHeader();
    movethepricebox();
    setTheProductBackground();
    setTheShoppingFooter();
  } else {
    //normal page
    displayTheNormalHeader();
    displayTheNormalBackground();
  }
  if (sPath.match(re_checkoutpage)) {
    hideContinueShopping();
    var pageheader= document.getElementById('shopcartheadline'); 
    var thisTitle = document.title;
    if (thisTitle=="Shopping Cart"){
       pageheader.innerText="Booking: Customer Info";
       hideContinueShopping();
    } else if (thisTitle=="Order Checkout: Customer Info"){ 
      pageheader.innerText="Booking: Customer Info"; 
      hideshippinginfopart();
    } else if (thisTitle=="Order Checkout: Payment"){
      pageheader.innerText="Booking: Payment"; 
      //payment page
      hideshippingonpaymentpage();
    } else if (thisTitle=="Order Checkout: Review"){ 
      //payment page
      pageheader.innerText="Booking: Review"; 
      hideshippingonreviewpage();
    } else if (thisTitle=="Order Checkout: Thank You") {
      pageheader.innerText="Booking: Thank You"; 
      //thank you page
      hideshippingonthankyoupage();
    }
    document.getElementById('shopcartheadline').style.color="#21527b";
    setTheShoppingHeader();
    setTheShoppingArea();
    setTheTableToHoldBasketDetails();
    setTheShoppingFooter();
  }
}

function setTheProductPageWidth() {
  var aryClassElements = getElementsByClassName('maincontent', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'maincontent') {
      aryClassElements[i].style.width="925px";      
      //aryClassElements[i].style.border="1px solid black";      
    }
   } 
}

function movethepricebox() {
  var tableelement;
  //get table price table(1) element on this page
  tableelement = document.getElementsByTagName("table")[1];
  tableelement.style.width = "35%";
  tableelement.style.marginRight = "30px";
}

function setTheShoppingHeader() {
    //Set the top nav on the shopping pages
    var TopNavPanel = document.getElementById('topnavpanel');    
    TopNavPanel.style.backgroundImage="url('https://www.zinestudio.co.uk/northeastevents/images/shoppingtopnav.gif')";
    TopNavPanel.style.height="67px";
    TopNavPanel.style.visible="visible";
    TopNavPanel.style.display="block"; 
}

function displayTheNormalHeader() {
    //Set the top nav on the other pages
    var TopNavPanel = document.getElementById('topnavpanel');    
    TopNavPanel.style.backgroundImage="url('https://www.zinestudio.co.uk/northeastevents/images/sty_topnavback.jpg')";
    TopNavPanel.style.height="55px";
    TopNavPanel.style.visible="visible";
    TopNavPanel.style.display="block"; 
}

function setTheShoppingArea() {
    //set the td class maincontent
    var shoppingarea = document.getElementById('mainbody').getElementsByTagName('td')[0];
    shoppingarea.style.width="1013px";
    shoppingarea.style.background="url('https://www.zinestudio.co.uk/northeastevents/images/shoppingbackground.jpg') repeat-y";
    //shoppingarea.style.border="1px solid red";
}

function setTheTableToHoldBasketDetails() {
    //set the div holds the table for shopping
    var shoppingdiv = document.getElementById('mainbody').getElementsByTagName('div')[0];
    shoppingdiv.style.width="1013px";
    shoppingdiv.style.background="transparent";
    shoppingdiv.style.top="0px";
    //shoppingdiv.style.border="1px solid yellow";
    shoppingdiv.style.marginLeft="auto";
    shoppingdiv.style.marginRight="auto";
    shoppingdiv.style.marginLeft="5px";
}

function setTheShoppingFooter() {
    //Set the footer & bottom nav on the shopping pages
    var BotNavPanel = document.getElementById('botnavpanel');    
    BotNavPanel.style.backgroundImage="url('https://www.zinestudio.co.uk/northeastevents/images/sty_botnavback.jpg')";
    var shoppingFooter = document.getElementById('footerpanel');
    shoppingFooter.style.backgroundImage="url('https://www.zinestudio.co.uk/northeastevents/images/sty_footback.gif')";
}

function setTheProductBackground() {
  //set the product background to white
  var aryClassElements = getElementsByClassName('maincontent', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'maincontent') {
      aryClassElements[i].style.background="url('https://www.zinestudio.co.uk/northeastevents/images/productbackground.jpg') repeat-y";      
    }
   } 
}

function displayTheNormalBackground() {
  //set the normal background
  var aryClassElements = getElementsByClassName('maincontent', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'maincontent') {
      aryClassElements[i].style.background="transparent url('https://www.zinestudio.co.uk/northeastevents/images/sty_maincontentback.jpg') left top no-repeat";      
    }
   } 
}

function hideContinueShopping() {
  var aryClassElements = getElementsByClassName( 'cartlink', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'cartlink') {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }
}

function hideshippinginfopart() {
  document.all.ch_shipSame.checked = true ;
  var aryClassElements = getElementsByClassName( 'cart', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'cart' && (i==3 || i==4)) {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }
}


function hideFirstContinueShopping(){
  var aryClassElements = getElementsByClassName( 'cartlinkhidden', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'cartlinkhidden') {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }
}

function hideshippingonpaymentpage() {
  var tableelement;
  var aryClassElements = getElementsByClassName('ordertotalline', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'ordertotalline' && (i>=0 && i<=5)) {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }
  aryClassElements = getElementsByClassName('cart', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'cart' && i==5) {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }

}

function hideshippingonreviewpage() {
  var tableelement;
  //get table shipping table(8) element on this page
  tableelement = document.getElementsByTagName("table")[8];
  tableelement.style.visibility = "hidden";
  tableelement.style.display = "none";
  var aryClassElements = getElementsByClassName('ordertotalline', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'ordertotalline' && (i>=0 && i<=5)) {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }
}

function hideshippingonthankyoupage() {
  var aryClassElements = getElementsByClassName('custbasicinfotable', document.body );    
  for ( var i = 0; i < aryClassElements.length; i++ ) {        
    if (aryClassElements[i].className = 'custbasicinfotable' && (i==1)) {
      aryClassElements[i].style.visibility = "hidden";
      aryClassElements[i].style.display = "none";
    }
   }
  var aryClassElementsship = getElementsByClassName('ordertotalline', document.body );    
  for ( var i = 0; i < aryClassElementsship.length; i++ ) {        
    if (aryClassElementsship[i].className = 'ordertotalline' && (i>=0 && i<=5)) {
      aryClassElementsship[i].style.visibility = "hidden";
      aryClassElementsship[i].style.display = "none";
    }
   }

}

function readCookie(cookie_name) {   
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if (results)
    return (unescape(results[2]));
  else
    return null;
}

function capitaliseforformheader(value)
{
 if (value != "") {
   var words = value.split(" "); 
   for (var i=0 ; i < words.length ; i++){ 
      var testwd = words[i]; 
      var firLet = testwd.substr(0,1); 
      var rest = testwd.substr(1, testwd.length -1) 
      words[i] = firLet.toUpperCase() + rest 
   } 
  }
  return words.join(" ");
}

function capitalise(value)
{
 if (value != "") {
   var firstLetter = value.substring(0, 1).toUpperCase();
   var restOfWord = value.substring(1, value.length).toLowerCase(); 
   value = firstLetter + restOfWord;
   var newvalue= value.replace(/\+/g," ");
 }
  return newvalue;
}

function setDisplayOn(e){
  element = document.getElementById(e);
  if (element){
   //if IE
   if (element.currentStyle){
       element.style.display='block';
       element.style.visible='visible';
   } else {
    //if FF
    element.setAttribute( 'style', 'display:block');
   }
  }
}

function capitaliseall(value)
{
 if (value!= "") {
    var word = value.toUpperCase(); 
    var newword = word.replace(/\+/g," ");
 }  
  return newword;
}

function deletedayactivity(deleteitem) {
  var i;
  var cookiestring="";
  var cookiecontent=readCookie("cookie_day");
  var mySplitResult = cookiecontent.split("|");
  for(i = 0; i < mySplitResult.length; i++){
    if(i!=deleteitem) {
      //build cookie string
      cookiestring = cookiestring+escape(mySplitResult[i])+"|";
    }
 }
  var strLen =cookiestring.length;
  var last_char=cookiestring.charAt(strLen -1);
  if(last_char=="|") {
    cookiestring = cookiestring.slice(0,-1); 
  }
  //delete cookie
  var d = new Date();
  document.cookie = "cookie_day;expires=" + d.toGMTString() + ";" + ";";
  document.cookie = "cookie_day="+cookiestring ; 
  alert('Your daytime activity has been removed');
  location.reload(true);
}

function deleteeveningactivity(deleteitem) {
  var i;
  var cookiestring="";
  var cookiecontent=readCookie("cookie_evening");
  var mySplitResult = cookiecontent.split("|");
  for(i = 0; i < mySplitResult.length; i++){
    if(i!=deleteitem) {
      //build cookie string
      cookiestring = cookiestring+escape(mySplitResult[i])+"|";
    }
 }
  var strLen =cookiestring.length;
  var last_char=cookiestring.charAt(strLen -1);
  if(last_char=="|") {
    cookiestring = cookiestring.slice(0,-1); 
  }
  //delete cookie
  var d = new Date();
  document.cookie = "cookie_evening;expires=" + d.toGMTString() + ";" + ";";
  //create new cookie
  document.cookie = "cookie_evening="+cookiestring; 
  alert('Your evening activity has been removed');
  location.reload(true);
}

function deleteaccommodation(deleteitem) {
  var i;
  var cookiestring="";
  var cookiecontent=readCookie("cookie_acc");
  var mySplitResult = cookiecontent.split("|");
  for(i = 0; i < mySplitResult.length; i++){
    if(i!=deleteitem) {
      //build cookie string
      cookiestring = cookiestring+escape(mySplitResult[i])+"|";
    }
 }
  var strLen =cookiestring.length;
  var last_char=cookiestring.charAt(strLen -1);
  if(last_char=="|") {
   cookiestring = cookiestring.slice(0,-1); 
  }
  //delete cookie
  var d = new Date();
  document.cookie = "cookie_acc;expires=" + d.toGMTString() + ";" + ";";
  document.cookie = "cookie_acc="+cookiestring; //
  alert('Your accommodation selection has been removed');
  location.reload(true);
}

function deleterestaurant(deleteitem) {
  var i;
  var cookiestring="";
  var cookiecontent=readCookie("cookie_restaurant");
  var mySplitResult = cookiecontent.split("|");
  for(i = 0; i < mySplitResult.length; i++){
    if(i!=deleteitem) {
      //build cookie string
      cookiestring = cookiestring+escape(mySplitResult[i])+"|";
    }
  }
  var strLen =cookiestring.length;
  var last_char=cookiestring.charAt(strLen -1);
  if(last_char=="|") {
    cookiestring = cookiestring.slice(0,-1); 
  }
  //delete cookie
  var d = new Date();
  document.cookie = "cookie_restaurant;expires=" + d.toGMTString() + ";" + ";";
  document.cookie = "cookie_restaurant="+cookiestring;
  alert('Your restaurant selection has been removed');
  location.reload(true);
}

function validatesupplierform(frm)
{
    // Check the Name field is not blank
    if (frm.txtname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.txtname.focus();
        return false;
    }
    // Check the postal address field is not blank
    if (frm.txtpostaladdress.value.length == 0)
    {
        alert("Please enter postal address.");
        frm.txtpostaladdress.focus();
        return false;
    }
    // Check the city field is not blank
    if (frm.txtcity.value.length == 0)
    {
        alert("Please enter city.");
        frm.txtcity.focus();
        return false;
    }
    // Check the county field is not blank
    if (frm.txtcounty.value.length == 0)
    {
        alert("Please enter county.");
        frm.txtcounty.focus();
        return false;
    }
    // Check the postcode field is not blank
    if (frm.txtpostcode.value.length == 0)
    {
        alert("Please enter postcode.");
        frm.txtpostcode.focus();
        return false;
    }
    // Check the Email field to see if any characters were entered
    if (frm.txtemail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Now check the Email field for the "@" symbol
    if (frm.txtemail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Check the mobile is not blank
    if (frm.txtmobile.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.txtmobile.focus();
        return false;
    }

    // Check the category is not blank
    if (frm.txtcategory.value.length == 0)
    {
        alert("Please enter some category details.");
        frm.txtcategory.focus();
        return false;
    }
    // Check the category is not blank
    if (frm.txtdescription.value.length == 0)
    {
        alert("Please enter some description details.");
        frm.txtdescription.focus();
        return false;
    }
}

function validatepoledancingform(frm) 
{
    // Check the Name field is not blank
    if (frm.txtname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.txtname.focus();
        return false;
    }
    // Check the tel and mobile are not blank
    if (frm.txttelephone.value.length == 0 && frm.txtmobile.value.length == 0)
    {
        alert("Please enter either a telephone or mobile number.");
        frm.txttelephone.focus();
        return false;
    }
    // Check the Email field to see if any characters were entered
    if (frm.txtemail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Now check the Email field for the "@" symbol
    if (frm.txtemail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.txtemail.focus();
        return false;
    }
}

function validatebutlerandpamperform(frm) {
      // Check the Name field is not blank
    if (frm.txtname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.txtname.focus();
        return false;
    }
    // Check the Email field to see if any characters were entered
    if (frm.txtemail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Now check the Email field for the "@" symbol
    if (frm.txtemail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    // Check the mobile is not blank
    if (frm.txtmobile.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.txtmobile.focus();
        return false;
    }
    // Check the option is not blank, if applicable
    if (frm.cmboption.value != '0') {
      if (frm.cmboption.value.length == 0)
      {
        alert("Please select your activity option.");
        frm.cmboption.focus();
        return false;
      }
    }
    // Check the type of group is not blank
    if (frm.cmbgroup.value.length == 0)
    {
        alert("Please select your kind of group.");
        frm.cmbgroup.focus();
        return false;
    }
    // Check the date is not blank
    if (frm.txtarrival.value.length == 0)
    {
        alert("Please select a date.");
        frm.txtarrival.focus();
        return false;
    }
    // Check the people is not blank
    if (frm.txtpeople.value.length == 0)
    {
        alert("Please enter the number of people.");
        frm.txtpeople.focus();
        return false;
    }
    // Check the call time is not blank
    if (frm.cmbtimetocall.value.length == 0)
    {
        alert("Please select the best time to call you.");
        frm.cmbtimetocall.focus();
        return false;
    }
    // Check the where you hear about us is not blank
    if (frm.cmbhear.value.length == 0)
    {
        alert("Please select where you heard about us from.");
        frm.cmbhear.focus();
        return false;
    }

}

function validatespecialofferform(frm) 
{
    // Check the Name field is not blank
    if (frm.txtname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.txtname.focus();
        return false;
    }
    // Check the Email field to see if any characters were entered    if (frm.txtemail.value.length == 0)
        if (frm.txtemail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    //
    // Now check the Email field for the "@" symbol
    //
    if (frm.txtemail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    
    // Check the mobile is not blank
    if (frm.txtmobile.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.txtmobile.focus();
        return false;
    }
    // Check the city is not blank
    if (frm.cmbhotel.value.length == 0)
    {
        alert("Please select your hotel choice.");
        frm.cmbhotel.focus();
        return false;
    }
    
    // Check the date is not blank
    if (frm.txtarrival.value.length == 0)
    {
        alert("Please select a date.");
        frm.txtarrival.focus();
        return false;
    }
    // Check the people is not blank
    if (frm.txtpeople.value.length == 0)
    {
        alert("Please enter the number of people.");
        frm.txtpeople.focus();
        return false;
    }
    // Check the kind of group is not blank
    if (frm.cmbgroup.value.length == 0)
    {
        alert("Please select the kind of group.");
        frm.cmbgroup.focus();
        return false;
    }
    // Check the call time is not blank
    if (frm.cmbtimetocall.value.length == 0)
    {
        alert("Please select the best time to call you.");
        frm.cmbtimetocall.focus();
        return false;
    }
    // Check the where you hear about us is not blank
    if (frm.cmbhear.value.length == 0)
    {
        alert("Please select where you heard about us from.");
        frm.cmbhear.focus();
        return false;
    }
}


function validatecontactusform(frm) 
{
    // Check the Name field is not blank
    if (frm.txtname.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.txtname.focus();
        return false;
    }
    // Check the Email field to see if any characters were entered
    //
    if (frm.txtemail.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    //
    // Now check the Email field for the "@" symbol
    //
    if (frm.txtemail.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.txtemail.focus();
        return false;
    }
    
    // Check the mobile is not blank
    if (frm.txtmobile.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.txtmobile.focus();
        return false;
    }
    // Check the city is not blank
    if (frm.city.value.length == 0)
    {
        alert("Please select a city.");
        frm.city.focus();
        return false;
    }
    
    // Check the date is not blank
    if (frm.txtdate.value.length == 0)
    {
        alert("Please select a date.");
        frm.txtdate.focus();
        return false;
    }
    // Check the people is not blank
    if (frm.txtpeople.value.length == 0)
    {
        alert("Please enter the number of people.");
        frm.txtpeople.focus();
        return false;
    }
    // Check the kind of group is not blank
    if (frm.kind.value.length == 0)
    {
        alert("Please select the kind of group.");
        frm.kind.focus();
        return false;
    }
    // Check the call time is not blank
    if (frm.call.value.length == 0)
    {
        alert("Please select the best time to call you.");
        frm.call.focus();
        return false;
    }
    // Check the where you hear about us is not blank
    if (frm.hear.value.length == 0)
    {
        alert("Please select where you heard about us from.");
        frm.hear.focus();
        return false;
    }
}

function validatecreateform (frm) 
{
    if (frm.date.value.length == 0)
    {
        alert("Please enter the date required.");
        frm.date.focus();
        return false;
    }
    if (frm.people.value.length == 0)
    {
        alert("Please enter the number of people.");
        frm.people.focus();
        return false;
    }
    if (frm.cmbinterested.value.length == 0)
    {
        alert("Please select your interest.");
        frm.cmbinterested.focus();
        return false;
    }
    if (frm.name.value.length == 0)
    {
        alert("Please enter contact name.");
        frm.name.focus();
        return false;
    }
    if (frm.email.value.length == 0)
    {
        alert("Please enter an e-mail address.");
        frm.email.focus();
        return false;
    }
    if (frm.email.value.indexOf("@") == -1)
    {
        alert("Please enter a valid e-mail address.");
        frm.email.focus();
        return false;
    }
    if (frm.telephone.value.length == 0)
    {
        alert("Please enter contact number.");
        frm.telephone.focus();
        return false;
    }
    if (frm.cmbcall.value.length == 0)
    {
        alert("Please select the best time for contact.");
        frm.cmbcall.focus();
        return false;
    }
    if (frm.cmbhear.value.length == 0)
    {
        alert("Please select how you heard about us.");
        frm.cmbhear.focus();
        return false;
    }
    if (frm.chkterms.checked != 1)
    {
        alert("Please accept out terms and conditions to submit your enquiry.");
        frm.chkterms.focus();
        return false;
    }
}

function getElementsByClassName( strClassName, obj ) {    
  var ar = arguments[2] || new Array();    
  var re = new RegExp("\\b" + strClassName + "\\b", "g");    
  if ( re.test(obj.className) ) {        
    ar.push( obj );    
  }    
  for ( var i = 0; i < obj.childNodes.length; i++ ) getElementsByClassName( strClassName, obj.childNodes[i], ar );        
  return ar;
}