function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}


var newwindow;
function openwindow(url,name)//Mở cửa xỏ mới
{
	newwindow=window.open(url,name,'height=350,width=500,top=100,resizable=yes,scrollbars=yes,toolbar=no,status=yes');
	if (window.focus) {newwindow.focus()}
}
	
function destination(route)//Điểm kết thúc
	{
	switch (route)
		{
			case "0": divdestination.innerHTML="";
			break;
			case "1": divdestination.innerHTML="<select onchange=\"javascript:timego(theForm.txtstart.value,this.options[this.selectedIndex].value)\;\" name=txtdestination class='selectoption' style='width:100px;'><option value='0'>Nơi đến</option><option value='2'>Lào Cai</option></select>";
			break;
			case "2": divdestination.innerHTML="<select onchange=\"javascript:timego(theForm.txtstart.value,this.options[this.selectedIndex].value)\;\" name=txtdestination class='selectoption' style='width:100px;'><option value='0'>Nơi đến</option><option value='1'>Hà Nội</option></select>";
			break;
		}	
	}	
	
	

function destination_admin(route)//Điểm kết thúc
	{
	switch (route)
		{
			case "0": divdestination.innerHTML="";
			break;
			case "1": divdestination.innerHTML="<select name=txtdestination class='selectoption' style='width:100px;'><option value='0'>Nơi đến</option><option value='2'>Lào Cai</option></select>";
			break;
			case "2": divdestination.innerHTML="<select name=txtdestination class='selectoption' style='width:100px;'><option value='0'>Nơi đến</option><option value='1'>Hà Nội</option></select>";
			break;
		}	
	}		
	
	
	
	
function destination_updateticket(route)//Điểm kết thúc
	{
	switch (route)
		{
			case "0": divdestination.innerHTML="";
			break;
			case "1": divdestination.innerHTML="Đến:&nbsp;<select onchange=\"javascript:ajaxpage('cnnel.php?cid=22,29&txtstart='+theForm.txtstart.value+'&txtdestination='+this.options[this.selectedIndex].value, 'divchairtype');\" name=txtdestination class='selectoption' style='width:100px;'><option value='0'>Nơi đến</option><option value='2'>Lào Cai</option></select>";
			break;
			case "2": divdestination.innerHTML="Đến:&nbsp;<select onchange=\"javascript:ajaxpage('cnnel.php?cid=22,29&txtstart='+theForm.txtstart.value+'&txtdestination='+this.options[this.selectedIndex].value, 'divchairtype');\" name=txtdestination class='selectoption' style='width:100px;'><option value='0'>Nơi đến</option><option value='1'>Hà Nội</option></select>";
			break;			
		}	
	}	
function timego(start,destination)//Khi mình chọn điểm đi, điểm đến, nó sẽ show ra mấy thông tin này cho khách hàng xem nhé
	{
		if(start=="1")
			{
				if(destination=="0")
					divtimego.innerHTML="";				
				if(destination=="2")
					divtimego.innerHTML="Khởi hành: 23:00,<br>Đến nơi: 08:00";								
			}
		if(start=="2")
			{
				if(destination=="0")
					divtimego.innerHTML="";
				if(destination=="1")
					divtimego.innerHTML="khởi hành: 12:15,<br> Đến nơi: 21:00";								
			}		
	}	
	
	
	function getCheckedValue(radioObj) 
	{
		if(!radioObj)
			return "";
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
				return radioObj.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++) 
		{
			if(radioObj[i].checked) 
			{
				return radioObj[i].value;
			}
		}
		return "";
	}
