function createCookie(name,value,days) {
	var name = name + "=";
	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 appendCookie(name,value,element) {
	if(readCookie(name)!= null){
		var currentValue = unescape(readCookie(name));
		var newValue = "";
		var values = currentValue.split(',');
		var found = false;
		for(var i=0;i<values.length;i++){
			if(values[i]==value){
				found=true;
			}else{
				if(newValue==""){
					newValue=newValue+values[i];
				}else{
					newValue=newValue+","+values[i];
				}
			}
		}
		if(found==false){
			newValue=newValue+','+value;
			createCookie(name,newValue,30);
			element.src="assets/itineryMinus.gif";
			element.setAttribute("title","Remove this entry from your Itinerary");
		}else{
			createCookie(name,newValue,30);
			element.src="assets/itinery.gif";
			element.setAttribute("title","Add this entry to your Itinerary");		
		}
	}else{
		createCookie(name,value,30);
		element.src="assets/itineryMinus.gif";
		element.setAttribute("title","Remove this entry from your Itinerary");
	}
}
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);
}

function screenWidth(){
	if(window.innerWidth){
		myWidth=window.innerWidth;
	}else if(document.documentElement.clientWidth){
		var myWidth=document.documentElement.clientWidth;
	}else if(document.body.clientWidth){
		var myWidth=document.body.clientWidth;
	}else{
		myWidth=800;
	}
	return myWidth;
}
function hide(elem){
	document.getElementById(elem).className="hide";
}
function show(elem){
	document.getElementById(elem).className="show";
}
function socialPop(){
	if(!document.getElementById("social"))return false;
	if(readCookie('social')== null){
		show('social');
		createCookie('social','set',1);
	}
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
addLoadEvent(socialPop);

