
//var timeoutId = -1;

function jsFilterSetLocation(locationId)
{
    var select = gbid("hfeGeoCities");
    for(i=0; i < select.options.length; i++) {
        if(select.options[i].text == locationId) {
            select.selectedIndex = i;
            break;
        }
    }
    hfeFilterAction(1);
}

function hfeFilterAction(page)
{
	var param = [];
    
    location.hash = "#filterform";
    param["module"] = "hfe";
    param["entry"] = "hotels";
    param["action"] = "getHotels";
	param["lang"] = gbid("selected_lang").value;
	
    param["hfePage"] = page;
	
    if(gbid("hfeRange").selectedIndex > 0 && gbid("hfeGeoCities").selectedIndex == 0) {
		gbid("hfeRange").selectedIndex = 0;
		return; 
	}
	param["hfeGeoCities"] = gbid("hfeGeoCities").options[gbid("hfeGeoCities").selectedIndex].value;
    param["hfeRange"] = gbid("hfeRange").options[gbid("hfeRange").selectedIndex].value;
    param["hfeGuestsCount"] = gbid("hfeGuestsCount").options[gbid("hfeGuestsCount").selectedIndex].value;
    param["hfeConfPlaces"] = gbid("hfeConfPlaces").options[gbid("hfeConfPlaces").selectedIndex].value;
    param["hfeHotelCategory"] = gbid("hfeHotelCategory").options[gbid("hfeHotelCategory").selectedIndex].value;
	param["hfePriceClass"] = gbid("hfePriceClass").options[gbid("hfePriceClass").selectedIndex].value;

    ajaxQuery("POST", "/ajax/mi.php", filterActionResult, param, true, false, true);
    
}

function filterActionResult(res)
{
	gbid("Content").innerHTML = res;
	
	$('a[rel^=lightbox]').lightBox({useNavigation: 0});
	$('a[rel^=lightbox-1]').lightBox();
	$('a[rel^=lightbox-2]').lightBox();
	$('a[rel^=lightbox-3]').lightBox();
	$('a[rel^=lightbox-4]').lightBox();
	$('a[rel^=lightbox-5]').lightBox();
}


function addToMyEvent(type, id)
{
	var param = [];
	
	gbid("MyEventCont").innerHTML = "<img src='/img/myeventloader.gif' alt='progress' />";
	gbid("myitems_panel").style.display = 'block';
	param["lang"] = gbid("selected_lang").value;
    param["module"] = "hfe";
    param["entry"] = "myevent";
    param["action"] = "add";

	param["opt_ObjType"] = type;
	param["opt_ObjId"] = id;

    ajaxQuery("POST", "/ajax/mi.php", myEventRefresh, param, true, false, true);
}
function delFromMyEvent(type, id)
{
	var param = [];
    gbid("MyEventCont").innerHTML = "<img src='/img/myeventloader.gif' alt='progress' />";

	param["lang"] = gbid("selected_lang").value;
    param["module"] = "hfe";
    param["entry"] = "myevent";
    param["action"] = "del";

	param["opt_ObjType"] = type;
	param["opt_ObjId"] = id;
    
    ajaxQuery("POST", "/ajax/mi.php", myEventRefresh, param, true, false, true);
}
function myEventRefresh(str)
{
	var param = [];
	
	//if(timeoutId != -1)
	//	clearTimeout(timeoutId);
	gbid("MyEventCont").innerHTML = "<img src='/img/myeventloader.gif' alt='progress' />";
    param["lang"] = gbid("selected_lang").value;
    param["module"] = "hfe";
    param["entry"] = "myevent";
    param["action"] = "refresh";

    ajaxQuery("POST", "/ajax/mi.php", myEventRefreshResult, param, true, false, true);
}

function myEventRefreshResult(str)
{
	gbid("MyEventCont").innerHTML = str;
    if(gbid("itemsCount").value == '0')
        gbid("myitems_panel").style.display = 'none';
    
    if(gbid("hasHotel").value == '0')
        gbid("gotowizard").className="gotowizard";
    else
        gbid("gotowizard").className="gotowizard_orange";
	//timeoutId = setTimeout("myEventRefresh('1')", 10*1000);
}

function hfeExcursionFilterChange()
{
	window.location = "/" + gbid("selected_lang").value + "/excursions/showall/lid/"
		+ gbid("ExcursionsFilter").options[gbid("ExcursionsFilter").selectedIndex].value
		+ "/location-name/" + gbid("ExcursionsFilter").options[gbid("ExcursionsFilter").selectedIndex].text;
}
// wizard date functions for step 1 -------------------------------------------
var ONE_DAY = (1000 * 60 * 60 * 24);

function wizardS1ChangeDate()
{
	var sdate = new Date();
	var edate = new Date();
	var arr1 = [];
	var arr2 = [];
	var days = 0;
	
	if(gbid("s1_enddate").value != "" && gbid("s1_startdate").value != "") {
		arr1 = gbid("s1_startdate").value.toString().split(".");
		if(arr1.length != 3)
			return;
		
		arr2 = gbid("s1_enddate").value.toString().split(".");
		if(arr2.length != 3)
			return;
		
		sdate.setFullYear(arr1[2], arr1[1] -1, arr1[0]);
		edate.setFullYear(arr2[2], arr2[1] -1, arr2[0]);
		days = Math.ceil((edate.getTime() - sdate.getTime())/ONE_DAY);
		if(days < 0)
			days = 0;
		gbid("s1_days").value = days.toString();	
	} else
		wizardS1ChangeDays();
}


function wizardS1ChangeDays()
{
	var sdate = new Date();
	var edate = new Date();
	var arr1 = [];
	
	if(gbid("s1_startdate").value != "" && gbid("s1_days").value != "") {
		arr1 = gbid("s1_startdate").value.toString().split(".");
		if(arr1.length != 3)
			return;
		
		sdate.setFullYear(arr1[2], arr1[1] -1, arr1[0]);
		edate.setTime(sdate.getTime() + gbid("s1_days").value * ONE_DAY);

		gbid("s1_enddate").value = edate.getDate() + '.' + (edate.getMonth()+1) + '.' + edate.getFullYear();	
	} else if(gbid("s1_enddate").value != "" && gbid("s1_days").value != "") {
		arr1 = gbid("s1_enddate").value.toString().split(".");
		if(arr1.length != 3)
			return;
		
		sdate.setFullYear(arr1[2], arr1[1] -1, arr1[0]);
		edate.setTime(sdate.getTime() - gbid("s1_days").value * ONE_DAY);

		gbid("s1_startdate").value = edate.getDate() + '.' + (edate.getMonth()+1) + '.' + edate.getFullYear();	
	}
}

function wizardS1RoomsChange(type)
{
	var mans;
	var i;
	switch(type){
		case(1):
			el = "s1_singleroom";
			break;
		case(2):
			el = "s1_doubleroom";
			break;
		case(3):
			el = "s1_visitorscount";
			break;
	}

	if(!isInteger(gbid(el).value) && gbid(el).value != "")
	{
		gbid(el).style.borderColor="#ff0000";
		return;
	}
	
	gbid(el).style.borderColor="#999999";
		
	$visitors = 0;
	
	if(isInteger(gbid("s1_singleroom").value) && gbid("s1_singleroom").value != "")
		$visitors += parseInt(gbid("s1_singleroom").value);
	
	if(isInteger(gbid("s1_doubleroom").value) && gbid("s1_doubleroom").value != "")
		$visitors += parseInt(gbid("s1_doubleroom").value) * 2;	

	mans = parseInt(gbid("s1_visitorscount").value) - $visitors;
	
	if(mans < 0)
		mans = 0;
		
	gbid("s1_visfree").innerHTML = mans;
	
	/* check hotels*/
	for(i=0; i<100; i++) {
		if(!gbid("s1h"+i))
			break;
		if(parseInt(gbid("single"+gbid("s1h"+i).value).innerHTML) < parseInt(gbid("s1_singleroom").value)) {
			gbid("single"+gbid("s1h"+i).value).style.color="#ff0000";
		} else
			gbid("single"+gbid("s1h"+i).value).style.color="#000000";
		
		if(parseInt(gbid("double"+gbid("s1h"+i).value).innerHTML) < parseInt(gbid("s1_doubleroom").value)) {
			gbid("double"+gbid("s1h"+i).value).style.color="#ff0000";
		} else
			gbid("double"+gbid("s1h"+i).value).style.color="#000000";
		
	}
}

function wizardS2EnableDisableHall(hallId)
{
	if (gbid("s2_h"+hallId+"_checked").checked) {
		$("#h"+hallId+"_optbox").slideDown(2000);
		$("#h"+hallId+"_schemabox").slideDown(2000);
	} else {
		$("#h"+hallId+"_optbox").slideUp(200);
		$("#h"+hallId+"_schemabox").slideUp(200);
	}

}

function wizardS2EnableDisableSimTrans(hallId)
{
	if (gbid("s2_h"+hallId+"_simtrans").checked) {
		$("#s2_h"+hallId+"_simtrans_box").slideDown("slow");
	} else {
		$("#s2_h"+hallId+"_simtrans_box").slideUp("slow");
	}

}

function wizardS2EnableDisableNeedTrans(hallId)
{
	if (gbid("s2_h"+hallId+"_needtrans").checked) {
		$("#s2_h"+hallId+"_lang_box").slideDown("slow");
	} else {
		$("#s2_h"+hallId+"_lang_box").slideUp("slow");
	}

}

function wizardS2EnableDisableOther(hallId)
{
	if (gbid("s2_h"+hallId+"_other").checked) {
		$("#s2_h"+hallId+"_other_box").slideDown("slow");
	} else {
		$("#s2_h"+hallId+"_other_box").slideUp("slow");
	}

}

function wizardS5EnableDisableEvtSup()
{
	if (gbid("event_supervising").checked)
		$("#evtSuperOpts").slideDown("slow");
	else
		$("#evtSuperOpts").slideUp("slow");
}
function wizardSXShowHide(triger, target)
{
	if (gbid(triger).checked) {
		$("#"+target).show();
	} else {
		$("#"+target).hide();
	}

}

function wizardS6Check()
{
    gbid("phone").style.borderColor = "#999999";
    gbid("mail").style.borderColor = "#999999";
    gbid("contactperson").style.borderColor = "#999999";
    
    if(gbid("phone").value == "") {
        gbid("phone").style.borderColor = "#ff0000";
        return false;
    }
 
    if(gbid("mail").value == ""
            || checkEmail(gbid("mail").value) == false) {
        gbid("mail").style.borderColor = "#ff0000";
        return false;
    }

    if(gbid("contactperson").value == "") {
        gbid("contactperson").style.borderColor = "#ff0000";
        return false;
    }

    return true;
}
