//Global JavaScript Function

function create_toggle_section()
{
	var section_list=$("*[id='toggle_section']");

	section_list.each(function(){
		var toggle_section = $(this);

		var section_title = toggle_section.attr('data-title');
		var section_close = toggle_section.attr('data-close');
		if ( toggle_section.find("*[id='html_title']").get(0) ){
			toggle_section.find("*[id='section_title']").html(toggle_section.find("*[id='html_title']").html());
		}
		else{
			toggle_section.find("*[id='section_title']").html(section_title);
		}
		var section_header = toggle_section.find("*[id='section_header']");
		section_header.click(function () {
			var Obj     = toggle_section.find("*[id='section_container']");
			var SpanID  = $(this).find("*[id='char']");

			if (Obj.is(":hidden")) {
				Obj.slideDown("slow");
				//SpanID.html(eval('"_"'));
				SpanID.html('<img src="images/up.png" />');
			}
			else {
				Obj.slideUp("slow");
				//SpanID.html(eval('"\\u25a1"'));
				SpanID.html('<img src="images/down.png" />');
			}
		});

		section_header.find("*[id='close']").click(function () {
			toggle_section.remove();
		});

		var section_status = toggle_section.attr('data-status');
		if(section_status=='min'){
			toggle_section.find("*[id='section_container']").hide();
			//section_header.find("*[id='char']").html(eval('"\\u25a1"'));
			section_header.find("*[id='char']").html('<img src="images/down.png" />');
		}

	});
}

function create_autocomplete(SectionID, AutocompleteOptions_ItemID, AutoInputID, _mustMatch, _multiple )
{
	if(document.getElementById("" + AutocompleteOptions_ItemID + "")){

		var jq_autocomplete_options = $('#' + AutocompleteOptions_ItemID).val().split(",");

		if (SectionID){
		var autoinput=$('#' + SectionID + " input[class='" + AutoInputID + "']");
		}else{
		var autoinput=$("input[class='" + AutoInputID + "']");
		}

		autoinput.each(function(){
			$(this).unbind();
			$(this).flushCache();
			$(this).unautocomplete();
			$(this).autocomplete(jq_autocomplete_options, {
				minChars: 0,
				cacheLength: 1,
				multiple: _multiple,
				max: 100,
				mustMatch: _mustMatch,
				autoFill: false
			});

		});

	}
}

function create_tab_section()
{
	$("div[id='tab_section']").each(function(){
			var activetab  = $(this).attr('data-activetab');
			activetab = (activetab) ? parseInt(activetab) : 1;

			$(this).tabs( activetab ,
						 {
							 fxSpeed: 'fast'

						 });
	});

}

//## Setup the ajax POPUP Menu ##{
//##################################################################################################
loading='<span style="font: 11px Verdana; padding: 0.5em 0.5em;background:#ccc;-moz-opacity: .9"><img src="images/progressbar.gif"> <b>Loading</b></span>';
function ajax_popup_creator(popupID,content)
{
	$("body").append('<div id="' + popupID + '"><table cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="middle">'+ content +'</td></tr></table></div>');
	$('#' + popupID).css({
		display:"none",
		margin:"0px",
		paddingLeft:"0px",
		paddingRight:"0px",
		paddingTop:"0px",
		paddingBottom:"0px",
		position:"absolute",
		border: "1px dashed #990000",
		background: "#000",
		"text-align": "center",
		"-moz-opacity": ".9",
		"z-index": "999",
		filter:"alpha(opacity=90)"
	});
	return $('#' + popupID);
}

function confirm_check(lock_obj,ok_link,confirm_text,comment)
{
	var confirm_content= '<span style="font: 14px;"><p style="background:#087;padding: 1em;color:white;">'+ comment +'<br><b>'+ confirm_text +'</b><br><button type="button" class="button-like" onclick="' + ok_link + '">Yes</button> <button type="button" class="button-like" onclick="$(\'#ajax_confirm\').remove();">NO</button></p></span>';
	var pos = lock_obj.offset();
	var ajax_confirm = ajax_popup_creator('ajax_confirm',confirm_content)
	ajax_confirm.css('left', pos.left).css('top', pos.top).css('opacity', '.9').width(lock_obj.width()).height(lock_obj.height());
	ajax_confirm.slideDown("fast");
}
////////////////////////////////////////////////////////////////////////////////////////////////// }

function remove_section(ItemID)
{
	var Obj = $('#' + ItemID);
	Obj.remove();
}

function create_tooltips()
{
	$('#tooltips').tooltip({
		track: true,
		delay: 100,
		showURL: false,
		bodyHandler: function() {
			return $("#tooltip_content").show();
		},
		extraClass: "pretty",
		left: -10
	});
}

function create_ToggleObj()
{
	$("legend[id='toggle']").each(function(){

		var sections      = $(this).attr('data-sections').split(",");
		var default_view  = $(this).attr('data-default_view');
		if (default_view == 'display'){
			$('#' + sections[0]).show();
		}
		else{
			$('#' + sections[0]).hide();
		}

		$(this).click(function(){
			ToggleObj(sections[0],sections[1]);
		});

	});
}

function ToggleObj(a_showItemID,a_hideItemID)
{
	var Obj1 = $('#' + a_hideItemID);
	var Obj2 = $('#' + a_showItemID);
	Obj1.slideUp('slow');
	Obj2.slideDown('slow');
}

function confirm_form()
{
	return true;

	/*
	$("#confirm_form").submit(function() {

		var re = new RegExp('^[a-z]{2,4}$');
		var confirm_text = $(this).attr('data_confirm_text');

		var field_val= $(this).find("input[id='check_val']").val().split(",");
		//alert (re.test(field_val[1]))

		if ($("input[@name='legal_bit']:checked").val() == 0){
			return true;
		}

		if (field_val[1] && field_val[1].match(re)){
			return true;
		}
		else{
			var answer = confirm(confirm_text)
			if (answer) {
				return true;
			}
			else{
				return false;
			}
		}

	});
	*/
}

/*
function assign_order_sum_checkbox()
{
    var order_sum = 0;
    $("input[type='checkbox'][class='order_sum']").each(function(){

	var order  = $(this);
	var order_unit  = order.attr('data_unit');

	if (order.attr('checked')) {
	    order_sum = parseFloat(order_sum) + parseFloat(order_unit);
	}

	if (order_sum > 0) {
	    $("span[id='order_sum']").html(order_sum);
	}

	order.click(function () {

	    if (order.attr('checked')) {
		order_sum = parseFloat(order_sum) + parseFloat(order_unit);
	    }
	    else{
		order_sum = parseFloat(order_sum) - parseFloat(order_unit);
	    }

	    $("span[id='order_sum']").html(order_sum);

	});

    });

    $("tr[id='order_sum']").show();

}
*/

function assign_create_tooltips()
{
    $("a[id='tooltips']").each(function(){

	var tooltip_link = $(this);
	var tooltip_content  = $('#' + tooltip_link.attr('data_tooltip'));

	tooltip_link.tooltip({
		track: true,
		delay: 100,
		showURL: false,
		bodyHandler: function() {
			return tooltip_content.show();
		},
		left: -10
	});


    });

}

/*
function show_login_announcement_box()
{
		if ( $("a[id='LoginAnnouncement']").get(0) ){

			$("a[id='LoginAnnouncement']").trigger('click');
			
			jQuery.each(jQuery.browser, function(i) {
				if($.browser.msie){
					$("#TB_window").css('right', '300');
				}
			});
		}
}
*/

function assign_radioTextBox()
{
    $("input[type='radio'][class='radioTextBox']").each(function(){
	$(this).click(function(){
		$('#radioTextBoxSection').find("input[type='text']").hide();
		$("div[class='radioTextBoxDiv']").hide();

		var tabindex = parseInt($(this).attr('tabindex')) + 1;
		var radioTextBox = $('#radioTextBoxSection').find("input[tabindex="+ tabindex +"]");
		radioTextBox.show();

		var radioDiv = $('#' + $(this).attr('data_radioDiv'));
		radioDiv.show();
	});

	if ($(this).attr('checked')) {
		$(this).trigger('click');
	}
    });
}

