function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function fDownload(){
	document.getElementById("fdownload").src = "download.php";
}
function changePro(curObj){
    window.location = "?pro="+curObj.value;
}
function changePage(curObj){
    if (window.location.href.indexOf("#") >=0){
        window.location.href = window.location.href.substr(0,window.location.href.indexOf("#")) + "#" + curObj.value;
    }else{
        window.location.href = window.location.href + "#" + curObj.value;
    }
}
function lhBeforeSubmit()
{
    // Full name
    if (trim(document.getElementById("fullname").value) == "")
    {
        alert("Vui lòng nhập [Họ tên]");
        document.getElementById("fullname").value="";
        document.getElementById("fullname").focus();    
        return false;            
    }

    // Valid email address
    if (trim(document.getElementById("email").value) != "" && !isValidEmail(trim(document.getElementById("email").value)))
    {
        alert("[Email] không đúng định dạng. Vui lòng nhập lại!");
        document.getElementById("email").focus();    
        return false;            
    }    

    // Phone
    if (trim(document.getElementById("phone").value) == "")
    {
        alert("Vui lòng nhập [Điện thoại]");
        document.getElementById("phone").value = "";
        document.getElementById("phone").focus();    
        return false;            
    }

    // Content
    if (trim(document.getElementById("content").value) == "")
    {
        alert("Vui lòng nhập [Nội dung]");
        document.getElementById("content").value="";
        document.getElementById("content").focus();    
        return false;            
    }
}
function lhCancel()
{
    document.getElementById("fullname").value="";
    document.getElementById("email").value="";
    document.getElementById("phone").value = ""; 
    document.getElementById("content").value="";  
    document.getElementById("fullname").focus(); 
}
function trim(str) {
    return str.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ');
}
function isValidEmail(strEmail)
{ 	
 	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
 	//
 	if (strEmail==null) {
       return false;
    }
    if (strEmail.length==0) {
        return false;
    }    
    // check to make sure all characters are valid
	for (var i=0; i < strEmail.length; i++) {
		var letter = strEmail.charAt(i).toLowerCase();
	    if (validchars.indexOf(letter) != -1)
	      continue;
	    return false;
	}
	//
    if (strEmail.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (strEmail.lastIndexOf(".") <= strEmail.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (strEmail.indexOf("@") == strEmail.length) {  // @ must not be the last character
        return false;
    } else if (strEmail.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
    } else if (strEmail.indexOf(".") == strEmail.length) {  // . must not be the last character
		return false;
    }
    return true;
}