﻿function OpenMenuPage(pageName) {
	window.open(pageName, 'mywindow','width=500,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

function OpenMenuPage1(pageName) {
    window.open(pageName, 'mywindow', 'width=840,height=680,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

function OpenMenuPageDubai(pageName) {
    window.open(pageName, 'mywindow', 'width=650,height=450,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

function WriteEmailAddress (name, domain, topLevelDomain, css)
{
  document.write('<a');
  if (css.length > 0)
  {
    document.write(' class=\"' + css + '\"');
  }
  document.write(' href=\"mailto:' + name + '@' + domain + '.' + topLevelDomain + '\">');
  document.write(name + '@' + domain + '.' + topLevelDomain + '</a>;');
}

function WriteFlashObject(flashURL, width, height, uniqueId)
{
	var theUniqueid = '';
	if (uniqueId != null)
	{
		if (uniqueId.length > 0)
		{
			theUniqueid = ' id=\"' + uniqueId + '\"';
		}
	}
	if (navigator.userAgent.indexOf("MSIE") == -1)
	{
		document.write('<embed src="' + flashURL + '"' + theUniqueid + ' quality="high" wmode="transparent" pluginspage="<http://www.macromedia.com/go/getflashplayer>http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width +'" height="' +  height +'"></embed>');
	} else if(navigator.userAgent.indexOf("MSIE") != -1)
	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="<http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0>http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"  width="' + width +  '" height="' + height + '"><param name="movie" value="'  +  flashURL +'" /><param name="wmode" value="transparent" /><param name="quality" value="high" /></object>');
	}
}

function ToggleElement(elementId, mustDisplay)
{
	var element = document.getElementById(elementId);
	if (mustDisplay)
	{
		element.style.display = 'block';
	}
	else
	{
		element.style.display = 'none';
	}
}


// Checks if the three date elements together form a valid date
function IsDate (year, month, day)
{
	if (isEmpty(year) || isNaN(year)) return false;
	if (isEmpty(month) || isNaN(month)) return false;
	if (isEmpty(day) || isNaN(day)) return false;
	var longMonth;
	var isFebruary;
	longMonth = false;
	isFebruary = false;
	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
	{
		longMonth = true;		
	}
	if (month == 2)
	{
		isFebruary = true;
	}
	if (longMonth && day > 31) return false;
	if (!longMonth && day > 30) return false;
	if (isFebruary && day > daysInFebruary(year)) return false;
	return true;
}

// Internal function. Returns 29 when a leap year, else 28
function daysInFebruary (year)
{ // 29 days in febr, when it's a leap year. Not with a century, unless dev. by 400
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}


function isEmpty(s)
{   
  s = Trim(s)
  return ((s == null) || (s.length == 0))
}

// Trims all spaces to the left of a specific string
function LTrim(str)
{
  var whitespace = new String(" \t\n\r "); // last space character is not a space, but alt+0160, another invisible char.
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...
    var j=0, i = s.length;
    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        j++;
    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }
  return s;
  }

// Trims all spaces to the right of a specific string
function RTrim(str)
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in whitespace
  var whitespace = new String(" \t\n\r "); // last space character is not a space, but alt+0160, another invisible char.
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...
    var i = s.length - 1;       // Get length of string
    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        i--;
    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }
  return s;
}

// Trims all spaces to the left and right of a specific string by calling RTim and LTrim
function Trim(str)
{
  return RTrim(LTrim(str));
}

function AddMonthsToDate(startDate, numberOfMonths)
{
//alert('Test');
  var addYears = Math.floor(numMonths/12);
  var addMonths = numMonths - (addYears * 12);
  var newMonth = startDate.getMonth() + addMonths;
  if (startDate.getMonth() + addMonths > 11) {
    ++addYears;
    newMonth = startDate.getMonth() + addMonths - 12;
  }
  var newDate = new Date(startDate.getYear()+addYears,newMonth,startDate.getDate(),startDate.getHours(),startDate.getMinutes(),startDate.getSeconds());

  // adjust to correct month
  while (newDate.getMonth() != newMonth) {
    newDate = addDaysToDate(newDate, -1);
  }
  return newDate;
}

function AddDaysToDate(startDate, numberOfDays)
{
	/// <summary>Adds the specified number of days to the date passed in startDate.</summary>
	/// <param name="startDate">The date to which the number of days must be added.</param>
	/// <param name="numberOfDays">The number of days to add the date.</param>
  return new Date(startDate.getTime() + numberOfDays * 24 * 60 * 60 * 1000);
}

function MM_mousehover(id) {
//    document.getElementById("dubaibeforehoverimage").value = id.style.backgroundImage;
    id.style.backgroundImage = "url(/Images/Dubai/hg.jpg)";
}
function MM_mouseout(id, defaultname) {
    var isselect = (document.getElementById(defaultname).style.display != 'none');
    if (isselect) {
        id.style.backgroundImage = "url(/Images/Dubai/xz.jpg)";
    } else {
        id.style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
    }
}

function DubaiHotelTabChange(id) {
    var tabindex = id;
    if (tabindex == 0) {
        document.getElementById("tab_hotel_div").style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
        document.getElementById("tab_flightAndhotel_div").style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
        document.getElementById("tab_flight_div").style.backgroundImage = "url(/Images/Dubai/xz.jpg)";
        ToggleElement('tab_flight_container', true);
        ToggleElement('tab_hotel_container', false);
        ToggleElement('tab_flightAddHotel_container', false);
    }
    else {
        if (tabindex == 1) {
            document.getElementById("tab_flight_div").style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
            document.getElementById("tab_flightAndhotel_div").style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
            document.getElementById("tab_hotel_div").style.backgroundImage = "url(/Images/Dubai/xz.jpg)";
            ToggleElement('tab_flight_container', false);
            ToggleElement('tab_hotel_container', true);
            ToggleElement('tab_flightAddHotel_container', false);
        }
        else {
            document.getElementById("tab_flight_div").style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
            document.getElementById("tab_hotel_div").style.backgroundImage = "url(/Images/Dubai/pt.jpg)";
            document.getElementById("tab_flightAndhotel_div").style.backgroundImage = "url(/Images/Dubai/xz.jpg)";
            ToggleElement('tab_flight_container', false);
            ToggleElement('tab_hotel_container', false);
            ToggleElement('tab_flightAddHotel_container', true);
        }
    }
}

function getWeek(id) {
    var week = "";
    switch (id) {
        case 0:
            week = "Sun";
            break;
        case 1:
            week = "Mon";
            break;
        case 2:
            week = "Tue";
            break;
        case 3:
            week = "Wed";
            break;
        case 4:
            week = "Thu";
            break;
        case 5:
            week = "Fri";
            break;
        case 6:
            week = "Sat";
            break;
        default:
            break;
    }
    return week;
}

function getMonth(id) {
  var month = "";
  switch (id) {
      case 0:
          month = "Jan";
          break;
      case 1:
          month = "Feb";
          break;
      case 2:
          month = "Mar";
          break;
      case 3:
          month = "Apr";
          break;
      case 4:
          month = "May";
          break;
      case 5:
          month = "Jun";
          break;
      case 6:
          month = "Jul";
          break;
      case 7:
          month = "Aug";
          break;
      case 8:
          month = "Sep";
          break;
      case 9:
          month = "Oct";
          break;
      case 10:
          month = "Nov";
          break;
      case 11:
          month = "Dec";
          break;     
      default:
          break;
  }
  return month;
}

function cls(obj, default_value) {
    //onfus
    var isie = document.all ? true : false;
    //  2010.5.19 zhangbin
    if (default_value != null) {
        if (isie) {
            with (event.srcElement) {
                if (value == default_value) value = "";
            }
        }
        else {
            if (obj.value == default_value) obj.value = "";
        }
        obj.style.fontSize = '10pt';
        return;
    }
    //
    if (isie) {
        with (event.srcElement) {
            if (value == defaultValue) value = "";
        }
    }
    else {
        if (obj.value == obj.defaultValue) obj.value = "";
    }
    obj.style.fontSize = '10pt';
}
function res(obj, default_value) {
    //onblur
    var isie = document.all ? true : false;
    // 2010.5.19 zhangbin
    if (default_value != null) {
        if (isie) {
            with (event.srcElement) {
                if (value == "") {
                    value = default_value;
                    obj.style.fontSize = 'smaller';
                }
            }
        }
        else {
            if (obj.value == "") {
                obj.value = default_value;
                obj.style.fontSize = 'smaller';
            }
        }
        return;
     }
    //
    if (isie) {
        with (event.srcElement) {
            if (value == "") {
                value = defaultValue;
                obj.style.fontSize = 'smaller';
            }
        }
    }
    else {
        if (obj.value == "") {
            obj.value = obj.defaultValue;
            obj.style.fontSize = 'smaller';
        }
    }
}
function cls2(obj) {
    //onfus
    var isie = document.all ? true : false;
    var defaultfromtext = FromAndTo_1.fromnodeinfo;
    var defaulttotext = FromAndTo_1.tonodeinfo;
    var boolflag = (obj.value == defaultfromtext || obj.value == defaulttotext);
    if (isie) {
        with (event.srcElement) {
            if (boolflag)
                value = "";
//            else if (value != defaultValue)
//                 value = "";
        }
    }
    else {
        if (boolflag) obj.value = "";
    }
    obj.style.fontSize = '9px';
}
function res2(obj) {
    //onblur
    var defaultfromtext = FromAndTo_1.fromnodeinfo;
    var objvalue = obj.defaultValue;
    var obje = event.srcElement ? event.srcElement : event.target;
    var objfontsize = obj.style.fontSize;
    var isie = document.all ? true : false;
    if (isie) {
        with (event.srcElement) {
            if (value == "") {
                value = defaultfromtext;
                //obj.style.fontSize = objfontsize;
                obj.style.fontSize = 'smaller';
            }
        }
    }
    else {
        if (obj.value == "") {
            obj.value = defaultfromtext;
            obj.style.fontSize = 'smaller';
            //obj.style.fontSize = objfontsize;
        }
    }
}
function res3(obj) {
    //onblur
    var defaulttotext = FromAndTo_1.tonodeinfo;
    var objvalue = obj.defaultValue;
    var obje = event.srcElement ? event.srcElement : event.target;
    var objfontsize = obj.style.fontSize;
    var objvalue = obj.defaultValue;
    var isie = document.all ? true : false;
    if (isie) {
        with (event.srcElement) {
            if (value == "") {
                value = defaulttotext;
                obj.style.fontSize = 'smaller';
            }
        }
    }
    else {
        if (obj.value == "") {
            obj.value = defaulttotext;
            obj.style.fontSize = 'smaller';
        }
    }
}
function setresourcesvalue(info) {
    return info;
}
function __FromAndToText() {
    this.fromnodeinfo = "this from";
    this.AddFromNode = function(info) { this.fromnodeinfo = info; };
    this.tonodeinfo = "this to";
    this.AddToNode = function(info) { this.tonodeinfo = info; };
}
var FromAndTo_1 = new __FromAndToText();

//var const_fix_display_objid;
//var const_client_x;
//var const_client_y;
//function FixDisplay(objid, client_x, client_y) {
//    if (objid == null || objid =="")
//        return;
//    var obj = $get(objid);
//    if (obj == null)
//        return;
//    client_x = client_x == null ? $(obj).offset().left : client_x;
//    client_y = client_y == null ? $(obj).offset().top : client_y;
//    const_fix_display_objid = objid;
//    const_client_x = client_x;
//    const_client_y = client_y;
//    $("#" + const_fix_display_objid).css({ "left": (const_client_x + $(window).scrollLeft()) + "px", "top": (const_client_y + $(window).scrollTop()) + "px" });
//    $(window).resize(fun);
//    $(window).scroll(fun);
//}
//function fun() {
//    $("#" + const_fix_display_objid).css({ "left": (const_client_x + $(window).scrollLeft())+"px", "top": (const_client_y + $(window).scrollTop())+"px" });
//}
var my_timer = null;
var fixDisplayDivs = new Array;
function FixDiv() {
}
function FixDisplay(objid, client_x, client_y,top_ele_id,left_ele_id,bottom_ele_id) {
    if (objid == null || objid == "")
        return;
    var obj = $get(objid);
    if (obj == null)
        return;
    client_x = client_x == null ? $(obj).offset().left : client_x;  //  get customer seted left distance
    client_y = client_y == null ? $(obj).offset().top : client_y;   //  get customer seted top distance

    var fix_div = new FixDiv();         //  create a new fix display div object
    fix_div.id = objid;              //  save the div object id
    fix_div.x = client_x;        //  save the object left distance
    fix_div.y = client_y;        //   save  the object top distance
    fix_div.tid = top_ele_id;    //    save the element id on the object
    fix_div.lid = left_ele_id;  //  save the object left element id
    fix_div.bid = bottom_ele_id;  //  save the element id under the object

    fixDisplayDivs[fixDisplayDivs.length] = fix_div;   //  add to the fix display div array
    fun();
    if (my_timer == null) {
        my_timer = setInterval(fun,100);
     }
}
function fun() {
    var sl = $(window).scrollLeft();
    var st = $(window).scrollTop();

    var obj_offset;
    var obj;
    for (var i = 0; i < fixDisplayDivs.length; i++) {        //   iterate the object save in fix display array
        if (fixDisplayDivs[i] == null)
            continue;

        if (fixDisplayDivs[i].tid != null || fixDisplayDivs[i].lid != null || fixDisplayDivs[i].bid != null) {
            FixDisplayWithRelative(fixDisplayDivs[i], sl, st);
         }
         else {
             FixDisplayWithoutRelative(fixDisplayDivs[i], sl, st);
         }
         continue;
    }
}

function FixDisplayWithoutRelative(obj, sl, st) {
    $("#" + obj.id).css({ "left": (obj.x + sl) + "px", "top": (obj.y + st) + "px" });
}

function FixDisplayWithRelative(obj, sl, st) {
    var id, x, y, fix_obj;

    id = obj.id;      //  object id
    x = obj.x;         //  left distance
    y = obj.y;        //  top distance
    fix_obj = $("#"+id);
    
    var top_ele, left_ele, bottom_ele;
    var bottomEle_y, topEle_y, leftEle_x;
    top_ele = obj.tid == null ? null : $("#" + obj.tid);     //  top element
    left_ele = obj.lid == null ? null : $("#" + obj.lid);       //  left element
    bottom_ele = obj.bid == null ? null : $("#" + obj.bid);        // bottom element

    obj_offset = fix_obj.offset();

    topEle_y = top_ele == null ? 0 : top_ele.offset().top + top_ele.height();
    bottomEle_y = bottom_ele == null ? 0 : bottom_ele.offset().top;

    var isHigherThanWindow=$(window).height() < fix_obj.height();     
    var isHigherThanDistance = bottomEle_y - topEle_y < fix_obj.height();
    var hasCoverTopElement = top_ele == null ? false : obj_offset.top < topEle_y;
    var hasCoverBottomElement = bottom_ele == null ? false : (obj_offset.top + fix_obj.height() > bottomEle_y);
    var hasExceedWindowTop = obj_offset.top < st;
    var hasExceedWindowBottom = $(window).height() + st < obj_offset.top + fix_obj.height();

    var hasEnoughTop = bottomEle_y > obj_offset.top + fix_obj.height();
    var hasEnoughBottom = st + $(window).height() - topEle_y > fix_obj.height();

    //   set top
    var topBeforeSet = obj_offset.top;
    
    if (isHigherThanDistance) {
        fix_obj.css({ "top": topEle_y + "px" });
    }
    else if (isHigherThanWindow) {
        if (topEle_y>st) {
            fix_obj.css({ "top": topEle_y + "px" });
        }
        else if (bottomEle_y < $(window).height() + st) {
            fix_obj.css({ "top": bottomEle_y - fix_obj.height() + "px" });
        }
        else {
            fix_obj.css({ "top": st + "px" });
        }
    } else {
        if (hasCoverTopElement) {
            fix_obj.css({ "top": topEle_y + "px" });
        } else if (hasCoverBottomElement) {
            fix_obj.css({ "top": bottomEle_y - fix_obj.height() + "px" });
        }
        else if (hasExceedWindowTop) {
            if (hasEnoughTop) {
                fix_obj.css({ "top": st + "px" });
            }
            else {
                fix_obj.css({ "top": bottomEle_y - fix_obj.height() + "px" });
            }
        }
        else if (hasExceedWindowBottom) {
            if (hasEnoughBottom) {
                fix_obj.css({ "top": $(window).height() + st - fix_obj.height() + "px" });
            } else {
                fix_obj.css({ "top": topEle_y + "px" });
            }
        }
    }
    //   clear the auto complete content
    if (fix_obj.offset().top != topBeforeSet) {
        $(":text", fix_obj).each(function() {
            $(this).blur();
        });
     }
    
    // set left
    if (left_ele != null) {              //  if the fix display object has left base element
        leftEle_x = left_ele.offset().left + left_ele.width();
        if (leftEle_x > sl) {
            fix_obj.css({ "left": leftEle_x + "px" });
        }
        else {
            fix_obj.css({ "left": sl + "px" });
        }
    } else {
        fix_obj.css({ "left": x + sl + "px" });
    }
 }
