

function oc_load () {
	png_fix();
	cookiedata_onload();
	newsbar_load();
	scalendar_flush();
}



function print_this_page () {
	alert('This page has special printing formatting\nReady to print');
	window.print();
}

function bookmark_this_page () {
	if (navigator.appName == "Microsoft Internet Explorer") {
		window.external.AddFavorite(document.location, 'Office Christmas - '+document.title);
	} else {
		alert('To bookmark this page simply close this message box and then press:\n\nCtrl + D');
	}
}

function dateselect ( d ) {
  var s = document.getElementById('dateselect');
	for (var i = 0; i < s.options.length; i++) {
		if (s.options[i].value == d) {
			s.selectedIndex = i;
		}
	}
}

function locationselect ( l ) {
  var s = document.getElementById('locationselect');
	for (var i = 0; i < s.options.length; i++) {
		if (s.options[i].value == l) {
			s.selectedIndex = i;
		}
	}
}



_datetable_keys = new Array();

function datetable_switch ( name , y ) {

	var years = _datetable_keys[name];

	for (var i = 0; i < years.length; i++) {
		if (years[i] == y) {
			var div = 'show';
			var td = 'on';
		} else {
			var div = 'hide';
			var td = 'off';
		}
		ge('dt_'+name+'_div_'+years[i]).className = 'datetable-'+div;
		ge('dt_'+name+'_td_'+years[i]).className = 'datetable-'+td;
	}

}



_hotelhover_current = '';

function hotelhover_over ( id ) {
	if (_hotelhover_current != '') {
		ge('hotelhover_'+_hotelhover_current).style.display = 'none';
	} else {
		ge('hotelhover_default').style.display = 'none';
	}
	ge('hotelhover_'+id).style.display = 'block';
	_hotelhover_current = id;
}
function hotelhover_out () {
	if (_hotelhover_current != '') {
		ge('hotelhover_'+_hotelhover_current).style.display = 'none';
	}
	ge('hotelhover_default').style.display = 'block';
	_hotelhover_current = '';
}




function png_fix () {

	var arVersion = navigator.appVersion.split("MSIE")
	if (arVersion.length > 1) {
		var version = parseFloat(arVersion[1])
		if (version >= 5.5 && version < 7 && document.body.filters) {
			DD_belatedPNG.fix('.png');
		}
	}

}


/* locations expander */

_lex_open = '';

function lex_click ( id ) {
	if (_lex_open != '') {
		$('#lex-'+_lex_open).slideUp();
	}
	if (_lex_open == id) {
		_lex_open = '';
	} else {
		_lex_open = id;
		$('#lex-'+id).slideDown();
	}
}



/* tpgrid */

function tpgrid_over ( obj, type ) {
	obj.style.backgroundImage = 'url('+document.getElementsByTagName('base')[0].href+'design/tpgrid-bgover-'+type+'.jpg)';
}
function tpgrid_out ( obj, type ) {
	obj.style.backgroundImage = 'url('+document.getElementsByTagName('base')[0].href+'design/tpgrid-bg-'+type+'.jpg)';
}



/* tp bar stuff */


function tpbar_load () {
	var i = document.getElementById('tpbar-input');
	if (_cookiedata['q']) {
		if (_cookiedata['q'] != '' && _cookiedata['q'] != 'enter location') {
			i.value = _cookiedata['q'];
		}
	}
	if (i.value != 'enter location') {
		_cookiedata['q'] = '';
		$('#tpbar-input').click();
	}
}

function tpbar_submit () {
	var i = document.getElementById('tpbar-input');
	if (i.value == '' || i.value == 'enter location') {
		alert('Please enter a Town/Postcode in the location box and try again.');
	} else {
		document.getElementById('tpbar-form').submit();
	}
}


// new style tpbar extensions
$(document).ready(function(){

	$('#tpbar-input').focus(function(){
		var input = $(this);
		var div = $('#tpbar-focused');
		if (input.is(':animated')) {
			input.stop();
		}
		if (div.is(':animated')) {
			div.stop();
		}
		input.animate({borderColor: '#fbde5a'}, 300);
		div.fadeTo(300, 1);
	});

	$('#tpbar-input').blur(function(){
		var input = $(this);
		var div = $('#tpbar-focused');
		if (input.is(':animated')) {
			input.stop();
		}
		if (div.is(':animated')) {
			div.stop();
		}
		input.animate({borderColor: '#aaaaaa'}, 300);
		div.fadeTo(300, 0);
	});

	$('#tpbar-focused').css('opacity', 0);

});





/* tp box stuff */


function tpbox_load () {
	if (document.getElementById('tpbox')) {
		tpbox_select(document.getElementById('tpbox-type'));
		tpbox_select(document.getElementById('tpbox-budget'));
	}
	if (document.getElementById('tpbox-locselect')) {
		tpbox_locselect_load();
	}
	if (document.getElementById('tpbox-distance')) {
		tpbox_distance_load();
	}
	if (document.getElementById('tpbox-guests')) {
		tpbox_guests_load();
	}
}


function tpbox_locselect () {
	var t = 650;
	var s = document.getElementById('tpbox-locselect');
	if (s.selectedIndex == 0) {
		document.getElementById('tpbox-distances-title').innerHTML = 'My Location';
		$('#tpbox-distances-title').fadeOut(0).fadeIn(t);
		document.getElementById('tpbox-distances-note').innerHTML = '* Enter your town/postcode<br />&nbsp; to find parties near you';
		$('#tpbox-distances-note').fadeOut(0).fadeIn(t);
		$('#tpbox-distances-star').fadeIn(t);
		document.getElementById('tpbox-heading-note').innerHTML = '* = Required field';
	} else {
		document.getElementById('tpbox-distances-title').innerHTML = 'Distance from';
		$('#tpbox-distances-title').fadeOut(0).fadeIn(t);
		document.getElementById('tpbox-distances-note').innerHTML = '* Use this field to find out<br />&nbsp; how far you have to travel';
		$('#tpbox-distances-note').fadeOut(0).fadeIn(t);
		$('#tpbox-distances-star').fadeOut(t);
		document.getElementById('tpbox-heading-note').innerHTML = '* All fields are optional';
	}
}
function tpbox_locselect_load () {
	var s = document.getElementById('tpbox-locselect');
	if (s.selectedIndex == 0) {
		document.getElementById('tpbox-distances-title').innerHTML = 'My Location';
		document.getElementById('tpbox-distances-note').innerHTML = '* Enter your town/postcode<br />&nbsp; to find parties near you';		
		document.getElementById('tpbox-distances-star').style.display = 'inline';
		document.getElementById('tpbox-heading-note').innerHTML = '* = Required field';
	}
}


function tpbox_distance_input () {
	var i = document.getElementById('tpbox-distance');
	if (i.value == 'town/postcode') {
		i.value = '';
	}
	i.style.fontStyle = 'normal';
	i.style.color = 'black';
}
function tpbox_distance_load () {
	var i = document.getElementById('tpbox-distance');
	if (i.value != 'town/postcode') {
		tpbox_distance_input();
	}
}


function tpbox_guests_input () {
	var i = document.getElementById('tpbox-guests');
	if (i.value == 'number') {
		i.value = '';
	}
	i.style.fontStyle = 'normal';
	i.style.color = 'black';
}
function tpbox_guests_load () {
	var i = document.getElementById('tpbox-guests');
	if (i.value != 'number') {
		tpbox_guests_input();
	}
}


function tpbox_select ( obj ) {
	if (obj.selectedIndex == 0) {
		obj.style.color = '#b12b19';
		obj.style.fontStyle = 'italic';
	} else {
		obj.style.color = 'black';
		obj.style.fontStyle = 'normal';
	}
}

function tpbox_open_home () {
	var t = 700;
	$('#tpbox').animate({width: 720}, t);
	$('#tpbox-content').animate({width: 709, height: 342}, t);
	$('#tpbox-spacer').animate({height: 404}, t);
	$('#tpbox-dateinput').fadeOut(t);
	$('#tpbox-calendar-header').fadeIn(t);
	$('#tpbox-calendar').fadeTo(0,0).animate({height: 180, opacity: 1}, t);
}

function tpbox_open_sae () {
	var t = 700;
	$('#tpbox').animate({width: 720}, t);
	$('#tpbox-content').animate({width: 709, height: 342}, t);
	$('#tpbox-spacer').animate({height: 404}, t);
	$('#tpbox-dateinput').fadeOut(t);
	$('#tpbox-calendar-header').fadeIn(t);
	$('#tpbox-calendar').fadeTo(0,0).animate({height: 180, opacity: 1}, t);
	$('#tpbox-holder').animate({paddingLeft: 12}, t);
}

function tpbox_open_location () {
	var t = 700;
	$('#tpbox').animate({width: 720}, t);
	$('#tpbox-content').animate({width: 709, height: 372}, t);
	$('#tpbox-spacer').animate({height: 434}, t);
	$('#tpbox-dateinput').fadeOut(t);
	$('#tpbox-calendar-header').fadeIn(t);
	$('#tpbox-calendar').fadeTo(0,0).animate({height: 180, opacity: 1}, t);
	$('#tpbox-holder').animate({paddingLeft: 12}, t);
}

function tpbox_open_results () {
	var t = 700;
	$('#tpbox').animate({width: 720}, t);
	$('#tpbox-content').animate({width: 709, height: 372}, t);
	$('#tpbox-spacer').animate({height: 437}, t);
	$('#tpbox-dateinput').fadeOut(t);
	$('#tpbox-calendar-header').fadeIn(t);
	$('#tpbox-calendar').fadeTo(0,0).animate({height: 180, opacity: 1}, t);
	$('#tpbox-holder').animate({paddingLeft: 12}, t);
}

function tpbox_open_results_addlocation () {
	var t = 700;
	$('#tpbox').animate({width: 720}, t);
	$('#tpbox-content').animate({width: 709, height: 425}, t);
	$('#tpbox-spacer').animate({height: 491}, t);
	$('#tpbox-dateinput').fadeOut(t);
	$('#tpbox-calendar-header').fadeIn(t);
	$('#tpbox-calendar').fadeTo(0,0).animate({height: 180, opacity: 1}, t);
	$('#tpbox-holder').animate({paddingLeft: 12}, t);
}

function tpbox_submit () {
	var v = document.getElementById('tpbox-location').value;
	if (v == '' || v == 'enter location') {
		alert('Please enter a Town/Postcode in the location box and try again.');
	}	else {
		document.getElementById('tpbox-form').submit();
	}
}

function tpbox_submit_location () {
	document.getElementById('tpbox-form').submit();
}

function tpbox_submit_results () {
	if (document.getElementById('tpbox-locselect')) {
		var s = document.getElementById('tpbox-locselect');
		if (s.selectedIndex == 0) {
			var v = document.getElementById('tpbox-distance').value;
			if (v == '' || v == 'town/postcode') {
				alert('Please enter a Town/Postcode in the My Location box and try again.');
			}	else {
				document.getElementById('tpbox-form').submit();
			}
		} else {
			document.getElementById('tpbox-form').submit();
		}
	} else {
		var v = document.getElementById('tpbox-location').value;
		if (v == '' || v == 'enter location') {
			alert('Please enter a Town/Postcode in the location box and try again.');
		}	else {
			document.getElementById('tpbox-form').submit();
		}
	}
}



/* chunky button */

function chunkybutton_over ( obj ) {
	obj.style.backgroundPosition = 'right -50px';
	obj.style.color = '#f46a1f';
}

function chunkybutton_out ( obj ) {
	obj.style.backgroundPosition = 'right 0px';
	obj.style.color = '#b12b19';
}


/* newsbar */

function newsbar_email_input () {
	var e = document.getElementById('newsbar_email');
	if (e.value == 'enter email address') {
		e.value = '';
	}
	e.style.color = 'black';
	e.style.fontStyle = 'normal';
}

function newsbar_submit () {
	var e = document.getElementById('newsbar_email');
	if (e.value == '' || e.value == 'enter email address') {
		alert('Please enter your email address and try again');
	} else {
		document.getElementById('newsbar_form').submit();
	}
}

function newsbar_load () {
	if (document.getElementById('newsbar_email')) {
		var e = document.getElementById('newsbar_email');
		if (e.value != 'enter email address') {
			newsbar_email_input();
		}
	}
}


/* cookie stuff */

_cookiedata = new Array();

function cookiedata_onload () {
	var c = readCookie('oc_cookiedata');
	if (c == null) { return; }
	c = c.split(' ');
	for (var i = 0; i < c.length; i++) {
		var d = c[i].split(':');
		_cookiedata[d[0]] = urldecode(d[1]);
	}
}

function cookiedata_update ( obj ) {
	var n = obj.name;
	var v = obj.value;
	if (_cookiedata[n] != v) {
		_cookiedata[n] = v;
		cookiedata_write();
	}
}

function cookiedata_write () {
	var ar = new Array();
	for (var k in _cookiedata) {
		ar[ar.length] = k + ':' + urlencode(_cookiedata[k]);
	}
	createCookie('oc_cookiedata', ar.join(' '), 1095);
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 eraseCookie(name) {
	createCookie(name,"",-1);
}



/* urlencode */

function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

function urldecode ( utftext ) {
		utftext = unescape(utftext);
		utftext = utftext.split('+').join(' ');

		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
}


/* html entities */

function htmlentities (string, quote_style) {
    // Convert all applicable characters to HTML entities  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/htmlentities    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');    // *     returns 1: 'Kevin &amp; van Zonneveld'
    // *     example 2: htmlentities("foo'bar","ENT_QUOTES");
    // *     returns 2: 'foo&#039;bar'
    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();    
    if (false === (hash_map = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    hash_map["'"] = '&#039;';    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
        return tmp_str;
}

function get_html_translation_table (table, quote_style) {
    // Returns the internal translation table used by htmlspecialchars and htmlentities  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/get_html_translation_table    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, hash_map = {}, decimal = 0, symbol = '';    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
     useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
 
    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');        // return false;
    }
 
    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';        entities['255'] = '&yuml;';
    }
 
    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';    entities['62'] = '&gt;';
 
 
    // ascii decimals to real symbols
    for (decimal in entities) {        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }
    
    return hash_map;
}



