function calcHeight(idframe)
{
	//SH Iframe Height Auto Resize v.01
	//Used to resize the height of IFRAME to fit the content without any scrollbar.
	//Coded by Silvery Hat Hacker 2006
	var dodai_trang = document.getElementById(idframe).contentWindow.document.body.scrollHeight;
	document.getElementById(idframe).height=dodai_trang;
}

function goTo(dlName) {
	var sE = null, url;
	if(document.getElementById) {
		sE = document.getElementById(dlName);
	} 
	else if(document.all) 
	{
		sE = document.all[dlName];
	}
	if(sE && (url = sE.options[sE.selectedIndex].value)) 
	{
		window.open(url);
	}
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
	  {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function getEmailAndPass(form){
	email =	document.form_login.txtEmail.value;
	pass = document.form_login.txtPass.value;
	if(	checkmail(email))
		Login(email, pass);
}

function checkmail(e){
	var txtEmail = e;
		var err=''
		if (txtEmail == ''){
			err += "Dia chi email khong hop le";
			alert(err);
			return false;
		}
		if (txtEmail.indexOf('@') <= 0 || txtEmail.indexOf('@') == txtEmail.length -1){
			err += "Dia chi email khong hop le";
		} else {
			var substr = txtEmail.substring(txtEmail.indexOf('@'),txtEmail.length);
			if (txtEmail.indexOf('.') <= 0) {
				err += "Dia chi email khong hop le\n";
			}
		}
		
		if (err != '') {
			alert(err);
			return false;
		}		
		return true;
}

function doClick(buttonName,e)
{//the purpose of this function is to allow the enter key to point to the correct button to click.
	var key;

	 if(window.event)
		  key = window.event.keyCode;     //IE
	 else
		  key = e.which;     //firefox

	if (key == 13)
	{
		//Get the button the user wants to have clicked
		var btn = document.getElementById(buttonName);
		if (btn != null)
		{ //If we find the button click it
			btn.click();
			event.keyCode = 0
		}
	}
}


function popup(mylink)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, '', 'width=600,height=500,scrollbars=yes,status=no');
}

function checkformReg(f) {

	var txtEmail = f.txtEmail.value;
	var err=''
	if (txtEmail == ''){
		err += "Dia chi email khong hop le";
		alert(err);
		f.txtEmail.focus();
		return false;
	}
	if (txtEmail.indexOf('@') <= 0 || txtEmail.indexOf('@') == txtEmail.length -1){
		err += "Dia chi email khong hop le";
	} else {
		var substr = txtEmail.substring(txtEmail.indexOf('@'),txtEmail.length);
		if (txtEmail.indexOf('.') <= 0) {
			err += "Dia chi email khong hop le\n";
		}
	}
	
	if (err != '') {
		alert(err);
		f.txtEmail.focus();
		return false;
	}		
	var txtPassword = f.txtPass.value;
	if (txtPassword == ""){
		alert('Vui long nhap vao mat khau');
		f.txtPass.focus();
		return false;
	}

	
	var txtFullName = f.txtFullname.value;
	
	if (txtFullName == '') {
		alert('Nhap vao ho ten');
		f.txtFullname.focus();
		return false;
	}
	
	
	code = f.txtCode.value;		
	if(code == '') {
		alert('+ Nhap ma an toan khong dung!\n+ Ma an toan la so nam trong o mau xanh');
		f.txtCode.focus();
		return false;
	}
	
	return true;
}

function checkformLogin(f) {

	var txtEmail = f.txtEmail.value;
	var err=''
	if (txtEmail == ''){
		err += "Dia chi email khong hop le";
		alert(err);
		f.txtEmail.focus();
		return false;
	}
	if (txtEmail.indexOf('@') <= 0 || txtEmail.indexOf('@') == txtEmail.length -1){
		err += "Dia chi email khong hop le";
	} else {
		var substr = txtEmail.substring(txtEmail.indexOf('@'),txtEmail.length);
		if (txtEmail.indexOf('.') <= 0) {
			err += "Dia chi email khong hop le\n";
		}
	}
	
	if (err != '') {
		alert(err);
		f.txtEmail.focus();
		return false;
	}		
	var txtPassword = f.txtPass.value;
	if (txtPassword == ""){
		alert('Vui long nhap vao mat khau');
		f.txtPass.focus();
		return false;
	}
	
	return true;
}

function AllowSubmit(form){
	var a=form.amount.value;
	if(isNaN(a))
	{
		alert("So luong khong hop le, vui long nhap lai");		
		return false;
	}
	a=Number(a);
	if(a<0)
	{
		alert("So luong phai lon hon 0 ( >0 )");
		return false;
	}
	return true
}