//javascript function
/**
*
*/
function reloadCaptcha() {
	document.captcha_img.src="includes/captcha/cp/visual-captcha.php?var="+Math.random();
}

/**
 * Sets the cursor position for the passed control
 */

function setCaretPosition(ctrl, pos)
{

    if(ctrl.setSelectionRange)
    {
        ctrl.focus();
        ctrl.setSelectionRange(pos,pos);
    }
    else if (ctrl.createTextRange) {
        var range = ctrl.createTextRange();
        range.collapse(true);
        range.moveEnd('character', pos);
        range.moveStart('character', pos);
        range.select();
    }
}

function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function stateChanged() 
{
    if (xmlHttp.readyState==4) {
        //logic goes here
		document.getElementById("game_details").innerHTML=xmlHttp.responseText;
    } /*else if(xmlHttp.readyState<4) {
		document.getElementById("game_details").innerHTML="Loading datas, Please wait...";
    }*/
}

function showDetails(id)
{
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null){
       alert ("Your browser does not support AJAX!");
       return;
    }
    
    var url="ajax_viewGameDetails.php?id=" + id;
    //parameters passed here
	xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);

  }

/*function checkLogin(obj)
{
	email = document.frmlogin.email.value;
	pass = document.frmlogin.password.value;
	if (email=="")
	{
		alert("Email is not empty!");
		document.frmlogin.email.focus();
		return false;
	}

	re=/^\w+@(\w+\.)+[a-zA-Z]{2,4}$/
	if (re.test(email)==false)
	{
		alert("wrong email!");
		document.frmlogin.email.focus();
		return false;
	}

	if (pass=="" )
	{
		alert("password is not empty!");
		document.frmlogin.pass.focus();
		return false;
	}
	
}*/

function validateForm1() {	
	
	if(emailValidate(document.getElementById("email").value)==false) {
		alert("Please Enter Valid Email Address");
		return false;
	}
	
	if(document.getElementById("captcha").value=="") {
		alert("Please Enter Verification Code");
		return false;
	}
	
	return true;
}


function emailValidate(str){
	    var  filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	    if (filter.test(str))
	        testresults=true;
			
	    else{
	       testresults=false;
	    }
	
	    return (testresults);
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("txtGames").innerHTML=xmlHttp.responseText;
	}
}

function showVitalStatis(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="ajax_getVital.php?site="+str;
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("show_statistic").innerHTML=xmlHttp.responseText;
	}
}


function showGamePage(game,page)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="ajax_gamePage.php?game="+game+"?p="+page;
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("game_page").innerHTML=xmlHttp.responseText;
	}
}

function showNewsDetail(news_id)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="ajax_newsDetail.php?news_id="+news_id;
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged4;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged4() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("news").innerHTML=xmlHttp.responseText;
	}
}

function checkfrm1() {		
	if(document.getElementById("title").value=="") {
		alert("please type title!!!");
		return false;
	}		
	return true;
}

function checkall(obj){
	var i=0;
	for(i=0;i<obj.length;i++){
		obj.elements[i].checked=true;
	}
	document.frmList.boxchecked.value = obj.length-3;
}


function uncheckall(obj){
	var i=0;
	for(i=0;i<obj.length;i++){
		obj.elements[i].checked=false;
	}
	document.frmList.boxchecked.value = 0;
	
}

function isChecked(isitchecked){
	if (isitchecked == true){
		document.frmList.boxchecked.value++;
	}
	
	else {
		document.frmList.boxchecked.value--;
	}
}


function checkfrm2() {	
	var ok=1;	
	if(document.getElementById("title").value==""){
		alert("plz fill all fields!!!");
		return false;
	}
	return true;

}

function checkfrm3(){
	if(emailValidate(document.getElementById("email").value)==false) {
		alert("Please Enter Valid Email Address");
		return false;
	}
	if((isNaN(document.getElementById("phone1").value))||(isNaN(document.getElementById("phone2").value))){
		alert("phone is required a number!!!");
		return false;
	}	
	if(isNaN(document.getElementById("state").value)){
		alert("state is required a number!!!");
		return false;
	}	
	if(isNaN(document.getElementById("fax").value)){
		alert("fax is required a number!!!");
		return false;
	}

}

function checkfrm4(){
	
	if((isNaN(document.getElementById("home_phone").value))||(isNaN(document.getElementById("other_phone").value))){
		alert("phone is required a number!!!");
		return false;
	}	
	
	if(isNaN(document.getElementById("state").value)){
		alert("state is required a number!!!");
		return false;
	}
	
	if(isNaN(document.getElementById("post_zip").value)){
		alert("post zip is required a number!!!");
		return false;
	}
	
}


function confirm_delete(){
	if(document.frmList.boxchecked.value == 0) {
		alert("Please make a selection from the list to Delete");
		return false;
	}
	else{
		var r=confirm("Are you sure you want to delete?");
		if (r==true)
		  {
		  return true;
		  }
		else
		  {
		  return false;
		  }			
	}
}

function showMemByPerm(perm)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="ajax_showPermMem.php?perm="+perm;
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged5;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged5() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("mem_by_perm").innerHTML=xmlHttp.responseText;
	}
}

function showPermOfMem(mem)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="ajax_showPermOfMem.php?mem="+mem;
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged6;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged6() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	document.getElementById("show_perm").innerHTML=xmlHttp.responseText;
	}
}

function confirmUpdate(){	
	var r=confirm("Are you sure?");
	if (r==true){
		return true;
	}
	else{
	  	return false;
	}	
}

function checkradio(){
	ok=0;
	for(i=0;i<document.form1.rad_edit.length;i++){
		if(document.form1.rad_edit[i].checked==true){
			ok=1;
			break;		
		}	
	}
	if (ok==0){
		alert('Please select one to edit!');
		return false;
	}
}

function checkfrm5(){
	var txt=document.getElementById("pass").value;
	if(emailValidate(document.getElementById("email").value)==false) {
		alert("Please Enter Valid Email Address!");
		document.getElementById("email").style.background="yellow";
		return false;
	}	
	
	if(document.getElementById("pass").value=="") {
		alert("Please Enter password!");
		document.getElementById("pass").style.background="yellow";
		return false;
	}
	
	if(txt.length<6){
		alert("Password is too short!");
		document.getElementById("pass").style.background="yellow";
		return false;	
	}
		
	if(document.getElementById("repass").value==""){
		alert("Please re-enter password!");
		document.getElementById("repass").style.background="yellow";
		return false;
	}
	
	if(document.getElementById("pass").value!=document.getElementById("repass").value){
		alert("Both passwords don't match!");
		document.getElementById("pass").style.background="yellow";
		document.getElementById("repass").style.background="yellow";
		return false;		
	}		
}

function checkfrm6(){
	var txt=document.getElementById("pass").value;
	if(emailValidate(document.getElementById("email").value)==false) {
		alert("Please Enter Valid Email Address!");
		document.getElementById("email").style.background="yellow";
		return false;
	}	
	if ((txt!='')&&(txt.length<6)){
		document.getElementById("pass").style.background="yellow";
		alert("Password is too short!");
		return false;	
	}	

	if(document.getElementById("pass").value!=document.getElementById("repass").value){
		alert("Both passwords don't match!");
		document.getElementById("pass").style.background="yellow";
		document.getElementById("repass").style.background="yellow";
		return false;		
	}		
	
}

function checkfrm7(){
	if(document.getElementById('site_name').value==""){
		alert("Please enter a site name.");
		document.getElementById("site_name").style.background="yellow";
		return false;		
	}	
	if(document.getElementById('expires').value==""){
		alert("Please set the expire date.");
		document.getElementById("expires").style.background="yellow";
		return false;		
	}	
	
}

function setStyle(x){
	document.getElementById(x).style.background="white";	
}



/**************SCRIPT FOR INPUT TYPE = FILE****************/
/**************Thang nn$$$$$$$$$$$$$$$****************/


function clearInput(control, sValue){
  
  if(control.value == sValue){
    control.value="";
  }
    
}

/**
*
*/
