﻿// JScript File

function color(obj, color)
{
    obj.style.color=color
}

function cursor(obj, cursor)
{
    obj.style.cursor = cursor;
}

function bg(obj, bgColor)
{
    obj.style.backgroundColor = bgColor;
}

function fontSize(obj, size)
{
     obj.style.fontSize = size;
}

function fontWeight(obj, style)
{
    obj.style.fontWeight = style;
}

function changeImage(obj,col)
{
	obj.src = col;
}

var lastMarkedObj;

function colorMark(obj, lastMarkedObj, oldColor, changeColor)
{
    if (oldColor.length > 0 && obj.id == lastMarkedObj)
    {
        obj.style.backgroundColor = oldColor;
        return;
    }
    
    obj.style.backgroundColor = changeColor;
}

function singleSelected(obj, markColor, unmarkColor)
{
    // refresh last row's background color.
    if (lastMarkedObj != null && lastMarkedObj.length > 0)
        document.getElementById(lastMarkedObj).style.backgroundColor = unmarkColor;
    
    // retrive ID of selected row
    lastMarkedObj = obj.id;
        
    obj.style.backgroundColor = markColor;
}


function validate(id) {
        var obj = document.getElementById(id);

        if (obj.value.length == 0) {
            obj.style.backgroundColor = '#EFD8D7';
            return false;
        }

        obj.style.backgroundColor = '#fff';
        return true;
    }

    function getValidates(scr) {
        var chess = 0;
        for (var i = 0; i < scr.length; i++) {
            if (!validate(scr[i]))
                chess++;
        }

        if (chess > 0) {
            alert("Vui lòng nhập đầy đủ thông tin !!!");
            return false;
        }
        
        return true;
    }
	
	function noNumbers(e) {	
		var keynum
		var returnValue = false
		if (window.event) // IE
		{
			keynum = e.keyCode
		}
		else if (e.which) // Netscape/Firefox/Opera
		{
			keynum = e.which
		}
		if (((keynum >= 48) && (keynum <= 57)) || ((keynum >= 96) && (keynum <= 105)) || // All numerics
					   (keynum == 8) || (keynum == 9) ||     // Backspace and Tab
					   (keynum == 46) || //Delete
					   (keynum == 37) || (keynum == 39) || (keynum == 35) || (keynum == 36) ||
					   (keynum == 188) || (keynum == 116) || (keynum == 13))     // Carriage Return
			returnValue = true;

		return returnValue;
	}
	function IsNumeric(sText)
	{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for(i=0;i<sText.length&&IsNumber==true;i++)
	{
	  Char=sText.charAt(i);
	  if(ValidChars.indexOf(Char)==-1){IsNumber=false;}
	  }
	return IsNumber;
	}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Địa chỉ Email không hợp lệ !!!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Địa chỉ Email không hợp lệ !!!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Địa chỉ Email không hợp lệ !!!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Địa chỉ Email không hợp lệ !!!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Địa chỉ Email không hợp lệ !!!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Địa chỉ Email không hợp lệ !!!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Địa chỉ Email không hợp lệ !!!")
		    return false
		 }

 		 return true					
	}

function emailValidate(emailID){
	if(emailID){
		/*
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID")
			emailID.focus()
			return false
		}
		*/
		if (echeck(emailID.value)==false){
			emailID.value=""
			emailID.focus()
			return false
		}
		return true
	}
}

function add_khachhang(){
	var array = new Array('ten_kh','diachi_kh','dienthoai_kh','nguoilienhe_kh');
	if (!getValidates(array)){
		return false;
	} else {
		return true;
	}
}

function add_cuochen(){
	var array = new Array('ten_ch','noidung_ch','calendar_inputField');
	if (!getValidates(array)){
		return false;
	} else {
	return true;
	}
}

function add_nhanvien(){
	var array = new Array('ten_nv','tendangnhap_nv');
	if (!getValidates(array)){
		return false;
	} else {
	return true;
	}
}

function add_phieuchi(){
	var array = new Array('noidungchi_pc','sotienchi_pc','daduyet_pc');
	if (!getValidates(array)){
		return false;
	} else {
	return true;
	}
}

function add_phieuthu(){
	var array = new Array('noidungthu_pt','sotienthu_pt');
	if (!getValidates(array)){
		return false;
	} else {
	return true;
	}
}
function edit_yeucau(frm){
	//var array = new Array('noidungthu_pt','sotienthu_pt');
	
	if (!getValidates(array)){
		return false;
	} else {
	return true;
	}
}

