﻿ function showtxt(str,id)
{
if (str.length==0)
{
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="../act.php";

url=url+"?act="+str;
xmlHttp.onreadystatechange=function() { stateChanged(xmlHttp,id); };
//alert(url);
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged(xmlHttp,id)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
 if (xmlHttp.status==200)
 {
	 	 document.getElementById(id).innerHTML="";
		 document.getElementById(id).height="10px";
	 document.getElementById(id).innerHTML=xmlHttp.responseText;
	 if(id=="newscontent")
	 showtxt('listnews&page=1','listView');
	 if(id=="projectcontent")
{
		stopslide =true;
	initImageGallery('imageSlideshowHolder2');

}
if(id=="thumnail")
	autoheight('projectpage', new Array('projectcontent'));
if(id=="subContent")
	autoheight('projectpage', new Array('leftcol'));
if(id=="detail")
	autoheightdev('projectpage', new Array('leftcol'));
 }

}

}

function GetXmlHttpObject()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest();
if (objXMLHttp.overrideMimeType) {
                objXMLHttp.overrideMimeType('text/xml');

            }

}
else if (window.ActiveXObject)
{
        try {
                objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
}
return objXMLHttp
}
function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }

function Validate_Email_Address(email_address)
         {
  
         at = email_address.indexOf('@');
         dot = email_address.indexOf('.');
         
         if(at == -1 || 
            dot == -1 || 
            dot <= at + 1 ||
            dot == 0 || 
            dot == email_address.length - 1)
            return(false);
            
         user_name = email_address.substr(0, at);
         domain_name = email_address.substr(at + 1, email_address.length);                  
         
         if(Validate_String(user_name) === false || 
            Validate_String(domain_name) === false)
            return(false);                     
         
         return(true);
         }

function emailus()
{
	if(	document.getElementById("email").value=="")
		alert ("Dien dia chi Email!");
		else
		{
			if(	document.getElementById("mess").value=="")
			alert ("Dien noi dung!");
			else
			{
			if(Validate_Email_Address(document.getElementById("email").value)==false)
				alert("Dia chi email khong dung!");
			else
			{
				xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="../act.php";

url=url+"?act="+"email&email="+document.getElementById("email").value+"&mess="+document.getElementById("mess").value;
document.getElementById("emailme").innerHTML="Đang gởi email đi...<br/> <br/>";
xmlHttp.onreadystatechange=function() { stateChanged(xmlHttp,"emailme"); };
//alert(url);
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
				}}
			}
	}
function clearme()
{
	document.getElementById("email").value="";
	document.getElementById("mess").value="";
	}