function googleTranslateElementInit() {
	new google.translate.TranslateElement({
		pageLanguage: 'vi',
		includedLanguages: 'vi,en,'
	}, 'google_translate_element');
}


var userAgent = navigator.userAgent.toLowerCase();
var ie = false;
var ie6 = false;
var root_url = 'http://sanbds.vn';
var root_title = 'Sàn bất động sản DTJ';
var dom = null;
var event = null;

if (userAgent.indexOf('msie') > -1) {
	ie = true;
	if (userAgent.indexOf('msie 6.0') > -1) {
		ie6 = true;
	}
}


if (ie) {
	_('<link rel="stylesheet" type="text/css" href="/common/v1/css/ie7.css" />');
}
if (ie6) {
	_('<link rel="stylesheet" type="text/css" href="/common/v1/css/ie6.css" />');
}

function _(str) {
	document.write(str);
}

function $(id) {
	return document.getElementById(id);
}


var isCate = false;
var isArticle = false;
var cate = document.getElementById('cate-id');

var module = ['connection','json','paginator', 'animation', 'calendar', 'container', 'tabview', 'carousel', 'menu', 'button', 'treeview','dragdrop'];

if (cate) {
	var article = document.getElementById('article-id');
	//module.push('paginator');

	if (article.innerHTML) {
		isArticle = true;
		document.getElementById('mycomment').value= '';
	}
	else {
		isCate = true;
	}
}

// Using YUI loader 
try {
	var loader = new YAHOO.util.YUILoader({ 
			base: '/common/v1/yui/build/',
			onSuccess: function (o) {
				loadSuccess();
				
			}
	});
}
catch (e) {}


loader.addModule({
	name: 'ad',
	type: 'js',
	fullpath: '/library/js/ad.js?'
}); 

loader.addModule({
	name: 'Avim',
	type: 'js',
	fullpath: '/common/v1/js/avim.js'
});

loader.addModule({
	name: 'function',
	type: 'js',
	fullpath: '/common/v1/js/function.js?' + Math.random()
});

//loader.addModule({
//	name: 'accordion',
//	type: 'js',
//	fullpath: 'common/v1/js/accordion.js'
//});

loader.addModule({
	name: 'ddtabmenu',
	type: 'js',
	fullpath: '/common/v1/js/ddtabmenu.js'
});

loader.addModule({
	name: 'RealMarket',
	type: 'js',
	fullpath: '/library/js/realmarket.js?' + Math.random()
});

loader.addModule({
	name: 'Project',
	type: 'js',
	fullpath: '/library/js/project.js?' + Math.random()
});

if (!ie6) {
	loader.addModule({
		name: 'googleTranslateInit',
		type: 'js',
		fullpath: 'http://translate.google.com/translate_a/element.js?' + Math.random()
	});
	module.push('googleTranslateInit');
}


module.push('ad');
//module.push('accordion');
module.push('function');
module.push('ddtabmenu');
module.push('Avim');

loader.require(module);
loader.insert();


function loadSuccess() {
	dom = YAHOO.util.Dom;
    event = YAHOO.util.Event;
    var selected_menu = 0;
    try{
		var menuSelected = document.getElementById('menu-selected');
		var menuTranslated = menuSelected.getElementsByTagName('span');
		if(menuTranslated[0]) {
			selected_menu = menuTranslated[0].innerHTML;
		} else {
			selected_menu = dom.get('menu-selected').innerHTML;
		}
		
    }catch(e){selected_menu = 2}
    
    if(isObject('tabmenu')) ddtabmenu.init("tabmenu", selected_menu);
    

    if(isObject('ca1')) initCarousel('ca1', [1, 1], 2000, true, true);
	if(isObject('ca2')) initCarousel('ca2', [1, 1], 2000, true, true);
	if(isObject('ca3')) initCarousel('ca3', [1, 1], true, false);
    var lienKetTrang = [1, 1], autoPlayInterval = 2000;
    if(isObject('lien-ket-san')) {
     if(dom.get('lien-ket-san-carousel').getElementsByTagName('li').length > 5)
        initCarousel('lien-ket-san', lienKetTrang, autoPlayInterval, true, true);
     dom.get('lien-ket-san-carousel').parentNode.style.width = '615px';
     dom.get('lien-ket-san-carousel').parentNode.style.height = '78px';
     dom.get('lien-ket-san').style.width = '615px';
    }
    
    if(isObject('tab-duan')) new YAHOO.widget.TabView('tab-duan');
    if(isObject('tab-trainghiem')){
        new YAHOO.widget.TabView('tab-trainghiem');
        if(isObject('yui-content-kttg')) $('yui-content-kttg').style.display='block';
    }
    if(isObject('tab-khonggiansong')){
        new YAHOO.widget.TabView('tab-khonggiansong');
        if(isObject('yui-content-khuvuctamlinh')) $('yui-content-khuvuctamlinh').style.display='block';
        if(isObject('yui-content-phongngu')) $('yui-content-phongngu').style.display='block'; 
    }
    if(isObject('list-province')) new YAHOO.widget.TabView('list-province');

    if(isObject('mua-ban')) new YAHOO.widget.TabView('mua-ban');
    if(isObject('canthue-chothue'))new YAHOO.widget.TabView('canthue-chothue');
	    
    
    
    try{
        var province = get_url_params("province");	
       if (province=='cactinhkhac'){
	        initTooltip(true);
	    }else{
	        initTooltip(false);
	    }
    }
    catch(e){}
    
 	try {
		createButtonSelecBox('Nhucau');
		createButtonSelecBox('Loaitin');
		createButtonSelecBox('Trangthai');
		createButtonCheckBox('Loaitaisan', 'Nhiều loại');
		createButtonSelecBox('Matbang');
		createButtonSelecBox('Loaihinh');
	}
	catch (e) {} 
	
	try{
	   if(isObject('txtkeyword')) {
	        articles_search('list-cate-next');
	   }
	}
	catch(e){}
	try{
	    if(isObject('project_type_alias')) {
	       var type = dom.get('project_type_alias').innerHTML;
	       projects_get_list(type); 
	   }
	}
	catch(e){}
	try{
	    if(isObject('project-search-list')) {
	       projects_get_search(); 
	   }
	}
	catch(e){}
	try{
	    if(isObject('question-list')) {
	      questions_get_by_page('question-list'); 
	   }
	}
	catch(e){}
	try{
	    if(isObject('special-list')) {
	      realmarket_get_special_list('special-list','tin-dac-biet'); 
	     
	   }
	}
	catch(e){}
	
	try{
	   if(isObject('san-dtj-list')) {
	      realmarket_get_sandtj_list('san-dtj-list','san-dtj'); 
	   }
    }
	catch(e){}
	
	try{
	    if(isObject('san-bds-list')) {
	      realmarket_get_sanbds_list('san-bds-list','san-bds'); 
	   }
	}
	catch(e){}
	
	try {
        if(isObject('provice-panel')) {
	          var province = get_url_params("province");	    
	          province = (province)? province : 'hanoi';
              var provinces = dom.get('provice-panel').getElementsByTagName('a');
              for(var i = 0; i < provinces.length; i++) {
                if(province == provinces[i].getAttribute('dir')){
                    if(isObject('project_search_box')) {
                        onclickProviceProjectSearchPanel(province,provinces[i].innerHTML);
                        break; 
                    }else{
                        onclickProvicePanel(province,provinces[i].innerHTML);
                        break; 
                    }
                }
              }
	    }
	}
	catch(e){}
	
	try{
	   if(isObject('bds-member-list')) {
	      realmarket_search_by_member('bds-member-list'); 
	   }
    }
	catch(e){}
	
	try{
	    if(isObject('result-search-by-cate')) {
	        var cate = get_url_params("cate");
	        if (cate == 'san-bds'){
	            realmarket_search_sanbds('result-search-by-cate',cate);
	        }else{
	            realmarket_search_sandtj('result-search-by-cate',cate);
	        }
	   }
	}
	catch(e){}
	
    try{
        tooltip();
		treeInit();
	 }
    catch(e){}
/*
  try{
        var panelWarning = new YAHOO.widget.Panel("panel-warning", {
			visible:false,
			constraintoviewport:true, 
			underlay: 'none',
			context: ["_ctl0_ContentPlaceHolder1_sanbds_post1_txtTitle", "tl", "tr", 'onfocus', [-5, 15]],
			iframe: true,
			zIndex: 999,
			draggable:true
		});
		panelWarning.render();

		var newTitleWarning = document.getElementById("_ctl0_ContentPlaceHolder1_sanbds_post1_txtTitle");

		if(newTitleWarning) {
			newTitleWarning.onfocus = function() {
				panelWarning.show();
			};
			newTitleWarning.onblur = function() {
				panelWarning.hide();
			}
		}
    }
    catch(e){}
	*/

	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_post1_txtTitle')) initPanel('panel1', '_ctl0_ContentPlaceHolder1_sanbds_post1_txtTitle');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_post1_txtDisplayPrice')) initPanel('panel2', '_ctl0_ContentPlaceHolder1_sanbds_post1_txtDisplayPrice');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_post1_txtTotalArea')) initPanel('panel3', '_ctl0_ContentPlaceHolder1_sanbds_post1_txtTotalArea');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_post1_txtTag')) initPanel('panel4', '_ctl0_ContentPlaceHolder1_sanbds_post1_txtTag');
	
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_consign1_txtTitle')) initPanel('panel1', '_ctl0_ContentPlaceHolder1_sanbds_consign1_txtTitle');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_consign1_txtDisplayPrice')) initPanel('panel2', '_ctl0_ContentPlaceHolder1_sanbds_consign1_txtDisplayPrice');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_consign1_txtTotalArea')) initPanel('panel3', '_ctl0_ContentPlaceHolder1_sanbds_consign1_txtTotalArea');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_consign1_txtTag')) initPanel('panel4', '_ctl0_ContentPlaceHolder1_sanbds_consign1_txtTag');
	
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_edit1_txtTitle')) initPanel('panel1', '_ctl0_ContentPlaceHolder1_sanbds_edit1_txtTitle');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_edit1_txtDisplayPrice')) initPanel('panel2', '_ctl0_ContentPlaceHolder1_sanbds_edit1_txtDisplayPrice');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_edit1_txtTotalArea')) initPanel('panel3', '_ctl0_ContentPlaceHolder1_sanbds_edit1_txtTotalArea');
	if(isObject('_ctl0_ContentPlaceHolder1_sanbds_edit1_txtTag')) initPanel('panel4', '_ctl0_ContentPlaceHolder1_sanbds_edit1_txtTag');
	
    try {
        load_ads(); 
    }
    catch (e){}
    
    try {
	    if (!ie6) {
		    cb = googleTranslateElementInit();
	    }
    }
    catch (e){}
    
    YAHOO.namespace("vsolutions.container");

    function init() {

	    // Instantiate a Panel from markup
	    YAHOO.vsolutions.container.img = new YAHOO.widget.Panel("img", {
		    fixedcenter: true,
		    visible: false,
		    close: true,
		    constraintoviewport: true,
		    effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25},
		    modal: false
	    });
	    YAHOO.vsolutions.container.img.render();
    }

    event.onDOMReady(init);

    try{
        if(isObject('necessary-info')){
            var myTabs = new YAHOO.widget.TabView("necessary-info");
            if(isObject('san-hnx')) $('san-hnx').style.display='block';
            if(isObject('exchange')) $('exchange').style.display='block';
		    var nav = document.getElementById('necessary-info-nav');
		    var liTags = $('tabview-111-1').getElementsByTagName('li');
		    liTags[1].style.borderRight = '1px solid #FFF';

		    myTabs.set('cacheData', false);
		    myTabs.set('cache', false);
    		    
		    myTabs.addListener('activeIndexChange', function(e) {
			    if(e.newValue == 2) {
				    liTags[0].style.borderRight = '1px solid #FFF';
				    liTags[2].style.borderLeft = '';
				    liTags[1].style.borderLeft = '';
				    liTags[1].style.borderRight = '';
			    }
			    if(e.newValue == 0) {
				    liTags[2].style.borderLeft = '1px solid #FFF';
				    liTags[0].style.borderRight = '';
				    liTags[1].style.borderLeft = '';
				    liTags[1].style.borderRight = '';
			    }
			    if(e.newValue == 1) {
				    liTags[1].style.borderLeft = '1px solid #FFF';
				    liTags[1].style.borderRight = '1px solid #FFF';

				    liTags[2].style.borderLeft = '';
				    liTags[0].style.borderRight = '';
			    }
		    });
        }
    }catch(e){}
}

function show(image) {
	YAHOO.vsolutions.container.img.show();
	document.getElementById('img-view').src = image;
}


	try {
		YAHOO.namespace("vsolutions");

		YAHOO.vsolutions.accordion = {
			properties : {
				animation : true,
				animationDuration : 5,
				multipleOpen : false
			},
			init : function(animation,animationDuration,multipleOpen) {
				if(animation) {
					this.animation = animation;
				}
				if(animationDuration) {
					this.animationDuration = animationDuration;
				}
				if(multipleOpen) {
					this.multipleOpen = multipleOpen;
				}
				var accordionObjects = dom.getElementsByClassName("accordion");

				if(accordionObjects.length > 0) {
					for(var i=0; i<accordionObjects.length; i++) {
						if(accordionObjects[i].nodeName == "DL") {
							var headers = accordionObjects[i].getElementsByTagName("dt");
							var bodies = headers[i].parentNode.getElementsByTagName("dd");
						}
						this.attachEvents(headers,i);
					}
				}
			},

			attachEvents : function(headers,nr) {
				for(var i=0; i<headers.length; i++) {
					var headerProperties = {
						objRef : headers[i],
						nr : i,
						jsObj : this
					}
					
					event.addListener(headers[i],"click",this.clickHeader,headerProperties);
				}
			},

			clickHeader : function(e,headerProperties) {
				var parentObj = headerProperties.objRef.parentNode;
				var headers = parentObj.getElementsByTagName("dd"); 
				var header = headers[headerProperties.nr];

				if(dom.hasClass(header,"open")) {
					headerProperties.jsObj.collapse(header);
				} else {
					if(headerProperties.jsObj.properties.multipleOpen) {
						headerProperties.jsObj.expand(header);
					} else {
						for(var i=0; i<headers.length; i++) {
							if(dom.hasClass(headers[i],"open")) {
								headerProperties.jsObj.collapse(headers[i]);
							}
						}
						headerProperties.jsObj.expand(header);
					}
				}
			},
			
			collapse : function(header) {
				dom.removeClass(dom.getPreviousSibling(header),"selected");
				if(!this.properties.animation) {
					dom.removeClass(header,"open");
				} else {
					this.initAnimation(header,"close");
				}
			},
			expand : function(header) {
				dom.addClass(dom.getPreviousSibling(header),"selected");
				if(!this.properties.animation) {
					dom.addClass(header,"open");
				} else {
					this.initAnimation(header,"open");
				}
			},
			
			initAnimation : function(header,dir) {
				if(dir == "open") {
					dom.setStyle(header,"visibility","hidden");
					dom.setStyle(header,"height","auto");
					dom.addClass(header,"open");
					var attributes = {
						height : {
							from : 0,
							to : header.offsetHeight
						}
					}
					dom.setStyle(header,"height",0);
					dom.setStyle(header,"visibility","visible");
					
					var animation = new YAHOO.util.Anim(header,attributes);
					animationEnd = function() {
						// leave it here
					}
					animation.duration = this.properties.animationDuration;
					animation.useSeconds = false;
					animation.onComplete.subscribe(animationEnd);
					animation.animate();
				} else if ("close") {
					var attributes = {
						height : {
							to : 0
						}
					}			
					animationEnd = function() {
						dom.removeClass(header,"open");
					}
					var animation = new YAHOO.util.Anim(header,attributes);
					animation.duration = this.properties.animationDuration;
					animation.useSeconds = false;
					animation.onComplete.subscribe(animationEnd);
					animation.animate();
				}
			}
		}
	}
	catch (e) {}
		
function VertDateTime(strupset) {
	var str ='';
	var	strSecond='';
	var	strMinute='';
	var	strHours='';
	var	strDay='';
	var strMonth='';
	var strYear='';
	
	strHours = strupset.substring(8,10); 
	strMinute = strupset.substring(10,12); 
	strSecond = strupset.substring(12,14); 
	
	strDay = strupset.substring(6,8); 
	strMonth = strupset.substring(4,6); 
	strYear = strupset.substring(0,4); 
	//str = '' + strHours + ':' + strMinute + ':' + strSecond ;
	str =  ' ' + strDay + '/' + strMonth + '/' + strYear + ' ' + strHours + ':' + strMinute + ':' + strSecond;
	return str;
}


