//****************************
//	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?");
}

/*******************************************************
 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();
}

// Loan View Popup
function LoanViewPop(id,Mode){
	winpopup('/debtor_information/history_debt_pop_main.aspx?mode='+ Mode +'&LoanId='+id, id, 700,500, true, true);
}	

/*************************
 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();
}
// 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);
}



//*****************************************************
//	menu Link 

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function pop(l, t, w, h, URL) {
	var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes" + ",left=" + l + ",top=" + t + ",width=" + w + ",height=" + h;
	window.open(URL,"_blank",windowprops);
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//*****************************************************
//	post back Link 
function NoPostBack(sNewFormAction)
{
	if(document.layers)
	{
		document.layers['Content'].document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
		document.layers['Content'].document.forms[0].action = sNewFormAction;
		document.layers['Content'].document.forms[0].submit();
	}
	else
	{
		document.forms[0].action = sNewFormAction;
		document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
		document.forms[0].submit();
	}
	
}			

//*****************************************************
//	book mark url link
function bookmarksite(url, title)
{
	if (window.sidebar)
		window.sidebar.addPanel(title, url,"");// Gecko/firefox*/
	else if (window.external)
		window.external.AddFavorite(url,title); // IE4 and later
}		


