﻿function showCityListingDistance()
{
    CityListingDistance.cityListingDistanceURL(currURL, $('cityListingDistanceLocality').value, cityListingDistanceSuccess, onFailure);
}

function onFailure(sender, e)
{
    //alert("Problem retrieving XML data");
}

function cityListingDistanceSuccess(sender, e)
{
    var returnedURL = sender;
    if(returnedURL == 'invalidLocality')
    {
        alert('No information is present regarding the locality you specified');
    }
    else
    {
        window.location = returnedURL;
    }
}

function $(id)
{
    return document.getElementById(id);
}

function onEnterShowDistance(evt)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if(charCode == 13)
    {
        showCityListingDistance();
    }
}

function ShowMZNUnit(hotelID)
{
    MznService.TrackThis("Check Rates",window.location.href,OnTrackSuccess,onTrackFailure);
    MznService.getFloatingMZNUnit(hotelID, ShowFloatingDiv, onFailure);
}

function ShowFloatingDiv(sender, e)
{
    mznModel = new MznCombinedModel();
	mznModel = sender;
	$("floatingMZNUnit").innerHTML = mznModel.UI;
	$("floatingMZNUnit").style.left=(x-70)+"px";
	$("floatingMZNUnit").style.top=(y+15)+"px";
	$("floatingMZNUnit").style.display="block";
	
	SetupCalendar("rfrFloatCheckInDate");	
	SetupCalendar("rfrFloatCheckOutDate");

	SetupCalendar("floatCheckInDate");
	SetupCalendar("floatCheckOutDate");
}

function handleRequestFloat()
{
	if (checkIfDateGreater($("rfrFloatCheckInDate").value,$("rfrFloatCheckOutDate").value))
	{
	    $('rfrFloatCheckDates').style.display="block";
	    return false;
	}
	else
	    $('rfrFloatCheckDates').style.display="none";
	
	if(validateEmailConsistencyFloat())
	{
		MznService.TrackThis("Send Request Float",window.location.href,OnTrackSuccess,onTrackFailure);
		MM_openBrWindowRFR('about:blank','formtarget','width=620, height=680,toolbar=no, menubar=no,scrollbars=auto,resizable=no');
		copyFieldsToProxyFormFloat();
		document.hiddenForm.submit();
		return true;
	}else 
		return false;		    
}

function copyFieldsToProxyFormFloat()
{
	$('proxyName').value = $('floatfullName').value;
	mznModel.name = $('floatfullName').value;
	$('proxyEmail').value = $('floatemailID1').value;
	mznModel.email = $('floatemailID1').value;
    //	$('proxyCity').value = mznModel.city;
	$('proxyHotelId').value = mznModel.hotelID;
}

function validateEmailConsistencyFloat()
{
    //debugger;
    if($('mznCityName2') != null && $('mznCityName2').value == $('mznCityName2').defaultValue)
    {
        //alert('code reached inside ... 1');
        if($('specifyCity2'))
        $('specifyCity2').style.display="block";
        $('floatemailsnotentered').style.display="none";
			$('floatemailmismatch').style.display="none";
			$('floatinvalidEmailId').style.display="none";
			$('floatinvalidName').style.display="none";
			$('mznCityName2').focus();
        return false;
    }
	else if($('floatemailID1').value == '')
	{
		$('floatemailsnotentered').style.display="block";
		$('floatemailmismatch').style.display="none";
		$('floatinvalidEmailId').style.display="none";
		$('floatinvalidName').style.display="none";
		if($('specifyCity2'))
		$('specifyCity2').style.display="none";
		$('floatemailID1').focus();
		return false;
	}
	else if($('floatemailID2').value == '')
	{
		$('floatemailsnotentered').style.display="block";
		$('floatemailmismatch').style.display="none";
		$('floatinvalidEmailId').style.display="none";
		$('floatinvalidName').style.display="none";
		if($('specifyCity2'))
		$('specifyCity2').style.display="none";
		$('floatemailID2').focus();
		return false;
	}
	else
	{
	    if($('floatfullName').value == 'Enter your Full Name' || $('floatfullName').value.length < 5)
		{
			$('floatemailsnotentered').style.display="none";
			$('floatemailmismatch').style.display="none";
			$('floatinvalidEmailId').style.display="none";
			$('floatinvalidName').style.display="block";
			if($('specifyCity2'))
			$('specifyCity2').style.display="none";
			$('floatfullName').focus();
			return false;
		}
		else if($('floatemailID1').value != 'Enter your Email ID' &&
				$('floatemailID2').value != confirmPrompt &&
				!doEmailsMatchFloat()
		  )
		{
			$('floatemailsnotentered').style.display="none";
			$('floatemailmismatch').style.display="block";
			$('floatinvalidEmailId').style.display="none";
			$('floatinvalidName').style.display="none";
			if($('specifyCity2'))
			$('specifyCity2').style.display="none";
			$('floatemailID1').focus();
			return false;
		}else if(echeck($('floatemailID1').value)==false)
		{
			$('floatemailsnotentered').style.display="none";
			$('floatemailmismatch').style.display="none";
			$('floatinvalidEmailId').style.display="block";
			$('floatinvalidName').style.display="none";
			if($('specifyCity2'))
			$('specifyCity2').style.display="none";
			$('floatemailID1').focus();
			return false;
		}
		else if(echeck($('floatemailID2').value)==false)
		{
			$('floatemailsnotentered').style.display="none";
			$('floatemailmismatch').style.display="none";
			$('floatinvalidEmailId').style.display="block";
			$('floatinvalidName').style.display="none";
			if($('specifyCity2'))
			$('specifyCity2').style.display="none";
			$('floatemailID2').focus();
			return false;
		}
		else
		{
			$('floatemailsnotentered').style.display="none";
			$('floatemailmismatch').style.display="none";
			$('floatinvalidEmailId').style.display="none";
			$('floatinvalidName').style.display="none";
			if($('specifyCity2') != null)
			{
			    $('specifyCity2').style.display="none";
			}
		}
	}
	if($('floatemailID1').value != '' 
			&& doEmailsMatchFloat() && echeck($('floatemailID1').value))
		return new Boolean(true);

}

function doEmailsMatchFloat()
{
	return $('floatemailID1').value.toLowerCase() == $('floatemailID2').value.toLowerCase();
}

function splitCheckInCheckOutDateFloat()
{
	var checkIn = $('floatCheckInDate').value;
	var checkOut = $('floatCheckOutDate').value;
	mznModel.checkInDay = checkIn.split('/')[0];
	mznModel.checkInMonth = checkIn.split('/')[1];
	mznModel.checkInYear = checkIn.split('/')[2];
	mznModel.checkOutDay = checkOut.split('/')[0];
	mznModel.checkOutMonth = checkOut.split('/')[1];
	mznModel.checkOutYear = checkOut.split('/')[2];
}

function loadRevCompParamsFloat()
{
	splitCheckInCheckOutDateFloat();
	//debugger;
	$('TGU_CID').value = mznModel.checkInDay;
	$('TGU_CIM').value = mznModel.checkInMonth;    
	$('TGU_CIY').value = mznModel.checkInYear;
	$('TGU_COD').value = mznModel.checkOutDay;
	$('TGU_COM').value = mznModel.checkOutMonth;
	$('TGU_COY').value = mznModel.checkOutYear;
	$('tgcity').value = mznModel.city;    

	$('TOC_CID').value = mznModel.checkInDay;
	$('TOC_CIM').value = mznModel.checkInMonth;
	$('TOC_COD').value = mznModel.checkOutDay;
	$('TOC_COM').value = mznModel.checkOutMonth;
	$('toccity').value = mznModel.city;

	var one_day=1000*60*60*24
		dateCheckOut = new Date(mznModel.checkOutYear, mznModel.checkOutMonth-1, mznModel.checkOutDay);
	dateCheckIn = new Date(mznModel.checkInYear, mznModel.checkInMonth-1, mznModel.checkInDay);
	var dayDiff = (dateCheckOut.getTime() - dateCheckIn.getTime())/one_day;

	$('TOC_LOS').value = dayDiff;
	$('YRA_CID').value = mznModel.checkInDay + '/' + mznModel.checkInMonth + '/' + mznModel.checkInYear;
	$('ycity').value = mznModel.city;
	$('YRA_COD').value = mznModel.checkOutDay + '/' + mznModel.checkOutMonth + '/' + mznModel.checkOutYear; 

	$('CTP_CID').value = mznModel.checkInDay + '/' + mznModel.checkInMonth + '/' + mznModel.checkInYear;
	$('CTP_COD').value = mznModel.checkOutDay + '/' + mznModel.checkOutMonth + '/' + mznModel.checkOutYear; 
	$('ctcity').value = mznModel.CTPCity; 
	//$('ctdest').value = '<%Response.Write(hotelReq1.CTPDest);%>'; 

	$('MMT_CID').value = mznModel.checkInDay + '/' + mznModel.checkInMonth +'/'+mznModel.checkInYear;
	$('MMTDeep_CID').value = mznModel.checkInDay + '/' + mznModel.checkInMonth +'/'+mznModel.checkInYear;
	$('MMT_COD').value = mznModel.checkOutDay + '/' + mznModel.checkOutMonth + '/' + mznModel.checkOutYear; 
	$('MMTDeep_COD').value = mznModel.checkOutDay + '/' + mznModel.checkOutMonth + '/' + mznModel.checkOutYear; 
	$('MMTcitycode').value = mznModel.cityCode;
    $('MMTDeepcitycode').value = mznModel.cityCode;
	$('MMTcityName').value = mznModel.city;
	$('MMTcityName2').value = mznModel.city;
	$('MMTDeepcityName').value = mznModel.city;
	$('MMTDeepHotelName').value = mznModel.mmtDeepHotelName;
	$('MMTDeepHotelCode').value = mznModel.mmtDeepHotelCode;
}

function checkRatesOnlineFloat()
{
    //alert("came in check rates online");
	//mznModel.siteChecked = new object[6];
	if (checkIfDateGreater($("floatCheckInDate").value,$("floatCheckOutDate").value))
	{
	    $('floatcheckDates').style.display="block";
	    return false;
	}
	else
	    $('floatcheckDates').style.display="none";
	
	sitesChecked = new Array();

	loadRevCompParamsFloat();

	var winFeature = 'width=620, height=600,toolbar=yes, menubar=yes,scrollbars=yes,resizable=yes';
	//alert('ok 1'+ mznModel.otaCodes.length);
	oneWindowOpened = false;
	for (i=0;i<mznModel.otaCodes.length;i++)
	{
		var form1 = mznModel.otaCodes[i] +'Form';
		//alert('form is ' + form1);
		MM_openBrWindowFloat('about:blank', form1, winFeature);
	}
	//alert('ok 1');

	if(oneWindowOpened== true)
	{
	MznService.storeStats(mznModel, sitesChecked, onSuccessStore, function() {new OnFailure(1).onFailure();});
	$("floatnoOTAselected").style.display='none'
	}
	else
	{
	$("floatnoOTAselected").style.display='block';
	}
	//alert('ok 2');
}

function MM_openBrWindowFloat(theURL,winName,features) 
{ //v2.0
//    alert($(winName+'CBactual'));
	if ($('Float'+winName+'CBactual') != null && $('Float'+winName+'CBactual').checked)
	{
	    
		sitesChecked[count] = winName;++count;
		if( winName == 'HWSForm')
			theURL = mznModel.hotelWebsiteURL;
		var child = window.open(theURL,winName,features);
		oneWindowOpened = true;
		if( winName != 'HWSForm')
			$(winName).submit();
	}
} 

function onSuccessRequestPhoneFloat(sender, e)
{
    if(sender == "Y")
        $('smsSentNotificationFloat'+currFloatDivID).innerHTML = '<font color=\"green\">Hotel Number has been sent as an SMS!</font>';
    else
        $('smsSentNotificationFloat'+currFloatDivID).innerHTML = '<font color=\"red\">Sorry! Hotel Number could not be found</font>';
}
var currFloatDivID;
function requestPhoneFloat(divID)
{
	currFloatDivID=divID;
	var visitorMobile = $('visitorMobileFloat'+currFloatDivID).value;
	if(visitorMobile != 'Enter your Mobile number')
	{
	    MznService.requestPhone(mznModel.hotelID, mznModel.hotelName, visitorMobile, onSuccessRequestPhoneFloat, new OnFailure(0).onFailure());
	    $('visitorMobileFloat'+currFloatDivID).value = $('visitorMobileFloat'+currFloatDivID).defaultValue;
	    
	    $('invalidNumberFloat'+currFloatDivID).style.display='none';
	    return true;
	}
	else
	{
	    $('invalidNumberFloat'+currFloatDivID).style.display='block';
	    return false;
	}
}

function callTabPhoneCheckFloat(evt, divID)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if(charCode == 8 || charCode == 9)
    return true;
    var strToTest = $('visitorMobileFloat'+divID).value;
    if(charCode != 13)
        strToTest += String.fromCharCode(charCode);
    callTabMobilePat = /^9([0-9])*$/;
    if(!callTabMobilePat.test(strToTest)){
        return false;
    }
    else
    {
	if(charCode == 13)
	{
		requestPhone();
		return false;
	}
	return true;
    }
}