//==============================================================================
//The  only global object - it is used only for 'core' system.
//PLEASE do not use this object for side views and objects that are 'partially'
// customized

var wiresJS = new Object();

// bug 6405 BEGIN - Firefox 3.0 issue; code is moved to top
//==============================================================================

wiresJS.hideProgress = function ()
{
    $(document.body).children(".IbeProgressView").css({'visibility': 'hidden', 'left': '-3000px'});
}

//==============================================================================

$(window).unload(wiresJS.hideProgress); // bug 6405 END - Firefox 3.0 issue;

//==============================================================================

wiresJS.displayProgress = function(progressIndicator)
{
    if(progressIndicator && progressIndicator != "None") {
       $(".ProgressText").html(wiresJS.progressTexts[progressIndicator]);
       wiresJS.showProgress();
    }
}

//==============================================================================

wiresJS.showProgress = function ()
{
  $(document.body).children(".WiresPane").hide();
  $(document.body).children(".IbeProgressView").css({'visibility': 'visible', 'left': '0px'});
  if ($.browser.msie){
    setTimeout("wiresJS.imagesProgressPreloader()", 0);
  }
}

wiresJS.imagesProgressPreloader = function () {
     $(document.body).children(".IbeProgressView").find("img").each(function() {
      this.src = this.src; 
  });
}

//==============================================================================

wiresJS.popupWindow = function(url, target)
{
  window.open(url, target,'toolbar=0,scrollbars=1, resizable=1, ' +
             'width=800, height=550, status=0' +
             ', top =' + (window.screenTop  - 30) + 
             ', left='+  (window.screenLeft + 50));
}

//==============================================================================

wiresJS.loadform = function (id, action, window, button, progressIndicator)
{
     var form = document.getElementById(id);
     wiresJS.progressIndicator = progressIndicator;
    
    var serialized = "";
    $("form").each (function (ind, el) {
	serialized += wiresJS.serializeForm (el, ind);
    });
    
    form.action = action;
    form.target = window;
    
    if (button) {
	$("#wires_hidden_field").remove ();
	$(form).append ($("<input id='wires_hidden_field' type='hidden' name='" 
			  + button.name + "' value='" + button.value + "'>"));
    }
       
    $(form).submit ();
};

//==============================================================================
wiresJS.serializeForm = function  (form, ind)
{
    if (!form)
	return; 

    var form_name = wiresJS.elementName (form, ind); 
    var form_elements = [];
    
    $(":input", form).each (function (index, element) {
	var type = element.type; 
	
	switch (type) {
	case "radio":
	case "checkbox": 
	    if (!$(element).attr ("checked")) {
		return;
	    }
	    break;
	    
	case "select-one": 
	case "text" : 
	case "textarea": 
	    var val = $(this).val();
	    if (!val || val == "") {
		return;
	    }		
	    break;
	    
	case "select-multiple":
	    var val = $(this).val ();
	    if (!val || val == "") {
		return;
	    }
	    break;
	}

	element_name = form_name + (element.name ? element.name : "element") + index;	

	var val = $(element).val (); 
	if (val.constructor != Array) {
	    var tmp = [];
	    tmp.push (val);
	    val = tmp;
	}
	
	for (var i = 0; i < val.length; i++) {	    
	    element_name += "=" + encodeURIComponent (element.value);
	    form_elements.push (element_name);
	}
    });
    
    return form_elements.join ("&");
}

//==============================================================================
wiresJS.deserializeForms = function  (data)
{
    if (!data)
	return; 
    
    $("form").each (function (ind, form) {
	wiresJS.deserializeForm (form, data, ind);
    });
}

//==============================================================================
wiresJS.deserializeForm = function  (form, data, formindex)
{
    if (!form || !data)
	return; 
    
    var split_data = data.split ("&");
    var hash = Object();
    
    $.each (split_data, function (ind, el) {
	var tmp = el.split ("=");
	var key = tmp[0];
	var val = decodeURIComponent (tmp[1]);
	
	if (!hash[key]) {
	    hash[key] = [];
	}
	
	hash[key].push (val);	    
    });

    
    clearForm ();
    
    var form_name = wiresJS.elementName (form, formindex); 
    
    $(":input", form).each (function (ind, el) {
	el_name = form_name + wiresJS.elementName (el, ind); 
	if (!hash[el_name])
	    return;
	
	$(el).val (hash[el_name]);
    });
}

//==============================================================================
wiresJS.elementName = function  (el, ind)
{
    if (!el)
	return ""; 
    
    var dummy = el.tagName.toLowerCase () == "form" ? "form" : "element";
    
    return (el.name ? el.name : dummy) + ind;
}


//==============================================================================
wiresJS.clearForm = function  (form)
{
    if (!form)
	return; 
    
    $("input,select,textarea", form).each (function () {
  var t = this.type, tag = this.tagName.toLowerCase();
        if (t == 'text' || t == 'password' || tag == 'textarea')
            this.value = '';
        else if (t == 'checkbox' || t == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
}


//==============================================================================
wiresJS.validateDate = function (current_date, sel_month, sel_day) {
  if (current_date.getMonth()!=sel_month || current_date.getDate()!=sel_day) {
      return false;
  }
  return true;
}


//==============================================================================
wiresJS.getYear = function  (now_year, now_month, now_day, sel_month, sel_day) {
  if (now_month>sel_month)
    return (parseInt(now_year) + 1);
  else if (now_month==sel_month && now_day>sel_day)
    return (parseInt(now_year) + 1);
  return now_year;
}


//==============================================================================
wiresJS.getNumChildrenPerHotelRoom = function (roomtype) {
  if (roomtype=="TWNC")
    return 1;
  if (roomtype=="DBLC")
    return 1;
  if (roomtype=="TRIC")
    return 1;
  if (roomtype=="FPL")
    return 2;  
  return 0;
}
  
  
//==============================================================================
wiresJS.hideChildAgeSelectors = function  (obj_name, num_children){
  $("form select[name^='"+ obj_name +"'][name$='childage1']:gt("+num_children+")").each (
    function () {
      $(this).hide();
      $(this).val( "2" );
      if (num_children<0) {
        $(this).parents('tr').eq(0).hide();
      }
      else {
        $(this).parents('tr').eq(0).show();
      }

    }
  );
}

//==============================================================================

wiresJS.SetTsmhlocid = function (SelectorValue) {
  var OptionValue=SelectorValue;
  var IATA_CODEARR = OptionValue.split(",");
  $("form input[name='hotcity'],input[name='tocity']").val(IATA_CODEARR[0]);
  $("form input[name='tsmhlocid']").val(IATA_CODEARR[1]);
}
  

//==============================================================================
  
wiresJS.getRoomTypeNum = function () {
    return $("form select[name^='roomtypenum']");
}
  
//==============================================================================

wiresJS.getRoomType = function (jq_form) {
    var query = "select[name^='roomtype']:not([name^='roomtypenum']):not([name$='childage1'])";
    return wiresJS.getJqFormObject(jq_form, query);
}

//==============================================================================

wiresJS.buildDateObj = function (prefix, now_year, now_date) {
  var month= wiresJS.getMonth(prefix);
  var day  = wiresJS.getDay(prefix);
  var hour = wiresJS.getHourVal(prefix);
  var min = 0;
  var sec = 0;
  var hourText = wiresJS.getHourText(prefix);

  var re = new RegExp("\\d+:\\d+","ig");
  if(undefined != hourText && !re.test(hourText)) {
    hour = 23;
    min = 59;
    sec = 59;
  }
  var current_date_build = new Date();
  current_date_build.setFullYear(now_year, month.val(), day.val());
  current_date_build.setHours(hour);
  current_date_build.setMinutes(min);
  current_date_build.setSeconds(sec);
  current_date_build.setMilliseconds(0) 
  
  if (current_date_build<now_date) {
    current_date_build.setFullYear(parseInt(now_year)+1, month.val(), day.val());
  }
  return current_date_build;
}

//==============================================================================

wiresJS.getForm = function  (js_form) {
  //it is some kind of macros - just return js query form if present and all
  //forms if not ...
  if (js_form==undefined)
    return $(document.forms);
  return $(js_form);
}

//==============================================================================

wiresJS.getTripType = function (js_form) {
    return wiresJS.getForm(js_form).find("[name = 'triptype']");
}

//==============================================================================

wiresJS.getMonth = function  (prefix, js_form) {
  return wiresJS.getForm(js_form).find( "*[name='"+prefix+"month']" );
}

//==============================================================================

wiresJS.getDay = function  (prefix, js_form) {
  return wiresJS.getForm(js_form).find( "*[name='"+prefix+"day']" );
}

//==============================================================================

wiresJS.getHour = function  (prefix, js_form) {
  return wiresJS.getForm(js_form).find( "*[name='"+prefix+"hour']" );
}

//==============================================================================

wiresJS.getHourText = function  (prefix, js_form) {
  return wiresJS.getForm(js_form).find( "*[name='"+prefix+"hour'] :selected" ).text();
}

//==============================================================================

wiresJS.getAmPm = function  (prefix, js_form) {
  return wiresJS.getForm(js_form).find( "*[name='"+prefix+"ampm']" );
}

//==============================================================================

wiresJS.getHourVal = function  (prefix, js_form) {
  var hour = parseInt(wiresJS.getHour(prefix).val());
  var ampm = wiresJS.getAmPm (prefix).val();
  if (undefined!=ampm && ''!=ampm) {
    if ("AM" == ampm && 12 == hour) {
      hour=0;
    }
    else if("PM" == ampm) {
      if(12 != hour) {
          hour+=12;
      }
    }
  }
  return hour;
}

//==============================================================================
wiresJS.getJqFormObject = function (jq_form, query) {
  return wiresJS.getForm(jq_form).find(query);
}

//==============================================================================

wiresJS.getFieldFromForm = function  (field_type, jq_form, has_text_in_name, has_not_text_in_name) {
  var query = field_type+"[name*='"+has_text_in_name+"']";
  if (undefined!=has_not_text_in_name) {
    query+= ":not([name*='"+has_not_text_in_name+"'])";
  }
  return wiresJS.getJqFormObject(jq_form, query);
}

//==============================================================================

wiresJS.getTextField = function  (jq_form, has_text_in_name, has_not_text_in_name) {
  return wiresJS.getFieldFromForm(":text", jq_form, has_text_in_name, has_not_text_in_name);
}

//==============================================================================

wiresJS.getHiddenField = function  (jq_form, has_text_in_name, has_not_text_in_name) {
  return wiresJS.getFieldFromForm(":hidden", jq_form, has_text_in_name, has_not_text_in_name);
}

//==============================================================================

wiresJS.getSelectField = function  (jq_form, has_text_in_name, has_not_text_in_name) {
  return wiresJS.getFieldFromForm(":input", jq_form, has_text_in_name, has_not_text_in_name);
}

//==============================================================================

wiresJS.getRadioField = function  (jq_form, has_text_in_name, has_not_text_in_name) {
  return wiresJS.getFieldFromForm(":radio", jq_form, has_text_in_name, has_not_text_in_name);
}

//==============================================================================

wiresJS.getCheckBoxField = function  (jq_form, has_text_in_name, has_not_text_in_name) {
  return wiresJS.getFieldFromForm(":checkbox", jq_form, has_text_in_name, has_not_text_in_name);
}

//==============================================================================

wiresJS.getFieldWithClassName = function  (jq_form, class_name) {
  return wiresJS.getJqFormObject(jq_form, "."+class_name);
}

//==============================================================================

wiresJS.getFieldWithId = function  (jq_form, id) {
  return wiresJS.getJqFormObject(jq_form, "#"+id);
}

//==============================================================================

wiresJS.hasEmptyTextField = function  (jq_form, has_text_in_name, has_not_text_in_name) {
  var res = false;
  wiresJS.getTextField (jq_form, has_text_in_name, has_not_text_in_name).each( function () {
    if (!res && (''==$(this).val())) {
      res=true;
    }
  } );
  return res;
}

//==============================================================================

wiresJS.textFieldMatchRE = function  (jq_form, reg_exp, has_text_in_name, has_not_text_in_name) {
  var res = true;
  wiresJS.getTextField (jq_form, has_text_in_name, has_not_text_in_name).each( function () {
    res = res && reg_exp.test($(this).val());
  } );
  return res;
}

//==============================================================================

wiresJS.PopUp = new Object();

wiresJS.PopUp.isPopUpShown = false;
wiresJS.PopUp.PopUpBox = null;
wiresJS.PopUp.PopUpBoxContent = null;
wiresJS.PopUp.currentElement = null;
wiresJS.PopUp.isIEorOpera = null;
wiresJS.PopUp.isIE6orLess = null;
wiresJS.PopUp.realOffsetLeft = 0;
wiresJS.PopUp.realOffsetTop = 0;
wiresJS.PopUp.pageWidth = 0;
wiresJS.PopUp.direction = 'ltor';
wiresJS.PopUp.tail = null;
wiresJS.PopUp.tailRight = null;
wiresJS.PopUp.x = 0;
wiresJS.PopUp.y = 0;

wiresJS.PopUp.PopUpBalloon = function (text, e , force, detailsUrl) {
    if (force) {
        this.isPopUpShown = false;
        $("#PopUpFrameBoxContent").css({"position" : "static"});
        $("#PopUpFrameBoxCloseButton").css({"display": "block", "position": "static"});
        $("#PopUpFrameBoxContent").css({"overflow" : "visible", "width": "auto", "height": "auto"});

        var detailsCloseButon = $("#PopUpFrameBoxDetailsCloseButton");
        detailsCloseButon.css({"display": "none"});
        detailsCloseButon.unbind("click");
        detailsCloseButon.click(wiresJS.GMap.loadHotelInfo);

        var detailsButon = $("#PopUpFrameBoxDetailsButton");
        detailsButon.css({"display": "block"});
        detailsButon.unbind("click");
        detailsButon.click(function() { wiresJS.GMap.loadDetails( detailsUrl) });
    }
    else {
        this.isPopUpShown = false;
    }

    if(!this.isPopUpShown ) {
        if (!force) {
            $("#PopUpFrameBoxCloseButton").css({"display": "none"});
            $("#PopUpFrameBoxDetailsButton").css({"display": "none"});
            $("#PopUpFrameBoxDetailsCloseButton").css({"display": "none"});
            $("#PopUpFrameBoxContent").css({"overflow" : "visible", "width": "auto", "height": "auto"});
        }
        this.tail = $("#PopUpFrameBoxWraper .PopUpFrameBoxTail");
        this.tailRight = $("#PopUpFrameBoxWraper .PopUpFrameBoxTailRight");
        this.isIEorOpera = ((document.all) ? true : false);
        this.isIE6orLess = ((navigator.appName == 'Microsoft Internet Explorer' &&
        parseFloat(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE") + 4)) <= 6.5)
        ? true : false);
        this.PopUpBox = document.getElementById("PopUpFrameBoxWraper");
        this.PopUpBoxContent = document.getElementById("PopUpFrameBoxContent");
        if (this.isIEorOpera) {
            this.currentElement = event.srcElement;
        }
        else {
            this.currentElement = e.currentTarget;
        }
        this.PopUpBoxContent.innerHTML = text;
        this.pageWidth = document.body.clientWidth;
        this.realOffsetLeft = this.PopUpBox.offsetParent.offsetLeft;
        this.realOffsetTop = this.PopUpBox.offsetParent.offsetTop;


        this.PopUpBox.style.zIndex = 1000;
        this.PopUpBox.style.position = "absolute";


    }
  
  if (this.isIEorOpera) {
    this.x = this.mouseX(event);
    this.y = this.mouseY(event);
  }
  else {
    this.x = this.mouseX(e);
    this.y = this.mouseY(e);
  }
  
  var additionalWidth = 0;
  if (force) {
      additionalWidth = 500;
  }
  
  if ((this.x + this.PopUpBox.clientWidth + additionalWidth) > this.pageWidth && !this.isPopUpShown) {
    this.direction = 'rtol';
    this.tail.css("visibility", "hidden");
    this.tailRight.css("visibility", "visible");
  }
  else if (!this.isPopUpShown){
    this.direction = 'ltor';
    this.tail.css("visibility", "visible");
    this.tailRight.css("visibility", "hidden");
  }
  
  if (this.x < this.PopUpBox.clientWidth && this.direction == 'rtol' && !this.isPopUpShown) {
      this.PopUpBox.style.width = this.x + "px";
  }
  
  if (this.isIE6orLess && !this.isPopUpShown) {
    $("#PopUpFrameBoxWraper iframe").css('height', (this.PopUpBox.clientHeight - 16) + "px");
  }
  
  this.isPopUpShown = true;
  this.x -= this.realOffsetLeft;
  this.y -= this.realOffsetTop;
  this.x -= 10;
  this.y -= this.PopUpBox.clientHeight + 3;
  if (this.direction == 'rtol') { 
    this.x += 20;
    this.x -= this.PopUpBox.clientWidth
  }
  this.PopUpBox.style.left = this.x + "px";
  this.PopUpBox.style.top = this.y + "px";
}

wiresJS.PopUp.PopUpBalloonHide = function () {
  if (this.PopUpBox) {
      this.isPopUpShown = false;
      this.PopUpBox.style.zIndex = -1000;
      this.PopUpBox.style.left = -3000 + "px";
      this.PopUpBox.style.top = -3000 + "px";
      this.PopUpBox.style.width = "auto";
  }
}

wiresJS.PopUp.mouseX = function (e) {
  if (e.pageX) {
    return e.pageX;
  }
  else if (e.clientX){
     return e.clientX + (document.documentElement.scrollLeft ?
     document.documentElement.scrollLeft :
     document.body.scrollLeft);
  }
  else return null;
}

wiresJS.PopUp.mouseY = function(e) {
  if (e.pageY) {
    return e.pageY;
  }
  else if (e.clientY){
     return e.clientY + (document.documentElement.scrollTop ?
     document.documentElement.scrollTop :
     document.body.scrollTop);
  }
  else return null;
}

wiresJS.showHideBaggagesBillboard = function (form_id, show) {
  var jq_form=$('#'+form_id);
  var baggage_el=wiresJS.getHiddenField (jq_form, 'numberofbags');
  var baggage_billboard = baggage_el.parents('.Billboard').eq(0);
  baggage_billboard.find('select').change();
  if (show)
    baggage_billboard.show();
  else
    baggage_billboard.hide();
}

wiresJS.PopUpAnnotatedListResize = function() {
  var left = $("#PopUpAnnotatedList .PopUpAnnotatedListColumn").eq(0);
  if (left.length == 0) { 
    return;
  }
  var leftColumn = $(".PaneBox", left).filter(function(index){
    return $(this).css('display') != 'none';
  });
  left = $(".PaneBoxContent", leftColumn);
  var leftHeights = new Array();
  var right = $("#PopUpAnnotatedList .PopUpAnnotatedListColumn").eq(1);
  var rightColumn = $(".PaneBox", right).filter(function(index){
    return $(this).css('display') != 'none';
  });
  right = $(".PaneBoxContent", rightColumn);
  var rightHeights = new Array();
  var leftHeight = 0;
  var rightHeight = 0;

  if (wiresJS.annotatedListBoxes.length != 0) {
    for(var i=0;i<left.length;i++) {
      if (wiresJS.LastAnnotatedListBoxes[$(leftColumn[i]).attr('id')] != left[i].clientHeight) {
        leftHeights[$(leftColumn[i]).attr('id')] = wiresJS.LastAnnotatedListBoxes[$(leftColumn[i]).attr('id')] +  (left[i].clientHeight - wiresJS.LastAnnotatedListBoxes[$(leftColumn[i]).attr('id')]);
        leftHeights.length++;
      }else{
        leftHeights[$(leftColumn[i]).attr('id')] = wiresJS.LastAnnotatedListBoxes[$(leftColumn[i]).attr('id')];
        leftHeights.length++;
      }
      leftHeight += leftHeights[$(leftColumn[i]).attr('id')] + 30;
    }
    for(var i=0;i<right.length;i++) {
      if (wiresJS.LastAnnotatedListBoxes[$(rightColumn[i]).attr('id')] != right[i].clientHeight) {
        rightHeights[$(rightColumn[i]).attr('id')] = wiresJS.LastAnnotatedListBoxes[$(rightColumn[i]).attr('id')] + (right[i].clientHeight - wiresJS.LastAnnotatedListBoxes[$(rightColumn[i]).attr('id')]);
        rightHeights.length++;
      }
      else{
        rightHeights[$(rightColumn[i]).attr('id')] = wiresJS.LastAnnotatedListBoxes[$(rightColumn[i]).attr('id')];
        rightHeights.length++;
      }
      rightHeight += rightHeights[$(rightColumn[i]).attr('id')] + 30;
    }
  }
  else {
    for(var i=0;i<right.length;i++) {
      wiresJS.annotatedListBoxes[$(rightColumn[i]).attr('id')] = right[i].clientHeight;
      wiresJS.annotatedListBoxes.length++;
      rightHeights[$(rightColumn[i]).attr('id')] = wiresJS.annotatedListBoxes[$(rightColumn[i]).attr('id')];
      rightHeights.length++;
      rightHeight += rightHeights[$(rightColumn[i]).attr('id')] + 30;
    }
    for(var i=0;i<left.length;i++) {
      wiresJS.annotatedListBoxes[$(leftColumn[i]).attr('id')] = left[i].clientHeight;
      wiresJS.annotatedListBoxes.length++;
      leftHeights[$(leftColumn[i]).attr('id')] = wiresJS.annotatedListBoxes[$(leftColumn[i]).attr('id')];
      leftHeights.length++;
      leftHeight += leftHeights[$(leftColumn[i]).attr('id')] + 30;
    }
  }

  var currentHeight = 0;
  var addHeight = leftHeight - rightHeight;
  
  if (addHeight < 0) {
    addHeight = Math.abs(addHeight);
    for(var i=0;i<left.length;i++) {
      currentHeight = (addHeight * (leftHeights[$(leftColumn[i]).attr('id')] +30) /  leftHeight) + leftHeights[$(leftColumn[i]).attr('id')];
      $(left[i]).css('height', Math.round(currentHeight));
    }
  }
  else if (addHeight > 0) {
    for(var i=0;i<right.length;i++) {
      currentHeight = (addHeight * (rightHeights[$(rightColumn[i]).attr('id')] + 30) / rightHeight) + rightHeights[$(rightColumn[i]).attr('id')];
      $(right[i]).css('height', Math.round(currentHeight));
      
    }
  }
  
  addHeight = leftHeight - rightHeight;
  for(var i=0;i<left.length;i++) {
    wiresJS.LastAnnotatedListBoxes[$(leftColumn[i]).attr('id')] = left[i].clientHeight;
    wiresJS.LastAnnotatedListBoxes.length++;
    if (addHeight > 0) {
      $(left[i]).css('height', Math.round(leftHeights[$(leftColumn[i]).attr('id')]));
    }
  }

  for(var i=0;i<right.length;i++) {
    wiresJS.LastAnnotatedListBoxes[$(rightColumn[i]).attr('id')] = right[i].clientHeight;
    wiresJS.LastAnnotatedListBoxes.length++;
    if (addHeight < 0) {
      $(right[i]).css('height', Math.round(rightHeights[$(rightColumn[i]).attr('id')]));
    }
  }
};

//==============================================================================
wiresJS.EntitiesToText = function (strEncodedText) 
{
    var strData    = String(strEncodedText);
    var objRegExp  = new RegExp("&#(x?)([0-9A-Z]+);", "ig");

    /* FOR EACH MATCH TO ANY ENTITY, REPLACE THAT
    ENTITY GLOBALLY WITH ITS SINGLE CHAR EQUIVALENT */
    var matched = strData.match(objRegExp);
    if (matched != null) {
        for (var i=0;i < matched.length;i++) {
            matched[i].match(objRegExp);
            var strCharMatch   = RegExp.$2;
            var strRadixMatch  = RegExp.$1;
            var strRadix 	   = 10;		// Default is dec (10)
            if (strRadixMatch == 'x') strRadix = 16;
            var objRegExpMatch = new RegExp("&#x?" + strCharMatch + ";", "ig");
            strData = strData.replace(objRegExpMatch, String.fromCharCode(parseInt(strCharMatch, strRadix)));
        }
    }
    return strData;
}

// we redeclare alert function, because html entities are not displayed correctly
wiresJS_originalAlert = window.alert;
window.alert = function (str) {
	wiresJS_originalAlert(wiresJS.EntitiesToText(str));
}

wiresJS_originalConfirm = window.confirm;
window.confirm = function (str) {
	return wiresJS_originalConfirm(wiresJS.EntitiesToText(str));
}


wiresJS.setAllowedDestinations = function (fromCode, toSelectId)
{
    if (wiresJS.alloweddestinations[fromCode]) {
        var listOfOptions = wiresJS.alloweddestinations[fromCode];
        var toSelect = $("#"+toSelectId)[0];
        var lenToSelect = toSelect.options.length;
        for (var i = 1;i<lenToSelect; i++) {
            toSelect.remove(1);
        }
        
        for(var i = 0;i<listOfOptions.length; i++) {
            var tmpOption = document.createElement('option');
            tmpOption.value = listOfOptions[i].code;
            tmpOption.text = listOfOptions[i].cityname;
            if ($.browser.msie) {
                toSelect.add(tmpOption);
            }
            else {
                toSelect.add(tmpOption, null);
            }
        }
        
    }
}


wiresJS.fillFormByNames = function (obj)
{
    var name;
    var element;
    for(name in obj) {
        element = $("[name="+name+"]", document.forms).eq(0);
        element.val(obj[name]);
        element.change();
    }
}


wiresJS.numptc_onchange = function (obj)
{
  var total = 0;

  $('select[name*=numptc]').each( function() {
    total = total + parseInt($(this).val());
  } );
  
  if(total > 9){
    obj.selectedIndex = 0;
    return true;
  }
}

wiresJS.getGeonameId = function (form){
  var geoname_id = form.find('#geoname_id');
  var hotcity = form.find('#hotcity');
  if(geoname_id.length)
    return geoname_id;
}
