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);
}
var buttonTracking = new Array();
function PageButton(disabled,className){
	this.disabled = disabled;
	this.className = className;
}
function already_disableButtons(){
	var buttons = document.getElementsByTagName("input");
	buttonTracking = new Array(buttons.length);
	var track = new Array();
	// alert(buttonTracking);
	for (var i=0;i<buttons.length;i++){
		if (buttons[i].type == 'image'){
			//buttons[i].disabled = true;					trackdisable
			//alert(buttons[i].disabled);
			//track[buttons[i].name] = buttons[i].disabled;
			createCookie(buttons[i].name,buttons[i].disabled,1);					
		}
	}
}
function disableButtons(){
	var buttons = document.getElementsByTagName("input");
	buttonTracking = new Array(buttons.length);
	for (var i=0;i<buttons.length;i++){
		if (buttons[i].type == 'image'){
			var s = buttons[i].src; 	
			var d = s.lastIndexOf('.');
			//alert(s.substring(s.lastIndexOf('/') + 1, d < 0 ? s.length : d));
			if(s.substring(s.lastIndexOf('/') + 1, d < 0 ? s.length : d)=='date_icon') {
				//alert('abc');		
			} else {
				buttonTracking[i] = new PageButton(buttons[i].disabled,buttons[i].className);
				buttons[i].disabled = true;
				buttons[i].src = 'images/book_it_btn.jpg';
			}
		}
	}
}
function restoreButtons(buttonName){
	//alert(buttonName);
	var buttons = document.getElementsByTagName("input");
	for (var i=0;i<buttons.length;i++){
		if (buttons[i].type == 'image'){
			if(buttons[i].name==buttonName){
				//var checkDis = readCookie(buttons[i].name)
				//if(checkDis=='false')
				//{
				buttons[i].disabled = false;
				buttons[i].src = 'css/images/book_btn.jpg';
				//}
			}else{
				continue;
			}
		}
	}  
}
if (document.getElementById('ProgBar')){							
	//document.getElementById('commonframework').style.visibility ='hidden';
	//document.getElementById('ProgBar').style.display = 'none';
	//document.getElementById('commonframework').style.display = 'none';
}	//source_type,hotel_id,source_hotel_id,unique_id,no_class,keyIndex
function write_data(source_type,hotel_id,source_hotel_id,unique_id,no_class,keyIndex,localHotelId) {		
	//     document.getElementById('loading'+keyIndex).style.display = 'block';	

	//alert('humm');
	document.frm_booking.hotel_id.value = hotel_id ;
	document.frm_booking.unique_id = unique_id ;
	document.frm_booking.source_hotel_id.value = source_hotel_id ;								
	document.frm_booking.sourceType.value = source_type ;			
	document.frm_booking.keyIndex.value = keyIndex;
	document.frm_booking.localHotelId.value = localHotelId;
	var url = 'write_cache.php?type=write&source_type='+source_type+'&unique_id='+unique_id+'&hotel_id='+hotel_id+'&source_hotel_id='+source_hotel_id+'&no_class='+no_class+'&localHotelId='+localHotelId;
	//alert(url);
	var form = $("#"+hotel_id+"_"+source_type+"_form");	
	var serializedForm = form.serialize();				
	$.post(url, serializedForm, function(data)
			{				
		//	keyIndex = document.frm_booking.keyIndex.value;
		document.getElementById('loading'+keyIndex).style.display = 'none';
		<!--document.frm_booking.isValidSelection.value = ajax.response;-->
		if(data=='good'){						
			document.frm_booking.submit();
		}else{
			//disableButtons();
		}      
			});
}
function cancellation_policy(source_type,hotel_id,source_hotel_id,unique_id,no_class,keyIndex) {				
	//document.getElementById('loading'+keyIndex).style.display = 'block';	
	document.frm_booking.hotel_id.value = hotel_id ;
	document.frm_booking.unique_id = unique_id ;
	document.frm_booking.source_hotel_id.value = source_hotel_id ;								
	document.frm_booking.sourceType.value = source_type ;			
	document.frm_booking.keyIndex.value = keyIndex;
	$('#dialog-form').html("<table width='100%' height='95%'><tr><td valign='middle'><center><img src='images/write_loading.gif'></center></td></tr></table>");
	$( "#dialog-form" ).dialog( "open" );
	
	var url = 'write_cache.php?type=write&source_type='+source_type+'&unique_id='+unique_id+'&hotel_id='+hotel_id+'&source_hotel_id='+source_hotel_id+'&no_class='+no_class;   
	var form = $("#"+hotel_id+"_"+source_type+"_form");	
	var serializedForm = form.serialize();				
	$.post(url, serializedForm, function(data)
			{				
		//	keyIndex = document.frm_booking.keyIndex.value;
		//	document.getElementById('loading'+keyIndex).style.display = 'none';
		//document.frm_booking.isValidSelection.value = ajax.response;
		if(data=='good'){						
			url1="book_now.php?cancellation_policy=true";
			var form1 = $("#frm_booking");	

			var serializedForm1 = form1.serialize();	
			$.post(url1, serializedForm1, function(data1)
			{				
				//keyIndex = document.frm_booking.keyIndex.value;
				//document.getElementById('loading'+keyIndex).style.display = 'none';
				$('#dialog-form').html(data1);
			});
		}else{
			//disableButtons();
		}      
			});
}
function save_data(source_type,hotel_id,class_unique_id,keyIndex) {				
	document.getElementById('loading'+keyIndex).style.display = 'block';																											
	document.frm_booking.keyIndex.value = keyIndex;
	ajax.requestFile = 'write_cache.php?type=check&class_unique_id='+class_unique_id+'&hotel_id='+hotel_id+'&source_type='+source_type;
	ajax.onCompletion = hide_loading;
	ajax.runAJAX();		
}
function hide_loading(){
	keyIndex = document.frm_booking.keyIndex.value;
	document.getElementById('loading'+keyIndex).style.display = 'none';
}
function hideme(){												
	keyIndex = document.frm_booking.keyIndex.value;
	document.getElementById('loading'+keyIndex).style.display = 'none';
	document.frm_booking.isValidSelection.value = ajax.response;
	if(ajax.response=='good'){	
		document.frm_booking.submit();
	}else{
		//disableButtons();
	}
	//document.getElementById(write_loading_div).style.display='none';		
}
function show_hotel_details(id,source_type,hotel_name) {
	winx = window.open('hotel_details.php?id='+id+'&source_type='+source_type,'hotel','width=850,height=800,resizable=1,scrollbars=1');
	winx.title = hotel_name;
}
function go(formObj) {
	var hotel_location= document.getElementById("sel_location").value;
	//alert(hotel_location);
	document.forms["go_frm"].selected_location.value=hotel_location;
	document.forms["go_frm"].submit();
	return false;
}
function book_now(display_curr,can_book,source_type,hotel_id,price){	
	if(can_book == "1"){
		document.frm_booking.hotel_id.value = hotel_id ;					
		document.frm_booking.sourceType.value = source_type ;														
		document.frm_booking.price.value = price ;
		document.frm_booking.display_curr.value = display_curr ;
		document.frm_booking.submit();
	} else {
		alert("You are not allowed to make a booking. You can just check the prices.");
	}
}				
function restrict_booking() {																		
	alert('You can not proceed with this booking.');
	return false;
}
function show_plus(id) {																		
	if(document.getElementById('record_'+id).style.display == 'block'){
		document.getElementById('record_'+id).style.display = 'none';								
		document.getElementById('minus_'+id).style.display = 'none';								
		document.getElementById('plus_'+id).style.display = 'block';									
	} else {									
		document.getElementById('record_'+id).style.display = 'block';								
		document.getElementById('minus_'+id).style.display = 'block';								
		document.getElementById('plus_'+id).style.display = 'none';
	}
	return false;
}
function show_minus(id) {
	document.getElementById('minus_'+id).style.display = 'none';
	document.getElementById('record_'+id).style.display = 'none';
	document.getElementById('plus_'+id).style.display = 'block';
	return false;
}
function cancel_show_plus(id) {																		
	if(document.getElementById('cancel_record_'+id).style.display == 'block'){
		document.getElementById('cancel_record_'+id).style.display = 'none';								
		document.getElementById('cancel_minus_'+id).style.display = 'none';								
		document.getElementById('cancel_plus_'+id).style.display = 'block';									
	} else {									
		document.getElementById('cancel_record_'+id).style.display = 'block';								
		document.getElementById('cancel_minus_'+id).style.display = 'block';								
		document.getElementById('cancel_plus_'+id).style.display = 'none';
	}
	return false;
}
function cancel_show_minus(id) {
	document.getElementById('cancel_minus_'+id).style.display = 'none';
	document.getElementById('cancel_record_'+id).style.display = 'none';
	document.getElementById('cancel_plus_'+id).style.display = 'block';
	return false;
}
function callAdvancedFilters(value, frmObj)
{
	frmObj.page.value=1;
	frmObj.sort_data.value=1;
	if(value=='price' || value=='alphabet' || value=='rating' || value=='availability'){
		frmObj.sorting.value=value;
		frmObj.filter.value='';
	}else{
		frmObj.sorting.value='price';
		frmObj.filter.value=value;
	}
	frmObj.submit();
}
