var Cookie = {
  data: {},
  options: {expires: 1, domain: "", path: "", secure: false},

init: function(options, data) {
  Cookie.options = Object.extend(Cookie.options, options || {});

  var payload = Cookie.retrieve();
        if(payload) {
            Cookie.data = payload.evalJSON();
        }
        else {
            Cookie.data = data || {};
        }
        Cookie.store();
    },
    getData: function(key) {
        return Cookie.data[key];
    },
    setData: function(key, value) {
        Cookie.data[key] = value;
        Cookie.store();
    },
    removeData: function(key) {
        delete Cookie.data[key];
        Cookie.store();
    },
    retrieve: function() {
        var start = document.cookie.indexOf(Cookie.options.name + "=");

        if(start == -1) {
            return null;
        }
        if(Cookie.options.name != document.cookie.substr(start, Cookie.options.name.length)) {
            return null;
        }

        var len = start + Cookie.options.name.length + 1;   
        var end = document.cookie.indexOf(';', len);

        if(end == -1) {
            end = document.cookie.length;
        } 
        return unescape(document.cookie.substring(len, end));
    },
    store: function() {
        var expires = '';

        if (Cookie.options.expires) {
            var today = new Date();
            expires = Cookie.options.expires * 86400000;
            expires = ';expires=' + new Date(today.getTime() + expires);
        }

        document.cookie = Cookie.options.name + '=' + escape(Object.toJSON(Cookie.data)) + Cookie.getOptions() + expires;
    },
    erase: function() {
        document.cookie = Cookie.options.name + '=' + Cookie.getOptions() + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    },
    getOptions: function() {
        return (Cookie.options.path ? ';path=' + Cookie.options.path : '') + (Cookie.options.domain ? ';domain=' + Cookie.options.domain : '') + (Cookie.options.secure ? ';secure' : '');      
    }
};
function switchView(key,value)
{
	Cookie.init({name: 'nychpgfunc', path: '/'});
	
	if(key == 'layout')
		if(Cookie.getData('layout')==3)
			Cookie.setData('pagesize',6);
		else
			Cookie.setData('pagesize',6);
			
	Cookie.setData(key,value);
	
	curhref = window.location.href;
	
	newhref = curhref.split("/p-");
	//alert(newhref[0]);
	if(newhref.length > 1) {
		test = newhref[0].split("/artist-");
		if(test.length > 1) window.location.href = newhref[0]+"/";
		else window.location.href = newhref[0]+"/p-1/";
	}
	else window.location.reload();
}
function bookmarksite(title, url)
{
    if (document.all) window.external.AddFavorite(url, title);
    else if (window.sidebar) window.sidebar.addPanel(title, url, "");
}
function get_document_window_width()
{
   if (top.document.body && top.document.body.clientWidth)
      return top.document.body.clientWidth;
   else if (top.window && top.window.innerWidth) return top.window.innerWidth;
   else if (top.document.documentElement && top.document.documentElement.offsetWidth)
      return top.document.documentElement.offsetWidth;
   else if (top.document.body && top.document.body.offsetWidth)
      return top.document.body.offsetWidth;
   return 0;
}

function get_document_window_height()
{
   if (top.document.body && top.document.body.clientHeight &&
       (top.document.body.clientHeight > 1)) return top.document.body.clientHeight;
   else if (top.window && top.window.innerHeight) return top.window.innerHeight;
   else if (top.document.documentElement && top.document.documentElement.offsetHeight)
      return top.document.documentElement.offsetHeight;
   else if (top.document.body && top.document.body.offsetHeight)
      return top.document.body.offsetHeight;
   return 0;
}

function convert_width(width,window_width)
{
   if (width == null) {
      if (page_width) width = page_width + 52;
      else width = window_width;
   }
   else if (typeof(width) == 'string') {
      var percent_pos = width.indexOf('%');
      if (percent_pos != -1)
         width = window_width * (width.substr(0,percent_pos) / 100);
   }
   if (! document.all) {
      if (width > (window_width - 25)) width = window_width - 25;
   }
   else if (width > (window_width - 10)) width = window_width - 10;
   return width;
}

function convert_height(height,window_height)
{
   if (height == null) height = window_height;
   else if (typeof(height) == 'string') {
      var percent_pos = height.indexOf('%');
      if (percent_pos != -1)
         height = window_height * (height.substr(0,percent_pos) / 100);
   }
   if (height > (window_height - 40)) height = window_height - 40;
   return height;
}

function calculate_left(width,window_width)
{
   var left = (window_width - width) / 2;
   if (! document.all) left += 10;
   if (left < 0) left = 0;
   return left;
}

function calculate_top(height,window_height)
{
   var top = ((window_height - height) / 2) - 3;
   if (top < 0) top = 0;
   return top;
}

window.onunload = function(){

};
function nycMapPopup(maphref,myloc){
		var windowwidth=get_document_window_width();
//		alert(windowwidth);
		var windowheight=get_document_window_height();
//		alert(windowheight);
		var mywidth=windowwidth*.9;
//			alert(mywidth);
		var myheight=windowheight*.6-22;
//				alert(myheight);
//		alert(window.open(maphref,"GoogleMap","height="+myheight+", width="+mywidth));
			if(window.open(maphref,"GoogleMap","height="+myheight+", width="+mywidth)){
				return false;
			}else{
				return true;
			}
}

function editHrefSend(me){
	var checkin=new Date();
	checkin.setDate(checkin.getDate()+20);
	var checkout=new Date();
	checkout.setDate(checkout.getDate()+21);
	var chkinyr = (checkin.getYear()*1)
//	alert(chkinyr);
	if((chkinyr<1900)){
//		alert('fix');
		chkinyr=(checkin.getYear()*1+1900)
	}
	var chkoutyr = (checkout.getYear()*1)
//	alert(chkoutyr);
	if((chkoutyr<1900)){
//		alert('fix');
		chkoutyr=(checkout.getYear()*1+1900)
	}
	me.href+="?doa_dd="+checkin.getDate()+"&doa_mm="+(checkin.getMonth()*1+1)+"&doa_yy="+chkinyr;
	me.href+="&dod_dd="+checkout.getDate()+"&dod_mm="+(checkout.getMonth()*1+1)+"&dod_yy="+chkoutyr;
	me.href+="&chk_in="+checkin.getDate()+"/"+(checkin.getMonth()*1+1)+"/"+chkinyr;
	me.href+="&chk_out="+checkout.getDate()+"/"+(checkout.getMonth()*1+1)+"/"+chkoutyr;
//	alert(me.href);
//chk_out=
//chk_in=09%2F10%2F2009
//	checkin.getMonth();
//	checkin.getDate();
//	checkin.getYear();
//	&doa_mm=&doa_yy=&dod_dd=&dod_mm=&dod_yy=
}
var currentShowId="";
var currentShowLnk="";
function toggleClass(id, me){
	if(currentShowId==""){
		if($('airports')!=null && $('airports').className.indexOf('hide')<0 ){
			currentShowId=$('airports');
		}
		else if($('multiAttraction')!=null && $('multiAttraction').className.indexOf('hide')<0){
			currentShowId=$('multiAttraction');
		}else currentShowId=="";
	}
	if($(id).className.indexOf('hide')>-1){
		$(id).addClassName('show');
		$(id).removeClassName('hide');
		me.parentNode.addClassName('selected');
	}
	if(currentShowId!=""){
		currentShowId.removeClassName('show');
		currentShowId.addClassName('hide');
		currentShowLnk.parentNode.removeClassName('selected');
		//currentShowId="";
	}
	if($(id).className.indexOf('show')>-1){
		currentShowId=$(id);
		currentShowLnk=me;
	}
}
function nychotelsInit(){
	if(currentShowId==""){
		if($('airports')!=null && $('airports').className.indexOf('hide')<0 ){
			currentShowId=$('airports');
			currentShowLnk=$('airportlnknyc');
		}
		else if($('multiAttraction')!=null && $('multiAttraction').className.indexOf('hide')<0){
			currentShowId=$('multiAttraction');
			currentShowLnk=$('multiattrlnknyc');
		}
		else if($('reservations')!=null && $('reservations').className.indexOf('hide')<0){
			currentShowId=$('reservations');
			currentShowLnk=$('reservationslnk');
		}else currentShowId=="";
	}
}

function loadTripForm()
{
	 var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }
	 
	 var ajaxstr="include/ajax-search.html";
	 xmlhttp.open("GET",ajaxstr,true);
	 xmlhttp.send(null);
	 xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4)
  	{
		  document.getElementById('tripSearchForm').innerHTML=xmlhttp.responseText;
			hotelInitCal();
	validateError.cityError='enter a city';
	validateError.dateError='enter dates';
	loadErrorTranslation(validateError);	airInitCal();
	validateError.cityError='enter a city';
	validateError.dateError='enter dates';


	loadErrorTranslation(validateError);
	
	//air hotel frame
	ctInitCal();
	validateError.cityError='enter a city';
	validateError.dateError='enter dates';
	loadErrorTranslation(validateError);

	//lmd
	init_originations();

	initform();

	//car
 carInitCal(); 
 
 nychotelsInit();
  	}
	}
	 
}


function loadWeather(zip,element)
{
	 var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }
	 
	 var ajaxstr="weather/weather.php?";
	 ajaxstr+="zipcode="+zip;
	 xmlhttp.open("GET",ajaxstr,true);
	 xmlhttp.send(null);
	 xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4)
  	{
		  document.getElementById(element).innerHTML=xmlhttp.responseText;
  	}
	}
	 
}