// Eviivo HTML search box 
// Author: Piotr Rochala 
// Date: 16.07.07       

var url_begin, cityname;
//url_begin = "http://192.168.27.167/IntechConnect/Search/Result.aspx";  
//url_begin = "http://203.189.91.165/IntechConnect/Search/Result.aspx";  
//url_begin = "http://localhost:2243/IntechConnect/Search/Result.aspx";  
url_begin = "http://in-bookings.intechhs.com/BookingTool/Search/Result.aspx";  
cityname = "New Delhi";   // City Name
function showDivs(x) {  // show / hide divs on rooms selection

if (x == 1) {
document.getElementById('pers2').style.display = 'none';
document.getElementById('pers2').style.visibility = 'hidden';
document.getElementById('pers3').style.display = 'none';
document.getElementById('pers3').style.visibility = 'hidden';
}

if (x == 2) {
document.getElementById('pers2').style.display = 'block';
document.getElementById('pers2').style.visibility = 'visible';
document.getElementById('pers3').style.display = 'none';
document.getElementById('pers3').style.visibility = 'hidden';
}

if (x == 3) {
document.getElementById('pers2').style.display = 'block';
document.getElementById('pers2').style.visibility = 'visible';
document.getElementById('pers3').style.display = 'block';
document.getElementById('pers3').style.visibility = 'visible';
}
}

function selectValue(selname) { // show selected value in input type=select 
var value;
value = document.getElementById(selname).options[document.getElementById(selname).selectedIndex].value;
return value;
}

function selectinputValue(selname) {  // show selected value in input type=text 
var value;
value = document.getElementById(selname).value;
return value;
}


function doSearch(city,affiliate) { // create url to reload page for hotels accommodation
var dest, week, day, month, year, rating, nights, rooms, a1, a2, a3, ch1, ch2, ch3, URL;

cityname = city;
//day = selectinputValue("sel_chi");
//month = selectinputValue("sel_month");
//year = selectinputValue("sel_year");

var startdate = selectinputValue('txtdate');
var dateparts = startdate.split('-');

day = dateparts[0];
month = dateparts[1];
year = dateparts[2];

nights = selectinputValue("sel_nights");
rooms = selectValue("sel_rooms");

a1 = selectValue("sel_adults1");
a2 = selectValue("sel_adults2");
a3 = selectValue("sel_adults3");
ch1 = selectValue("sel_child1");
ch2 = selectValue("sel_child2");
ch3 = selectValue("sel_child3");
//week = selectinputValue("week");

var dayNameArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
//var dayName = dayNameArray[week];
var dayName = '';
//alert(url_begin);

URL = url_begin + '?city=' + cityname + "&Affiliate=" + affiliate + "&ICType=1&"
+ "StartDate="+ day + "/" + month + "/" + year + "&"
+ "EndDate=10/11/" + year + "&"
+ "StartTime=&EndTime="
+ "&Duration=" + nights 
+ "&NoOfRooms=" + rooms 
+ "&Adults1=" + a1
+ "&Children1=" + ch1
+ "&Concessions1=" + 0
+ "&Adults2=" + a2
+ "&Children2=" + ch2
+ "&Concessions2=" + 0
+ "&Adults3=" + a3
+ "&Children3=" + ch3
+ "&Concessions3=" + 0;

//alert(URL);
//document.getElementById('urlString').innerHTML = URL;
//parent.location.href = URL;

//window.open(URL,'_new');
window.location.href = URL;
//document.write(URL);
}


function ShowImg(number) {
var url, url2;
url = "url(gallery/" + number + "m.png) no-repeat center";
url2 = "gallery/" + number + "b.png";
document.getElementById('image_field').style.background = url;
document.getElementById('img_click').href = url2;
}




function LookForAddress() {

function selectinputValue(selname) {  // show selected value in input type=text 
var value;
alert(selname);
value = document.getElementById(selname).value;
return value;
}

var postcode;
postcode = selectinputValue("saddr")
postcode = postcode.replace(/ /gi, "+")
window.open("http://maps.google.co.uk/maps?saddr=" + postcode + "&daddr=+++++&hl=en")

}
function ValidateSearcgBox()
{
    var message = 'Following correct the following errors : \n ------------------------------------------\n';
    var validate = true;
    var ddlroomcount = document.getElementById('sel_rooms');
    var ddladult1 = document.getElementById('sel_adults1');
    var ddlchild1 = document.getElementById('sel_child1');
    var ddladult2 = document.getElementById('sel_adults2');
    var ddlchild2 = document.getElementById('sel_child2');
    var ddladult3 = document.getElementById('sel_adults3');
    var ddlchild3 = document.getElementById('sel_child3');
    var nights = document.getElementById('sel_nights');
    
    if (trim(nights.value)=='')
        {
            message = message + 'Number of nights cannot be blank\n';
            validate = false;
        }
     else
        {
            if (!validateInteger(trim(nights.value)))
            {
                message = message + 'Please enter valid numeric value for Number of nights\n';
                validate = false;
            }
        }   
    
    
    if (ddlroomcount.value =='1' || ddlroomcount.value == '2' || ddlroomcount.value == '3')
    {
        if (ddladult1.value=='0' && ddlchild1.value=='0')
            {
                message = message + 'Please select either adult or child or both value for the room 1\n';
                validate = false;
            }
     }
     if (ddlroomcount.value == '2' || ddlroomcount.value == '3')
        {       
            if (ddladult2.value == '0' && ddlchild2.value == '0')
                {
                    message = message + 'Please select either adult or child or both value for the room 2\n';
                    validate = false;
                }    
        }
    if (ddlroomcount.value == '3')
    {    
        if (ddladult3.value=='0' && ddlchild3.value=='0')
            {
                message = message + 'Please select either adult or child or both value for the room 3\n';
                validate = false;
            }
     }       
    
    if (!validate)
    {
        alert(message);
    }
    return validate;
}

function ValidateRooms(message)
{
    //alert('setting values');
    
    var validate = true;
    
    
}


function trim(text)
{
    return text.replace(/^\s+|\s+$/, '');
}
function validateInteger( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
  var objRegExp  = /(^-?\d\d*$)/;

  //check for integer characters
  return objRegExp.test(strValue);
}
function showProducts(link,container,radio_collection_ids)
{   
    var containers = document.getElementById('page_room_prices_ids').value.split(',');
    var links = document.getElementById('links').value.split(',');
    
    radio_collection_ids = radio_collection_ids.split(',');
    //alert(radio_collection_ids.length);
    for (var i = 0; i < radio_collection_ids.length; i++) 
            {
            
                //alert(document.getElementById(radio_collection_ids[i]);
                if (trim(document.getElementById(radio_collection_ids[i]).value)!='')
                    select_me(document.getElementById(radio_collection_ids[i]).value.split(',')[0],radio_collection_ids[i]);
                
            }
            
    for (var i = 0; i < containers.length-1; i++) 
            {
                document.getElementById(containers[i]).style.visibility = 'hidden';
                document.getElementById(containers[i]).style.display = 'none';
                if (document.getElementById(links[i]).id != document.getElementById(link).id)
                    document.getElementById(links[i]).innerHTML = '<< Show Room Prices';
            }
    
    //alert(document.getElementById(link).innerHTML);
    if (document.getElementById(link).innerText == '>> Hide Room Prices')
    {
        document.getElementById(link).innerHTML = '<< Show Room Prices';
        document.getElementById(container).style.visibility = 'hidden';
        document.getElementById(container).style.display = 'none';
    }
     else
     {
            document.getElementById(link).innerHTML = '>> Hide Room Prices';
            document.getElementById(container).style.visibility = 'visible';
            document.getElementById(container).style.display = 'block';
        }
}
function select_me(rbtnradio,rbtnradio_collection)
{
    radio = document.getElementById(rbtnradio);
    radio_collection = document.getElementById(rbtnradio_collection).value.split(',');
    //alert(document.getElementById(rbtnradio_collection).value);
    for (var i = 0; i < radio_collection.length-1; i++) 
            {
                document.getElementById(radio_collection[i]).checked = false;
                //alert(document.getElementById(radio_collection[i]).checked);
            }
    radio.checked = true;
    
}
function GetSelectedProducts(radio_collection_ids)
{
 radio_collection_ids = radio_collection_ids.split(',');
 var querystring = '';
    
    for (var i = 0; i < radio_collection_ids.length; i++) 
            {
            
                if (trim(document.getElementById(radio_collection_ids[i]).value)!='')
                    {
                      radio_collection = trim(document.getElementById(radio_collection_ids[i]).value).split(',');
                      for (var j = 0; j < radio_collection.length-1; j++) 
                        {
                            if (document.getElementById(radio_collection[j]).checked == true)
                                {
                                    querystring += document.getElementById(radio_collection[j]).value;
                                }
                            
                        }
                        
                    }
                
            } 
            //alert(querystring);
              if (trim(querystring)!='')
                    BookNow(querystring);
              else
                    alert('Please select a product.'); 
}