
fullpath=location.pathname;
var mySplitResult = fullpath.split("/");
var rootname = mySplitResult[1]; 
var foldername = mySplitResult[1].replace("devonandcornwall", "devoncornwall");

function bookmarksite(title,url){
 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))
	window.sidebar.addPanel(title, url, "");
else if(window.opera){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url,title);
else 
alert('To Bookmark Sugarvine Press control and d');
}

//<![CDATA[
var mobi = ['opera', 'iemobile', 'safari'];
var midp = ['blackberry', 'symbian'];
var ua = navigator.userAgent.toLowerCase();
if ((ua.indexOf('midp') != -1) || (ua.indexOf('mobi') != -1) || ((ua.indexOf('ppc') != -1) && (ua.indexOf('mac') == -1))) {
	document.write('<link rel="stylesheet" href="/css/allmobile.css" type="text/css" media="all"/>');
	if (ua.indexOf('midp') != -1) {
		for (var i = 0; i < midp.length; i++) {
			if (ua.indexOf(midp[i]) != -1) {
				document.write('<link rel="stylesheet" href="/css/' + midp[i] + '.css" type="text/css"/>');
				document.write('<meta name="viewport" content="width=320,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"/>');
			}
		}
	}
	else {
		if ((ua.indexOf('mobi') != -1) || (ua.indexOf('ppc') != -1)) {
			for (var i = 0; i < mobi.length; i++) {
				if (ua.indexOf(mobi[i]) != -1) {
					document.write('<link rel="stylesheet" href="/css/' + mobi[i] + '.css" type="text/css"/>');
					document.write('<meta name="viewport" content="width=240"/>');
				}
			}
		}
	}
}
//]]>

<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->

function areajump(selObj,restore){ //v3.0
  eval("parent.location='/"+ rootname + "/search/location_search.asp?town=" + selObj.options[selObj.selectedIndex].text+"'");
  if (restore) selObj.selectedIndex=0;
}

function cuisjump(selObj,restore){ //v3.0
  eval("parent.location='/"+ rootname + "/search/cuisine_search.asp?cuisine_type=" + selObj.options[selObj.selectedIndex].text+"'");
  if (restore) selObj.selectedIndex=0;
}

function postjump(selObj,restore){ //v3.0
  eval("parent.location='/"+ rootname + "/search/postcode_search.asp?postcode=" + selObj.options[selObj.selectedIndex].text+"'");
  if (restore) selObj.selectedIndex=0;
}

var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

function trackclick(url, aid) {
	
	var clickstr = location.host
if (clickstr.replace(/www./, "") == 'sugarvine.com')
{

    if(document.images){ 
        (new Image()).src='/inc/clicktrack.asp?url=' + url + '&rid=' + aid + '&pagename='+sPage+'&folder=' + foldername;
		 } 

    return true;
	
}
}

function open_win(url, wid, hi)
   {
   window.open(url,'voucher','width=' + wid + ',height=' + hi + ',menubar=no,status=no,location=yes,toolbar=no,scrollbars=yes');
   }
     
   
var loadstatustext="<div style=\"background-image:url(/images/loading.gif); background-position:center center;background-repeat:no-repeat;width:296px;height:219px;background-color:#f3f3f3;display:block;\"></div>"  

var req;

function callPage(pageUrl, divElementId, wid, hi) {

callPage.errorstatustext='Error in Loading page';

this.defaultIframe='<iframe src="about:blank" scroling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="width:' + wid + 'px;height:' + hi + 'px; overflow:hidden;"></iframe>'
this.defaultIframe=this.defaultIframe.replace(/<iframe/i, '<iframe name="'+divElementId+'"')

     document.getElementById(divElementId).innerHTML = loadstatustext;
	 
     try {
     req = new XMLHttpRequest(); /* e.g. Firefox */
     } catch(e) {
       try {
       req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
       } catch (e) {
         try {
         req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
         } catch (E) {
          req = false;
         } 
       } 
     }
     req.onreadystatechange = function() {responsefromServer(divElementId, pageUrl);};
     req.open("GET",pageUrl,true);
     req.send(null);
  }

function responsefromServer(divElementId, pageUrl) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
	  
         if (typeof window.frames[divElementId]!="undefined"){
			try{delete window.frames[divElementId]} //delete iframe within Tab content container if it exists (due to bug in Firefox)
			catch(err){}
		}
		document.getElementById(divElementId).innerHTML=this.defaultIframe
		window.frames[divElementId].location.replace(pageUrl) //load desired page into iframe
		
         } else {
         document.getElementById(divElementId).innerHTML = callPage.errorstatustext+"\n"+output;
         }
      }
  }
  
  

  
  
  
function loaddiv(name, div, url, target, w, h) {
 
  document.getElementById(div).innerHTML = '<div style=\"background-image:url(/images/loading.gif); background-position:center center;background-repeat:no-repeat;width:736px;height:300px;background-color:#f3f3f3;display:block;\"></div>';
  
try {
req = new XMLHttpRequest(); /* e.g. Firefox */
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
} catch (E) {
req = false;
} 
} 
}
req.onreadystatechange = function() {loaddivDone(name, div, url, target, w, h);};
req.open("GET",name,true);
req.send(null);
}

function loaddivDone(name, div, url, target, w, h) {
   var output = '';
   if(req.readyState == 4) {
      if(req.status == 200) {
	  
        
		document.getElementById(div).innerHTML= req.responseText;
		
		callPage(url,target,w,h);
		
         } else {
         document.getElementById(div).innerHTML = callPage.errorstatustext+"\n"+output;
         }
      }
	  
  }
  
  
  // advanced search
  
  function testadvanced (pvar, tvar)

{

var alvar = '';


var townvar = pvar;
var cuisvar = tvar;	

		if (townvar == 'Please Select')
		{
		alvar = 'Please Select A Location.\n';
		document.getElementById("chloc").innerHTML = "Select A Location:";
		document.getElementById("chloc").style.color = "#ff0000";
		}
		else
		{
		document.getElementById("chloc").innerHTML = "Change Location:";
		document.getElementById("chloc").style.color = "#FFFFFF";
		}
	
		if (cuisvar ==  'Please Select')
		{
		alvar = alvar + 'Please Select A Category.\n';
		document.getElementById("chcuis").innerHTML = "&nbsp;Select A Category:";
		document.getElementById("chcuis").style.color = "#ff0000";
		}
		else
		{
		document.getElementById("chcuis").innerHTML = "&nbsp;Change Cuisine Type:";
		document.getElementById("chcuis").style.color = "#FFFFFF";
		}

	
	if (alvar !== '')
		{
		// alert (alvar);
		return false;
		}
	
	
	}
	


	
	function checkPostCode (toCheck) {
	
	
	// new regex? /^(GIR 0AA|BFPO ([0-9]{1,4})|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) [0-9][ABD-HJLNP-UW-Z]{2})$/



  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);

  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {
    //return postCode;
	url = '/' + rootname + '/map/postcode/location.asp'
    var frm = document.forms["restsearch"]; 
	frm.action = url; 
	frm.submit();

  } else
  	url = '/' + rootname + '/search/name_search.asp'
    var frm = document.forms["restsearch"]; 
	frm.action = url; 
	frm.submit();
  // return false;
}
	
	
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-8308188-2']);
  _gaq.push(['_trackPageview']);
	
	
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
  	
  	
  jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


