function change_btn(img, img_src) {
	$(img).attr('src',img_src);
}

function change_btn_div(ele, from_class, to_class) {
	//$('#top-tab-4').css('background-image',img_src);
	$(ele).removeClass(from_class).addClass(to_class);
}

function get_analysis_data(target_div, quote_id, country_id, limit) { //quote_id, limit
	$('#'+target_div).html('&nbsp;'); //box-gray-content-inner
	$.get('/includes/ajax/ajax.php', { action: 'get_analysis', limit:limit, quote_id:quote_id, country_id:country_id }, function(data) {

		$('#'+target_div).html(data);
		//document.getElementById('box-gray-content-inner').innerHTML = data;
		
	}); 
}
function get_news_data(target_div, quote_id, page_id, limit) { //quote_id, limit 
	$('#'+target_div).html('&nbsp;'); //box-gray-content-inner
	$.get('/includes/ajax/ajax.php', { action: 'get_news', limit:limit, quote_id:quote_id, page_id:page_id}, function(data) {

		$('#'+target_div).html(data);
		//document.getElementById('box-gray-content-inner').innerHTML = data;
		
	});
}

function get_data(quote_id, page_id, action, html_element_id, limit) {
	$.get('/includes/ajax/ajax.php', { action: action, limit:limit, quote_id:quote_id, page_id:page_id }, function(data) {

		if(action=='get_news_according_page') {
		
			//$('#'+html_element_id).html(data);
			var xml;
			if (window.DOMParser)
			  {
			  parser=new DOMParser();
			  xml=parser.parseFromString(data,"text/xml");
			  }
			else // Internet Explorer
			  {
				xml=new ActiveXObject("Microsoft.XMLDOM");
				xml.async="false";
				xml.loadXML(data);
			  } 			
//			if (typeof data == "string") {
//				xml = new ActiveXObject("Microsoft.XMLDOM");
//				xml.async = false;
//				xml.loadXML(data);				
//			} else {
//				xml = data;
//			}
//			xml = data;

			$("root", xml).each(function(){
				var news_id = parseInt( $("news_id", data).text() );
				var title      = $("title", data).text();
				var body_text  = $("body_text", data).text();
				var date       = $("date", data).text();
				var link1      = $("link1", data).text();
				var quote_id   = $("quote_id", data).text();
				var page_id   = $("page_id", data).text();
				var error      = $("error", data).text();

				if(news_id > 0 && title != '') {
					$('#map-box-title').text('');
					$('#map-box-title').append('<a href="'+link1+'">'+title+'</a>');
					$('#map-box-body').text('');
					$('#map-box-body').text(body_text);
				} else {
					$('#map-box-title').text(error);
					$('#map-box-body').text('');
				}
			});
			
		}
		
	});
}
function change_tabs(page_id_div_name, newTab,newTabID,currTabID) {
	var current_page_id = document.getElementById(page_id_div_name).value;
	current_page_id = parseInt( current_page_id );
	
	// remove highlight from current tab
	$('#tab_'+current_page_id).removeClass('tab_center').addClass('tab_center_off');
	
	$('#tab_right_'+current_page_id).removeClass('tab_right').addClass('tab_right_off'); // 77
	document.getElementById(page_id_div_name).value = newTabID; // 78
	
	$(newTab).parent().removeClass('tab_center_off').addClass('tab_center'); // 83

	$(newTab).parent().parent().siblings().each(function(){ 
			if($(this).is('.tab_right_off')) {
				$(this).removeClass('tab_right_off').addClass('tab_right'); // 87
			}
		}
	);
	$('#tab_right_'+newTabID).removeClass('tab_right_off').addClass('tab_right'); // 91
}

function OnClickHandler(Element,page_id_div_name) {
	
	change_tabs( page_id_div_name,$(Element).children().children(), $(Element).children().children().attr("id"), $('#'+page_id_div_name).attr('value') );
	$(Element).unbind('click').siblings().each(function() { if($(this).attr('class')=='sibling') { $(this).click(function() {OnClickHandler(this,page_id_div_name);}); } });
}
////////////////////////
function OnClickItemsHandler(Element,identifier_id) {
	change_items_tabs( identifier_id, $(Element).children().children(), $(Element).children().children().attr("id"), $('#'+identifier_id+'_itemID').attr('value') );
	$(Element).unbind('click').siblings().each(function() { if($(this).attr('class')=='sibling') { $(this).click(function() {OnClickItemsHandler(this,identifier_id);}); } });
}
function change_items_tabs(identifier_id,newTab,newTabID,currTabID) {
	var currItemID = document.getElementById(identifier_id+"_itemID").value;
	currItemID = currItemID;
	// remove highlight from current tab
	if ($('#tab_'+currItemID).is('.tabs7_1')) { // first tab
		$('#tab_'+currItemID).removeClass('tabs7_1').addClass('tabs7_1_off');
		//alert('first');
	} else { 
		$('#tab_'+currItemID).removeClass('tabs8_1').addClass('tabs8_1_off');
		//alert('second');
	}
	$('#tabs7_2_'+currItemID).removeClass('tabs7_2').addClass('tabs7_2_off');
	document.getElementById(identifier_id+"_itemID").value = newTabID;

	if ($(newTab).parent().is('.tabs7_1_off')) { // first tab
		$(newTab).parent().removeClass('tabs7_1_off').addClass('tabs7_1');
	} else {
		$(newTab).parent().removeClass('tabs8_1_off').addClass('tabs8_1');
	}
	$(newTab).parent().parent().siblings().each(function(){ 
			if($(this).is('.tabs7_2_off')) {
				$(this).removeClass('tabs7_2_off').addClass('tabs7_2');
			}
		}
	);
	$('#tabs7_2_'+newTabID).removeClass('tabs7_2_off').addClass('tabs7_2');
	
	$('#item_data_box_'+currTabID).css('display','none');
	$('#item_data_box_'+newTabID).css('display','block');
	
}
// Tabs Gray ////////////////////////////////////////////////////////////////////////////////
function OnClickItemsGrayHandler(Element,identifier_id) {
	change_items_gray_tabs( identifier_id, $(Element).children().children(), $(Element).children().children().attr("id"), $('#'+identifier_id+'_itemID').attr('value') );
	$(Element).unbind('click').siblings().each(function() { if($(this).attr('class')=='sibling') { $(this).click(function() {OnClickItemsGrayHandler(this,identifier_id);}); } });
}
function change_items_gray_tabs(identifier_id,newTab,newTabID,currTabID) {
	var currItemID = document.getElementById(identifier_id+"_itemID").value;
	currItemID = currItemID;
	// remove highlight from current tab: 
	//first
	if ($('#'+identifier_id+'_tab_left_'+currItemID).is('.left-first-selected')) { 
		$('#'+identifier_id+'_tab_left_'+currItemID).removeClass('left-first-selected').addClass('left-first');
	} else if($('#'+identifier_id+'_tab_left_'+currItemID).is('.left-selected')){ 
		$('#'+identifier_id+'_tab_left_'+currItemID).addClass('no-display');
	}
	
	//middle
	if ($('#'+identifier_id+'_tab_'+currItemID).is('.repeat-selected')) { 
		$('#'+identifier_id+'_tab_'+currItemID).removeClass('repeat-selected').addClass('repeat');
	}
	// right
	if ($('#'+identifier_id+'_tabs_right_'+currItemID).is('.right-last-selected')) { 
		$('#'+identifier_id+'_tabs_right_'+currItemID).removeClass('right-last-selected').addClass('right-last');
	} else if($('#'+identifier_id+'_tabs_right_'+currItemID).is('.right-selected')){ 
		$('#'+identifier_id+'_tabs_right_'+currItemID).removeClass('right-selected').addClass('right');
	} else if($('#'+identifier_id+'_tabs_right_'+currItemID).is('.left-selected')){
		$('#'+identifier_id+'_tabs_right_'+currItemID).removeClass('left-selected').addClass('right');
	}
	if( $('#'+currItemID).parent().parent().prev() != 0) {
		$('#'+currItemID).parent().parent().prev().children().each(function(){
							if($(this).is('.right-tab')) {
								$(this).removeClass('left-selected').addClass('right');
							}
		});
	}
	document.getElementById(identifier_id+"_itemID").value = newTabID;

	//add highlight to new tab
	//first
	if ($('#'+identifier_id+'_tab_left_'+newTabID).is('.left-first')) { 
		$('#'+identifier_id+'_tab_left_'+newTabID).removeClass('left-first').addClass('left-first-selected');
	} else if($('#'+identifier_id+'_tab_left_'+newTabID).is('.left-selected')){ 
		$('#'+identifier_id+'_tab_left_'+newTabID).removeClass('no-display');
	}
	
	//middle
	if ($('#'+identifier_id+'_tab_'+newTabID).is('.repeat')) { 
		$('#'+identifier_id+'_tab_'+newTabID).removeClass('repeat').addClass('repeat-selected');
	}
	// right
	if( $(newTab).parent().parent().prev() != 0) {
		$(newTab).parent().parent().prev().children().each(function(){
							if($(this).is('.right-tab')) {
								$(this).removeClass('right-selected').removeClass('right').addClass('left-selected');
							}
		});
	}	
	if ($('#'+identifier_id+'_tabs_right_'+newTabID).is('.right-last')) { 
		$('#'+identifier_id+'_tabs_right_'+newTabID).removeClass('right-last').addClass('right-last-selected');
	} else if($('#'+identifier_id+'_tabs_right_'+newTabID).is('.right')){ 
		$('#'+identifier_id+'_tabs_right_'+newTabID).removeClass('right').addClass('right-selected');
	}
	//
	
	$('#'+identifier_id+'_item_data_box_'+currTabID).css('display','none');
	$('#'+identifier_id+'_item_data_box_'+newTabID).css('display','block');
	
}
// Map box
function changeTabsById(containerId,idToShow) {
	
//	$('#'+containerId+' .box-items').css('display','none');
//	$('#'+idToShow).css('display','block');
	$('#'+containerId+' .box-items').hide();
	$('#'+idToShow).show();
}
function changeTopTabsSectionsBox(idNumToShow) {
	if(idNumToShow == 1) {
		idNumToHide = 2;
		$('#top-section-center').removeClass('section-center-left-selected').addClass('section-center-right-selected');
	} else {
		idNumToHide = 1;
		$('#top-section-center').removeClass('section-center-right-selected').addClass('section-center-left-selected');
	}
	$('#top-section-'+idNumToShow).removeClass('section-repeat-not-selected').addClass('section-repeat-selected');
	$('#top-section-'+idNumToHide).removeClass('section-repeat-selected').addClass('section-repeat-not-selected');
	
	$('#box-item-'+idNumToShow).show();
	$('#box-item-'+idNumToHide).hide();
}
//Cross rates 
function getCrossRates(currency_id,keyId) {
	//var waiting_container = '<div class="markets_list_border" style="height:100px;"><img src="/images/ajax-loader.gif" style="margin:30px 70px 0px 70px;" /></div>';
	var loading_container = '<div class="site-float" style="width:100%;height:100px;"><img src="/includes/images/ajax-loading.gif" style="margin:30px 238px 0px 0px;" /></div>';

	$('#RatesOuterContainer'+keyId).html(loading_container);
	
	$.get('/includes/ajax/ajax.php', { action: 'get_cross_rates', currency_id:currency_id, keyId:keyId }, function(data) {
		$('#RatesOuterContainer'+keyId).html(data);
	});
}
//Converter
function convertRate() {
	//var waiting_container = '<div class="markets_list_border" style="height:100px;"><img src="/images/ajax-loader.gif" style="margin:30px 70px 0px 70px;" /></div>';
	var loading_container = '<div class="site-float" style="margin:30px 180px 0px 140px;"><img src="/includes/images/ajax-loading.gif" /></div>';

	$('#ResultRow').html(loading_container);
	
	var from = $('#convertfrom').val();
	var to = $('#convertto').val();
	var amount = $('#convamount').val();
	
	$.get('/includes/ajax/converter_ajax.php', { action: 'convert_rates', from:from, to:to, amount:amount }, function(data) {
		$('#ResultRow').html(data);
	});
}
