
function open_win(link, w, h) 
{
     var options = "scrollbars,resizable,height=" + h + ",width=" + w;
     window.open(link, 'ed_pop_win', options);
}

function setCompare(obj){              
	if(obj.checked==true){
		compareCheckList[compareCheckList.length] = obj.value;         
	}else{
		for(i =0 ; i < compareCheckList.length ; i++){
			if(compareCheckList[i] == obj.value ){
				delete compareCheckList[i];
			}// End if
		} //End for
	}//End else       
}

function checkProperty()
{
	var count = 0;
	var strArg = new Array();
	for(i =0; i < compareCheckList.length ; i++){
		if(compareCheckList[i] != 'undefined'){
			if(parseInt(compareCheckList[i]) > 0){
				strArg[count++] = 'list[]=' +  parseInt(compareCheckList[i]);          
			}
		}
	}
	if(count < 2)
	{
		alert("You have to select at least 2 properties to compare");
		return false;
	}
	else if(count > 5)
	{
		alert("You have to select up to 5 properties to compare");
		return false;
	}
	else{
		
		var ids = strArg.join("&");
		window.open('compare_listings.php?'+ids+'&cat='+listTypeName,'mywindow','width=810,height=500,scrollbars=yes,resizable=yes');
	}    
	return false;
} 
function uncheckList(i){
	var listCatID = document.listings.listCatID;
	if(listCatID[i].value!=0){
		var chkSub = eval("document.listings.chkSubCat_"+listCatID[i].value);
		if(chkSub.length>0){
			for(var j=0; j<chkSub.length; j++){
				chkSub[j].checked = false;
				//chkSubCat[j].disabled = false;
				if(document.getElementById('catAmenity_'+chkSub[j].value)){
					document.getElementById('catAmenity_'+chkSub[j].value).style.display = "none";
				}
			}
		}
	}
	
	if(listCatID[i].value == 2 || listCatID[i].value == 5){
		var chkRegion = eval("document.listings.chkListRegions_"+listCatID[i].value);
		if(chkRegion.length>0){
			for(var j=0; j<chkRegion.length; j++){
				chkRegion[j].checked = false;
			}
		}
	}
	//this is for amenities
	/*
	if(listCatID[i].value == 2 || listCatID[i].value == 5 || listCatID[i].value == 3 || listCatID[i].value == 9){
		var chkAmenity = eval("document.listings.chkListAmenities_"+listCatID[i].value);
		if(chkAmenity.length>0){
			for(var j=0; j<chkAmenity.length; j++){
				chkAmenity[j].checked = false;
			}
		}
	}
	//this is for meals included
	if(listCatID[i].value == 2){
		var chkMealsIncluded = eval("document.listings.chkListMealsIncluded_"+listCatID[i].value);
		if(chkMealsIncluded.length>0){
			for(var j=0; j<chkMealsIncluded.length; j++){
				chkMealsIncluded[j].checked = false;
			}
		}
	}
	//this is for meals included
	if(listCatID[i].value == 5){
		var chkMealsServed = eval("document.listings.chkListMealsServed_"+listCatID[i].value);
		if(chkMealsServed.length>0){
			for(var j=0; j<chkMealsServed.length; j++){
				chkMealsServed[j].checked = false;
			}
		}
	}
	*/
	//Added condition to uncheck all the compare checkboxs By Bharathi
	if(compareCheckList.length>0){
		for(var z =0 ; z < compareCheckList.length ; z++){
			if(document.getElementById(compareCheckList[z]))
			{
				document.getElementById(compareCheckList[z]).checked = false;
			}
			delete compareCheckList[z];
		}
	}     
}

// This function will check for all check box filter records related to CatID
function getSubCheckbox(div_id,catID,view_all){
if(div_id!=-1){
	show(div_id);
}
var chkSubCat = eval("document.listings.chkSubCat_"+catID);
var chkRegion = eval("document.listings.chkListRegions_"+catID);
var chkAmenity = eval("document.listings.chkListAmenities_"+catID);
var chkMealsIncluded = eval("document.listings.chkListMealsIncluded_"+catID);
var chkMealsServed = eval("document.listings.chkListMealsServed_"+catID);
var chkArr = new Array();
var index = 0;
var flag = false;
var regionChecked = false;
var typeChecked = false;
var amenityChecked = false;
var mealsIncludedChecked = false;
var mealsServedChecked = false;
if(view_all==0){
	if(catID == 2 || catID == 5){
		if(chkRegion.length>0){
			for(var k=0; k < chkRegion.length ; k++){
				if(chkRegion[k].checked == true){
					regionChecked = true; 
				}
			}
		}
	}
	/* All amenity stuff removed by Rick Estavillo per Sherena
	if(catID == 2 || catID == 5 || catID == 3 || catID == 9){
		if(chkAmenity.length>0){
			for(var k=0; k < chkAmenity.length ; k++){
				if(chkAmenity[k].checked == true){
					amenityChecked = true; 
				}else{
					chkAmenity[k].checked = false;
				}
			}
		}
	}
	//checking for meals included for accomudations
	if(catID == 2){
		if(chkMealsIncluded.length>0){
			for(var k=0; k < chkMealsIncluded.length ; k++){
				if(chkMealsIncluded[k].checked == true){
					mealsIncludedChecked = true; 
				}
			}
		}
	}
	//checking for meals served for dining
	if(catID == 5){
		if(chkMealsServed.length>0){
			for(var k=0; k < chkMealsServed.length ; k++){
				if(chkMealsServed[k].checked == true){
					mealsServedChecked = true; 
				}
			}
		}
	}
	
	if(chkSubCat.length>0){
		for(var k=0; k < chkSubCat.length ; k++){
			if(chkSubCat[k].checked == true){
				typeChecked = true;
				if(document.getElementById('catAmenity_'+chkSubCat[k].value))
					document.getElementById('catAmenity_'+chkSubCat[k].value).style.display = "block";
			}else{
				if(document.getElementById('catAmenity_'+chkSubCat[k].value))
					document.getElementById('catAmenity_'+chkSubCat[k].value).style.display = "none";
			}
		}
	}
	*/
	for(var j=0; j < chkSubCat.length ; j++){
		if(mealsIncludedChecked || mealsServedChecked || amenityChecked){
			/*
			if(amenityChecked==true){
				for(var k=0; k < chkAmenity.length ; k++){
					if(chkAmenity[k].checked == true){
						chkArr[index] = new Array();
						chkArr[index][0] =  '';
						chkArr[index][1] =  '';
						chkArr[index][2] =  chkAmenity[k].value;
						chkArr[index][3] = ''
						// flag set to true means one checkbox is atleast selected
					}
					index++;
				}
			}else if(mealsIncludedChecked==true){
				for(var k=0; k < chkMealsIncluded.length ; k++){
					if(chkMealsIncluded[k].checked == true){
						chkArr[index] = new Array();
						chkArr[index][0] =  '';
						chkArr[index][1] =  '';
						chkArr[index][2] =  '';
						chkArr[index][3] = chkMealsIncluded[k].value;
						// flag set to true means one checkbox is atleast selected
					}
					index++;
				}
			}else if(mealsServedChecked==true){
				for(var k=0; k < chkMealsServed.length ; k++){
					if(chkMealsServed[k].checked == true){
						chkArr[index] = new Array();
						chkArr[index][0] =  '';
						chkArr[index][1] =  '';
						chkArr[index][2] =  '';
						chkArr[index][3] = chkMealsServed[k].value;
						// flag set to true means one checkbox is atleast selected
					}
					index++;
				}
			}
			*/
		}else if(regionChecked && typeChecked){
			for(var k=0; k < chkRegion.length ; k++){
				if(chkSubCat[j].checked == true &&  chkRegion[k].checked == true){
					
					chkArr[index] = new Array();
					chkArr[index][0] =  chkSubCat[j].value;
					chkArr[index][1] =  chkRegion[k].value;
					chkArr[index][2] =  '';
					chkArr[index][3] =  '';
					// flag set to true means one checkbox is atleast selected
					flag = true;
				}
				/*if(chkSubCat[j].checked == true ){
					flag = true;
				}
				else{
					chkSubCat[j].disabled = true;     
				}*/
				 index++;
			}
		}else if(regionChecked==true && typeChecked==false && mealsIncludedChecked==false && mealsServedChecked ==false && amenityChecked == false){
			for(var k=0; k < chkRegion.length ; k++){
				if(chkRegion[k].checked == true ){
					chkArr[index] = new Array();
					chkArr[index][0] =  '';
					chkArr[index][1] =  chkRegion[k].value;
					chkArr[index][2] =  '';
					chkArr[index][3] =  '';
					// flag set to true means one checkbox is atleast selected
				}
				index++;
			}
		}else{
			if(chkSubCat[j].checked == true ){
					chkArr[index] = new Array();
					chkArr[index][0] =  chkSubCat[j].value;
					chkArr[index][1] =  '';
					chkArr[index][2] =  '';
					chkArr[index][3] =  '';
					// flag set to true means one checkbox is atleast selected
					flag = true;          
				}
				/*else{
					chkSubCat[j].disabled = true;     
				}*/
				 index++;
		}
	}
}
getCatId(catID, chkArr,view_all);      
}

// Not used currently
function show(id)
{
		var el;
		if(display_cat_div != '' && display_cat_div != id){
			el = document.getElementById(display_cat_div);
			el.style.display = 'none';
			document.getElementById(display_cat_div+'_left').className = 'ListIconLeft';
			CheckUncheckAll();
			//document.getElementById(display_cat_div+'_down').style.display = 'none';
		}
		if(display_cat_div != '' && display_cat_div == id)
		{
			CheckUncheckAll();
		}
		if(id != -2){
			el = document.getElementById(id);
			el.style.display = 'block';
			document.getElementById(id+'_left').className = 'ListIconDown';
			//document.getElementById(id+'_left').style.display = 'none';
			display_cat_div = id;
		}
}

function CheckUncheckAll()
{
        var currForm = document.getElementById('listings');
        for (var i = 0; i < currForm.elements.length; i++)
        {
           currForm.elements[i].checked = false;
        }
}
function openWin(theURL,winName,features) {
		window.open(theURL,winName,features);
}

/*
	* This function is used to add listing/events as favourites
*/
function AddSite(user_id, listing_id, cat_name, record_type, action)
{      
	var Url = "sajax.inc.php";
	var divname = "fav_"+listing_id;
	var Flds = "user_id="+user_id+"&listing_id="+listing_id+"&cat_name="+cat_name+"&type="+record_type+"&action="+action;
	CallAJax(2,Url,Flds,divname);
}
function checkDiv(name,id){
	var typeName = document.getElementById(name+'_'+id);
	if(typeName.style.display == "none"){
		//typeName.style.visibility = "visible";
		typeName.style.display = "block";
	}
	else{
		//typeName.style.visibility = "collapse";
		typeName.style.display = "none";
	}
}
function checkListing(list)
{  
	var listIcons = document.listings.listIcons;
	if(list=='list'){
		document.getElementById('map_canvas').style.visibility = "hidden";
		document.getElementById('map_canvas').style.display = "none";
                document.getElementById('map_wrapper').style.display = "none";
		document.getElementById('listGrayBar').style.display = "block";
		document.getElementById('listOrangeBar').style.display = "none";
		$('span.list_marker_icon').css({visibility : 'hidden', display : 'none'});
        }else{
		
		document.getElementById('map_canvas').style.visibility = "visible";
		document.getElementById('map_canvas').style.display = "block";
                document.getElementById('map_wrapper').style.display = "block";
		document.getElementById('listGrayBar').style.display = "none";
		document.getElementById('listOrangeBar').style.display = "block";

		initialize();
		buildMarker();

                $('span.list_marker_icon').css({visibility : 'visible', display : 'block'});
                
	}
}
function getListingsCheck(div_id,catID,catname,subcatid)
{
	if(div_id!=-1){
		show(div_id);
	}
	var chkSubCat = eval("document.listings.chkSubCat_"+catID);
	var chkRegion = eval("document.listings.chkListRegions_"+catID);
	var chkAmenity = eval("document.listings.chkListAmenities_"+catID);
	var chksubArr = '';
	var chkamenityArr = '';
	var chkregionArr = '';
	var regionChecked = false;
	var typeChecked = false;
	var amenityChecked = false;
	if(chkSubCat != undefined && chkSubCat.length>0){
		for(var k=0; k < chkSubCat.length ; k++){
			if(chkSubCat[k].checked == true){
				chksubArr += chkSubCat[k].value+"$$";
				if(document.getElementById('catAmenity_'+chkSubCat[k].value))
					document.getElementById('catAmenity_'+chkSubCat[k].value).style.display = "block";
			}else{
				if(subcatid == chkSubCat[k].value){
					if(document.getElementById(chkSubCat[k].value) != null){
					var avalues = document.getElementById(chkSubCat[k].value).value;
					var avalues1 = avalues.split('///');
						for(var i=0; i < chkAmenity.length ; i++){
							if(chkAmenity[i].checked == true){
								for(var z =0; z<avalues1.length;z++){
									if(chkAmenity[i].value == avalues1[z]){
										chkAmenity[i].checked = false;
									}
								}
							}
						}
					}
				}
				if(document.getElementById('catAmenity_'+chkSubCat[k].value)){
					document.getElementById('catAmenity_'+chkSubCat[k].value).style.display = "none";
				}
			}
		}
	}
	if(chkAmenity != undefined && chkAmenity.length>0){
		for(var i=0; i < chkAmenity.length ; i++){
			if(chkAmenity[i].checked == true){
				chkamenityArr += chkAmenity[i].value+"$$";
			}
		}
	}
	if(catID == 2 || catID == 5){
		if(chkRegion.length>0){
			for(var k=0; k < chkRegion.length ; k++){
				if(chkRegion[k].checked == true){
					regionChecked = true;
				}
			}
		}
	}
	if(regionChecked){
		for(var k=0; k < chkRegion.length ; k++){
			if(chkRegion[k].checked == true){
				chkregionArr += chkRegion[k].value+"$$";
			}
		}
	}
	getListingRecords(-1, -1, 1, -1, catname,chksubArr,chkregionArr,chkamenityArr,'fromRight');
}
