/* 17u hotel */
function _17u_hotel_city_suggester_simple(inputEL,onSelect,onEnter,onDatabaseLoaded)
{

    this.parent.construct(this,inputEL,onSelect,onEnter,onDatabaseLoaded);

}

_17u_hotel_city_suggester_simple.class_extend(ctrip_city_suggester_simple);

_17u_hotel_city_suggester_simple.prototype.get_city_list_url=function()
{
    return '/copartner/17u/ajax/hotel_city_list.ue';
};




placeholderSetup('ctrip_jiudian_name');

/** -------    预定框中选择不同预定项目   显示处理            --------------  **/

var arr_preconcert_view_id = ["place-preconcert-view-jiudian","place-preconcert-view-canguan","place-preconcert-view-jipiao","place-preconcert-view-xianlu"]; 
var arr_preconcert_bar_id = ["place-preconcert-bar-jiudian","place-preconcert-bar-canguan","place-preconcert-bar-jipiao","place-preconcert-bar-xianlu"];
var last_view_id = 3; 

function place_preconcert_onclick(id){
    if (id != last_view_id){
	var el = ge(arr_preconcert_bar_id[last_view_id]);
	RemoveClass(el,"place-preconcert-bar-td-active");
	
	el = ge(arr_preconcert_bar_id[id]);
	AddClass(el,"place-preconcert-bar-td-active");
	
	el = ge(arr_preconcert_view_id[last_view_id]);
	RemoveClass(el,"place-preconcert-div-view-active");
	
	el = ge(arr_preconcert_view_id[id]);     
	AddClass(el,"place-preconcert-div-view-active");
	last_view_id = id;
    }
}

/**   机票单选按钮 对日期框 的影响JS处理  开始        **/

/** 同城机票单选按钮处理 **/
var oText_jipiao_fcdate = document.getElementById("jipiao_fcdate");
var oText_jipiao_fctime = document.getElementById("jipiao_fctime");
var jipiao_radio_last_value = 0;

oText_jipiao_fcdate.disabled = true;
oText_jipiao_fctime.disabled = true;

function jipiao_selectTriptype(value){
    var el;
    if (value == 0){
	if(jipiao_radio_last_value == 1){
	    oText_jipiao_fcdate.disabled = true;
	    oText_jipiao_fctime.disabled = true;
	    el = ge("jipiao_fcdate");
	    AddClass(el,"place-preconcert-inputtext-dis-active");
	    el = ge("jipiao_fctime");
	    AddClass(el,"place-preconcert-inputtext-dis-active");
	    jipiao_radio_last_value = 0;
	}
    }else{
	if (jipiao_radio_last_value == 0){
	    oText_jipiao_fcdate.disabled = false;
            oText_jipiao_fctime.disabled = false;
	    el = ge("jipiao_fcdate");
            RemoveClass(el,"place-preconcert-inputtext-dis-active");
            el = ge("jipiao_fctime");
            RemoveClass(el,"place-preconcert-inputtext-dis-active");
	    jipiao_radio_last_value = 1;
	}
    }
}


/**   预定框中城市input框 选择后的回调处理  BEN       **/
function onyuding_jiudian_cityname_737(g,sg)
{
  //alert(DumpObj(g));
    var oText_jiudian_cityname = document.getElementById("jiudian_city_name");
    var oText_jiudian_cityId = document.getElementById("jiudian_cityId"); 
   
    oText_jiudian_cityname.value = g.name;
    oText_jiudian_cityId.value = g.id;
    //alert(oText_jiudian_cityID.value);
    sg.do_not_reset = true;
    setTimeout(function(){sg.close_suggester();},100);
}
onloadRegisterHandler(function(){
    var el = ge("jiudian_city_name");
  //  var x = new ctrip_city_suggester_simple(el,onyuding_jiudian_cityname_737,null,null,true);
    var x = new _17u_hotel_city_suggester_simple(el,onyuding_jiudian_cityname_737,null,null,true);
    addEventBase(el,'mousedown',x.search_build_checker.bind(x),el.id);
});

function onyuding_jipiao_cf_cityname_737(g,sg)
{
    var oText_jipiao_cf_cityname = document.getElementById("jipiao_cf_cityname");
    var oText_jipiao_cf_cityvalue = document.getElementById("jipiao_cf_city_value");
    
    oText_jipiao_cf_cityname.value = g.name;
    oText_jipiao_cf_cityvalue.value = g.val;
    
    sg.do_not_reset = true;
    setTimeout(function(){sg.close_suggester();},100);

}
onloadRegisterHandler(function(){
    var el = ge("jipiao_cf_cityname");
    var x = new _17u_city_suggester_simple(el,onyuding_jipiao_cf_cityname_737.bind(this),null,null,true);
    addEventBase(el,'mousedown',x.search_build_checker.bind(x),el.id);
});

function onyuding_jipiao_zd_cityname_737(g,sg)
{
    var oText_jipiao_zd_cityname = document.getElementById("jipiao_zd_cityname");
    var oText_jipiao_zd_cityvalue = document.getElementById("jipiao_zd_city_value");

    oText_jipiao_zd_cityname.value = g.name;
    oText_jipiao_zd_cityvalue.value = g.val;
    
    sg.do_not_reset = true;
    setTimeout(function(){sg.close_suggester();},100);

}
onloadRegisterHandler(function(){
    var el = ge("jipiao_zd_cityname");
    var x = new _17u_city_suggester_simple(el,onyuding_jipiao_zd_cityname_737.bind(this),null,null,true);
    addEventBase(el,'mousedown',x.search_build_checker.bind(x),el.id);
});



/** 预定框中日期input框  日历框的调入处理  BEG**/
onloadRegisterHandler(function(){
    try{
	new CtripCalendar(ge('ctrip_starttime')).build_selecter();
	new CtripCalendar(ge('ctrip_deptime')).build_selecter();
	/** 同城机票部分  **/
	new CtripCalendar(ge('jipiao_cfdate')).build_selecter();
        new CtripCalendar(ge('jipiao_fcdate')).build_selecter();

/**  国航机票部分  
    new CtripCalendar(ge('jipiao_cftime')).build_selecter();
    new CtripCalendar(ge('jipiao_zztime')).build_selecter();
    new CtripCalendar(ge('jipiao_fctime')).build_selecter();
  **/
    }catch(ex){ alert(ex); }
});
/** 预定框中日期input框  日历框的调入处理  END**/


/** 酒店预定中输入信息出错提示框 处理  BEG   **/
function AlertTip(el,tip,tp){

  this.sign = 'alerttip'+gen_unique();
    this.obj = null;
    this.iframe = null;
    this.target = el;
    this.tip = tip;
     
    if (arguments.length >= 3){
	this.tp = tp;
    }else{
	this.tp = 0;
    }
    this.build_tip();
    
    if(this.should_use_iframe)
      this.build_iframe();

    this.show();
}

AlertTip.prototype.should_use_iframe=ua.ie()<7||(ua.osx()&&ua.firefox());

AlertTip.prototype.hide = function(){
    this.obj.style.display = "none";
    if(this.iframe)  this.iframe.style.display = "none";
};
AlertTip.prototype.build_tip = function(){
    var div = document.createElement('div');
    div.setAttribute('style','');
    div.style.display = "none";
    div.style.position = "absolute";
    div.style.zIndex = '300';
    onloadRegisterHandler(function(){
        document.body.appendChild(div);
    });
    this.obj = div;
    
     if (this.tp == 1){
	 var html = "<div style=\"background-color:#FFFFC9;text-align:left;padding-top:2px;\"><span style=\"color:red;\">"+this.tip+"</span></div>";
    }else{
	if(this.tp == 2){
	    var html = "<div style=\"background-color:#FFFFFF;text-align:left;padding-top:2px;\"><span style=\"color:red;\">"+this.tip+"</span></div>";
	}else{
	    var html = "<div><span style=\"color:red;\">"+this.tip+"</span></div>";
	}
    }
    set_inner_html(this.obj,html);
    var d_mousedown = function(){
	this.hide();
    }.bind(this);
    addEventBase(document,"mousedown",d_mousedown,this.sign);
    
    var o_mousedown = function(e){
	stopPropagation(e);
    }
    
    addEventBase(this.obj,"mousedown",o_mousedown,this.sign);

    return this;

};
AlertTip.prototype.reset_tip = function(){
    var xy = GetPageOffset(this.target);
    var w = this.target.offsetWidth;
    
    if (this.tp){
	this.obj.style.left = (xy.x - 5)+'px';
	this.obj.style.top = (xy.y-18)+'px';
    }else{
	this.obj.style.left = (xy.x+2)+'px';
	this.obj.style.top = (xy.y-18)+'px';
    }
    if(this.should_use_iframe)
      this.reset_iframe();
};
AlertTip.prototype.show = function (){
    if(this.obj && this.obj.style.display){
	this.obj.style.visibility='hidden';
        this.obj.style.display='';
        this.reset_tip();
        this.obj.style.visibility='';
    }else{
	this.reset_tip();
    }
    return this;
};
AlertTip.prototype.build_iframe=function()
{

  if(!this.iframe&&!(this.iframe=ge('AlertTip_iframe'))){
    this.iframe=document.createElement('iframe');
    this.iframe.id='AlertTip_iframe';
  }

  this.iframe.frameBorder='0';

  this.iframe.setAttribute('style','');
  this.iframe.style.position='absolute';
  this.iframe.style.zIndex = 5;
  this.iframe.style.top = this.iframe.style.left = '-1000px';


  /** filter:alpha(opacity=0); **/
  if("opacity" in this.iframe.style){
    this.iframe.style.opacity=0;
  }else if("MozOpacity" in this.iframe.style){
    this.iframe.style.MozOpacity=0;
  }else if("filter" in this.iframe.style){
    this.iframe.style.filter="alpha(opacity=0)";
  }

  onloadRegisterHandler(function(){
      document.body.appendChild(this.iframe);
    }.bind(this));

  return this;
};

AlertTip.prototype.reset_iframe=function()
{
  this.iframe.style.display="";
  var xy = GetPageOffset(this.obj);

  this.iframe.style.top = xy.y+'px';
  this.iframe.style.left = xy.x+'px';
  this.iframe.style.width = this.obj.offsetWidth+'px';
  this.iframe.style.height = this.obj.offsetHeight+'px';
};
  /** 酒店预定中输入信息出错提示框 处理  END   **/
/**  酒店预定form提交处理 BEG  **/
function preconcert_jiudian_onsubmit(form,tp){
    var perdate=form["perdate"].value,postdate=form["postdate"].value;
    var perdateCalc=CtripCU.isDateTime(perdate);
    var postdateCalc=CtripCU.isDateTime(postdate);
    var cityname=form["cityname"].value,cityId=form["cityId"].value,city=form["city"].value,district=form["district"].value;
    var starttime=form["starttime"].value,deptime=form["deptime"].value;
    var b_TP = 0;
    if (arguments.length >= 2 && tp){
	b_TP = tp;
    }
    var Price=form["Price"].value;
    var bistrue = true;
    var flag=[];
  if (starttime == ""){
      new AlertTip(ge("ctrip_starttime"),"*请选择入住日期",b_TP); 
    bistrue = false;
  }else{
    flag[0]=CtripCU.isDateTime(starttime);
    if (!flag[0]){
	new AlertTip(ge("ctrip_starttime"),"*日期格式为yyyy-mm-dd",b_TP);
      bistrue = false;
    }else if (perdateCalc&&flag<perdateCalc){
	new AlertTip(ge("ctrip_starttime"),"*入住时间不能早于"+perdate,b_TP);
      bistrue = false;
    }
  }
  if (deptime == ""){
      new AlertTip(ge("ctrip_deptime"),"*请选择离店日期",b_TP);
    bistrue = false;
  }else{
    flag[1]=CtripCU.isDateTime(deptime);
    if (!flag[1]){
	new AlertTip(ge("ctrip_deptime"),"*日期格式为yyyy-mm-dd",b_TP);
      bistrue = false;
    }
  }
  if (bistrue){
    if (flag[1]<=flag[0]){
	new AlertTip(ge("ctrip_starttime"),"*离店日期必须晚于入住日期，请重新选择.",b_TP);
      bistrue = false;
    }else if (flag[1]-flag[0]>2419200000){
	new AlertTip(ge("ctrip_deptime"),"入住不能超过28天",b_TP);
      bistrue = false;
    }
  }
  if (cityname == ""){
      new AlertTip(ge("jiudian_city_name"),"*请选择宾馆所在城市",b_TP);
    bistrue = false;
  }
  if (bistrue){
    function adjustCityId(id){
      id=parseInt(id,10);
      if (id<20000)
	return id-100;
      if (id<80000)
	return id-20000;
      return id-80000;
    }
    if (cityId>80000){
      district = adjustCityId(cityId);
      city="";
    }else{
      city = adjustCityId(cityId);
      district ="";
    }
    form["city"].value = city;
    form["district"].value = district;
    if (form["htln"].getAttribute("placeholder") && form["htln"].value == form["htln"].getAttribute("placeholder")){
      form["htln"].value = "";
    }
  }
  return bistrue;
};
/**  酒店预定form提交处理 END  **/

/** 机票预定form递交处理 BEG  **/

function jipiao_onsubmit(form,tp){
    var cf_cityname = form["jipiao_cf_cityname"].value,zd_cityname = form["jipiao_zd_cityname"].value;
    var cf_cityval = form["jipiao_cf_city_value"].value,zd_cityval = form["jipiao_zd_city_value"].value;
    var cf_date = form["jipiao_cfdate"].value,fc_date = form["jipiao_fcdate"].value;
    var cf_time = form["jipiao_cf_time"].value,fc_time = form["jipiao_fc_time"].value;
    var triptype = ge("triptype-id").checked;
   
    var b_TP = 0;
    if (arguments.length >= 2 && tp){
	b_TP = tp;
    }
    var bistrue = true;
    var date_flag = [];
    
    if (cf_date =="" || (fc_date =="" && triptype)){
	new AlertTip(ge("jipiao_cfdate"),"*请选择出发日期/返程日期",b_TP);
	bistrue = false;
    }else{
	date_flag[0] = CtripCU.isDateTime(cf_date);
	date_flag[1] = CtripCU.isDateTime(fc_date);
	if ( !date_flag[0] || (!date_flag[1] && triptype)){
	    new AlertTip(ge("jipiao_cfdate"),"*日期格式需为yyyy-mm-dd",b_TP);
	    bistrue = false;
	}else{
	    if (triptype && (date_flag[1]<date_flag[0])){
		new AlertTip(ge("jipiao_cfdate"),"*返程日期不得早于出发日期",b_TP);
		bistrue = false;
	    }
	}
    }
    if (cf_cityname == "" || zd_cityname == ""){
	new AlertTip(ge("jipiao_cf_cityname"),"*请选择出发城市/到达城市",b_TP)
	bistrue = false;
    }else{
	if((cf_cityname == zd_cityname) || (cf_cityval == zd_cityval)){
	    new AlertTip(ge("jipiao_cf_cityname"),"*出发/到达城市不能相同",b_TP)
	    bistrue = false;
	}
    }
    
    return bistrue;
}

