
$(document).ready(
	function () {
		try {
			setTabbed();
			setAccountTab();
			navigation_set_equal_value('input#pageHidden');
//			setSelectorCheckboxes();
		}
		catch (e) {}
	}
);

function setAccountTab(){
	
	var selectedTab= $('#tabbed').html();
	switch(selectedTab){
		case "my_account_edit_profile":
			$('#securityTab').parent('li').removeAttr('id');
			$('#creditTab').parent('li').removeAttr('id');
			$('#editProfTab').parent('li').attr('id','current');
			break;
		case "my_account_security":
			$('#securityTab').parent('li').attr('id','current');
			$('#editProfTab').parent('li').removeAttr('id');
			$('#creditTab').parent('li').removeAttr('id');
			break;

		case "my_account_credit":
			$('#securityTab').parent('li').removeAttr('id');
			$('#editProfTab').parent('li').removeAttr('id');
			$('#creditTab').parent('li').attr('id','current');
			break;
	}
	
	
};

function setTabbed() {
	var par_id = ''; 
	var ele_class = '';
	var header_par_id = ''; 
	var tabs = $('.tabs li');
	
	ele_class = $('#tabbed').val();
	tabs.each(
		function(){
			var id = $(this).attr('id');
			var clasz = $(this).attr('class');
			if (id != null && id == 'current') {
				$(this).removeAttr('id');
			}
			else if (clasz != null && clasz == ele_class) {
				$(this).attr('id','current');
			}
		}
	);
	
	
	var tabbedId = $('#headerTabbed').val();
	if (null == tabbedId || tabbedId == '') {
		tabbedId = '_hometab';
	}
	
	var tabbedIdQ = $('#'+tabbedId);
	if (tabbedIdQ.parents('#topmenu').length > 0) {
		tabbedIdQ.find('a:first').attr('class','current');
	}
	else {
		tabbedIdQ.attr('class','current');
	}

	setupMessage();
	
}

function setupMessage(){
	if (jQuery.trim($('.info_box span').text()).length != 0) {
		$('.info_box').removeAttr('style');
		$('#captcha').val('');
	} 
	else if (jQuery.trim($('.error_box span').text()).length != 0) {
		$('.error_box').removeAttr('style');
		$('#captcha').val('');
	}
	else if (jQuery.trim($('.alert_box span').text()).length != 0) {
		$('.alert_box').removeAttr('style');
		$('#captcha').val('');
	}
}

function navigation_set_equal_value(ele) {
	var ele_value = $(ele).val();
							
	$('input.navigation_input_page').each(function() {
			$(this).val(ele_value);
		}
	);
	$('input#pageHidden').each(function() {
			$(this).val(ele_value);
		}
	);
}
function navigation_set_page_value(ele) {
	var ele_value = $(ele).val();
					
	$('select.navigation_item_per_page').each(function() {
			$(this).val(ele_value);
		}
	);
	$('input#perPageHidden').each(function() {
			$(this).val(ele_value);
		}
	);
}

function setSelectorCheckboxes() {
	var selector = $('.selector_all,.selector_none,.selector_free,.selector_shared,.selector_personal');

	$(selector).attr('href','javascript:void(0);');
	$(selector).click(function() {
			var class_ = $(this).attr('class');
			if (class_ == 'selector_all'){
				$('input[id="free_checkbox"],input[id="shared_checkbox"],input[id="personal_checkbox"]').each(function() {
					$(this).attr('checked','checked');
					}
				);
			}
			if (class_ == 'selector_none'){
				$('input[id="free_checkbox"],input[id="shared_checkbox"],input[id="personal_checkbox"]').each(function() {
						$(this).removeAttr('checked');
					}
				);
			}
			if (class_ == 'selector_free'){
				$('input[id="free_checkbox"]').each(function() {
						$(this).attr('checked','checked');
					}
				);
			}
			if (class_ == 'selector_shared'){
				$('input[id="shared_checkbox"]').each(function() {
						$(this).attr('checked','checked');
					}
				);
			}
			if (class_ == 'selector_personal'){
				$('input[id="personal_checkbox"]').each(function() {
						$(this).attr('checked','checked');
					}
				);
			}
		}
	);
}
