// screen resolution script
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 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;
}

if (!(readCookie("screen_res"))) { //only do this whole thing once per session
  function actualPageHeight() {
  		if (window.innerHeight) { //
  			return window.innerHeight;
  			}
  		else if (document.documentElement && document.documentElement.clientHeight) {
  			return document.documentElement.clientHeight;
  		}
  		else if (document.body) {
  			return document.body.clientHeight;
  		}
  		else return;
  	}	
  function actualPageWidth() {
  		if (window.innerWidth) {
  			return window.innerWidth;
  			}
  		else if (document.documentElement && document.documentElement.clientWidth) {
  			return document.documentElement.clientWidth;
  		}
  		else if (document.body && document.body.clientWidth) {
  			return document.body.clientWidth;
  		}
  		else return;
  	}	
  // check if cookies are enabled, if so - write the screen res cookie
	scr_width = actualPageWidth()
	scr_height = actualPageHeight()
  if ( (typeof(scr_width) == 'number') && (typeof(scr_height) == 'number') ) 
			{
  		createCookie ("arecookiesenabled", "true", 0); //try and write a cookie
			res = scr_width +"x"+ scr_height;  
  		if (readCookie("arecookiesenabled") == "true") createCookie("screen_res", res, 0);
			}
}
