// JavaScript Document
function CheckSearch()
{
	with (document.fs)
	{
		if (txtsearch.value=="")
		{
			alert("Please enter keyword!");
			txtsearch.focus();
			return false;
		}
	}
	return true;
}

function CheckLogin()
{
	with (document.fl)
	{
		if (username.value=="")
		{
			alert("Please enter username!");
			username.focus();
			return false;
		}
		if (password.value=="")
		{
			alert("Please enter password!");
			password.focus();
			return false;
		}
	}
	return true;
}

function CheckFormReg()
{
        with (document.FormName)
        {
                if (username.value==""||username.value.length < 3||username.value.length > 30)
                {
                        alert("Tên truy cập không hợp lệ");
                        username.focus();
                        return false;
                }
			   if (password.value==""||password.value.length < 6)
                {
                        alert("Mật khẩu không hợp lệ");
                        password.focus();
                        return false;
                }
                if (email.value=="")
                {
                        alert("Phải nhập vào email");
                        email.focus();
                        return false;
                }
                else
                {
                        if(email.value.indexOf("@")<0||email.value.indexOf(".")<0)
                        {
                                alert("Email không hợp lệ");
                                email.focus();
                                return false;
                        }

                }			
        }
        return true;
}

function CheckFormBuy()
{
        with (document.form1)
        {
                if (fullnamez.value=="")
                {
                        alert("Tên người nhận hàng cần phải có!");
                        fullname.focus();
                        return false;
                }
                if (emailz.value=="")
                {
                        alert("Phải nhập vào email người nhận");
                        email.focus();
                        return false;
                }
                else
                {
                        if(emailz.value.indexOf("@")<0||emailz.value.indexOf(".")<0)
                        {
                                alert("Email người nhận hàng không hợp lệ");
                                email.focus();
                                return false;
                        }

                }
				if (diachiz.value=="")
                {
                        alert("Phải có địa chỉ ngưòi nhận hàng!");
                        diachi.focus();
                        return false;
                }
				if (thanhphoz.value=="")
                {
                        alert("Phải nhập vào thành phố người nhận hàng!");
                        thanhpho.focus();
                        return false;
                }
				if (quocgiaz.value=="")
                {
                        alert("Phải nhập vào quốc gia người nhận hàng!");
                        quocgia.focus();
                        return false;
                }
        }
        return true;
}

function openImageNews(vLink, vHeight, vWidth)
{
	var sLink = (typeof(vLink.href)=='undefined') ? vLink : vLink.href;

	if (sLink=='')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,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);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>Chi tiết hình ảnh!</title><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

function sameto()
{	
	if(document.form1.muanhan.checked)
	{
	document.form1.fullnamez.value =	document.form1.fullname.value;
	document.form1.emailz.value =	document.form1.email.value;
	document.form1.dienthoaiz.value =	document.form1.dienthoai.value;
	document.form1.faxz.value =	document.form1.fax.value;
	document.form1.diachiz.value =	document.form1.diachi.value;
	document.form1.thanhphoz.value =	document.form1.thanhpho.value;
	document.form1.quocgiaz.value =	document.form1.quocgia.value;

	//disable
	
	//document.form1.fullnamez.readonly =	true;
	//document.form1.emailz.disabled =	true;
	//document.form1.dienthoaiz.disabled =	true;
	//document.form1.faxz.disabled =	true;
	//document.form1.diachiz.disabled =	true;
	//document.form1.thanhphoz.disabled =	true;
	//document.form1.quocgiaz.disabled =	true;
	}
	else
	{
	document.form1.fullnamez.value =	'';
	document.form1.emailz.value =	'';
	document.form1.dienthoaiz.value =	'';
	document.form1.faxz.value =	'';
	document.form1.diachiz.value =	'';
	document.form1.thanhphoz.value =	'';
	document.form1.quocgiaz.value =	'';

	//disable
	
	//document.form1.fullnamez.disabled=false;
	//document.form1.emailz.disabled=false;
	//document.form1.dienthoaiz.disabled=false;
	//document.form1.faxz.enabledisabled=false;
	//document.form1.diachiz.enabledisabled=false;
	//document.form1.thanhphoz.enabledisabled=false;
	//document.form1.quocgiaz.enabledisabled=false;
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


//SELECT CELL
	var theoldcell = ""
	function showhide(thecell)
	{	
		if(theoldcell == thecell){
			eval('document.all.'+thecell).style.display = 'none'
			eval('document.all.'+theoldcell).style.display = 'none'
			theoldcell = ""
		}else{
			if(theoldcell != thecell){
				if(theoldcell != "")
				eval('document.all.'+theoldcell).style.display = 'none'
				eval('document.all.'+thecell).style.display = ''
				theoldcell = thecell
			}
		}
	}


//MOUSE
	function mOvr(src) {
		//if (!src.contains(event.fromElement)) {
		src.style.cursor = 'pointer';
		//}
	}
	function mOut(src) {
		//if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		//}
	}
	function mClk(src) {
		if(event.srcElement.tagName=='TD'){
		src.children.tags('A')[0].click();
		}
	}
	
//NEW MOUSE
function showhidebrotherrows(currentrow)
{
	currentelement = document.getElementById(currentrow) ;
	menunumber = currentrow.split('mastermenu')[1] ;
	
	if (currentelement.parentNode.rows)
	{
		//alert(currentelement.parentNode.rows) ;
		//alert(menunumber) ;
		for (i=0; i<currentelement.parentNode.rows.length; i++)
		{
			subelement = currentelement.parentNode.rows[i] ;
			if (subelement.id != "")
			{
				subnumber = "" ;
				issubnumber = subelement.id.split('detailmenu')[0] ;
				if (issubnumber != subelement.id)
				{
					subnumber = subelement.id.split('detailmenu')[1] ;
					//alert("menunumber : " + menunumber + " id : " + subelement.id + " no : " + subnumber + " show hide : " + (subnumber == menunumber)) ;
					if (subnumber == menunumber)
					{
						if (subelement.style.display == "none")
							subelement.style.display = "" ;
						else
							subelement.style.display = "none" ;
					}
					else
					{
						subelement.style.display = "none" ;						
					}
				}
			}
		}
	}
	//alert(currentelement.parentNode) ;
	//alert(currentelement.parentNode.rows.length) ;
}


/*------------------------- COMMON -------------------------------------------*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {   
    window.onload = func;
  }
  else
  {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addLoadEventwithparam(func, param) {
  var oldonload = window.onload;
  //alert('1') ;
  if (typeof window.onload != 'function') 
  { 
  //alert('2') ;
    window.onload = func(param);
  }
  else
  {
  //alert('3') ;
    window.onload = function() {//alert('1') ;
      oldonload();//alert('2') ;
      func(param);//alert('3') ;
    }
  }
}

function preselectMenu(menuid)
{	
//menuid = "ul1_100" ;
//alert(menuid) ;
  var node = document.getElementById(menuid);
  if (node)
  {
  //alert('found node ' + menuid) ;
	  if (node.className.search(/classhide/) != -1)
	  {
	  //alert('1') ;
		node.className=node.className.replace(/classhide/g, "classshow");
		}
	  else
	  {
	  //alert('2') ;
	  	node.className += " classshow" ;
	}
  }
}

function toggleMenu(menuid)
{
	if (!document.getElementById) return false;
	if (!document.getElementById(menuid)) return false;
  
	var menu = document.getElementById(menuid) ;
			
	if (menu)
	{
		//x = menu.className ;
		if (menu.className.search(/classhide/) != -1)
			menu.className=menu.className.replace(/classhide/g, "classshow");
		else
		{
			if (menu.className.search(/classshow/) != -1)
				menu.className=menu.className.replace(/classshow/g, "classhide");
			else
				menu.className += " classshow" ;
		}		
		//alert(x + "-" + menu.className + "-" + menuid + "-" + document.getElementById("menuhtkh").className) ;
	}
}

function geturlparameter(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
	return "";
  else
	return results[1];
}

function displayid(id)
{
	var node = document.getElementById(id);
	if (node)
	{
		alert(id) ;
		node.style.display = "" ;
	}
}
