{
var isIE6=navigator.userAgent.toLowerCase().indexOf("msie 6.0")>0;
var SiteHeader = Class.create({
	currentTab: 'find_location_input',
	clientInfo: null,
	localAddrs: new Array(),
	//localRecs: new Array(),
	initialize: function(clientInfo){
		this.mapInput = $('input_field_gm'),
		this.mapLlInput = $('input_field_get_map_ll'),
		this.mapAddrInput = $('input_field_get_map_addr'),
		this.routeStartInput = $('input_field_st'),
		this.routeDestInput = $('input_field_ed'),
		this.routeStartLlInput = $('input_field_route_start_ll');
		this.routeDestLlInput = $('input_field_route_dest_ll');
		this.routeStartAddrInput = $('input_field_route_start_addr');
		this.routeDestAddrInput = $('input_field_route_dest_addr');
		this.poiKeyWordInput = $('input_field_poi_key_word'),
		this.poiInput = $('input_field_poi'),
		this.poiLlInput = $('input_field_poi_address_ll');
		this.poiAddrInput = $('input_field_poi_address_single');
		this.searchBarForm = $('searchBarForm');
		this.clientInfo = defaultClientInfo;
		if (clientInfo)
			this.clientInfo = $H(this.clientInfo).merge(clientInfo).toObject();
		//main panel
		$('find_location_input_btn').observe('click',this.switchPanel.bind(this,'find_location_input'));
		$('get_route_input_btn').observe('click',this.switchPanel.bind(this,'get_route_input'));
		$('search_poi_input_btn').observe('click',this.switchPanel.bind(this,'search_poi_input'));
		
		$('re_route').observe('click',this.reverseRouteAddress.bind(this));
		
		if ($("changeThemesLink")!=null) {
			$("changeThemesLink").observe("click", this.openThemesDialog.bind(this));
		}
		if ($('themeDiagTrigger')) $('themeDiagTrigger').observe("click", this.closeThemes.bind(this));
		if ($('themeClassic')) $('themeClassic').observe("click", this.applyTheme.bind(this, 'default'));
		if ($('themeClassicApplyBtn')) $('themeClassicApplyBtn').observe("click", this.applyTheme.bind(this, 'default'));
		if ($('themeClean')) $('themeClean').observe("click", this.applyTheme.bind(this, 'simple_gray'));
		if ($('themeCleanApplyBtn')) $('themeCleanApplyBtn').observe("click", this.applyTheme.bind(this, 'simple_gray'));
		if ($('themeLBlue')) $('themeLBlue').observe("click", this.applyTheme.bind(this, 'simple_blue'));
		if ($('themeLBlueApplyBtn')) $('themeLBlueApplyBtn').observe("click", this.applyTheme.bind(this, 'simple_blue'));
		
		//
		if($('map_btn_get_map'))
			$('map_btn_get_map').observe('click',this.getMap.bind(this));
		if($('map_btn_get_route'))
			$('map_btn_get_route').observe('click',this.getRoute.bind(this));
		if($('map_btn_get_pois'))
			$('map_btn_get_pois').observe('click',this.getPoi.bind(this));

		this.mapInput.observe('keydown',this.submitForm.bind(this,'input_field_gm'));
		
		this.handler = this.sendToPhone.bind(this);
		this.mapInput.observe('keyup', this.activeSendToPhoneLink.bind(this));
		
		this.routeStartInput.observe('keydown',this.submitForm.bind(this,'input_field_st'));
		this.routeDestInput.observe('keydown',this.submitForm.bind(this,'input_field_ed'));
		this.poiKeyWordInput.observe('keydown',this.submitForm.bind(this,'input_field_poi_key_word'));
		this.poiInput.observe('keydown',this.submitForm.bind(this,'input_field_poi'));
		
		//dropdown to get addresses
		if ($('loadAddrTrigger_gm'))
			$('loadAddrTrigger_gm').observe('click',this.fetchAddressList.bind(this,'get_map'));
		if ($('loadAddrTrigger_st'))
			$('loadAddrTrigger_st').observe('click',this.fetchAddressList.bind(this, 'route_start'));
		if ($('loadAddrTrigger_ed'))
			$('loadAddrTrigger_ed').observe('click',this.fetchAddressList.bind(this, 'route_dest'));
		if ($('loadAddrTrigger_poi'))
			$('loadAddrTrigger_poi').observe('click',this.fetchAddressList.bind(this, 'poi_address'));
			
	},
	
	getMapInputInfo: function(){
		return {'addr':this.mapInput.value,'ll':this.mapInput.value};
	},
	
	setMapInputInfo: function(addr,ll){
		if (addr) {
			this.mapInput.value = addr;
			this.mapAddrInput.value = addr;
		}
		if (ll) 
			this.mapLlInput.value = ll;
	},
	
	getRouteInputInfo: function() {
		return {'stAddr':this.routeStartInput.value,'deAddr':this.routeDestInput.value,
				'stll':this.routeStartLlInput.value,'dell':this.routeDestLlInput.value};
	},
	
	setRouteInputInfo: function(stAddr, deAddr, stll, dell) {
		if (stAddr) {
			this.routeStartInput.value = stAddr;
			this.routeStartAddrInput.value = stAddr;
		}
		if (deAddr) {
			this.routeDestInput.value = deAddr;
			this.routeDestAddrInput.value = deAddr;
		}
		if (stll)
			this.routeStartLlInput.value = stll;
		if (dell)
			this.routeDestLlInput.value = dell;
	},
	
	getPoiInputInfo: function() {
		return {'keyWord':this.poiKeyWordInput.value,'addr':this.poiInput.value,'ll':this.poiLlInput.value};
	},
	
	setPoiInputInfo: function(keyWord, addr, ll) {
		if (keyWord)
			this.poiKeyWordInput.value = keyWord;
		if (addr) {
			this.poiInput.value = addr;
			this.poiAddrInput.value = addr;
		}
		if (ll)
			this.poiLlInput.value = ll;
	},
	
	selectMapInput: function() {
		this.mapInput.select();
	},
	
	selectRouteStartInput: function() {
		this.routeStartInput.select();
	},
	
	selectRouteDestInput: function() {
		this.routeDestInput.select();
	},
	
	selectPoiInput: function() {
		this.poiInput.select();
	},
	
	sendToPhone: function() {
		if (this.clientInfo && this.clientInfo.doSendToPhone) 
			this.clientInfo.doSendToPhone(this.mapInput.value, this.mapLlInput.value);
	},
	
	fetchAddressList: function(flag, evt){
		if (this.clientInfo && this.clientInfo.doFetchAddressList) 
			this.clientInfo.doFetchAddressList(flag);

        Event.stop(evt);
	},

	getMap: function (){
		if (this.clientInfo && this.clientInfo.getMap) {
			var mapInfo = this.getMapInputInfo();
			if (mapInfo.addr != this.mapAddrInput.value) {
				this.mapLlInput.value = '';
				mapInfo.ll = '';
			}
			this.clientInfo.getMap(mapInfo.addr, mapInfo.ll);
		}
	},
	getRoute: function (){
		if (this.clientInfo && this.clientInfo.getRoute) {
			var routeInfo = this.getRouteInputInfo();
			if (routeInfo.stAddr != this.routeStartAddrInput.value) {
				this.routeStartLlInput.value = '';
				routeInfo.stll = '';
			}
			if (routeInfo.deAddr != this.routeDestAddrInput.value) {
				this.routeDestLlInput.value = '';
				routeInfo.dell = '';
			}
			this.clientInfo.getRoute(routeInfo.stAddr,routeInfo.deAddr,routeInfo.stll,routeInfo.dell);
		}
	},
	getPoi: function (){
		if (this.clientInfo && this.clientInfo.getPoi) {
			var poiInfo = this.getPoiInputInfo();
			if (poiInfo.addr != this.poiAddrInput.value) {
				this.poiLlInput.value = '';
				poiInfo.ll = '';
			}
			this.clientInfo.getPoi(poiInfo.keyWord,poiInfo.addr,poiInfo.ll);
		}
	},
	submitForm:function(id,event){
		if(event.keyCode==13){
			if(id=='input_field_gm'){
				this.getMap();
			}else if(id=='input_field_st' || id=='input_field_ed'){
				this.getRoute();
			}else if(id=='input_field_poi_key_word'|| id=='input_field_poi'){
				this.getPoi();
			}
			Event.stop(event);
		}
	},
	// switch the main tab "get_map dir poi"
	switchPanel:function(btn,evt){
		if (evt) {
			this.collapseAllAddressDropdowns(evt);
		}
		this.closeThemes();
		this.searchBarForm.select('ui/li[id$="input_tab"]').each(function(element){
			element.removeClassName('current');
		});
		this.searchBarForm.select('div[id$="input_box"]').each(function(element){
			element.hide();
		});
		this.currentTab=btn;
		var boxId=btn+"_box";
		$(btn+"_tab").addClassName("current");
		$(boxId).style.display="block";
		//if(evt)
		//	Event.stop(evt);
	},
		//reverse address; 
	reverseRouteAddress:function(){
		
		var stAddr=$('input_field_st').value;
		var deAddr=$('input_field_ed').value;
		if(stAddr.trim()=="" && deAddr.trim()==""){			
			return;
		}
		var stll=$('input_field_route_start_ll').value;
		var dell=$('input_field_route_dest_ll').value;
		$('input_field_st').value = deAddr;
		$('input_field_ed').value = stAddr;
		$('input_field_route_start_ll').value = dell;
		$('input_field_route_dest_ll').value = stll; 
		if(stAddr.trim()=="" || deAddr.trim()==""){			
			return;
		}
		//this.get_route();	
		
	},
	closeAllDialogs:function() {
		this.closeThemes();
	},
	openThemesDialog:function(evt) {

		if ($("changeThemesDlg")) {
			this.closeAllDialogs();

			if ($("content"))
				$("content").addClassName('zIdx');
			
			$("changeThemesDlg").show();

			var align = cookieHelper.getCookie("_search_panel_align");
			var theme = cookieHelper.getCookie("_user_theme");
			if ("true"==align) {
				var alignCenter = $(theme+"_AlignCenter");
				if (alignCenter)
					alignCenter.checked = true;
			}
			else {
				var alignLeft = $(theme+"_AlignLeft");
				if (alignLeft)
					alignLeft.checked = true;
			}		
			if (isIE6)
				headerUtils.coverSelectInIE6("changeThemesDlg");
			Event.observe(document,'click',this.closeThemes.bind(this));
		}
		if (evt)
			Event.stop(evt);
		else if (window.event)
			Event.stop(window.event);
	},
	
	closeThemes:function() {
		if ($("changeThemesDlg")) {
			$("changeThemesDlg").hide();
			$("changeThemesMask").hide();
			if ($("content")) $("content").removeClassName('zIdx');
			if (isIE6)
				headerUtils.uncoverSelectInIE6("changeThemesDlg");
			Event.stopObserving(document,'click', this.closeThemes);
		}
	},
	applyTheme:function(theme) {		
		var alignCenter = $(theme+"_AlignCenter");	
		
		if (alignCenter && alignCenter.checked)
			alignCenter = true;
		else
			alignCenter = false;
		var topDomain = "telenav.com";
		if (window.constTopDomain) {
			if (window.constTopDomain.indexOf('.')==0)
				topDomain = window.constTopDomain.substring(1,window.constTopDomain.length);
			else
				topDomain = window.constTopDomain;
		}
		cookieHelper.setCookie("_search_panel_align",alignCenter, null, '/', topDomain);
		cookieHelper.setCookie("_user_theme",theme, null, '/', topDomain);
		var heads = document.getElementsByTagName("HEAD");
		if (heads!=null && heads.length>0) {
			if ($("themeStyle")) {
				$("themeStyle").remove();
			}
				
			var themeStyle = document.createElement("link");
			themeStyle.setAttribute("id","themeStyle");
			themeStyle.setAttribute("rel","stylesheet");
			themeStyle.setAttribute("type","text/css");
			themeStyle.setAttribute("href", constIncludeDns + "/css/public-header-" + theme + ".css");
			heads[0].appendChild(themeStyle);
			if (alignCenter)
			   this.jscss("add", $('searchBar'), "center");
	    	else
			  this.jscss("remove", $('searchBar'), "center");
				
		}
		this.closeThemes();

	},
	
	jscss : function(a,o,c1,c2){
	  switch (a){
	    case 'swap':
	      o.className=!this.jscss('check',o,c1)?o.className.replace(c2,c1):
	      o.className.replace(c1,c2);
	    break;
	    case 'add':
	      if(!this.jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
	      break;
	    case 'remove':
	      var rep=o.className.match(' '+c1)?' '+c1:c1;
	      o.className=o.className.replace(rep,'');
	      break;
	    case 'check':
	      return new RegExp('\\b'+c1+'\\b').test(o.className);
	  }
	  return false;
	},
	
	setAddressField: function(fieldId, idx ){
		$(fieldId).value = this.localAddrs[parseInt(idx)];
	},
	collapseAllAddressDropdowns: function(evt){
		if ($("content")) $("content").removeClassName('zIdx');
		evt=evt?evt:(window.event?window.event:null);	
		var obj = evt.srcElement ? evt.srcElement : evt.target;
		if ($("addrDropdown_gm")){
			if(obj.id == "addrDropdown_gm")return false;
			if(Prototype.Browser.IE){
			    $("addrDropdown_gm").innerHTML = '';
				$("addrDropdown_gm").removeNode();
			}else{
			   $('siteHeader').removeChild($("addrDropdown_gm"));
			}
		}
		if ($("addrDropdown_st")){
			if(obj.id == "addrDropdown_st")return false;
			if(Prototype.Browser.IE){
			    $("addrDropdown_st").innerHTML = '';
				$("addrDropdown_st").removeNode();
			}else{
			   $('siteHeader').removeChild($("addrDropdown_st"));
			}
		}
		if ($("addrDropdown_ed")){
			if(obj.id == "addrDropdown_ed")return false;
			if(Prototype.Browser.IE){
			    $("addrDropdown_ed").innerHTML = '';
				$("addrDropdown_ed").removeNode();
			}else{
			   $('siteHeader').removeChild($("addrDropdown_ed"));
			}
		}
		if ($("addrDropdown_poi")){
			if(obj.id == "addrDropdown_poi")return false;
			if(Prototype.Browser.IE){
			    $("addrDropdown_poi").innerHTML = '';
				$("addrDropdown_poi").removeNode();
			}else{
			   $('siteHeader').removeChild($("addrDropdown_poi"));
			}
		}

		Event.stopObserving(document,'click', this.collapseAllAddressDropdowns);
	},
	activeSendToPhoneLink:function(){
		if ($('sendToPhone')) {
			var sendToPhoneBtn= $('sendToPhone');
			if(this.mapInput) {
				if (this.mapInput.value.length >= 3) {
					sendToPhoneBtn.addClassName('sendToPhone_active');
					sendToPhoneBtn.removeClassName('sendToPhone');
					Event.observe(sendToPhoneBtn,'click', this.handler);
				} else {
					sendToPhoneBtn.addClassName('sendToPhone');
					sendToPhoneBtn.removeClassName('sendToPhone_active');
					Event.stopObserving(sendToPhoneBtn, 'click', this.handler);
				}
			}
		}
		
		if ($('map_btn_send2phone')) {
			var sendToPhoneBtn2= $('map_btn_send2phone');
			if(this.mapInput) {
				if (this.mapInput.value.length >= 3) {
					Event.observe(sendToPhoneBtn2,'click', this.handler);
				} else {
					Event.stopObserving(sendToPhoneBtn2, 'click', this.handler);
				}
			}
		}
	},
	isSendToPhoneLinkActive: function(){
		return this.mapInput && this.mapInput.value.length >= 3;
	},
	showOnLoading: function() {
		if (this.clientInfo && this.clientInfo.showOnLoading)
			this.clientInfo.showOnLoading();
	},
	hideOnLoading: function() {
		if (this.clientInfo && this.clientInfo.hideOnLoading)
			this.clientInfo.hideOnLoading();
	}
});

var defaultClientInfo = {
	doSendToPhone: function() {
		defaultSendToPhone.doSendToPhone();
	},
	doFetchAddressList: function(flag,evt) {
		defaultFetchAddressList.doFetchAddressList(flag);
	},
	getMap: function() {
		var pagelink = constMapDns+'/maps/getMap.do?func=getmap';
		if (g_SiteHeader.mapLlInput){
			pagelink +='&addr='+g_SiteHeader.mapInput.value;
			window.location.href = pagelink;
		}		
	},
	getPoi: function() {
		var pagelink = constMapDns+'/maps/getPoi.do?func=poi';
		if (g_SiteHeader.poiKeyWordInput && g_SiteHeader.poiInput){
			pagelink +='&addr='+g_SiteHeader.poiInput.value+'&key='+g_SiteHeader.poiKeyWordInput.value;
			window.location.href = pagelink;
		}
	},
	getRoute: function() {
		var pagelink = constMapDns+'/maps/getRoute.do?func=dir';
		if (g_SiteHeader.routeStartInput && g_SiteHeader.routeDestInput){
			pagelink +='&stAddr='+g_SiteHeader.routeStartInput.value+'&deAddr='+g_SiteHeader.routeDestInput.value;
			window.location.href = pagelink;
		}
	}
	
};

var defaultSendToPhone = {
	initialized: false,
	hasResponse:false,
	timeoutFunc:null,
	doSendToPhone: function() {
		if (!this.initialized) {
			if ($('send_to_phone_submit')) 
				$('send_to_phone_submit').observe('click', this.sendAddr.bind(this));
			if ($('send_to_phone_close'))
				$('send_to_phone_close').observe('click', defaultSendToPhone.showOrHidePhoneBox.bind(this));
			this.initialized = true;
		}
		this.showOrHidePhoneBox();
	},
	showOrHidePhoneBox: function() {
		if ($('send_to_phone_box')) {
			if ($('send_to_phone_box').visible()) {
				$('send_to_phone_box').hide();
				$('send_to_phone_input').value = '';
			    if (this.timeoutFunc != null) {
			    	window.clearTimeout(this.timeoutFunc);
			    	this.timeoutFunc = null;
			    }
			} else {
				$('send_to_phone_box').show();
				this.showOrHidePhoneMessage(false);
			}
		}
	},
	showOrHidePhoneMessage: function(isShow) {
		if ($('send_to_phone_promp')) {
			if (isShow) {
				$('send_to_phone_promp').show();
			} else {
				$('send_to_phone_promp').hide();
				$('send_to_phone_message').innerHTML = '';
			}
		}
	},
	validateSendInfo: function (){
		if ($('input_field_gm')) {
			if ($F('input_field_gm').blank()) {
				$('send_to_phone_message').innerHTML = window.const_msg_phone_nullAddr;
				this.showOrHidePhoneMessage(true);
				return false;
			} 
		} else {
			return false;
		} 
		
		var numberPattern = new RegExp('[0-9]{10}');
		
		if ($('send_to_phone_input')) {
			var phoneNumber = $F('send_to_phone_input');
			if (!numberPattern.test(phoneNumber)) {
				$('send_to_phone_message').innerHTML = window.const_msg_phone_invalidNumber;
				this.showOrHidePhoneMessage(true);
				return false;
			}
		} else {
			return false;
		}
		return true;
	},
	sendAddr: function() {
		if (!this.validateSendInfo()) return;
		$('send_to_phone_message').innerHTML = '<span class="success_text">' + window.const_msg_phone_sending + '</span>';
		this.showOrHidePhoneMessage(true);
		var urlstr = window.constContentDns + '/public/sendToPhoneAjax.do';		
		var params = new Hash();
	    params.set("addr", $F('input_field_gm'));
	    params.set("receiver", $F('send_to_phone_input'));	
	    urlstr += '?' + params.toQueryString();
	    this.hasResponse = false;
	    jsLoader.load(urlstr, defaultSendToPhone.handleResponse.bind(this));
	    //No response after a long time
	    if (this.timeoutFunc != null) {
	    	window.clearTimeout(this.timeoutFunc);
	    	this.timeoutFunc = null;
	    }
	    this.timeoutFunc = function(){
	    	if (!this.hasResponse) {
				if($('send_to_phone_box').visible()){
					defaultSendToPhone.handleResponse('noResponse');
				}
	    	}
    	}.delay(30);
	},
	handleResponse: function(result) {
	    if (this.timeoutFunc != null) {
	    	window.clearTimeout(this.timeoutFunc);
	    	this.timeoutFunc = null;
	    }
		this.hasResponse = true;
		if (result == 'noResponse'){
			$('send_to_phone_message').innerHTML = window.const_msg_phone_failure;
			this.showOrHidePhoneMessage(true);
		}  else if (result.rtnCode == 'success'){
			$('send_to_phone_message').innerHTML = '<span class="success_text">' + window.const_msg_phone_success + '</span>';
			this.showOrHidePhoneMessage(true);
		} else if (result.rtnCode == 'NF') {
			$('send_to_phone_message').innerHTML = window.const_msg_phone_addrNotFound;	
			this.showOrHidePhoneMessage(true);
		} else {
			$('send_to_phone_message').innerHTML = window.const_msg_phone_failure;	
			this.showOrHidePhoneMessage(true);
		} 
		
		//Close phone box
		this.timeoutFunc = function(){
			var sendPhoneBox = $('send_to_phone_box');
			if(sendPhoneBox.visible()) {
				sendPhoneBox.hide();
				$('send_to_phone_input').value = '';
			}
		}.delay(15);
	}
};

var defaultFetchAddressList = {
	user_addr:null,
	current_drop:'',
	currentDropDom:null,
	user_fav_addrs:null,
	user_rec_addrs:null,
	inputHash:{'get_map':'gm',
				'route_start':'st',
				'route_dest':'ed',
				'poi_address':'poi'},
	doFetchAddressList: function(flag) {
		if (!constIsLogin)
			return;
		if (this.current_drop!="" && flag != this.current_drop) {
			this.currentDropDom.hide();
		}
		this.current_drop=flag;
		this.currentDropDom = $("input_field_"+flag+"_dropdown");;
		if(this.currentDropDom.style.display=="none"){
			if(this.user_addr==null){
				if (g_SiteHeader)
					g_SiteHeader.showOnLoading();
				jsLoader.load(constContentDns+"/content/fetchFavRecAddrs.do?",this.onAddressListLoad.bind(this));
			}else{
				this.showDropPanel();
			}
			Event.observe(document,'click',this.hideDropPanel.bind(this));
		}else{
			this.hideDropPanel();
		}
		
	},
	onAddressListLoad: function(result) {
		if (g_SiteHeader)
			g_SiteHeader.hideOnLoading();
		if(!result){
			this.currentDropDom.innerHTML="<p class='prompt_txt'>"+const_msg_addrNotFound+"</p>";
			this.currentDropDom.show();
			return;
		}
		if(result.status=="ok" && (result.favAddresses || result.recAddresses)){
			this.user_fav_addrs=new Hash();
			this.user_addr =new Hash();
			if (result.favAddresses) {
				for(var index=0; index<result.favAddresses.length; index++) {
					result.favAddresses[index].id=index;
					this.user_fav_addrs.set(index,result.favAddresses[index]);
					this.user_addr.set(index,result.favAddresses[index]);
				}
			}
			
			this.user_rec_addrs=new Hash();
			if (result.recAddresses) {
				for(var index2=0; index2<result.recAddresses.length; index2++) {
					result.recAddresses[index2].id=index+index2;
					this.user_rec_addrs.set(index+index2,result.recAddresses[index2]);
					this.user_addr.set(index+index2,result.recAddresses[index2]);
				}
			}
			
			this.showDropPanel();
		}else{
			this.currentDropDom.innerHTML="<p class='prompt_txt'>"+const_msg_addrNotFound+"</p>";
			this.currentDropDom.show();	
		}
	},
	hideDropPanel:function(evt){
		if (window.event)
			evt = window.event;
		if (evt) {
			var target = evt.target ? evt.target : evt.srcElement;
			if(target && $(target).descendantOf && $(target).descendantOf(this.currentDropDom)){
				return;
			}
		}
		this.hideDropPanelWithoutEvent();
	},
	getAddressBookHtml:function(fieldId,favJsonObj,recJsonObject){
		var template=new Array();
		  if(favJsonObj.size() > 0){
			template.push("<h3>"+const_text_my_favorite+"</h3>");
			favJsonObj.each(function(pair){
				var addr=pair.value;
				var ll=addr.lat+","+addr.lon;
				template.push("<p><a href='#' " +
						"onclick='defaultFetchAddressList.getUserMap(\""+fieldId+"\","+addr.id+");return false;'>" +
						addr.label+"</a></p>");
			});
		  }
		  
		  if(recJsonObject.size() > 0){
		
			template.push("<h3>"+const_text_recent_address+"</h3>");
			recJsonObject.each(function(pair){
				var addr=pair.value;
				var ll=addr.lat+","+addr.lon;
				template.push("<p><a href='#' " +
						"onclick='defaultFetchAddressList.getUserMap(\""+fieldId+"\","+addr.id+");return false;'>" +
						addr.label+"</a></p>");
			});
		  }
		return template.join('');
	},
	getUserMap:function(field_id,id){
		var addr=this.user_addr.get(id);
		if(this.currentDropDom){
			this.hideDropPanelWithoutEvent();
		}
		var input = $('input_field_' + this.inputHash[field_id]);
		if (input){
			input.value=addr.single;
			input.select();
			if (g_SiteHeader) {
				g_SiteHeader.activeSendToPhoneLink();
			}
		}
	},
	hideDropPanelWithoutEvent:function(){
		this.currentDropDom.hide();
		if (isIE6)
			headerUtils.uncoverSelectInIE6();
		Event.stopObserving(document,'click',this.hideDropPanel);
	},
	showDropPanel:function(){
		if (this.currentDropDom.innerHTML.trim() == '') {
			this.currentDropDom.innerHTML = this.getAddressBookHtml(this.current_drop,this.user_fav_addrs,this.user_rec_addrs);
		}
		this.currentDropDom.show();
		if (isIE6)
			headerUtils.coverSelectInIE6(this.currentDropDom);
	}
};

var cookieHelper={
	contextPath:constContextPath,
	getCookie: function(name) {
	    var dc = document.cookie;
	    var prefix = name + "=";
	    var begin = dc.indexOf("; " + prefix);
	    if (begin == -1) {
	        begin = dc.indexOf(prefix);
	        if (begin != 0) return null;
	    } else {
	        begin += 2;
	    }
	    var end = document.cookie.indexOf(";", begin);
	    if (end == -1) {
	        end = dc.length;
	    }
	    var buf = dc.substring(begin + prefix.length, end);
	    buf = String(buf).replace(/([+])/g, ' ');
	    return decodeURIComponent(buf);
	},
	setCookie: function (name, value, validTime, cookiePath, domain, secure){
	    var expires = new Date();
	    if (validTime != null) {
	    	if (validTime>0) {
		    	expires.setTime(expires.getTime() + validTime);
		    	expires = expires.toGMTString();
	    	} else
	    		expires = validTime;
	    } else {
	    	expires.setTime(expires.getTime() + 12 * 30 * 24 * 60 * 60 * 1000);
	    	expires = expires.toGMTString();
	    }
	    if (!cookiePath){
	    	cookiePath = this.contextPath;
	    }
	    if (secure)
	    	secure = ";secure";
	    if (domain == null)
	    	domain = "";
	    else
	    	domain = ";domain="+domain;
	    document.cookie = name + "=" + encodeURIComponent(value) + ";path="+cookiePath+";expires=" + expires + secure + domain;
	},
	removeCookie:function(name, cookiePath) {
		if (!cookiePath)
			cookiePath = this.contextPath;
		var expires = new Date();
		expires.setTime(expires.getTime()-1000);
		document.cookie = name + "=;path="+cookiePath+";expires=" + expires.toGMTString();
	}
};

var headerUtils = {
	coverSelectInIE6: function(div) {
		div = $(div);
		if (!div) return;
		var iframe = $('coverSelectIFrame');
		if (!iframe) {
			iframe = new Element('iframe');
			iframe.setAttribute('id','coverSelectIFrame');
			iframe.setStyle({position:'absolute',display:'none',filter:'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'});
		}
		else {
			iframe.remove();
		}
		div.up().insertBefore(iframe,div);
		iframe.style.width = div.getWidth()+'px';
		iframe.style.height = div.getHeight()+'px';
		iframe.style.left = div.positionedOffset().left+'px';
		iframe.style.top = div.positionedOffset().top+'px';
		iframe.style.zIndex = div.getStyle('zIndex')-1;
		iframe.show();
	},
	uncoverSelectInIE6: function() {
		var iframe = $('coverSelectIFrame');
		if (iframe) {
			iframe.hide();
			iframe.style.width = '0px';
			iframe.style.height = '0px';
			iframe.style.left = '0px';
			iframe.style.top = '0px';
			iframe.style.zIndex = -999;
		}
	}
};


var g_SiteHeader = null;

if (!window.initSiteHeader) {
//	Event.observe(window,"load",function() {
		g_SiteHeader = new SiteHeader();
//	});
}else{
//	Event.observe(window,"load", function() {
		g_SiteHeader = window.initSiteHeader();
//	});
}
}
