/**************************************************************************

**************************************************************************/


function isEmpty(str)
{
	var tmp,i;
	len = str.length;
	for(i=0; i<str.length && str.charAt(i)==' '; i++);
	if(i==len)
		return true;
	return false;
}


function longEnough(str, req_len) 
{
	len = str.length;
	if(len<req_len)
		return true;
	return false;
}


function pop_up(URL,popName,Width,Height,screenX,screenY) 
{
	if (Width =="" || Width == null) Width = 800;
	if (Height == "" || Height == null) Height = 500;
	if (screenX == "" || screenX == null) screenX = 15;
	if (screenY == "" || screenY == null) screenY = 15;

	var features =
	',directories=0'+
	',location=0'   +
	',menubar=0'   +
	',scrollbars=1'+
	',status=0'   +
	',toolbar=1'   +
	',resizable=1' +
	',width=' + Width +
	',height=' + Height +
	',screenX=' + screenX +
	',screenY=' + screenY +
	',top=' + screenY +
	',left=' + screenX;
	URL = URL.replace(/\s/,'%20');
	wind=window.open (URL, popName, features);
	if (!wind) return false;
	wind.focus();
}


function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	  begin = dc.indexOf(prefix);
	  if (begin != 0) return null;
	} else
	  begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	  end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}


function bookmark() {
	<!-- AddThis Bookmark Button BEGIN -->
	window.open('http://www.addthis.com/bookmark.php?wt=nw&pub=pintofmilk&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'addthis', 'scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100');
	<!-- AddThis Bookmark Button END -->
}


function switch_to_main(url) {
  if(typeof(window.opener.document) == "object") {
    window.opener.location.href = url;
    window.opener.focus();
  } 
  else {
    window.open(url, 'holex_main');
  }
  window.close();
  return false;
}


function character_countdown(textarea, counter, max_characters) {
  if (textarea.value.length > max_characters) {
    textarea.value = textarea.value.substring(0, max_characters);
  }
  counter.value = max_characters - textarea.value.length;
}



/**************************************************************************
Review and Question functions
**************************************************************************/

function report_vote(report_id, etype, vote)
{
  // Strip any user messages off end of current URL
  var returnUrl = top.location.href;
  var msgpos = returnUrl.indexOf("msg");
  if (msgpos > -1) {
    returnUrl = returnUrl.substring(0, msgpos);
  }

  var url  = '/site/report.php?report_id=' + report_id + '&etype=' + etype + '&vote=' + vote + '&submit_report_vote=1&return_to=' + escape(returnUrl);
  top.location.href = url;
  return true;
}


function review(eid, etype)
{
  var url  = '/site/report.php?' + etype + '_id=' + eid;
  top.location.href = url;
  return true;
}


function qa(eid, etype, question_id)
{
  var url  = '/site/qa.php?' + etype + '_id=' + eid + '&question_id=' + question_id;
  top.location.href = url;0
  return true;
}




/**************************************************************************
Dropdown navigation
**************************************************************************/

function select_country(dropdown)
{
  var myindex  = dropdown.selectedIndex;
  var SelValue = dropdown.options[myindex].value;
  if (SelValue == 0) return false;
  var url  = '/site/index.php?country_id=' + SelValue;
  top.location.href = url;
  return true;
}



function select_landmark(dropdown)
{
  var myindex  = dropdown.selectedIndex;
  var SelValue = dropdown.options[myindex].value;
  if (SelValue == 0) return false;
  var url  = '/site/index.php?landmark_id=' + SelValue;
  top.location.href = url;
  return true;
}



function select_hotel_description_js(dropdown)
{
  var myindex  = dropdown.selectedIndex;
  var SelValue = dropdown.options[myindex].value;
  if (SelValue == 0) return false;
  document.getElementById('description').innerHTML = supplier_descriptions[SelValue];
  return true;
}




function select_supplier_content_div(dropdown, content)
{
  var myindex  = dropdown.selectedIndex;
  var SelValue = dropdown.options[myindex].value;
  if (SelValue == 0) return false;
  
  // Hide all content divs
  for(i=dropdown.options.length-1; i>=0 ;i--)	{
		document.getElementById('div_' + content + '_' + dropdown.options[i].value).style.display = 'none';
	}
	// Display selected
  document.getElementById('div_' + content + '_' + SelValue).style.display = 'block';
  
  return true;
}





function show_partner_signup_div(dropdown)
{
  var myindex  = dropdown.selectedIndex;
  var SelValue = dropdown.options[myindex].value;
  if (SelValue == 0) return false;

  // Hide all content divs
  for(i=dropdown.options.length-1; i>0 ;i--)	{
		document.getElementById('div_partner_relationship_info_' + dropdown.options[i].value).style.display = 'none';
	}
	// Display selected
  document.getElementById('div_partner_relationship_info_' + SelValue).style.display = 'inline';
  
  return true;
}




/**************************************************************************
Emails
**************************************************************************/

function contact(url)
{
  pop_up('/site/contact.php?page=' + url, "contact", 600, 500, 100, 100);
}


function send_friend(otype, oid)
{
  var url  = '/site/recommend.php?otype=' + otype + '&oid=' + oid;
  pop_up(url, 'recommend', 600, 500, 100, 100);
}




/**************************************************************************
Date initialisation
**************************************************************************/
function hotel_engine_initDate(form) {
	var todayplus10 = new Date();
	todayplus10.setDate(todayplus10.getDate()+10)
	var mth = todayplus10.getMonth();
	var dd = todayplus10.getDate();
	var yy = todayplus10.getFullYear();
	if (mth < 10) {
	   mth == 0 + mth;
	}
	if (dd < 10) {
	   dd == 0 + dd;
	}
	if ((mth==11) && (dd>=29)) {
	form.doa_mm.selectedIndex = mth;
	form.doa_dd.selectedIndex = dd - 1;
	}
	else if (dd >= 29) {
	form.doa_mm.selectedIndex = mth;
	form.doa_dd.selectedIndex = dd - 1;
	}
	else {
	form.doa_mm.selectedIndex=mth;
	form.doa_dd.selectedIndex=dd + 1;
	}
}




/**************************************************************************
Search form
**************************************************************************/


function refresh_room_types(room_number)
{
	adults = document.getElementById(room_number + "adults").value;
	children = document.getElementById(room_number + "children").value;
	
	/*
	var guest_combos = new Array();
	guest_combos["1;0"] = "0,1,2,3";
	guest_combos["1;1"] = "0,2,3";
	guest_combos["1;2"] = "0,4,6,7";
	guest_combos["1;3"] = "0,5,8";
	guest_combos["2;0"] = "0,2,3";
	guest_combos["2;1"] = "0,4,6,7";
	guest_combos["2;2"] = "0,5,8";
	guest_combos["2;3"] = "0,8";
	guest_combos["3;0"] = "0,4";
	guest_combos["3;1"] = "0,5,8";
	guest_combos["3;2"] = "0";
	guest_combos["3;3"] = "0";
	guest_combos["4;0"] = "0,5";
	guest_combos["4;1"] = "0";
	guest_combos["4;2"] = "0";
	guest_combos["4;3"] = "0";
	
	var room_types = new Array();
	room_types[0] = "any";
	room_types[1] = "Single";
	room_types[2] = "Double";
	room_types[3] = "Twin";
	room_types[4] = "Triple";
	room_types[5] = "Quad";
	room_types[6] = "Twin+child";
	room_types[7] = "Double+child";
	room_types[8] = "Family";
	*/

	var guest_combos = new Array();
	guest_combos["1;0"] = "0,1,2,3";
	guest_combos["1;1"] = "0,2,3";
	guest_combos["1;2"] = "0,4";
	guest_combos["1;3"] = "0";
	guest_combos["2;0"] = "0,2,3";
	guest_combos["2;1"] = "0,4";
	guest_combos["2;2"] = "0";
	guest_combos["2;3"] = "0";
	guest_combos["3;0"] = "0,4";
	guest_combos["3;1"] = "0";
	guest_combos["3;2"] = "0";
	guest_combos["3;3"] = "0";
	guest_combos["4;0"] = "0";
	guest_combos["4;1"] = "0";
	guest_combos["4;2"] = "0";
	guest_combos["4;3"] = "0";
	
	var room_types = new Array();
	room_types[0] = "any";
	room_types[1] = "Single";
	room_types[2] = "Double";
	room_types[3] = "Twin";
	room_types[4] = "Triple";
	//room_types[5] = "Quad";
	//room_types[6] = "Twin+child";
	//room_types[7] = "Double+child";
	//room_types[8] = "Family";
	
	var room_types_list = guest_combos[adults + ';' + children];
	room_types_indices = room_types_list.split(",");
	
	var room_options;
	var selected;
	for (i=0; i < room_types_indices.length; i++) {
		selected = "";
		room_options = room_options + "<option value=" + room_types_indices[i] + " " + selected + ">" + room_types[room_types_indices[i]] + "</option>";
	}
	
	document.getElementById(room_number + "room_types").innerHTML = "<select id=" + room_number + "room_type_id>" + room_options + "</select>";
}

	




function refresh_room_display(total_rooms, max_rooms)
{
	for (j=1; j <= max_rooms; j++) {
		room_number = "r"+ j;
		div_name = "div_" + room_number;
		if (j <= total_rooms) {
			show(div_name);
			refresh_room_types(room_number);
			display_child_ages(room_number);
		}
		else {
			hide(div_name);
		}
	}

}






function display_child_ages(room_number)
{
	children = document.getElementById(room_number + "children").value;
	div_name = "div_" + room_number + "child_ages";
  	if (children == 0) {
  		hide(div_name);
		hide('header_child_ages');
	}
	else {
		document.getElementById(div_name).style.display = 'inline';
		document.getElementById('header_child_ages').style.display = 'inline';
	}
  	return true;
}







/**************************************************************************
Price display
**************************************************************************/

function show_prices(hotel_id) 
{
  show('price_div_' + hotel_id);
  show('price_div_' + hotel_id + '_hide');
  hide('price_div_' + hotel_id + '_show');
  return;
}



function hide_prices(hotel_id) 
{
  hide('price_div_' + hotel_id);
  hide('price_div_' + hotel_id + '_hide');
  show('price_div_' + hotel_id + '_show');
  return;
}
