// JavaScript Document

function search()
{
	var keyword = search_box.value;
	open("search.htm?keyword="+keyword, "_self");
}

function search_button_over()
{
	search_button_img.src="images/search_button_over.gif";
}

function search_button_down()
{
	search_button_img.src="images/search_button_down.gif";
}

function search_button_out()
{
	search_button_img.src="images/search_button_up.gif";
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function height_auto(){
var checkloadfirst=gup("home");
if(checkloadfirst == "on"){
    try { 

        if(document.getElementById("space_division").offsetHeight > 0) {  
            var div = document.getElementById("home_poster");
            //alert('oki'+ div);      
            var h = div.style.height;
            if(document.getElementById("home_poster").offsetHeight > 1){
                //alert("truoc: 3" + document.getElementById("home_poster").offsetHeight); 
                abc = document.getElementById("home_poster").offsetHeight;
                abc = parseInt(abc) - 2 + "px";
                //alert("truoc: 3" + abc); 
                div.style.height = abc;
                // alert("sau: " + div.style.height);
            } 
            else {
                //div.style.visibility = "hidden";
                div.style.height = 0 + "px";
                document.getElementById("space_division").style.height = 0 + "px";
                //div.style.backgroundColor = "#FFFFFF";
                // alert("sau: " + div.style.height);
                }
                setTimeout("height_auto()", 1);
            } 
        }
    catch (e) {
        alert(e);
        }
    }
    else {
        document.getElementById("home_poster").style.height = 0 + "px";
        document.getElementById("space_division").style.height = 0 + "px";
    }
}


function validate(theForm){

		if (theForm.ngui.value == "") {
				alert("Vui long nhap vao ten cua nguoi lien he !");
				theForm.ngui.focus();
				return false;
		}

	

        if (theForm.email.value == "" || theForm.email.value.indexOf('@',1)== -1 || theForm.email.value.indexOf('.',2)==-1){
                alert("Dia chi Email khong hop le, vui long nhap lai.");
                theForm.email.focus();
                return false;
        }
return true;
}

var newwindow;
function poptastic(url)
{
	if ("Explorer" == BrowserDetect.browser) {	
	params  = 'width='+800;
	params += ', height='+600;
	params += ', top=0, left=0';
	params += ',resizable=yes';
	params += ', fullscreen=no';
	params +=', directories=no';
	

 newwin=window.open(url,'windowname4', params);
	newwin.focus();
		} else {
			alert('This windows should be open with IE!');
			}
}

	
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

