function qvnboxOpen(qvnID) {
document.getElementById(qvnID).style.display = "block";
document.getElementById(qvnID).innerHTML="<a class='adong' href=\"javascript:qvnboxClose('" + qvnID + "');\">Đóng " + qvnID + "...</a>";
document.getElementById('fade').style.display='block';
}
function qvnboxClose(qvnID) {
document.getElementById(qvnID).style.display = "none";
document.getElementById(qvnID).innerHTML="<a class='adong' href=\"javascript:qvnboxOpen('" + qvnID + "');\">Mở " + qvnID + "...</a>";
document.getElementById('fade').style.display='none';
}
function autoClose(qvnID, time){
	setTimeout ( function() {
			qvnboxClose(qvnID);
			}, time);
}


//Select list move options
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
}
function isChecked(isitchecked){
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}
function checkAll( n, fldName ) {
  if (!fldName) {
     fldName = 'cb';
  }
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}
function SetValues(Form, CheckBox, Value)
{
    var objCheckBoxes = document.forms[Form].elements[CheckBox];
    var countCheckBoxes = objCheckBoxes.length;
    for(var i = 0; i < countCheckBoxes; i++)
     objCheckBoxes[i].checked = Value;
}
function shop_submit(a){
	document.adminForm.type.value = a;
	document.adminForm.submit();
}
function shop_addCart(id, url){
var id= id;
var url = url;
qty = document.getElementById('productQty_'+id).value;
window.location = url+'&qty='+qty+'&product_id='+id,'thongtin';
}
function qalert(mes) {
document.getElementById('thongtin').style.display = "block";
document.getElementById('thongtin').innerHTML='<a href="javascript:qvnboxClose(\'thongtin\')" class="adong">x</a>'+mes;
document.getElementById('fade').style.display='block'
}
function qconfirm(mes,a){
document.getElementById('thongtin').style.display = "block";
document.getElementById('thongtin').innerHTML='<a href="javascript:qvnboxClose(\'thongtin\')" class="adong">x</a>'+mes+'<div style="text-align: center; margin: 5px"><input type="button" value="Có" onclick="shop_submit(\''+a+'\')"/><input type="button" value="Không" onclick="document.adminForm.boxchecked.value=0;document.adminForm.toggle.checked=false;SetValues(\'adminForm\', \'sp_id[]\', false);qvnboxClose(\'thongtin\')"/></div>';
document.getElementById('fade').style.display='block';
}
function qconfirm2(mes){
document.getElementById('thongtin').style.display = "block";
document.getElementById('thongtin').innerHTML='<a href="javascript:SetValues(\'adminForm\', \'order_id[]\', false);qvnboxClose(\'thongtin\')" class="adong">x</a>'+mes+'<div style="text-align: center; margin: 5px"><input type="button" value="Có" onclick="document.adminForm.submit();"/><input type="button" value="Không" onclick="document.adminForm.boxchecked.value=0;document.adminForm.toggle.checked=false;SetValues(\'adminForm\', \'order_id[]\', false);qvnboxClose(\'thongtin\')"/></div>';
document.getElementById('fade').style.display='block';
}
function qconfirm_edit(mes, id){
document.getElementById('thongtin').style.display = "block";
document.getElementById('thongtin').innerHTML='<a href="javascript:SetValues(\'adminForm\', \''+id+'[]\', false);qvnboxClose(\'thongtin\')" class="adong">x</a>'+mes+'<div style="text-align: center; margin: 5px"><input type="button" value="Có" onclick="document.adminForm.submit();"/><input type="button" value="Không" onclick="document.adminForm.boxchecked.value=0;document.adminForm.toggle.checked=false;SetValues(\'adminForm\', \''+id+'[]\', false);qvnboxClose(\'thongtin\')"/></div>';
document.getElementById('fade').style.display='block';
}
function qaction(url){
window.location = url;
}
/********* toggle****/
function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
}
/*********check form dang ky va dang nhap *********/
function isEmail(s)
{   
  if (s=="") return false;
  if(s.indexOf(" ")>0) return false;
  if(s.indexOf("@")==-1) return false;
  var i = 1;
  var sLength = s.length;
  if (s.indexOf(".")==-1) return false;
  if (s.indexOf("..")!=-1) return false;
  if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
  if (s.lastIndexOf(".")==s.length-1) return false;
  var str="abcdefghikjlmnopqrstuvwxyz1234567890-@._"; 
  for(var j=0;j<s.length;j++)
	if(str.indexOf(s.charAt(j))==-1)
		return false;
   return true;
}
function checkForm(){
	if(document.dangky.username.value == "") {
		document.dangky.username.focus();
		formError('username');	return false;
	}else{
		fomrOk('username');
	}
	if(document.dangky.password.value == "") {
		document.dangky.password.focus();
		formError('password');	return false;
	}else{
		fomrOk('password');
	}
	if(document.dangky.password.value != document.dangky.password2.value) {
		document.dangky.password2.focus();
		formError('password2');	return false;
	} else {
		fomrOk('password2');
	}
	if(document.dangky.email.value == "") {
		formError('email');	return false;
	} else if (!isEmail(document.dangky.email.value)) {
		formError('email');	return false;
	}
	else {
		fomrOk('email');
	}
	
	if(document.dangky.first_name.value == "") {
		formError('first_name');	return false;
	}else{
		fomrOk('first_name');
	}
	if(document.dangky.last_name.value == "") {
		formError('last_name');	return false;
	}else{
		fomrOk('last_name');
	}
	if(document.dangky.phone.value == "") {
		formError('phone');	return false;
	}else{
		fomrOk('phone');
	}
	if(document.dangky.address.value == "") {
		formError('address');	return false;
	}else{
		fomrOk('address');
	}
	if(document.dangky.city.value == "") {
		formError('city');	return false;
	}else{
		fomrOk('city');
	}
	if(document.dangky.country.value == "") {
		formError('country');	return false;
	}else{
		fomrOk('country');
	}
	if(document.dangky.zip.value == "") {
		formError('zip');	return false;
	}else{
		fomrOk('zip');
	}
	if(document.dangky.terms.checked == false) {
		qalert('Điều khoản dịch vụ');	return false;
	}else{
		fomrOk('terms');
	}
	
	return true;
	
}
function formError(id){
	document.getElementById(id).style.border = '1px solid #f9a64a';
}
function fomrOk(id){
	document.getElementById(id).style.border = '1px solid #dee7a5';
}
