var current_menu_ref = null;// anchor obj of clicked menu item
var contentLoadedFlag = false; // true when AJAX has done its stuff
var loadedobjects = "";// used in css & js load functions
var preloadFlag = false;
var main_menu_items = []; // array holding menu contruction strings for main menu
var main_menu_DOM = [];// DOM object array for main menu
var sub_menu_items = []; // array holding menu contruction strings for submenu
var sub_menu_DOM = []; // DOM object array for submenu
var hotspot_items = []; // array holding menu contstruction strings for hotspots
var hotspots_DOM = []; // DOM object array for hotspots
var current_url = null;
var newhash = null; // special hash used to fetch pages via AJAX
var media_player_open = false; // true when media player div has been slid open
var timeout = null; // used for setting timeout of 'waiting' animating
var signup_email = null; // value used to block it being sent again by double clicking the button if server response is slow
var jumpIsPresent = false; // flag for anchor tag within page content
var returnees_page = -1; // keeps track of pages displayed on 'Returnees' page
var current_url = ""; // placeholder so we don't get error if EPG loads first
	


function setupAJAX() {
	if (window.XMLHttpRequest) {
          // If IE7, Mozilla, Safari, etc: Use native XMLHttpRequest
        var ajaxRequest = new XMLHttpRequest();
        return ajaxRequest;
		} else {
	if (window.ActiveXObject) {
          // ...otherwise, use the ActiveX control for IE5.x and IE6
         var ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		 return ajaxRequest;
          } else {
		alert("Sorry, this page won't work with this browser!\nYou need to upgrade to a recent version of\nFirefox, Safari, Opera or Internet Explorer.");
	  
		  }
	  }
	}
	
	//if(window.location.hostname.indexOf("www") ==-1) window.location.assign("http://www.radiocaroline.co.uk/index_IE6.html/"); // reload if "www" is missed off by user

	// kicked from body onload() event.......
	function initialise() {
	make_main_menu();
	make_sub_menu();
	preloadImages();
	get_profiles();
	//boot_EPG();
	pollHash();
	if(!window.location.hash) parse_hotspots(main_menu_DOM[0]);// display Home Page content if there is no pasted address
	swfobject.embedSWF("swf/AC&SPbanner2.swf", "AC_ad", "160", "200", "9.0.0"); // stick in AC Lighting ad
	var listen_click_div = document.getElementById('listen_click_div');
	listen_click_div.onclick = function(){alert('Sorry this feature does not work with Internet Explorer 6 - please upgrade');};
	document.onmousemove = follow; // function for popping up messages in profiles.js
	//alert(getBrowserWidth());
	}
	
	
	//MAKE MAIN MENU
	function make_main_menu() {
	var main_menuDiv = document.getElementById('main_menuDiv');
	var ul = document.createElement("ul");
	ul.id="menu";
	ul.onmouseover=function() {kill_menu_highlight();};
	ul.onmouseout=function() {menu_highlight();};
	// main_menu_items array is in menu_config.js
	for (var i=0; i<main_menu_items.length; i++){
	main_menu_DOM.push(new construct_menu_item(main_menu_items[i]));// pass through to constructor
	ul.appendChild(main_menu_DOM[main_menu_DOM.length-1].li);// append li of latest item in main_menu array to ul
	}
	main_menuDiv.appendChild(ul);// append menu to div
	
	current_menu_ref = main_menu_DOM[0].anchor;// get ref to 'Home' menu item which is the default 
	current_menu_ref.style.cssText = "background-color: #999999";// change it to grey
	for (var j=2; j<5; j++){
	main_menu_DOM[j].anchor.id = "indent";// would prefer to use 'class' but it causes an error
	}
	}
	
	//MAKE SUB MENU
	function make_sub_menu(){
	var sub_menuDiv = document.getElementById('sub_menuDiv');
	var ul = document.createElement("ul");
	ul.id="submenu";
	ul.onmouseover=function(){kill_menu_highlight();};
	ul.onmouseout=function(){menu_highlight();};
	// sub_menu_items array is in menu_config.js
	for (var i=0; i<sub_menu_items.length; i++){
	sub_menu_DOM.push(new construct_menu_item(sub_menu_items[i]));// pass through to constructor
	ul.appendChild(sub_menu_DOM[sub_menu_DOM.length-1].li);// append li of latest item in sub_menu array to ul
	}
	sub_menuDiv.appendChild(ul);// append menu to div
	}
	

	// menu item obj constructor
	function construct_menu_item(items){
	this.anchor = document.createElement("a");// create anchor which we add our own properties to
	this.anchor.menuname = items[0];// viewable text in menu item
	var mytextnode = document.createTextNode(items[0]);
	this.anchor.URL = items[1];// url used in AJAX function to bring in HTML content 
	this.anchor.externalURL = items[2]; // external url
	this.anchor.key = items[3]; // key for loader
	this.li = document.createElement("li"); // list item tag
	this.anchor.onclick = function(){parse_menu_item(this);return false;};// send anchor obj and all its properties to parser
	this.anchor.href="#";
	this.anchor.appendChild(mytextnode);
	this.li.appendChild(this.anchor);
	}
	
	
	// take clicks from hotspots - obj is DOM array
	function parse_hotspots(obj){
	kill_menu_highlight();
	current_menu_ref = obj.anchor;
	menu_highlight();
	parse_menu_item(current_menu_ref);
	}
	
	
	// take clicks from menus - obj is from anchor within DOM array
	function parse_menu_item(obj){
	current_menu_ref = obj;// needed by mouseover and mouseouts in menus
	if(obj.externalURL){
	window.open(obj.externalURL); // open url in external window
	return;
	}
	var url = obj.URL;
	var key = obj.key;
	if (key > 0) {
		newhash = url+"_"+key;// make hash & key
		}else{
		newhash = url; // make has only
		}
	window.location.hash = newhash; // apply hash to address bar
	}
	
	//This is for simple pages with no extra js or css
	function parse_clickable_link(url){
	window.location.hash = url;
	kill_menu_highlight();
	}
	
	// and to goto external URL
	function gotoURL(url){
	window.location = url;
	}
	
	function kill_menu_highlight(){
	if(current_menu_ref)current_menu_ref.style.backgroundColor = "";// kill this to allow CSS style to resume
	}
	
	// change colour current menu item on mouseout
	function menu_highlight(){
	if(current_menu_ref.parentNode.parentNode.id=="menu"){
	current_menu_ref.style.cssText = "background-color: #999999";
	}else{
	current_menu_ref.style.cssText = "background-color: #d3d3d3";
	}
	}
	
	
	function pollHash(){
    //URL_listener();
    window.setInterval("URL_listener()", 100);
    }
    
	
	function URL_listener(){
    if (window.location.hash != current_url){
    current_url = window.location.hash;
    get_content();
    }
	}
	
	
	function parse_history_pages(url){
	window.location.hash = url;
	}
	
	
	// decontructs URL in address bar to fetch content via AJAX - fires secondary AJAX function for extra data if needed
	function get_content(){
	returnees_page = -1; // in case we have just come from 'Returnees' page and are going back to it. Starts again.
	var second_url = 0;
	var second_div_id = 0;
	if ((current_url == "") || (current_url == "undefined")) return; // block blanks
	var url = current_url.substr(1);// get rid of hash symbol at front
	// get loader key
	var lastChar = current_url.substr(current_url.length-1,1); // look for loaderKey at last item of URL
	if(isNaN(lastChar)){
	var loaderKey = 0; // key for 'loader' obj for loading extra css and js
	}else{
	var loaderKey =	lastChar;
		if(loader[loaderKey].externalURL){
		window.open(loader[loaderKey].externalURL); // open external URL in own window
		return;
		}
	if(loader[loaderKey].secondItemURL) second_url = loader[loaderKey].secondItemURL;// the extra content URL
    if(loader[loaderKey].secondItemDiv) second_div_id = loader[loaderKey].secondItemDiv;// id of Div to put it in
	if(loader[loaderKey].css) load_css(loader[loaderKey]);// load css into doc head
	if(loader[loaderKey].js) load_js(loader[loaderKey]);// load js into doc head
	}
	try {
	if (loader[loaderKey].jsfunc && loader[loaderKey].jsfunc.indexOf("before")!=-1){
	eval(loader[loaderKey].jsfunc);// execute the js function
	document.title = "Radio Caroline - " + loader[loaderKey].menuname;
	return;
	}
	}catch(e){
	// if an error occurs valuating or executing special js function then throw to Home Page
	alert("Sorry, an error occured: "+e);
	window.location.hash = "home_content.html__mini_webshop/webshop_window.html__mini_shop__1"; // reload Home Page is error doesn't kill us
	return;
    }
	// clean-up url by extracting usable first part
	if (url.indexOf("html")!=-1 ){
	var url = url.split('.html')[0]+".html";
	}
	else if (url.indexOf("php")!=-1 ){
	var url = url.split('.php')[0]+".php";	
	}
	timeout = setTimeout("loading()",200);
	var ajaxRequest = setupAJAX();
  	var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	ajaxRequest.open("GET",url+bustcacheparameter, true);
	//read returned data from server and place it in div
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if (ajaxRequest.status == 200){
			var returned_data = ajaxRequest.responseText;
			window.scrollTo(0,0);// scroll to top of page
			clearTimeout(timeout);// stop 'loading' animation as content is about to be loaded
			document.getElementById('content_wrapper').innerHTML=returned_data;
			var legend = parse_page_title(url);
			document.title = "Radio Caroline - " + legend;
			if ((second_url) && (second_url != "0")) get_other_content(second_url, second_div_id);// second request for aditional content
			// deal with any extra js code that needs executing
			if (loaderKey && loader[loaderKey].jsfunc){
			try{
			if (loader[loaderKey].jsfunc.indexOf("after")!=-1) eval(loader[loaderKey].jsfunc);// execute any special JS code after page loads
			}catch(e){
			//alert("Sorry, an error while loading extra content\n"+e);
			}
			}
			}else{
			// first check if failing to find page is caused by a named anchor tag being on the existing page
			clearTimeout(timeout);
			var content = document.getElementById('content_wrapper');
			var atags = content.getElementsByTagName("a");
			for (var i=0; i<atags.length; i++) {
				try {
				if(atags[i].hasAttribute("name")) jumpIsPresent = true;
				}catch(e){
			alert("Sorry, an error while loading extra content\n"+e);
			}
			if (jumpIsPresent) return; // named anchor tag found
			}
			//
			// no anchor tag so display error message
			document.getElementById('content_wrapper').innerHTML= "<br /><br /><div id='try_againDIV' align='center'><p style='color: #99ccff; font-size: 16px;'>Sorry &#150; this content appears to be missing or there was a problem with your Internet connection<br /></div>";
			var try_again = document.createElement("input");
			try_again.setAttribute("type","button");
			try_again.setAttribute("value","Try again");
			try_again.style.cssText = "cursor: pointer;";
			try_again.onclick=function(){get_content();};
			var try_againDIV = document.getElementById('try_againDIV')
			try_againDIV.appendChild(try_again);
			}
	      }	
	}
	   ajaxRequest.send(null); 
	}
	  
	  
	  function loading(){
	  var content_wrapper = document.getElementById('content_wrapper');
	  content_wrapper.innerHTML = "<br /><br /><div align='center'><img src='images/ajax-loader.gif' />"  
	  }
	  

	
	function get_other_content(url,div_id){
	if(div_id == null) return; // safety net
	var ajaxRequest = setupAJAX();
  	var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	ajaxRequest.open("GET",url+bustcacheparameter, true);
	//read returned data from server and place it in div
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		if (ajaxRequest.status == 200) {
			var returned_data = ajaxRequest.responseText;
			try{
			document.getElementById(div_id).innerHTML = returned_data;
			}catch(e){
			// trap but ignore error
			}
			}else{
			document.getElementById(div_id).innerHTML= "<p style='color: #99ccff; text-align:center; font-family: Arial, Helvetica, sans-serif; font-size: 16px;'>Sorry &#150; this content appears to be missing or there was a problem with your Internet connection<br />Please try again.</p>";
			}
	      }
	    }
	   ajaxRequest.send(null); 
	  }
	
	// dynamically load css
	function load_css(obj){
	var css = "css/"+obj.menuname.toLowerCase()+".css";
	css = css.replace(/ /g, '_');// replace spaces with underscores
	if(loadedobjects.indexOf(css)!=-1) return;// stylesheet has already been loaded
	var fileref=document.createElement("link");
	fileref.setAttribute("media", "all");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("href", css);
	if (fileref!=""){
	document.getElementsByTagName("head").item(0).appendChild(fileref)
	loadedobjects+=css+" " //add to checking array
	}
	}
	
	// dynamically load js
	function load_js(obj){
	var js = "js/"+obj.menuname.toLowerCase()+".js";
	js = js.replace(/ /g, '_');// replace spaces with underscores
	if(loadedobjects.indexOf(js)!=-1) return;// stylesheet has already been loaded
	var fileref=document.createElement("script");
	fileref.setAttribute("type", "text/javascript");
	fileref.setAttribute("src", js);
	if (fileref!=""){
	document.getElementsByTagName("head").item(0).appendChild(fileref)
	loadedobjects+=js+" " //add to checking array
	}
	}
	
	// Button rollovers
	function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
		}
	}


	function changeImages(itsid,changeTo) {
	var this_button = document.getElementById(itsid);
	this_button.src = changeTo;
	}

	


function preloadImages() {
	if (document.images) {
		var imageArray = [
		["images/donate_button_selected_5.png"],
		["images/donate_button_5.png"],
		["images/donate_button_selected_10.png"],
		["images/donate_button_10.png"],
		["images/donate_button_selected_25.png"],
		["images/donate_button_25.png"],
		["images/donate_button_selected_50.png"],
		["images/donate_button_50.png"],
		["images/donate_panel.jpg"],
		["images/previous_button_over.png"],
		["images/previous_button.png"],
		["images/next_button_over.png"],
		["images/next_button.png"],
		["images/directly_help_button_over.jpg"],
		["images/directly_help_button.jpg"],
		["images/profile_new_bknd.png"],
		["images/bt_synergy_phone.png"],
		["images/more_streams.jpg"],
		["images/more_streams_over.jpg"],
		["images/arrow_036.png"]			  
		]
	var itslength = imageArray.length
	imageObj = new Image();
	 for(var i=0;i < itslength;i++) {
		imageObj.src = imageArray[i];
	 }
	 preloadFlag = true;
	 }
   }

    // used to delete text from fields
	function delete_content(obj){
	obj.value = "";
	}
	
	function write_log(text){
	var logDiv = document.getElementById('logDiv');
	var mytextnode = document.createTextNode(text);
	logDiv.appendChild(mytextnode);
	var mybr = document.createElement("br");
	logDiv.appendChild(mybr);
	}
	
	function post_data_to_studio(){
    var ajaxRequest = setupAJAX();
	if (!ajaxRequest){
	alert ("Sorry, there was a problem,\nplease use your email program instead.");
	return;
	}
	// get message and check for any nasties
	var message = document.getElementById('message').value;
	message = message.replace(new RegExp(/^\s+/),""); // remove any leading white space
    message = message.replace(new RegExp(/\s+$/),""); // remove any trailing white space
	if ((message == 'Don\'t forget your name!') || (message.length < 5)) return; // someone's playing silly buggers
	message = escape(message);
	// get e-mail address
	var email_address = document.getElementById('email_address').value;
	if ((email_address == 'Your e-mail address (if you want a reply)') || (message.length < 5)) email_address = "e-mail address: No return address given";
	email_address = escape(email_address);
	var timestamp = String(new Date());
	var sendstring = 'email_address='+email_address+'&message='+message+'&timestamp='+timestamp;
	post_data(sendstring, "php/email_to_studio.php", "messageDiv");
	}
	 
	function signup(){
	if (signup_email) return; // block multipule clicks
	var ajaxRequest = setupAJAX();
	signup_email = document.getElementById("email").value;
	ajaxRequest.open("GET","php/get_request.php?email="+signup_email, true);
	//read returned data from server and place it in div
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		if (ajaxRequest.status == 200) {
			document.getElementById("msg").innerHTML=ajaxRequest.responseText;
			}else{
			document.getElementById("msg").value= "Sorry there was an error";
			}
	      }
	    }
	   ajaxRequest.send(null); 
	  }
	 
	function post_data(poststring, php_url, messageDiv){
	var ajaxRequest = setupAJAX();
	 ajaxRequest.open("POST", php_url, true);
	//Send the proper header information along with the request
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//ajaxRequest.setRequestHeader("Content-length", sendstring.length);// this can generate an error in Webkit
	//ajaxRequest.setRequestHeader("Connection", "close"); // this can generate an error in Webkit
	ajaxRequest.onreadystatechange = function() {
	if(ajaxRequest.readyState == 4){
		if (ajaxRequest.status == 200) {
			var returned_message = ajaxRequest.responseText;
			if(messageDiv != "undefined") document.getElementById(messageDiv).innerHTML = returned_message;
			}else{
            alert ("Sorry, there was a server problem, please try again later.\n\nIf the problem persists please use your email program instead.");			
            }
	      }
	    }
	ajaxRequest.send(poststring);

	}
	
	/// communicate with EPG iframe
	
	function switch_to_schedule_page(){
	//window.frames["epg"].display_current_schedule(); // fire function in iframe
	}
	
	function boot_EPG(){
	//window.frames["epg"].get_schedule(); // fire function in iframe
	}
	
	  
	  
	  
	  
	// generic function to return the ContentDoc of an iframe node
	function get_iframeBody(theiframe){
	var myiFrame = document.getElementById(theiframe);
  			var myiFrameContentDoc = myiFrame.contentWindow || myiFrame.contentDocument;
  			if (myiFrameContentDoc.document) {
    		myiFrameContentDoc = myiFrameContentDoc.document;
   			}
   			return myiFrameContentDoc;
	        }
	
	function get_media_player(){
	var isWin = navigator.userAgent.toLowerCase().indexOf("windows") != -1;
    if (isWin) { 
   	start_WMplayer()
     }else{
	start_quicktime_player();
    }
	}
	
	function start_quicktime_player(){
	toggleBasicSlide('Quicktime_slideDiv');
	get_other_content('php/create_quicktime_player.php', 'quicktime_player');
	}
	
	function start_WMplayer(){
	if (media_player_open)  {
	toggleBasicSlide('WMP_slideDiv'); // slide up
	var wmplayer = document.getElementById("wmplayer");
	deleteprior(wmplayer); // remove player on close to prevent it restarting
	media_player_open = false;
	}else{
	toggleBasicSlide('WMP_slideDiv'); // slide down
	get_other_content('php/create_wmplayer.php', 'wmplayer');
	media_player_open = true;
	}
	}
	
	//this is duplicated from Top 15 js as it's called before that js has loaded for some reason
	function show_tracker(){
	 var tracker_header = document.getElementById("tracker_header");
	 deleteprior(tracker_header);// get rid of any old one
	 var mydiv = document.createElement("div"); // creat div to wrap header in
	 var mytextnode = document.createTextNode("Top Fifteen's Tracker");
	 mydiv.appendChild(mytextnode); // append text to div
	 tracker_header.appendChild(mydiv); // append div to main div
	 var my_delete_div = document.createElement("div"); // and another div
	 my_delete_div.style.cssText = "position: absolute; top: 3px; right: 20px;";
	 var newanchor = document.createElement("a"); // create <a> tag
	 var mytextnode = document.createTextNode("Show ");
	 newanchor.appendChild(mytextnode);
	 my_delete_div.appendChild(newanchor); //append icon to its div
	 var delete_icon = document.createElement("img");// create an image
	 delete_icon.src = 'images/down_arrow.png';
	 delete_icon.onmouseover = function(){this.style.cursor="pointer";};
	 my_delete_div.onclick = function(){display_tracker_info();};
	 newanchor.onmouseover = function(){delete_icon_over(this);};
	 newanchor.onmouseout = function(){delete_icon_out(this);};
	 my_delete_div.appendChild(delete_icon); //append icon to its div
	 tracker_header.appendChild(my_delete_div); // append div to main div
	}
	
	function submit_vip_entry(){
	 var name = escape(document.getElementById("name").value);
	 var address = escape(document.getElementById("address").value);
	 var mem_num = escape(document.getElementById("mem_num").value);
	 var telephone = escape(document.getElementById("telephone").value);
	 var email = escape(document.getElementById("email").value);
	 var sendstring = 'name='+name+'&address='+address+'&mem_num='+mem_num+"&telephone="+telephone+"&email="+email;
	 post_data(sendstring, "php/post_vip.php");
	}
	
	function load_blog(slidename, slidetable, blog_content_div_name, presenter){
	var url = "php/get_individule_blog.php?presenter="+presenter;
	var ajaxRequest = setupAJAX();
	var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	ajaxRequest.open("GET",url, true);
	//read returned data from server and place it in div
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		if (ajaxRequest.status == 200) {
			if(document.getElementById(slidename).style.display == "block"){
			toggleSlide(slidename, slidetable); // slide up
			window.scrollTo(0,0);// scroll to top of page
			}else{
			var blog_content_div =  document.getElementById(blog_content_div_name);// pick up div name which is different for each presenter
			blog_content_div.innerHTML = ajaxRequest.responseText;
			blog_content_div.style.cssText = "border-left: 1px solid #ddd; border-right: 1px solid #ddd; padding-left:15px; padding-right:15px;";
			toggleSlide(slidename, slidetable);
	        }
			}else{
			document.getElementById(blog_content_div).innerHTML= "Sorry there was an error";
			toggleSlide(slidename, slidetable);
			}
	      }
	    }
	   ajaxRequest.send(null); 
	}
	
	function resize_minishop(){
	//document.getElementById('minishop_iframe').src = "mini_webshop/webshop_window_dynamic.html";
	}
	
	
	function parse_page_title(str){
	var legend = str.replace(/_/g, " "); // remove underscores
	legend = legend.slice(0,(legend.length-5)); // knock off .html
    return legend.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); // convert to title case
    }
	
	function load_home_page_extras(){
	get_other_content("php/get_blog_teasers.php","blogs_teaser");
	var timenow = new Date();
	var theMinutes = timenow.getMinutes();
	if (theMinutes % 2 == 0){
	get_other_content("mini_innovations/mini_innovations.html","mini_shop"); // load on even minutes
	document.getElementById("lnh_adDiv").style.display = "block";
	}else{
	get_other_content("mini_webshop/webshop_window.html","mini_shop"); // load on odd minutes
	document.getElementById("lnh_adDiv").style.display = "block";
	}
	}
	
	function open_blogs_page(presenter){
	newhash = "php/get_blogs.php";// make hash
	window.location.hash = newhash; // apply hash to address bar which will load page
	var presenter_underscored = presenter.replace(/ /g, '_');// replace spaces with underscores
	var slidename = presenter_underscored+"_slide_div";
	var slidetable = presenter_underscored+"_slide_table";
	var blog_content_div_name = presenter_underscored+"_content";
	load_blog(slidename, slidetable, blog_content_div_name, presenter);
	}
	
	function next_returnees(){
	loading();
	returnees_page++; // accrue for next batch
	//alert("Next "+returnees_page);
	get_other_content("php/get_returnees.php?page="+returnees_page ,"content_wrapper");
	window.scrollTo(0,0);// scroll to top of page
	}
	function previous_returnees(){
	loading();
	returnees_page--; // accrue for next batch
	//alert("Previous "+returnees_page);
	get_other_content("php/get_returnees.php?page="+returnees_page ,"content_wrapper");
	window.scrollTo(0,0);// scroll to top of page
	
	}
	
	
	function getBrowserWidth(){

	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
};


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);
}