/* - - - - - - - - - - - - - - - - - - - - - - -
Ajax Javascript
 - - - - - - - - - - - - - - - - - - - - - - - */
var ie45,ns6,ns4,dom;
if (navigator.appName=="Microsoft Internet Explorer") ie45=parseInt(navigator.appVersion)>=4;
else if (navigator.appName=="Netscape"){  ns6=parseInt(navigator.appVersion)>=5;  ns4=parseInt(navigator.appVersion)<5;}
dom=ie45 || ns6;

var http=createRequestObject();
var objectId = '';
var loadok = 0;

function createRequestObject(htmlObjectId){
    var obj;
    var browser = navigator.appName;
    
    if(browser == "Microsoft Internet Explorer"){
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        obj = new XMLHttpRequest();
    }
    return obj;    
}

function sendReq(serverFileName, variableNames, variableValues,objId) {
	var paramString = '';
	
	objectId = objId;
	
	variableNames = variableNames.split(',');
	variableValues = variableValues.split(',');
	
	for(i=0; i<variableNames.length; i++) {
		paramString += variableNames[i]+'='+variableValues[i]+'&';
	}
	paramString = paramString.substring(0, (paramString.length-1));
			
	if (paramString.length == 0) {
	   	http.open('get', serverFileName);
	}
	else {
		http.open('get', serverFileName+'?'+paramString);
	}
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
	
	if (http.readyState == 4) {
		responseText = http.responseText;
		getobj(objectId).innerHTML = responseText;
    } else {
		getobj(objectId).innerHTML = "<br><div align=center><img src='images/loading.gif' border=0><br>&#272;ang l&#7845;y d&#7919; li&#7879;u ...</div>";
	}
		
}

function change_icon(imgDocID,url) {
document.images[imgDocID].src = url;
}  

function showhide(id) {
el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
els = dom ? el.style : el;
  if (dom){
    if (els.display == "none") {
        els.display = "";
      } else {
        els.display = "none";
      }
    }
  else if (ns4){
    if (els.display == "show") {
        els.display = "hide";
      } else { 
      els.display = "show";
         }
  }
}

function getobj(id) {
el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
return el;
}

function showobj(id) {
obj=getobj(id);
els = dom ? obj.style : obj;
 	if (dom){
	    els.display = "";
    } else if (ns4){
        els.display = "show";
  	}
}

function hideobj(id) {
obj=getobj(id);
els = dom ? obj.style : obj;
 	if (dom){
	    els.display = "none";
    } else if (ns4){
        els.display = "hide";
  	}
}

// khong the phong to cua so
function openPopUp(url, windowName, w, h, scrollbar) {
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
   win = window.open(url, windowName, winprops);
   if (parseInt(navigator.appVersion) >= 4) { 
       	win.window.focus(); 
   } 
}

// co the phong to cua so
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

function is_num(event,f){
if (event.srcElement) {kc =  event.keyCode;} else {kc =  event.which;}
if ((kc < 47 || kc > 57) && kc != 8 && kc != 0) return false;
return true;
}

function del_item(theURL) {
    if (confirm('Bạn có chắc muốn XOÁ không ?')) {
          window.location.href=theURL;
       }
       else {
          alert ('Phew~');
       } 
}

function selected_item(){
		var name_count = document.manage.length;

		for (i=0;i<name_count;i++){
			if (document.manage.elements[i].checked){
				return true;
			}
		}
		alert('Hãy chọn ít nhất 1 record');
		return false;
	}
	
function del_selected(action) {
		if (selected_item()){
			question = confirm('Bạn có chắc muốn XÓA không ?')
			if (question != "0"){
				document.manage.action=action;
				document.manage.submit();
			}else{
			  alert ('Phew~');
		    }
		}
	
}
function do_submit(action) {
	document.manage.do_action.value=action;
	if (action=="del"){
		if (selected_item()){
			question = confirm('Bạn có chắc muốn XOÁ không ?')
			if (question != "0"){
				document.manage.submit();
			}else{
			  alert ('Phew~');
		    }
		}
	}else{
		document.manage.submit();
	}
	
}
	
function checkall()	{
	for ( i=0;i < document.manage.elements.length ; i++ ){
		if (i>0 && document.manage.elements[i].type=="checkbox"){
			row_id = 'row_'+document.manage.elements[i].value;
		}else{
			row_id="";
		}
		
		if ( document.manage.all.checked==true ){
			document.manage.elements[i].checked = true;
			if (row_id!="" ){
				getobj(row_id).className = "row_select";
			}
		}
		else{
			document.manage.elements[i].checked  = false;
			if (row_id!="" ){
				if (i%2==0)
					getobj(row_id).className = "row1";
				else
					getobj(row_id).className = "row";
			}
		}
		
	}
}

function select_row(row_id)	{
	cur_class = getobj(row_id).className;
	if (cur_class=="row_select"){
		getobj(row_id).className ="row";	
	}else{
		getobj(row_id).className = "row_select";
	}

}


/* - - - - - - - - - - - - - - - - - - - - - - -
				checkform submit
 - - - - - - - - - - - - - - - - - - - - - - - */
// form add lang
function checkform_lang(f) {			
	var title = f.title.value;
	if (title == '') {
		alert('Plz enter Lang Name');
		f.title.focus();
		return false;
	}
		return true;
}


