 function tabSwitch(new_tab, new_content) {  
   
	document.getElementById('content_1').style.display = 'none';  
	//document.getElementById('content_2').style.display = 'none';    
	document.getElementById('content_2').style.display = 'none';   
	document.getElementById('content_3').style.display = 'none'; 
	document.getElementById('content_4').style.display = 'none'; 
	document.getElementById(new_content).style.display = 'block';     
   
	document.getElementById('tab_1').className = '';  
	//document.getElementById('tab_2').className = '';  
	document.getElementById('tab_2').className = ''; 
	document.getElementById('tab_3').className = '';  
	document.getElementById('tab_4').className = '';  
	document.getElementById(new_tab).className = 'active';    
 }
 
function showRateSilom(){
		xajax_showRateSilom();	
	}
 
function showRateKhonkaen(){
	xajax_showRateKhonkaen();	
}
function showRateSriracha(){
	xajax_showRateSriracha();	
}
function showRateOutlet(){
	xajax_showRateOutlet();		
}
function optionApply(){
	$('.display_checkbox').toggle();
	$('input:checkbox[name=chk]').attr('checked',false);
}
function optionShow(){
	$('.display_checkbox').toggle();
	//$("#showVal").text("All Currencies");
//	$('input:checkbox[name=chk]').attr('checked',false);	
	
}
function contactHeadOffice(){
	
	
	$('#contactHeadOffice').show();
	$('#ddlCurrency').hide();
	$('#divRate').hide();
	$('#divHistorialRate').hide();
	$('#divHistorialRateShow').hide();
	
}
function checkAll(value){
	 
	$('#chkAllCur').each( function() {
		var is_checked = $(this).attr('checked');
		$('input:checkbox[name=chk]').attr('checked', is_checked);
		applyChk(value);
	
	});
	
	
}
function applyChk(value){	
	 	
        var str =" ";  
        $("input:checked").each(function () { 
             str +=$(this).val()+" ";
            });
          $("#showVal").text(str);

}

function historialRate(){	
	$('#divHistorialRate').show();
	$('#divRate').hide();	
	$('.display_checkbox').hide();	
	$('#divHistorialRateShow').show();
	$('#ddlCurrency').hide();
}
function historialRateKhonkaen(){	
	$('#divHistorialRateKhonkaen').show();
	$('#divRateKhonkaen').hide();	
	
}
function historialRateSriracha(){	

}
function historialRateOutlet(){	

}

function showHistorialRate(){
	
	xajax_showHistorialRate($("#txtDate").val(),$("#showVal").text());
		

}
function showCal(keyname,typename){
	$('#ddlCurrency').show();
	$('#divRate').fadeOut(800);
	$('#divHistorialRate').hide();
	$('#divHistorialRateShow').hide();
	xajax_calRate(keyname,typename); 
	mform.scrolltoform('divCal');
	//mform.clearForm('ddlCurrency');
}
function showTotal(keyname){
	$('#divsumTotal').show();
	xajax_sumTotal(keyname);
}
function showRate(){
	// FIXED CODE
	$("#divHistorialRate").hide();
	xajax_doneClearRate();

	/*
	$('#ddlCurrency').show();
	//$('#divcal').fadeOut(800);
	$('#divRate').fadeIn(800);
	
	xajax_showRate('now','');
	mform.clearForm('ddlCurrency');*/
}
/********************** Edition ******************************/

function listCal(){	// Exchange Form
	$('#divCalHis').hide();
	$('#divCalForm').fadeIn(800);
	$('.imgClose').hide();
	xajax_listCal($('#txtCurCountry1').val(),$('#txtCurCountry2').val()); 
	
}
function closeForm(){
	$('#divCalHis').hide();
	$('.imgClose').hide();
	
}
function selltobuy(){
	
	xajax_sellToBuy($('#txtCurCountry1').val(),$('#txtCurCountry2').val()); 
}
function calPrice(orderid,kindy,rate,val){	// Calculate Form
	
	var sum = 0;
	if (!(jQuery.trim(val) == '')){	
		if (val.match(/^\d+$|^\d+\.\d{2}$/ )){
				if(kindy=='sell'){
					sum = val / rate;
				
					
				}else{
					if(kindy=='buy'){
						
						sum = val * rate;
					}else{
						
						alert("Error");
					};
				}
			
		}else{
				alert('Only numeric allow');
				mform.clearForm('divCalForm');
			}
	}
		
	document.getElementById('txtSum'+orderid).value = sum.toFixed(4); // FIXED CODE
}

function calPriceSellToBuy(orderid,kindy,rate,val){
	

	var sum= 0;
	if (!(jQuery.trim(val) == '')){	
		if (val.match(/^\d+$|^\d+\.\d{2}$/ )){
				if(kindy=='selltobuy'){
					sum = val * rate;
					
				}else{
					alert("Error");
				}
			
		}else{
				alert('Only numeric allow');
				mform.clearForm('divCalForm');
			}
	}
		
	document.getElementById('txtSum'+orderid).value = sum.toFixed(4); // FIXED CODE**/
}


function delexchange(val){ // Delete Exchange
	if(confirm('Are you sure to delete?' + val)){
		xajax_delRate(val);
	}else{
		return false;
	}
	
}
function saveRate(imax){	// Click save button for session
	$('#divCalHis').show();
	$('.imgClose').show();
	$('#divCalForm').hide();
	for ( var i = 1; i < imax; i++) {
		if($('#txtAmount'+i).val() > 0){
			xajax_sessionCalRate($('#hidCurrency'+i).val(),$('#txtAmount'+i).val(),$('#hidRate'+i).val(),$('#txtSum'+i).val());
			
		}
	}
}
// FIXED CODE

function disableOpt(selectA,selectB){
	
	var selectedValueA = $('#txtCurCountry1').children(":selected").attr("value");
	var selectedValueB = $('#txtCurCountry2').children(":selected").attr("value");
	
	var cur1 = document.getElementById('txtCurCountry1');
	var cur2 = document.getElementById('txtCurCountry2');
	
	for(var i = 0; i < cur2.options.length; i++ ){
		if(selectedValueA == cur2.options[i].value ){
			cur2.options[i].style.display = 'none';			
		}else{
			cur2.options[i].style.display = 'block';	
			}		
	}
	
	for(var i = 0; i < cur1.options.length; i++ ){
		if(selectedValueB == cur1.options[i].value ){
			cur1.options[i].style.display = 'none';
		}else{
			cur1.options[i].style.display = 'block';	
		}
	}	

	var selectedA = $("#txtCurCountry1 option:selected");	
	var selectedB = $("#txtCurCountry2 option:selected");
	var outputA = "";
	var outputB = "";
	
	if(selectedA.val() != 0 ){
		outputA = selectedA.text();
		$("#valFrom").html(outputA);
	}else{
		$("#valFrom").html('');
	}
		
	if(selectedB.val() != 0 ){
		outputB = selectedB.text();
		$("#valTo").html(outputB);
	}else{
		$("#valTo").html('');
	}

}
function printRate(){
	
	$('#divRate').jqprint();
	
}
function hidePractice(){	
	$(".practice").toggle();	
	$(".hideDes").hide();
	$(".showDes").show();
}
function showPractice(){	
		$(".practice").toggle();	
		$(".hideDes").show();
		$(".showDes").hide();
}

function scroll1() {
	
	// the element we want to apply the jScrollPane
	var $el	= $('.practice').jScrollPane({
		verticalGutter 	: -16
	}),
	

			
	// the extension functions and options 	
		extensionPlugin 	= {
			
			extPluginOpts	: {
				// speed for the fadeOut animation
				mouseLeaveFadeSpeed	: 500,
				// scrollbar fades out after hovertimeout_t milliseconds
				hovertimeout_t		: 1000,
				// if set to false, the scrollbar will be shown on mouseenter and hidden on mouseleave
				// if set to true, the same will happen, but the scrollbar will be also hidden on mouseenter after "hovertimeout_t" ms
				// also, it will be shown when we start to scroll and hidden when stopping
				useTimeout			: true,
				// the extension only applies for devices with width > deviceWidth
				deviceWidth			: 980
			},
			hovertimeout	: null, // timeout to hide the scrollbar
			isScrollbarHover: false,// true if the mouse is over the scrollbar
			elementtimeout	: null,	// avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbar
			isScrolling		: false,// true if scrolling
			addHoverFunc	: function() {
				
				// run only if the window has a width bigger than deviceWidth
				if( $(window).width() <= this.extPluginOpts.deviceWidth ) return false;
				
				var instance		= this;
				
				// functions to show / hide the scrollbar
				$.fn.jspmouseenter 	= $.fn.show;
				$.fn.jspmouseleave 	= $.fn.fadeOut;
				
				// hide the jScrollPane vertical bar
				var $vBar			= this.getContentPane().siblings('.jspVerticalBar').hide();
				
				/*
				 * mouseenter / mouseleave events on the main element
				 * also scrollstart / scrollstop - @James Padolsey : http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
				 */
				$el.bind('mouseenter.jsp',function() {
					
					// show the scrollbar
					$vBar.stop( true, true ).jspmouseenter();
					
					if( !instance.extPluginOpts.useTimeout ) return false;
					
					// hide the scrollbar after hovertimeout_t ms
					clearTimeout( instance.hovertimeout );
					instance.hovertimeout 	= setTimeout(function() {
						// if scrolling at the moment don't hide it
						if( !instance.isScrolling )
							$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );
					}, instance.extPluginOpts.hovertimeout_t );
					
					
				}).bind('mouseleave.jsp',function() {
					
					// hide the scrollbar
					if( !instance.extPluginOpts.useTimeout )
						$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );
					else {
					clearTimeout( instance.elementtimeout );
					if( !instance.isScrolling )
							$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );
					}
					
				});
				
				if( this.extPluginOpts.useTimeout ) {
					
					$el.bind('scrollstart.jsp', function() {
					
						// when scrolling show the scrollbar
					clearTimeout( instance.hovertimeout );
					instance.isScrolling	= true;
					$vBar.stop( true, true ).jspmouseenter();
					
				}).bind('scrollstop.jsp', function() {
					
						// when stop scrolling hide the scrollbar (if not hovering it at the moment)
					clearTimeout( instance.hovertimeout );
					instance.isScrolling	= false;
					instance.hovertimeout 	= setTimeout(function() {
						if( !instance.isScrollbarHover )
								$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );
						}, instance.extPluginOpts.hovertimeout_t );
					
				});
				
					// wrap the scrollbar
					// we need this to be able to add the mouseenter / mouseleave events to the scrollbar
				var $vBarWrapper	= $('<div/>').css({
					position	: 'absolute',
					left		: $vBar.css('left'),
					top			: $vBar.css('top'),
					right		: $vBar.css('right'),
					bottom		: $vBar.css('bottom'),
					width		: $vBar.width(),
					height		: $vBar.height()
				}).bind('mouseenter.jsp',function() {
					
					clearTimeout( instance.hovertimeout );
					clearTimeout( instance.elementtimeout );
					
					instance.isScrollbarHover	= true;
					
						// show the scrollbar after 100 ms.
						// avoids showing the scrollbar when moving from inside the element to outside, passing over the scrollbar								
					instance.elementtimeout	= setTimeout(function() {
						$vBar.stop( true, true ).jspmouseenter();
					}, 100 );	
					
				}).bind('mouseleave.jsp',function() {
					
						// hide the scrollbar after hovertimeout_t
					clearTimeout( instance.hovertimeout );
					instance.isScrollbarHover	= false;
					instance.hovertimeout = setTimeout(function() {
							// if scrolling at the moment don't hide it
						if( !instance.isScrolling )
								$vBar.stop( true, true ).jspmouseleave( instance.extPluginOpts.mouseLeaveFadeSpeed || 0 );
						}, instance.extPluginOpts.hovertimeout_t );
					
				});
				
				$vBar.wrap( $vBarWrapper );
				
			}
			
			}
			
		},
		
		// the jScrollPane instance
		jspapi 			= $el.data('jsp');
		
	// extend the jScollPane by merging	
	$.extend( true, jspapi, extensionPlugin );
	jspapi.addHoverFunc();

}


/********************** Edition ******************************/

$(document).ready(function(){
		
	 xajax_showRate('now','');
	$('#divHistorialRate').hide();
	$("#txtDate").datepicker({showOn: 'button', buttonImage: 'images/calendar_blue.png', buttonImageOnly: true,dateFormat: 'yy/mm/dd'});	
	$(".multiSelect").multiSelect({ selectAll: true,oneOrMoreSelected: '*' });

	scroll1();
	
	
	
	
/*	
	$("#btnSubmit").click(function(){
		var isnoterror = true;
		if (validate.valEmpty('txtDate','errtxtDate',lang.rate_date) == false){ isnoterror = false;}
		if(isnoterror){
			xajax_showRate($("#txtDate").val(),$("#txtTime").val());
			showRate();
			
		}
	});
*/

/*
	//create a bubble popup for each DOM element with class attribute as "text", "button" or "link" and LI, P, IMG elements.
	$('#convert').CreateBubblePopup({

								position : 'top',
								align	 : 'center',
								
								innerHtml: 'Covert Click!!!',

								innerHtmlStyle: {
													color:'#FFFFFF', 
													'text-align':'center'
												},
																	
								themeName: 	'all-black',
								themePath: 	'class/js/JQueryBubblePopup/images/jquerybubblepopup-theme'
							 
							});
	
	*/
});
