jQuery.fn.outerHTML = function(s) {
	return (s) ? this.before(s).remove() : jQuery("<p>").append(
			this.eq(0).clone()).html();
}
function setHomepage(url) {
	if (url == undefined) {
		url = window.location.href;//'http://www.chinasanxin.com/new/index.php';
	}
	if (document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(url);

	} else if (window.sidebar) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager
						.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
				return;
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1']
				.getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', url);
	}
}

function addfavorite(url, name) {
	if (url == undefined) {
		url = window.location.href;//'http://www.chinasanxin.com/new/index.php';
	}
	if (name == undefined) {
		name = 'chinasanxin';
	}
	if (document.all) {
		window.external.addFavorite(url, name);
	} else if (window.sidebar) {
		window.sidebar.addPanel(name, url, "");
	}
}

function showNews() {
	$("#dvHomeBackNews").show();
	$("#dvOnlyNews").hide();
}
function hideNews() {
	if ($("#dvHomeBackNews").is(":hidden") == false) {
		$("#dvHomeBackNews").hide();
		$("#dvOnlyNews").show();
	}
}
function $hideLoadingStatus(tm) {
	if (document.body.$__udLoadingStatusImg) {
		if (tm == undefined) {
			document.body.$__udLoadingStatusImg.hide();
		} else {
			document.body.$__udLoadingStatusImg.hide(tm);
		}
	}
}
function $showLoadingStatus($obj) {
	if (!document.body.$__udLoadingStatusImg) {
		var style = "position:absolute;z-index:9999;width:150px;height:25px;";
		document.body.$__udLoadingStatusImg = $('<img style="'+style+'" src="static/images/ajax-loader.gif"/>').appendTo(document.body);
		var top = ($(window).height() - document.body.$__udLoadingStatusImg.height())/2;top = top/2;
		var left = ($(window).width() - document.body.$__udLoadingStatusImg.width())/2; 
		var scrollTop = $(document).scrollTop();
		var scrollLeft = $(document).scrollLeft();
		document.body.$__udLoadingStatusImg.css({top:top+scrollTop,left:left+scrollLeft});
		$(window).bind('resize', function() {
			try {
				var top = ($(window).height() - document.body.$__udLoadingStatusImg.height())/2;top = top/2;
				var left = ($(window).width() - document.body.$__udLoadingStatusImg.width())/2; 
				var scrollTop = $(document).scrollTop();
				var scrollLeft = $(document).scrollLeft();
				document.body.$__udLoadingStatusImg.css({position:'absolute','top':top+scrollTop,left:left+scrollLeft});
			} catch (e) {}
		});	
	}
	document.body.$__udLoadingStatusImg.show();
}

function $load_ajax_main_page(url, $obj, parent_menu_id) {
	$showLoadingStatus();
	if (url == undefined) {
		url = 'index.php?c=main&menu_id=' + parent_menu_id;
	}
	$.ajax(
		{
			url:url + '&m=ajax_page_view',
			data:'r='+(new Date()).getTime(),
        	type:'GET',
			dataType:'html',
        	error: function(XMLHttpRequest, textStatus, errorThrown){
            	alert('error:' + XMLHttpRequest.responseText + '>' + textStatus + '>' + errorThrown);
            	$hideLoadingStatus();
			},
			success: function(html){
				if ($obj) {
					$(".current").removeClass("current");
					$obj.addClass("current");
					$(".current a").addClass("current");
				}
				$hideLoadingStatus();
				$('#main_page').html(html);
			}
		}
	);
}
function get_val_from_uri(uri, key) {
	try {
		var i = uri.indexOf('?');
		if (i > -1) {
			uri = uri.substring(i + 1);
		}
		var temp = uri.split('&');
		for (i = 0; i < temp.length; i++) {
			value = temp[i];
			if (value == '') continue;
			var vv = value.split('=');
			if (key == vv[0]) {
				return vv[1];
			}
		}
	} catch (e) {}
	return '';
}
function $load_ajax_main_nav(uri) {
	var level = get_val_from_uri(uri, 'level');
	var menu_id = get_val_from_uri(uri, 'menu_id');
	var p_menu_id = get_val_from_uri(uri, 'p_menu_id');
	var l = get_val_from_uri(uri, 'l');
	//$showLoadingStatus();
	var url = 'index.php?c=main&level='+level+'&menu_id='+menu_id+'&p_menu_id=' + p_menu_id + '&l=' + l;
	$.ajax(
		{
			url:url + '&m=ajax_nav_view',
			data:'r='+(new Date()).getTime(),
        	type:'GET',
			dataType:'html',
        	error: function(XMLHttpRequest, textStatus, errorThrown){
            	alert('error:' + XMLHttpRequest.responseText + '>' + textStatus + '>' + errorThrown);
            	$hideLoadingStatus();
			},
			success: function(html){
				//$hideLoadingStatus();
				$('#nav_link').html(html);
			}
		}
	);
}
function $post_message_data(_url, _ok_msg, _ng_msg){
	$showLoadingStatus();
	if (_url == undefined) {
		_url = 'index.php?c=message&m=ajax_message_add';
	}
	$.ajax(
		{
			url:_url + "&r=" +(new Date()).getTime(),
			data:{
				f_title:$("#f_title").val(),
				f_contents:$("#f_contents").val(),
				f_company:$("#f_company").val(),
				f_username:$("#f_username").val(),
				f_sex:$("#f_sex").val(),
				f_tel:$("#f_tel").val(),
				f_email:$("#f_email").val()
			},
        	type:'POST',
			dataType:'html',
        	error: function(XMLHttpRequest, textStatus, errorThrown){
            	$hideLoadingStatus();
            	alert(_ng_msg + ' >> error:' + XMLHttpRequest + '>' +  textStatus + '>' + errorThrown);
			},
			success: function(html){
				$hideLoadingStatus();
				//$menu_view();
				//alert(_ok_msg + "\n" + html);
				alert(_ok_msg);
				$("#f_title").val("");
				$("#f_contents").val("");
				$("#f_company").val("");
				$("#f_username").val("");
				$("#f_sex").val("");
				$("#f_tel").val("");
				$("#f_email").val("");
			}
		}
	);
}
