// JavaScript Document
var brower=getbrowser();
function getObj(name) 
{   if (document.getElementById) { return document.getElementById(name); }
			else if (document.all)       { return document.all[name]; }
			else if (document.layers)    { return document.layers[name]; }
}


function offsetLeft(el)
  {
    x = el.offsetLeft
    for (e = el.offsetParent; e; e = e.offsetParent)
      x += e.offsetLeft;
    return x
  } 

 function offsetTop(el)
  {
    y = el.offsetTop
    for (e = el.offsetParent; e; e = e.offsetParent)
      y += e.offsetTop;
    return y
 } 
  
  

function getbrowser(){
	detect = navigator.userAgent.toLowerCase();
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else{
	 browser = "An unknown browser";  
	}
	return browser;
} 
	
function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


function getcombox(obj,idarray){
		removecombox(obj);
		
		switch(brower){
			case "Netscape Navigator":
				addtocombox1(obj,idarray);
				break;
			case "Internet Explorer":
				addtocombox2(obj,idarray);
				break;

		}
		
		

}

function removecombox(obj){
		n=obj.options.length
		for( i=0;i<n;i++){
//			alert(obj.options[1].text);
			obj.remove(0);

		}

}

function addtocombox1(obj,idarray){
		combox=null;
		str= 'if(typeof(combo_' + idarray +')!="undefined"){ combox=combo_' + idarray +';}';
		eval(str);
		e=document.createElement("OPTION");
		e.value="";
		e.text="-- chọn quận/huyện --";
		obj.appendChild(e);		
		if(combox!=null){
			 for ( i = 0; i < combox.length; i++ ) {
				e=document.createElement("OPTION");
				parts = combox[i].split( '|' )
				e.value=parts[0];
				e.text=parts[1];
				obj.appendChild(e);		
			 }
		 }
	}

function addtocombox2(obj,idarray){
		combox=null;
		str= 'if(typeof(combo_' + idarray +')!="undefined"){ combox=combo_' + idarray +';}';
		eval(str);
		e=document.createElement("OPTION");
		e.value="";
		e.text="------------------";
		obj.add(e);		
		if(combox!=null){
			 for ( i = 0; i < combox.length; i++ ) {
				e=document.createElement("OPTION");
				parts = combox[i].split( '|' )
				e.value=parts[0];
				e.text=parts[1];
				obj.add(e);		
			 }
		 }
	}
	
var req=null;
var which=null;
function retrieveURL(url) {
	req=null;
	which=null;
	if (window.XMLHttpRequest) { // Non-IE browsers
		req = new XMLHttpRequest();
		req.onreadystatechange = processStateChange;
		try {
			req.open("GET", url, true);
		} catch (e) {
			alert(e);
		}
		req.send(null);
	} 
	else if (window.ActiveXObject) { // IE
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processStateChange;
			req.open("GET", url, true);
			req.send();
		}
	}

}

function processStateChange() {
	if (req.readyState == 4) { // Complete
		if (req.status == 200) { // OK response
			//document.getElementById("fileuploaded").innerHTML = req.responseText;
			alert(req.responseText);
		}
	 	else {
			alert("Problem: " + req.statusText);
		}
	}
}

function openMedia(url, vHeight, vWidth)
{	
	winDef = 'status=no,resizable=no,scrollbars=yes,toolbar=no,location=no,fullscreen=no,titlebar=no,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	var winmedia ;
	winmedia= window.open(url,'_blank', winDef);
	winmedia.focus();

}
function openPage(url, vHeight, vWidth)
{	
	winDef = 'status=yes,resizable=yes,scrollbars=yes,fullscreen=no,titlebar=no,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	var winmedia ;
	winmedia= window.open(url,'_blank', winDef);
	winmedia.focus();
	

}

function select_all_checkbox(tableid,checkname,checked){
		//this.checked=false; 
		//this.checked=!this.checked;
		table=getObj(tableid);
		input=table.getElementsByTagName("input");
		for(var no=0;no<input.length;no++){
			if((input[no].type=="checkbox")&&(input[no].name==checkname)){
				input[no].checked=checked;
			}
		}
}
	
function get_checked(tableid,checkname){
	
	array_id="";
	table=getObj(tableid);
	if(!table) return ;
	input=table.getElementsByTagName("input");
	for(var no=0;no<input.length;no++){
		if((input[no].type=="checkbox")&&(input[no].name==checkname)&&(input[no].checked==true)){
			array_id =array_id + input[no].value +"|";
		}
	}		
	n=array_id.length;
	if(n>0)	array_id=	array_id.substring(0,n-1);
	//alert(array_id);
	return array_id;
}

