﻿//var tempS1="<span style=\"margin: 6px 0pt 0pt 3px; float: left;\"><a href=\"javascript:void(0);\"onclick=\"return btnVietkeyHome_onclick('btnVietkey1');\" ><img id=\"btnVietkey1\" src=\""+pathClient+"images/V.gif\"/></a></span>"
var tempS1="";
var tempS2="<a href=\"javascript:SearchTopHeader();\"  style=\"float: right; width: 70px; height: 27px; cursor: pointer;\"></a>";
function ChangSearch(id)
{
	if(id==1)
	{	
		document.getElementById("input_searchnew").innerHTML=tempS1+"<input name=\"proSearchID\" id=\"proSearchID\" value=\"Nhập Mã BĐS\" onfocus=\"if(this.value=='Nhập Mã BĐS')this.value='';\" onblur=\"if(this.value=='')this.value='Nhập Mã BĐS';\" onkeypress=\"return mjSPressNumberOnly(event, this.value);\" type=\"text\">"+tempS2;
	}
	else if(id==2)
	{
		document.getElementById("input_searchnew").innerHTML=tempS1+"<input name=\"proSearchID\" id=\"proSearchID\" value=\"Nhập Từ khóa\" onfocus=\"if(this.value=='Nhập Từ khóa')this.value='';\" onblur=\"if(this.value=='')this.value='Nhập Từ khóa';\" onkeypress=\"return KeyPressSearchTopHeader(event);\"  type=\"text\">"+tempS2;
	}
	else if(id==3)
	{
		document.getElementById("input_searchnew").innerHTML=tempS1+"<input name=\"proSearchID\" id=\"proSearchID\" value=\"Nhập Tên dự án\" onfocus=\"if(this.value=='Nhập Tên dự án')this.value='';\" onblur=\"if(this.value=='')this.value='Nhập Tên dự án';\"  onkeypress=\"return KeyPressSearchTopHeader(event);\"  type=\"text\">"+tempS2;
	}
	else 
	{
		document.getElementById("input_searchnew").innerHTML=tempS1+"<input name=\"proSearchID\" id=\"proSearchID\" value=\"Chọn mục cần tìm\" onfocus=\"if(this.value=='Chọn mục cần tìm')this.value='';\" onblur=\"if(this.value=='')this.value='Chọn mục cần tìm';\"  type=\"text\">"+tempS2;	
	}
}

function SearchTopHeader()
{
	if(document.getElementById("searchTopHeader").value==0)
	{
		alert("Bạn phải chọn mục tìm kiếm!");
		document.getElementById("searchTopHeader").focus();
	}
	if(document.getElementById("searchTopHeader").value==1)
	{
		if(document.getElementById("proSearchID").value=='Nhập Mã BĐS'||document.getElementById("proSearchID").value=='')
		{
			alert("Bạn phải nhập Mã BĐS!");
			document.getElementById("proSearchID").focus();
		}
		else
			onSearchPropertyID();
	}
	if(document.getElementById("searchTopHeader").value==2)
	{
		if(document.getElementById("proSearchID").value=='Nhập Từ khóa'||document.getElementById("proSearchID").value=='')
		{
			alert("Bạn phải nhập Từ khóa!");
			document.getElementById("proSearchID").focus();
		}
		else
		{
			onSearchNews(document.getElementById("proSearchID").value);
		}
	}
	if(document.getElementById("searchTopHeader").value==3)
	{
		if(document.getElementById("proSearchID").value=='Nhập Tên dự án'||document.getElementById("proSearchID").value=='')
		{
			alert("Bạn phải nhập Tên dự án!");
			document.getElementById("proSearchID").focus();
		}
		else
		{
			onSearchEstate(document.getElementById("proSearchID").value);
		}
	}
}
function onSearchNews(t)
{
	window.location=pathClient+"ResultSearchTopHeader.aspx?kw="+conver_ascii(t)+"&pg=1";
}

function conver_ascii(s)
{
	var ascii="";
	if(s.length>0)
		for(i=0; i<s.length; i++)
		{
			var c = ""+s.charCodeAt(i);
			while(c.length < 3)
			c = "0"+c;
			if(i!=s.length-1)
				ascii += c+",";
			else ascii += c;
		}
	return(ascii);
}
function onSearchEstate(t)
{
	window.location=pathClient+"EstateList.aspx?namekw="+conver_ascii(t)+"&pindex=1";
}
function KeyPressSearchTopHeader(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode;	
	if (unicode == 13)
	{
		SearchTopHeader();
	}
}
function overlay(curobj,subobjstr,opt_position){if(document.getElementById){var subobj=document.getElementById(subobjstr)

subobj.style.display=(subobj.style.display!="block")?"block":"none"

var xpos=getposOffset(curobj,"left")+((typeof opt_position!="undefined"&&opt_position.indexOf("right")!=-1)?-(subobj.offsetWidth-curobj.offsetWidth):0)

var ypos=getposOffset(curobj,"top")+((typeof opt_position!="undefined"&&opt_position.indexOf("bottom")!=-1)?curobj.offsetHeight:0)

if(opt_position=='above'){var xpos=getposOffset(curobj,"left")-240;var ypos=getposOffset(curobj,"top")-165;}

subobj.style.left=xpos+"px"

subobj.style.top=ypos+"px"

return false}

else

return true}
function getposOffset(overlay,offsettype){var totaloffset=(offsettype=="left")?overlay.offsetLeft:overlay.offsetTop;var parentEl=overlay.offsetParent;while(parentEl!=null){totaloffset=(offsettype=="left")?totaloffset+parentEl.offsetLeft:totaloffset+parentEl.offsetTop;parentEl=parentEl.offsetParent;}

return totaloffset;}

function mjSPressNumberOnly(e, nav){
	var unicode=e.charCode? e.charCode : e.keyCode;	
	if (unicode!=8){
		if (unicode == 13 && nav)
			window.location = nav+".aspx";
		if (unicode<48||unicode>57)
			return false;
	} 
}
function isDigit (c)
{ return ((c >= "0") && (c <= "9"))

}

function isAllDigit (s)
{   

  var i;

  if (isEmpty(s)) 

     if (isAllDigit.arguments.length == 1) return false;

     else return (isDigital.arguments[1] == true);

  for (i = 0; i < s.length; i++)

  {   

    var c = s.charAt(i);

    if (isDigit(c)==false)

    return false;

  }

  return true;

}

function onSearchPropertyID()
{
	if((document.getElementById('proSearchID').value=='') || (document.getElementById('proSearchID').value=='Tìm theo Mã BÐS'))
	{
		alert('Bạn phải nhập Mã BÐS!');
		document.getElementById('proSearchID').focus();
		return;
	}
	else {
		window.location = pathClient+'/'+document.getElementById('proSearchID').value+'.aspx';
	}
}
function open_popup_noresize(ad,w,h)
{
   	window.open (ad, "", "height="+h+", width="+w+", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
}