﻿/*  AdCom.LibraryJS.Javascript
    Developer: Phạm Văn Phong
    ONENET - Nguyễn Khang - Cầu giấy - Hà Nội
    Mobile: 84-985348664
    Email: phongtn2010@gmail.com
    --------------------------------------------------------
*/
//-----------------------------------------------
function OnCollapseExpandTraLoi(imgXemChiTiet)
{
    var idXemChiTiet = imgXemChiTiet.id;
    var idDetail=idXemChiTiet.replace("img","div");
    if (document.getElementById(idDetail).style.display=="block")
    {
        document.getElementById(idDetail).style.display="none";		        
        //document.getElementById(idXemChiTiet).src="../../../Images/Skin/Default/Icons/icon_enter.gif";
    }
    else
    {
        document.getElementById(idDetail).style.display="block";
        //document.getElementById(idXemChiTiet).src="../../../Images/Skin/Default/Icons/icon_enter.gif";		        
    }
		
    return false;				
}
    
function trim(obj)
{
    return obj.replace(/^\s+$/g,"");
}
function isEmail(obj, lbl)
{
    var wgia = document.getElementById(lbl);
    obj.value = trim(obj.value)
    if (obj.value != "")
    {
        var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
        var check=/@[\w\-]+\./;
        var checkend=/\.[a-zA-Z]{2,4}$/;		        
        if(((obj.value.search(exclude) != -1)||(obj.value.search(check)) == -1)||(obj.value.search(checkend) == -1))
	    {
	        wgia.style.display = 'block';
            obj.style.borderColor = 'red';
	        //obj.focus();		      
	        return false;
	    }
        else
	    {
	        wgia.style.display = 'none';
            obj.style.borderColor = '#ccc';                    			      
	        return true;
	    }        
    }
    else
    {
        wgia.style.display = 'block';
        obj.style.borderColor = 'red';
	    //obj.focus();
	    return false;
    }
}

function isTen(obj, lbl)
{        
//alert(obj.id);
var msg = document.getElementById(lbl);
obj.value = trim(obj.value);
    if (obj.value == "")
    {
        msg.style.display = 'block';
        obj.style.borderColor = 'red';
        //obj.focus();         
        return false;
    }
    else
    {
        msg.style.display = 'none';
        obj.style.borderColor = '#ccc';                               
        return true;                     
    }
}
function check(idcontrol)
{
    var ten = document.getElementById(idcontrol + "_txtHoTen");
    var email = document.getElementById(idcontrol + "_txtEmail");
    var submit = document.getElementById(idcontrol + "_btnGui");
    if (isTen(ten,idcontrol + "_lblTen") == false)
    {
        ten.focus();
        return false;
    }
    if (isTen(email,idcontrol + "_lblchEmail")==false)
    {
        email.focus()
        return false;
    }
    if (isEmail(email, idcontrol + "_lblEmail") == false)
    {
        email.focus();
        return false;
    }
    return true;
}
function check_dap(senderID)
{
    var idcontrol ='';
    var i;
    
    for(i=senderID.length-1;i>=0;i--)
    {
        if(senderID.charAt(i)=="_")
        {
            idcontrol = senderID.substring(0,i);      
            break;
        }
    }
    var ten_nguoi_gui = document.getElementById(idcontrol + "_txtHoTenNguoiGui");
    var email_nguoi_gui = document.getElementById(idcontrol + "_txtEmailNguoiGui");
    var submit_nguoi_gui = document.getElementById(idcontrol + "_btnTraLoi");
    if (isTen(ten_nguoi_gui, idcontrol + "_lblTenNguoiGui")==false)
    {
        ten_nguoi_gui.focus();
        return false;
    }
    if (isTen(email_nguoi_gui, idcontrol + "_lblchEmailNguoiGui")==false)
    {
        email_nguoi_gui.focus();
        return false;
    }
    if (isEmail(email_nguoi_gui, idcontrol + "_lblEmailNguoiGui"))
    {
        email_nguoi_gui.focus();
        return false;
    }
    return true;
}

function CheckTextHoi(sender, args)
{
    var i_ch = args.Value;
    //alert(sender.id);

    if ((i_ch.length < 10 || i_ch.length>500) ) 
    {           
       args.IsValid = false;
       return;
    }
    args.IsValid = true;
}

