//$(function(){
	loadPageView='';
	function load_page_view(obj){
		loadPageView = $(obj).html();
	}
	
	// function load page with ajax include with loading
	function get_page_content(urlpage,obj,datapost,loadView,resultMode){
		var oldcontainer='';
		var theload = loadPageView;
		$.ajax({
			type: "POST",
			url: urlpage,
			//data: "name=John&location=Boston",
			data: datapost,
			beforeSend: function(){
				if(loadView){
					$(obj).hide();
					$(loadView).html(theload).show();
				}else
					$(obj).html(theload);
			},
			success: function(msg){ //alert(msg);
				if(msg=='logout'){ 
					alert(loginExpired);
					document.location.href=urlLogin;
				}
				if(loadView){
					$(loadView).html('').hide();
					if(resultMode=='val')
					$(obj).val(msg).show();
					else
					$(obj).html( msg ).show();
				}else
					$(obj).html( msg );
			}
		});
	}

	function get_page_content_withbox(urlpage,obj,datapost){
		$.ajax({
			type: "POST",
			url: urlpage,
			data: datapost,
			beforeSend: function(){
			},
			success: function(msg){
				if(msg=='logout'){ 
					alert(loginExpired);
					document.location.href=urlLogin;
				}else
					$(obj).html( msg );
			}
		});
	}


	// format digit for currency
	function format_to_curency(digit){
		var fullint = digit.replace(/\./g,''); //alert(fullint);
		var len = fullint.length; //alert(len);
		var lenDigit = 3;
		if(len>=lenDigit){
			var firstPartLen = len%lenDigit; //alert(firstPartLen); 
			var nextLen = len-firstPartLen;
			if(firstPartLen!=0){
				var firstPart = fullint.slice(0,firstPartLen)+'.';
				var nextPart = fullint.slice(firstPartLen);
			}else{
				var firstPart = '';
				var nextPart = fullint;
			}
			//alert(nextPart);
			var c=new Array();
			var p=0;
			for(i=0;p<nextLen;i++){ 
				c[i] = nextPart.slice(p,(lenDigit+p)); //alert(c[i]);
				p+=lenDigit;
			}
			var res = firstPart + c.join('.'); //alert(res);
			return res;
		}else
			return digit;
	}
	function clear_format_curency(digit,kecuali){
		var fullint = digit.replace(/\./g,''); //alert(fullint);
		var str = digit.split(""); //alert(str.length);
		var ret='';
		for(i=0;i<str.length;i++){ 
			if(str[i].charCodeAt()>=48 && str[i].charCodeAt()<=57){
				ret+=str[i];
			}
			if(kecuali==str[i]) ret+=str[i];
		}
		return ret;
	}

	// function compile data to post to ajax
	function compile_data_topost(obj){
		var d='';
		obj.each(function(){
			d+=$(this).attr('name')+'='+$(this).val()+'&';
		});
		return d;
	}

	// ask for question
	function are_u_sure(msg){
		if(confirm(msg)) return true;
		else return false;
	}

//});
