﻿var gc_TextBox = 1;

var gc_Label = 2;

var gc_Combo = 3;

var gc_Button = 4;

var gc_hidden = 5;

var gc_Tr  = 6;

// Catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

/**
* Function to emulate document.getElementById
*
* @param	string	Object ID
*
* @return	mixed	null if not found, object if found
*/
function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}

// #############################################################################
// Cookie handlers

/**
* Sets a cookie
*
* @param	string	Cookie name
* @param	string	Cookie value
* @param	date	Cookie expiry date
*/
function set_cookie(name, value, expires)
{
	document.cookie = name + '=' + escape(value) + '; path=/' + (typeof expires != 'undefined' ? '; expires=' + expires.toGMTString() : '');
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components	 
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		alert(a_all_cookies);
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

/**
* Fetches the value of a cookie
*
* @param	string	Cookie name
*
* @return	string
*/
function fetch_cookie(name)
{
	cookie_name = name + '=';
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (';', value_begin);
			if (value_end == -1)
			{
				value_end = cookie_length;
			}
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(' ', cookie_begin) + 1;
		if (cookie_begin == 0)
		{
			break;
		}
	}
	return null;
}

// #############################################################################
// Collapsible element handlers

/**
* Toggles the collapse state of an object, and saves state to 'vbulletin_collapse' cookie
*
* @param	string	Unique ID for the collapse group
*
* @return	boolean	false
*/
function toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}

	obj = fetch_object('collapseobj_' + objid);
	img = fetch_object('collapseimg_' + objid);
	cel = fetch_object('collapsecel_' + objid);

	if (!obj)
	{
		// nothing to collapse!
		if (img)
		{
			// hide the clicky image if there is one
			img.style.display = 'none';
		}
		return false;
	}

	if (obj.style.display == 'none')
	{
		obj.style.display = '';
		save_collapsed(objid, false);
		if (img)
		{
			img_re = new RegExp("_collapsed\\.gif$");
			img.src = img.src.replace(img_re, '.gif');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
			cel.className = cel.className.replace(cel_re, '$1');
		}
	}
	else
	{
		obj.style.display = 'none';
		save_collapsed(objid, true);
		if (img)
		{
			img_re = new RegExp("\\.gif$");
			img.src = img.src.replace(img_re, '_collapsed.gif');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)$");
			cel.className = cel.className.replace(cel_re, '$1_collapsed');
		}
	}
	return false;
}

/**
* Updates vbulletin_collapse cookie with collapse preferences
*
* @param	string	Unique ID for the collapse group
* @param	boolean	Add a cookie
*/
function save_collapsed(objid, addcollapsed)
{
	var collapsed = fetch_cookie('vbulletin_collapse');
	var tmp = new Array();

	if (collapsed != null)
	{
		collapsed = collapsed.split('\n');

		for (var i in collapsed)
		{
			if (collapsed[i] != objid && collapsed[i] != '')
			{
				tmp[tmp.length] = collapsed[i];
			}
		}
	}

	if (addcollapsed)
	{
		tmp[tmp.length] = objid;
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	set_cookie('vbulletin_collapse', tmp.join('\n'), expires);
}

function confirm_message(message)
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm(message))
	{
	    ht[0].style.filter = "";
		return true;
	}
	else
	{
		ht[0].style.filter = "";
		return false;
	}
}

function confirm_approved(message)
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	
    var check = document.body.getElementsByTagName("input");
    var val = false;
    for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && check(i).checked==true && check[i].name.indexOf("cbxSelect",0)>=0)
		{
			val = true;
		}
	}
	
	if (val==false) {
	    alert(message);
	    ht[0].style.filter = "";
	    return false;
	}
}

function confirm_denied_approved(message1, message2)
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	
    var check = document.body.getElementsByTagName("input");
    var val = false;
    for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && check(i).checked==true && check[i].name.indexOf("cbxSelect",0)>=0)
		{
			val = true;
		}
	}
	
	if (val==false) {
	    alert(message1);
	    ht[0].style.filter = "";
	    return false;
	}
	else
	{
		var v_text = document.body.getElementsByTagName("input");
		var v_txtNotApproveReason;
		for (var i=0; i<v_text.length; i++)
		{
			if (v_text[i].getAttribute("type") == "text")
			{
				var v_ctrlName = v_text[i].getAttribute("id");
				if(v_ctrlName.indexOf("txtNotApproveReason") != -1)
				{
					v_txtNotApproveReason = document.getElementById(v_ctrlName);
				}
			}
		}
		
		var v_text = document.getElementById(v_txtNotApproveReason.id);
		if (v_text.value == '')
		{
			alert(message2);
			v_text.focus();
			ht[0].style.filter = "";
			return false;
		}
	}
}

function confirm_delete(message1, message2)
{
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	
    var check = document.body.getElementsByTagName("input");
    var val = false;
    for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && check(i).checked==true && check[i].name.indexOf("cbxSelect",0)>=0)
		{
			val = true;
		}
	}
	
	if (val==false) {
	    alert(message1);
	    ht[0].style.filter = "";
	    return false;
	}
	else {
		if (confirm(message2)) {
	        ht[0].style.filter = "";
		    return true;
	    }
	    else {
		    ht[0].style.filter = "";
		    return false;
	    }
	}
}

function CheckAll(chk)
{
	var check = document.body.getElementsByTagName("input");
	var val = chk.checked;
	var i, j;

	for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).disabled && check[i].name.indexOf("cbxSelect",0)>=0)
		{
			check(i).checked = val;
		}
	}
}

function Check()
{
    var check = document.body.getElementsByTagName("input");
	var v_count = 0;

	for (var i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).checked && check[i].name.indexOf("cbxSelect",0)>=0)
		{
			v_count = v_count + 1;
		}
	}
	
	var v_cbxAllSelect;
    for (var i=0; i<check.length; i++)
    {
        if (check[i].getAttribute("type") == "checkbox")
        {
			var v_ctrlName = check[i].getAttribute("id");
			if(v_ctrlName.indexOf("cbxAllSelect") != -1)
			{
				v_cbxAllSelect = document.getElementById(v_ctrlName);
			}
        }
    }
	
	if (document.getElementById(v_cbxAllSelect.id)==null)
        alert('Khong tim thay Control');
    else {
        var v_objCheck = document.getElementById(v_cbxAllSelect.id);
        if (v_count == 0)
            v_objCheck.checked=true;
        else
            v_objCheck.checked=false;
    }
}

function CheckAllTab(chk)
{
	var check = document.body.getElementsByTagName("input");
	var val = chk.checked;
	var i, j;

	for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).disabled && check[i].name.indexOf("cbxCheckTab",0)>=0)
		{
			check(i).checked = val;
		}
	}
}

function CheckTab()
{
    var check = document.body.getElementsByTagName("input");
	var v_count = 0;

	for (var i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).checked && check[i].name.indexOf("cbxCheckTab",0)>=0)
		{
			v_count = v_count + 1;
		}
	}
	
	var v_cbxCheckAllTab;
    for (var i=0; i<check.length; i++)
    {
        if (check[i].getAttribute("type") == "checkbox")
        {
			var v_ctrlName = check[i].getAttribute("id");
			if(v_ctrlName.indexOf("cbxCheckAllTab") != -1)
			{
				v_cbxCheckAllTab = document.getElementById(v_ctrlName);
			}
        }
    }
	
	if (document.getElementById(v_cbxCheckAllTab.id)==null)
        alert('Khong tim thay Control');
    else {
        var v_objCheck = document.getElementById(v_cbxCheckAllTab.id);
        if (v_count == 0)
            v_objCheck.checked=true;
        else
            v_objCheck.checked=false;
    }
}

function CheckAllMenu(chk)
{
	var check = document.body.getElementsByTagName("input");
	var val = chk.checked;
	var i, j;

	for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).disabled && check[i].name.indexOf("cbxCheckMenu",0)>=0)
		{
			check(i).checked = val;
		}
	}
}

function CheckMenu()
{
    var check = document.body.getElementsByTagName("input");
	var v_count = 0;

	for (var i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).checked && check[i].name.indexOf("cbxCheckMenu",0)>=0)
		{
			v_count = v_count + 1;
		}
	}
	
	var v_cbxCheckAllMenu;
    for (var i=0; i<check.length; i++)
    {
        if (check[i].getAttribute("type") == "checkbox")
        {
			var v_ctrlName = check[i].getAttribute("id");
			if(v_ctrlName.indexOf("cbxCheckAllMenu") != -1)
			{
				v_cbxCheckAllMenu = document.getElementById(v_ctrlName);
			}
        }
    }
	
	if (document.getElementById(v_cbxCheckAllMenu.id)==null)
        alert('Khong tim thay Control');
    else {
        var v_objCheck = document.getElementById(v_cbxCheckAllMenu.id);
        if (v_count == 0)
            v_objCheck.checked=true;
        else
            v_objCheck.checked=false;
    }
}

function CheckAllModule(chk)
{
	var check = document.body.getElementsByTagName("input");
	var val = chk.checked;
	var i, j;

	for (i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).disabled && check[i].name.indexOf("cbxCheckModule",0)>=0)
		{
			check(i).checked = val;
		}
	}
}

function CheckModule()
{
    var check = document.body.getElementsByTagName("input");
	var v_count = 0;

	for (var i=0; i<check.length; i++)
	{
		if (check(i).type=="checkbox" && !check(i).checked && check[i].name.indexOf("cbxCheckModule",0)>=0)
		{
			v_count = v_count + 1;
		}
	}
	
	var v_cbxCheckAllModule;
    for (var i=0; i<check.length; i++)
    {
        if (check[i].getAttribute("type") == "checkbox")
        {
			var v_ctrlName = check[i].getAttribute("id");
			if(v_ctrlName.indexOf("cbxCheckAllModule") != -1)
			{
				v_cbxCheckAllModule = document.getElementById(v_ctrlName);
			}
        }
    }
	
	if (document.getElementById(v_cbxCheckAllModule.id)==null)
        alert('Khong tim thay Control');
    else {
        var v_objCheck = document.getElementById(v_cbxCheckAllModule.id);
        if (v_count == 0)
            v_objCheck.checked=true;
        else
            v_objCheck.checked=false;
    }
}

function ToggleLayer(whichLayer)
{
	var elem, vis;
	if (document.getElementById) // this is the way the standards work    
		elem = document.getElementById( whichLayer );
	else if (document.all) // this is the way old msie versions work      
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works    
		elem = document.layers[whichLayer];  
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)    
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function ChoiceObj(msg, obj)
{
	v_text = "";
    v_id = document.getElementById(obj);
    for (i=0; i < v_id.options.length; i++)
        if (v_id.options[i].selected)
            v_text = v_id.options[i].text;
            
	if (v_text == "")
	{
		alert(msg);
		return false;
	}
	else
		return true;
}

function MsgBox(msg1, obj, msg2, msg3)
{
    v_text = "";
    v_id = document.getElementById(obj);
    for (i=0; i < v_id.options.length; i++)
        if (v_id.options[i].selected)
            v_text = v_id.options[i].text;
         
    ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (v_text == "")
	{
		alert(msg3);
		return false;
	}
	else
	{
		var v_textNew = v_text.split("|_ ");
		if (v_textNew[1] == undefined)
			v_textNew = v_text.split("|_ ");
		else
			v_textNew = v_textNew[1];
		
		if (confirm(msg1 + v_textNew + msg2))
		{
			ht[0].style.filter = "";
			return true;
		}
		else
		{				
			ht[0].style.filter = "";
			return false;
		}
	}
}

// Unselectable Text
var Unselectable = {
	enable : function(e) {
		var e = e ? e : window.event;
 
		if (e.button != 1) {
			if (e.target) {
				var targer = e.target;
			} else if (e.srcElement) {
				var targer = e.srcElement;
			}
 
			var targetTag = targer.tagName.toLowerCase();
			if ((targetTag != "input") && (targetTag != "textarea")) {
				return false;
			}
		}
	},
 
	disable : function () {
		return true;
	} 
}
 
if (typeof(document.onselectstart) != "undefined") {
	document.onselectstart = Unselectable.enable;
} else {
	document.onmousedown = Unselectable.enable;
	document.onmouseup = Unselectable.disable;
}

function RequestClientSynchronous(pv_strURL,pv_fucName)
{			 
	//alert("OK");
	//Th?c hi?n lock page tru?c khi request t?i server	
	//LockPage();
	
	if(window.XMLHttpRequest)
	{   
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=pv_fucName
		xmlhttp.open("GET",pv_strURL,false)
		//LockPage();
		xmlhttp.send()
	}
	else if (window.ActiveXObject)
	{ 
		try
			{
			xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");                          
			}
		catch(e)
			{
			alert("Exception");
			try
			{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch(e){}
		}
		if(xmlhttp)
		{
			try
			{                             
				xmlhttp.onreadystatechange=pv_fucName;
				//alert(pv_strURL);
				xmlhttp.open("GET",pv_strURL,false);
				//LockPage();			
				xmlhttp.send();
			}
			catch(e){}  
		}//if(xmlhttp)
		}//else if (window.ActiveXObject)

}
//Ham gui Request toi server theo phuong thuc khong dong bo
function RequestClientAsynchronous(pv_strURL,pv_fucName)
{			 
	//alert("OK");
	//Th?c hi?n lock page tru?c khi request t?i server	
	//LockPage();
	
	if(window.XMLHttpRequest)
	{   
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=pv_fucName
		xmlhttp.open("GET",pv_strURL,true)
		//LockPage();
		xmlhttp.send()
	}
	else if (window.ActiveXObject)
	{ 
		try
			{
			xmlhttp= new ActiveXObject("Msxml2.XMLHTTP");                          
			}
		catch(e)
			{
			alert("Exception");
			try
			{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch(e){}
		}
		if(xmlhttp)
		{
			try
			{                             
				xmlhttp.onreadystatechange=pv_fucName;
				//alert(pv_strURL);
				xmlhttp.open("GET",pv_strURL,true);
				//LockPage();			
				xmlhttp.send();
			}
			catch(e){}  
		}//if(xmlhttp)
		}//else if (window.ActiveXObject)

}
function switchTab(v_strTab) 
{	
	var tblContent = document.getElementById('tblTodayMarket');
	//var tblTr = tblContent.getElementsByTagName("tr");
	//alert(tblContent.id);	
	var v_strURL = "frmAjaxServer.aspx";
	RequestClientSynchronous(v_strURL,function(){FillDataList(".//DataSet//Table","");})
}
function FillDataList(pv_strDataSetID,pv_strDataListID)
{
	if(xmlhttp.readyState==4&&xmlhttp.status==200)
	{
		try
		{			
			var rows=xmlhttp.responseXML.selectNodes(pv_strDataSetID);
			var v = rows[0].childNodes;
			alert(rows[1].getElementsByTagName("bond_period")(0).text);			 
		} // End -- try
		catch (e)
		{
			alert("Have exception in function FillData(): " + e.message);
		}		
	} // End -- if(xmlhttp.readyState==4&&xmlhttp.status==200)
}

function SetTabActive(value)
{
	var hidTabActive = document.getElementById('hidTabActive');
	hidTabActive.value = value;
	alert(hidTabActive.value);
}
//Purpose: Hàm thực hiện việc xác định ControlName

//Input: Chuỗi gần giống tên Control

//                      Kiểu của Control là Label, Textbox, Combo, button

//Output: Tên Control

function getNameOfControl(v_likename,v_TypeControl)

{
            try

            {

                        if(v_TypeControl==gc_TextBox)//TextBox

                        {

                                    var v_Input = document.getElementsByTagName("Input");

                                    for (var i = 0 ; i<v_Input.length;i++)

                                    {

                                                if (v_Input[i].getAttribute("type")=="text")

                                                {

                                                            var v_ctrlName = v_Input[i].getAttribute("id");

                                                            if(v_ctrlName.indexOf(v_likename)!=-1)

                                                            {

                                                                        var v_control = document.getElementById(v_ctrlName);

                                                                        return v_control;

                                                            }

                                                }
                                                else if (v_Input[i].getAttribute("type")=="checkbox")
                                                {

                                                            var v_ctrlName = v_Input[i].getAttribute("id");

                                                            if(v_ctrlName.indexOf(v_likename)!=-1)

                                                            {

                                                                        var v_control = document.getElementById(v_ctrlName);

                                                                        return v_control;

                                                            }

                                                }

                                    }

                        }

                        else if(v_TypeControl==gc_Label)//Label

                        {

                                    var v_Spans = document.getElementsByTagName("span");

                                    for (var i = 0 ; i<v_Spans.length;i++)

                                    {

                                                var v_ctrlName = v_Spans[i].getAttribute("id");

                                                if(v_ctrlName.indexOf(v_likename)!=-1)

                                                {

                                                            var v_control = document.getElementById(v_ctrlName);

                                                            return v_control;

                                                }

                                                else

                                                {

                                                            //alert("khong co name do trong ten control");

                                                }

                                    }

                        }

                        else if(v_TypeControl==gc_Combo)//combo = select

                        {

                                    try

                                    {

                                                var v_InputSelect = document.getElementsByTagName("select");

                                                for (var i = 0 ; i<v_InputSelect.length;i++)

                                                {

                                                            var v_ctrlName = v_InputSelect[i].getAttribute("id");

                                                            if(v_ctrlName.indexOf(v_likename)!=-1)

                                                            {

                                                                        var v_control = document.getElementById(v_ctrlName);

                                                                        return v_control;

                                                            }

                                                }

                                    }

                                    catch(exSelect)

                                    {

                                               // alert("Lỗi tại hàm getNameOfControl() phần Combo: " + exSelect.message);

                                    }

                        }

                        else if(v_TypeControl==gc_Button)//Command = Button

                        {

                                    var v_InputButton = document.getElementsByTagName("Input");

                                    for (var i = 0 ; i<v_InputButton.length;i++)

                                    {

                                                if (v_InputButton[i].getAttribute("type")=="button")

                                                {

                                                            var v_ctrlName = v_InputButton[i].getAttribute("id");

                                                            if(v_ctrlName.indexOf(v_likename)!=-1)

                                                            {

                                                                        var v_control = document.getElementById(v_ctrlName);

                                                                        return v_control;

                                                            }

                                                }

                                    }

                        }

                        else if(v_TypeControl==gc_hidden)//hidden = hidden

                        {

                                    try

                                    {

                                                var v_InputHidden = document.getElementsByTagName("Input");

                                                for (var i = 0 ; i<v_InputHidden.length;i++)

                                                {

                                                            if (v_InputHidden[i].getAttribute("type")=="hidden")

                                                            {

                                                                        //alert("Vao day");

                                                                        var v_ctrlName = v_InputHidden[i].getAttribute("id");

                                                                        

                                                                        if(v_ctrlName.indexOf(v_likename)!=-1)

                                                                        {

                                                                                    //alert(" v_ctrlName : " + v_likename + " : " + v_ctrlName);

                                                                                    var v_control = document.getElementById(v_ctrlName);

                                                                                    return v_control;

                                                                        }

                                                            }

                                                }

                                    }

                                    catch(exHidden)

                                    {

                                                alert("Lỗi tại hàm getNameOfControl() phần hidden: " + exHidden.message);

                                    }

                        }

                        else if(v_TypeControl==gc_Tr)//hidden = hidden

                        {

                                    try

                                    {

                                                var v_Trow = document.getElementsByTagName("Tr");

                                                for (var i = 0 ; i<v_Trow.length;i++)

                                                {

                                                            var v_ctrlName = v_Trow[i].getAttribute("id");

                                                            if(v_ctrlName.indexOf(v_likename)!=-1)

                                                            {

                                                                        //alert(" v_ctrlName : " + v_likename + " : " + v_ctrlName);

                                                                        var v_control = document.getElementById(v_ctrlName);

                                                                        //alert("v_control.id: " + v_control.id);

                                                                        return v_control;

                                                            }

                                                }

                                    }

                                    catch(exTrow)

                                    {

                                                alert("Lỗi tại hàm getNameOfControl() phần Trow: " + exTrow.message);

                                    }

                        }

                        else

                        {

                        }

            }

            catch(e)

            {

                        //alert("Lỗi tại hàm getNameOfControl(): " + e.message);

            }

            return null;

}

/*TuanNV3 added 25/10/2008*/
function SetDropMonth()
{
	var v_objDrpYear = getNameOfControl('drpYear',gc_Combo);
	var v_objDrpMonth = getNameOfControl('drpMonth',gc_Combo);
	var d = new Date();
	var curr_year = d.getFullYear();

    if (v_objDrpYear.value < curr_year)
    {
        v_objDrpMonth.disabled = true;
    }  else
    {
		v_objDrpMonth.disabled = false;
    }
}

 function HideDDL(value)
{
	try
	{
		var v_objDrpYear = getNameOfControl('drpYear',gc_Combo);
		var v_objDrpBond = getNameOfControl('drpBond',gc_Combo); 
	if(value == 0)
	{	
	/*Truong hop la an*/
		v_objDrpYear.style.display = "none";
		v_objDrpBond.style.display = "none";
	}
	else
	{
	/*Truong hop la hien*/
		v_objDrpYear.style.display = "block";
		v_objDrpBond.style.display = "block";
	}
	}
	catch(e)
	{
		//Chang lam gi ca
	}
	
	
}
/*End of TuanNV3*/

function ResetValue()
{
	//alert(event.srcElement.value);
	if(event.srcElement.value == "Từ khóa tìm kiếm..." || event.srcElement.value == "input key search...")
	{
		event.srcElement.value = "";
	}
	//alert(event.srcElement.value);	
}
function GetValue(pv_intLnaguageID)
{
	if(event.srcElement.value == "")
	{
		if (pv_intLnaguageID == 1)
		{
			event.srcElement.value = "Từ khóa tìm kiếm...";
		}
		else
		{
				event.srcElement.value = "input key search...";
		}
		
	}
	//alert(event.srcElement.value);	
}
function isDate(format) 
{	 
	if (event.srcElement.value != "")
	{
		var date=getDateFromFormat(event.srcElement.value,format);
		if (date==0) 
		{ 
			alert("Ngày tháng phải nhập đúng định dạng dd/mm/yyyy.Xin vui lòng nhập lại!");
			event.srcElement.focus();
			event.srcElement.value = ""; 
		}
	}  	 		 
}
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;	
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}		
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}	 
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	
	// If there are any trailing characters left in the value, it doesn't match
	//**********************************************************8
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
}
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
	//KhanhND added 20112008
	function DoEnter(value)
	{
		var key = event.keyCode;
		if (key==13)
		{
			return false;
		}
	}
function openWindow(url) {
   var opt = 'dialogWidth:800px; dialogHeight:600px; center:yes; scroll:yes; status:no;help:no;';
   window.showModalDialog(url, self, opt); 
} 	
