//****************************
//	Check box all
//****************************
	function fncCheckAll(bstatus, frm, objchk) {
		if (objchk)
		{
			if (!objchk.length)
			{
				objchk.checked = bstatus;
			} else {
				for (i=0; i < objchk.length;i++)
						objchk[i].checked = bstatus;
			}
		}
	}

/*****************************************************
* Check & Uncheck All checkbox in DataGrid 
******************************************************/
	function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) {

        re = new RegExp(':' + aspCheckBoxID + '$')

        for(i = 0; i < document.forms[0].elements.length; i++) {

            elm = document.forms[0].elements[i]

            if (elm.type == 'checkbox') {

                if (re.test(elm.name)) {

                    elm.checked = checkVal
                }
            }
        }
    }

/*******************************
//	Popup Delete Confirm
*******************************/
function goDelete()
{
	var bOk = false;
	var frm = document.forms[0];
	var strDelValues = Chk_ServerDeleteId(frm, "chkItem");

	if(strDelValues == "")
		alert("Please select record(s) that you want to delete.");
	else if(confirm("Are you sure you want to delete these selected record(s)?"))
	{
		frm.deleteid.value = strDelValues;
		bOk = true;
	}

	return bOk;
}

function DeleteConfirm()
{
	return confirm("Are you sure you want to delete this record?");
}

function confirmMoveToMember(obj){
	return confirm("Do you want to move this Member Application to Member zone?");
}

function confirmRejectApplication(obj){
	return confirm("Do you want to Reject this Member Application?");
}

/*******************************************************
 Check and add value to hidden input for delete
 ******************************************************/
function  Chk_ServerDeleteId(frm,chkname) 
{ 
	var del_id = "";
	var count = 0;
	for (var i = 0; i < frm.elements.length; i++)
	{ 
		if(frm.elements[i].name.indexOf(chkname) != -1 )	 
		{ 
			if (frm.elements[i].checked == true ) {
				if(frm.elements[i].value.length > 0) {
					if (count > 0)
					{
						del_id = del_id + ","
					}
					del_id = del_id+frm.elements[i].value;
					count++;
				}
			}
		}       
	} 
	return del_id;
}	
//*****************************************************
//	Popup Windows
// htmlFile = document you want to display
// wWidth   = window width if not define set to 730
// wHeight  = window height if not define set to 440
// residebar= 1 is allow reside, not define is can't reside
// scrollbar= 1 is allow scroll, not define is can't scroll

function winpopup(htmlFile, strWname, wWidth,wHeight, bScroll, bReside) 
	{
	if (navigator.userAgent.substring(0,9) == "Mozilla/4") {
	res_w = screen.width;
	res_h = screen.height;
	}else 	// For netscape 3.0
	{
	res_w = 800;	// enter Screen resolution width
	res_h = 600;	// enter Screen resolution height
	}

	win_width			= (wWidth)		?	wWidth :730;
	win_height		= (wHeight)		?	wHeight :440;
	bresideBar		= (bReside)		?	"yes"	:"no";
	bscroll				= (bScroll)		?	"yes"	:"no";

	screen_x = (res_w - win_width)  /  2;
	screen_y = (res_h - win_height) /  2;

	pop = window.open(htmlFile, strWname, 'width=' + win_width + ',height=' + win_height + ',screenx=' + screen_x + ',screeny=' + screen_y + ',left=' + screen_x + ',top=' + screen_y + ',scrollbars=' + bscroll + ',resizable=' + bresideBar +'');
	pop.focus();
	}

// check picture is exist for preview.
/*function fncPicView(frm, strPathFileName) {
	if (frm.PicNameShow.value == "") {
		alert("Please click Browse for upload picture first");
		frm.btnBrowse.focus();
		return false;
	} else {
		if (frm.PicNameSave.value != "") {
			winpopup('/BackEnd/Include/preview.jsp?location=/Upload/Temp/&name=' + frm.PicNameSave.value,'preview',500,500, true, true);
		} else {
			winpopup('/BackEnd/Include/preview.jsp?location='+ strPathFileName +'&name=' + frm.PicNameShow.value,'preview',500,500, true, true);
		}
	}
}
*/
function fncPicView(objFileName, objFileTemp, strPathFileName) {
	if (objFileName.value == "") {
		alert("Please upload picture first");
		return false;
	} else {
		if (objFileTemp.value != "") {
			winpopup('/BackEnd/UploadPage/UploadPreview.aspx?location=/Upload/Temp/&name=' + objFileTemp.value,'preview',500,500, true, true);
		} else {
			winpopup('/BackEnd/UploadPage/UploadPreview.aspx?location='+ strPathFileName +'&name=' + objFileName.value,'preview',500,500, true, true);
		}
	}
}
// check picture is exist for delete;
function fncPicDelete(frm) {
	if (frm.PicNameShow.value == "") {
		alert("No picture to delete");
		frm.btnBrowse.focus();
		return false;
	} else {
		frm.PicNameShow.value = "";
		frm.PicNameSave.value = "";
		frm.PicNameOrinal.value = "";
		alert("Delete picture complete");
	}
}

// Gen Calendar
function genCalendar(fielddate, fieldmonth, fieldyear)
{
	w = window.open("/Include/util/popCalendar.aspx","Calendar","width=180,height=180");
	field_date = fielddate;
	field_month = fieldmonth;
	field_year = fieldyear;
	if (w.opener == null )
		w.opener = self;
	w.focus();
}

/*************************
 Popup upload picture
 Create by : Naris
 Create Date : 2003-03-19
	strObjFileName		: filename hidden field
	strObjFileNameTemp	: temp filename hidden field
	bDesc				: have a description or not?
	strObjDesc			: description hidden field
	bSingle				: upload singlie or not?
	strObjTarget		: fielname of showing
	isPicture			: picture file only?
 *************************/
function OpenUpload(strObjFileName, strObjFileNameTemp, bDesc, strObjDesc, bSingle, strObjTarget, isPicture)
{
	if (bDesc == true){
		bDesc = 1;
	}else{
		bDesc = 0;
	}
	
	if (bSingle == true){
		bSingle = 1;
	} else{
		bSingle = 0;
	}
	
	if (isPicture == true){
		isPicture = 1;
	} else{
		isPicture = 0;
	}
	
	FileName = strObjFileName;
	FileTemp = strObjFileNameTemp;
	FileDesc = strObjDesc;
	ObjTarget = strObjTarget;
	
	w = winpopup('../../UploadPage/UploadFile.aspx?desc='+ bDesc +'&isSingle='+ bSingle+ '&IsPic='+ isPicture,'upload',420,170,false,false); return false;
	if (w.opener == null )
		w.opener = self;
	w.focus();
}

function OpenUpload2(strObjFileName, strObjFileNameTemp, bDesc, strObjDesc, bSingle, strObjTarget, isPicture)
{
	if (bDesc == true){
		bDesc = 1;
	}else{
		bDesc = 0;
	}
	
	if (bSingle == true){
		bSingle = 1;
	} else{
		bSingle = 0;
	}
	
	if (isPicture == true){
		isPicture = 1;
	} else{
		isPicture = 0;
	}
	
	FileName = strObjFileName;
	FileTemp = strObjFileNameTemp;
	FileDesc = strObjDesc;
	ObjTarget = strObjTarget;
	
	w = winpopup('../UploadPage/UploadFile.aspx?desc='+ bDesc +'&isSingle='+ bSingle+ '&IsPic='+ isPicture,'upload',420,170,false,false); return false;
	if (w.opener == null )
		w.opener = self;
	w.focus();
}
// End *****************************************************

function FormatCurrency(num) {
// http://javascript.internet.com/forms/currency-format.html
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

