$("body").ready(function(){
	$("#img_from_checkall").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/gui/bttn-check02.gif");
		},
		function(){
			$(this).attr("src","img/gui/bttn-check01.gif");
		}
	);
	$("#img_from_uncheckall").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/gui/bttn-uncheck02.gif");
		},
		function(){
			$(this).attr("src","img/gui/bttn-uncheck01.gif");
		}
	);
	$("#img_from_apply").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/shr/apply_02.gif");
		},
		function(){
			$(this).attr("src","img/shr/apply_01.gif");
		}
	);
	
	
	/// #########################
	$("#img_checkall").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/gui/bttn-check02.gif");
		},
		function(){
			$(this).attr("src","img/gui/bttn-check01.gif");
		}
	);
	$("#img_uncheckall").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/gui/bttn-uncheck02.gif");
		},
		function(){
			$(this).attr("src","img/gui/bttn-uncheck01.gif");
		}
	);
	$("#img_apply").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/shr/apply_02.gif");
		},
		function(){
			$(this).attr("src","img/shr/apply_01.gif");
		}
	);
	
	$("#img_checkall").click(
		function(){
		   var swap=$("#main_popup input[type='checkbox']");
			var chk_length=swap.length;
			for(i=0;i<chk_length;i++){
				if(i==0){
					swap[i].checked=true;
					swap[i].disabled=false;
				}else{
					swap[i].checked=false;
					swap[i].disabled=true;
				}
			}
			//alert(chk_length);
		}
	);
	$("#img_uncheckall").click(
		function(){
			var swap=$("#main_popup input[type='checkbox']");
			var chk_length=swap.length;
			for(i=0;i<chk_length;i++){
				swap[i].checked=false;
				swap[i].disabled=false;
			}
			$("#cur_all span").html("All Currencies");
			//alert(chk_length);
		}
	);
	
	$("#img_from_uncheckall").click(
		function(){
			var swap=$("#from_popup input[type='checkbox']");
			var chk_length=swap.length;
			for(i=0;i<chk_length;i++){
				swap[i].checked=false;
				swap[i].disabled=false;
			}
			$("#from_currency span").html("Please select currency");
			//alert(chk_length);
		}
	);
	
	$("#img_from_close").click(function(){
         $("#from_popup").hide("slow");							   
	});
	
	$("#img_close").click(function(){
         $("#main_popup").hide("slow");							   
	});
	
	$("#img_apply").click(
		function(){
		    var chk_length=$("#main_popup input[type='checkbox']").length;
			var chk=0;
			for(i=0;i<chk_length;i++){
				if($("#main_popup input[type='checkbox']")[i].checked){
					chk++;
					//break;
				}
			}
			if(chk>0 && chk < chk_length-1){
				$("#cur_all option[value=Selected]").attr("selected","selected");
			}else{
				$("#cur_all option[value=All]").attr("selected","selected");
			}
			$("#main_popup").hide("slow");
		}
	);
	
	$("#cur_all").click(
		function(){
		   	$("#main_popup").show("slow");
		}
	);
	
    $("#main_popup input[type='checkbox']").click(function(){
			var chk_swap=	$("#main_popup input[type='checkbox']");										 
			var chk_length=chk_swap.length;
			var chk=1;
			for(i=0;i<chk_length;i++){
				if(chk_swap[i].checked){
					chk++;
				}
			}	
			if(chk>1){
				for(i=0;i<chk_length;i++){
					if(chk_swap[i].checked==false){
						chk_swap[i].disabled=true;
					}
				}
				$("#cur_all span").html(this.value);
			}else{
				for(i=0;i<chk_length;i++){
						chk_swap[i].disabled=false;
			
				}
				$("#cur_all span").html("All Currencies");
			}
	  });
	
	
	
	////////////// #####################
	
	$("#imgcheckall").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/gui/bttn-check02.gif");
		},
		function(){
			$(this).attr("src","img/gui/bttn-check01.gif");
		}
	);
	$("#imguncheckall").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/gui/bttn-uncheck02.gif");
		},
		function(){
			$(this).attr("src","img/gui/bttn-uncheck01.gif");
		}
	);
	$("#imgapply").hover(
		function(){
			$(this).css({'cursor':'pointer'});
			$(this).attr("src","img/shr/apply_02.gif");
		},
		function(){
			$(this).attr("src","img/shr/apply_01.gif");
		}
	);
	
	$("#imgcheckall").click(
		function(){
			var swap=$("#result_popup input[type='checkbox']");
			var chk_length=swap.length;
			for(i=0;i<chk_length;i++){
				if(i<=4){
					swap[i].checked=true;
					swap[i].disabled=false;
				}else{
					swap[i].checked=false;
					swap[i].disabled=true;
					
				}
			}
			//alert(chk_length);
		}
	);
	$("#imguncheckall").click(
		function(){
		   var swap=$("#result_popup input[type='checkbox']");
			var chk_length=swap.length;
			for(i=0;i<chk_length;i++){
				swap[i].checked=false;
				swap[i].disabled=false;
			}
			$("#to_currency span").html("Please select currency");
			//alert(chk_length);
		}
	);
	
	$("#imgapply").click(
		function(){
		   var swap=$("#result_popup input[type='checkbox']");
		    var chk_length=swap.length;
			var chk=0;
			for(i=0;i<chk_length;i++){
				if(swap[i].checked){
					chk++;
					//break;
				}
			}
			if(chk>0 && chk < chk_length-1){
				$("#to_currency option[value=Selected]").attr("selected","selected");
			}else{
				$("#to_currency option[value=All]").attr("selected","selected");
			}
			$("#result_popup").hide("slow");
		}
	);
	$("#result_popup input[type='checkbox']").click(function(){
		    var swap=$("#result_popup input[type='checkbox']");												 
			var chk_length=swap.length;
			var val=$("#to_currency span").html();
			var check=val.indexOf(this.value);
			if(val=="Please select currency"){
				$("#to_currency span").html(this.value);
			}else{
				if(this.checked){
					val+=" "+this.value;
					$("#to_currency span").html(val);
				}else{
					val=val.replace(this.value,"");
					$("#to_currency span").html(val);
				}
			}
			
			
			
			var chk=0;
			for(i=0;i<chk_length;i++){
				if(swap[i].checked){
					chk++;
				}
			}	
			if(chk>4){
				for(i=0;i<chk_length;i++){
					if(swap[i].checked==false){
						swap[i].disabled=true;
					}
				}			
			}else if(chk==0){
				$("#to_currency span").html("Please select currency");
			}else{
				for(i=0;i<chk_length;i++){
						swap[i].disabled=false;
				}
				//
			}
	  });
	
	$("#img_from_apply").click(
		function(){
		   var swap=$("#from_popup input[type='checkbox']");
		    var chk_length=swap.length;
			var chk=0;
			for(i=0;i<chk_length;i++){
				if(swap[i].checked){
					chk++;
					//break;
				}
			}
			if(chk==0){
				alert("Please select a currency you have");
			}else{
				$("#from_popup").hide("slow");
			}
			/*if(chk>0 && chk < chk_length-1){
				$("#to_currency option[value=Selected]").attr("selected","selected");
			}else{
				$("#to_currency option[value=All]").attr("selected","selected");
			}*/
			
		}
	);
	
	$("#from_popup input[type='checkbox']").click(function(){
			//alert(this.value);	
			var swap=$("#from_popup input[type='checkbox']");
			var chk_length=swap.length;
			var chk=1;
			for(i=0;i<chk_length;i++){
				if(swap[i].checked){
					chk++;
				}
			}	
			if(chk>1){
				for(i=0;i<chk_length;i++){
					if(swap[i].checked==false){
						swap[i].disabled=true;
					}
				}
				$("#from_currency span").html(this.value);			
			}else{
				for(i=0;i<chk_length;i++){
						swap[i].disabled=false;
			
				}
				$("#from_currency span").html("Please select currency");	
			}
	  });
	
	$("#to_currency").click(
		function(){
		   	$("#result_popup").show("slow");
		}
	);
	
	$("#from_currency").click(
		function(){
		   	$("#from_popup").show("slow");
		}
	);
	
	$("#imgclose").click(function(){
         $("#result_popup").hide("slow");							   
	});
})

function sendSubmit(frm,queryString){
		frm.action="history_exchange.jsp";
		frm.action+="?"+queryString;
		frm.target="_top";
		frm.submit();
}

function sendPrint(frm,queryString,tg){
	frm.action=tg;
	frm.action+="?"+queryString;
	frm.target="_blank";
	frm.submit();
}