﻿var globalMetroList; 
var globalCityList;
var globalCalendarFiled
var globalSuiteList;

// JScript File
function OpenModalWindow(url)
{
	//window.open(url, 'Turne', 'width=1100, location=yes, toolbar=no, directories=no, status=no, resizable=no, scrollbars=no, fullsize=no');
	OpenModalWindowOptions(url,false,false,0,0);
}

//if width it is not defined parameter then width<=0, height the same way
function OpenModalWindowOptions(url,withScroll,resizable,width,height)
{
	var win = window.open(url, 'Turne', 
	    'width='+(width>0?width.toString():'1100')+(height>0?',height='+height.toString():'')+
	    ', location=yes, toolbar=no, directories=no, status=no, resizable='+(resizable?'yes':'no')+
	    ', scrollbars='+(withScroll?'yes':'no')+', fullsize=no');
	win.focus();
}

function OpenOrderRequestCheck(useGlobal) {
    if (useGlobal
        && (globalCityList == null || globalCityList == undefined)
    ) {
        alert('Дождитесь полной загрузки страницы');
        return false;
    }
    return true;
}

function OpenOrderRequest(url, tourId, suiteId, useGlobal)
{
    var tId = !useGlobal || (globalCalendarFiled != null)
        ? tourId
        : GetTourIdByDate(ConvertDate(GetCorrectDate(globalCalendarFiled.value)));

	var sId = !useGlobal || (globalSuiteList == null || globalSuiteList == undefined)
	        ? suiteId 
	        : globalSuiteList.options[globalSuiteList.selectedIndex].value;
	var cid = !useGlobal || (globalCityList == null || globalCityList == undefined)
	    ? 0 
	    : globalCityList.options[globalCityList.selectedIndex].value;
	var mid = !useGlobal || (globalMetroList == null || globalMetroList == undefined)
	    ? 0 
	    : globalMetroList.options[globalMetroList.selectedIndex].value;
		
	url = url.replace("metrostationid=0", "metrostationid=" + mid);
	url = url.replace("cityid=0", "cityid=" + cid);
	url = url.replace("-0/", "-" + tId + "/");
	url = url.replace("hsid=0", "hsid=" + sId);
	OpenModalWindowOptions(url, true, true,790,0);
}

function ConvertDate(date)
{
    var _month = date.getMonth() + 1;
    var _day = date.getDate();
    if(_month <=9 )_month = '0' + _month;
    if(_day <=9 )_day = '0' + _day;
    var _year = date.getFullYear() + 100;
    return _day + '.' + _month + '.' +_year ;
}
