// JavaScript Document
if (jQuery.browser.msie) {
	if (parseInt(jQuery.browser.version) == 6) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		}catch(e){
		}
	}
}
function trim() {
    if (typeof (arguments[0]) != "undefined") {
        var stringToTrim = arguments[0];
        return stringToTrim.replace(/^\s+|\s+$/g, "");
    } else {
        return "";
    }
}
function rehash() {
	var hashstr = arguments[0];
	var pagetitle = document.title;
	if (typeof (hashstr) != "undefined" && typeof (hashstr) != "object") {
		var port = "";
		if (jQuery.url.attr("query") == null) {
			document.location.href = jQuery.url.attr("protocol") + "://" + jQuery.url.attr("host") + jQuery.url.attr("path") + "#" + hashstr;
		} else {
			document.location.href = jQuery.url.attr("protocol") + "://" + jQuery.url.attr("host") + jQuery.url.attr("path") + "?" + (jQuery.url.attr("query") || "") + "#" + hashstr;
		}
	}
	document.title = pagetitle;
} 
function checkhash() {
	var tmp_urlanchor = jQuery.url.attr("anchor");
	var tmp_obj = new Object;
	if (tmp_urlanchor != null) {
		var tmp_hash = tmp_urlanchor.split("&");
		var tmp_b;
		for (var loopi = 0; loopi < tmp_hash.length; loopi++) {
			tmp_b = tmp_hash[loopi].split("=");
			eval("tmp_obj." + tmp_b[0] + "= '" + tmp_b[1] + "';");
		}
	}
	return tmp_obj;
} 
function blockblack() {
	var msg = "";
    if (typeof (arguments[0]) != "undefined") {
        msg = arguments[0];
    }
	var timeout;
	timeout = parseInt(arguments[1]);
	if (isNaN(timeout)) { timeout = 0; }
	if (timeout > 0 && timeout < 3000) {timeout = 3000; }
	$.blockUI({ message: '<h1>' + msg + '</h1>', css: {
		border: 'none',
		padding: '15px',
		backgroundColor: '#000',
		'-webkit-border-radius': '10px',
		'-moz-border-radius': '10px',
		opacity: '.5',
		color: '#fff'
		}
	});
	if (timeout > 0) {
		setTimeout($.unblockUI, timeout);
	}
}
function blocklight() {
	var msg = "";
    if (typeof (arguments[0]) != "undefined") {
        msg = arguments[0];
    }
	var timeout;
	timeout = parseInt(arguments[1]);
	if (isNaN(timeout)) { timeout = 0; }
	if (timeout > 0 && timeout < 3000) { timeout = 3000; }
	$.blockUI({ message: '<h1><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"/><b style="color:blue;">Message:</b><br>' + msg + '</h1>', css: {
		border: '1px solid #FAD42E',
		color: '#363636',
		padding: '7px',
		background: '#FBEC88',
		'-webkit-border-radius': '5px',
		'-moz-border-radius': '5px',
		'text-align': 'left'
		}
	});
	if (timeout > 0) {
		setTimeout($.unblockUI, timeout);
	}
}
function blockerr() {
	var msg = "";
    if (typeof (arguments[0]) != "undefined") {
        msg = arguments[0];
    }
	var timeout;
	timeout = parseInt(arguments[1]);
	if (isNaN(timeout)) { timeout = 0; }
	if (timeout > 0 && timeout < 3000) { timeout = 3000; }
	$.blockUI({ message: '<h1><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"/><b style="color:red;">Error:</b><br>' + msg + '</h1>', css: {
		border: '1px solid #CD0A0A',
		color: '#363636',
		padding: '7px',
		background: '#FEF1EC',
		'-webkit-border-radius': '5px',
		'-moz-border-radius': '5px',
		'text-align': 'left'
		}
	});
	if (timeout > 0) {
		setTimeout($.unblockUI, timeout);
	}
}
function blockcheck() {
	var msg = "";
    if (typeof (arguments[0]) != "undefined") {
        msg = arguments[0];
    }
	var js = function(){};
    if (typeof (arguments[1]) == "function") {
        js = arguments[1];
    }
	var tmphtml = '<div style="width: 600px;" id="blockcheck" class="ui-dialog ui-widget ui-widget-content ui-corner-all">';
	tmphtml += '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">';
	tmphtml += '<span class="ui-dialog-title">Message</span>';
	tmphtml += '<a href="#" class="ui-dialog-titlebar-close ui-corner-all blockcheck_close"><span class="ui-icon ui-icon-closethick">close</span></a></div>';
	tmphtml += '<div id="dialog" class="ui-dialog-content ui-widget-content" style="height: auto; min-height: 63px; width: auto;">';
	tmphtml += '<p>' + msg + '</p>';
	tmphtml += '</div>';
	tmphtml += '<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><button type="button" class="ui-state-default ui-corner-all blockcheck_do">Ok</button><button type="button" class="ui-state-default ui-corner-all blockcheck_close">Cancel</button></div>';
	tmphtml += '</div>';
	$.blockUI({ message: tmphtml, css: {
		border: 'none',
		color: '#363636',
		padding: '0px',
		background: '#FEF1EC',
		'-webkit-border-radius': '5px',
		'-moz-border-radius': '5px',
		'text-align': 'left'
		}
	});
	$(".blockcheck_close").bind("click", function() { $.unblockUI(); });
	$(".blockcheck_do").bind("click", js);
	$(".blockcheck_close, .blockcheck_do").bind("mouseenter", function() { $(this).addClass("ui-state-hover"); });
	$(".blockcheck_close, .blockcheck_do").bind("mouseleave", function() { $(this).removeClass("ui-state-hover"); });
}
function settip(jqueryobj) {
	if (typeof(jqueryobj.attr("note")) != "undefined") {
		var position = jqueryobj.offset();
		var objLeft = position.left;
		var objTop = position.top;
		var objWidth = jqueryobj.width();
		var tiphtml = '<div class="STARTOOLTIP" style="margin-left:' + objLeft + 'px;width:' + objWidth + 'px;"><div class="TIPTEXT">' + jqueryobj.attr("note") + '</div></div>';
		$("body").append(tiphtml);
		var tipHeight = $(".STARTOOLTIP").height() + 4;
		$(".STARTOOLTIP").css("top", objTop - tipHeight);
	}
}
function checkform() {
	var checkint = 0;
	if ($(".upload_check").length > 0) {
		$(".upload_check").each(function(){
			checkint += parseInt($(this).val());						 
		});
	}
	if (checkint > 0) {
		blockblack("檔案上傳中，請稍後...");
		if (typeof(recheckform) != "undefined") {
			clearTimeout(recheckform);
		}
		recheckform = setTimeout('checkform()', 2000);
	} else {
		if (typeof(formsend.url) == "undefined") {
			formsend.url = "ajax/action.php";
		}
		if (typeof(formsend.mod) == "undefined") {
			formsend.mod = "POST";
		}
		formsend.mod = formsend.mod.toUpperCase();
		if (formsend.mod != "GET") {
			formsend.mod = "POST";
		}
		if (typeof (formsend.msg) == "undefined") {
			formsend.msg = "請稍後...";
		}
		if (formsend.debug != true) {
			formsend.debug = false;
		}
		var serial = "";
		var json_serial = new Object;
		if (typeof (formsend.basecol) == "object") {
			$.each(formsend.basecol, function(k, v) {
				serial += "&" + v + "=" + encodeURIComponent(trim($("#" + v).val()));
				eval("json_serial." + v + "=encodeURIComponent(trim($('#" + v + "').val()));");
			});
		}
		if (typeof (formsend.classcol) == "object") {
			$.each(formsend.classcol, function(k, v) {
				tmpv = "";
				$("." + v).each(function(){
					if (typeof ($(this).val()) != "undefined") {		
						if (tmpv.length > 0) { tmpv += ","; }
						if ($(this).val().length > 0) {
							tmpv += encodeURIComponent($(this).val());
						} else {
							tmpv += encodeURIComponent(" ");
						}
					}
					serial += "&" + v + "=" + tmpv;
					eval("json_serial." + v + "=tmpv;");
				});
			});
		}
		if (typeof (formsend.multicol) == "object") {
			$.each(formsend.multicol, function(k, v) {
				var tmpv = "";
				if ($("#" + v + " input").length > 0) {
					$("#" + v + " input:checked").each(function() {
						if (typeof ($(this).val()) != "undefined") {		
							if (tmpv.length > 0) { tmpv += ","; }
							tmpv += $(this).val();
						}
					});
				} else if ($("#" + v + " option:selected").length > 0) {
					$("#" + v + " option:selected").each(function() {
						if (typeof ($(this).val()) != "undefined") {		
							if (tmpv.length > 0) { tmpv += ","; }
							tmpv += $(this).val();
						}
					});
				}
				serial += "&" + v + "=" + encodeURIComponent(tmpv);
				eval("json_serial." + v + "=encodeURIComponent(tmpv);");
			});
		}
		if (typeof (formsend.ckeditorcol) == "object") {
			$.each(formsend.ckeditorcol, function(k, v) {
				var tmp_v = eval("CKEDITOR.instances." + v + ".getData()");
				serial += "&" + v + "=" + encodeURIComponent(tmp_v);
				eval("json_serial." + v + "=encodeURIComponent(tmp_v);");
			});
		}
		serial += "&" + new Date().getTime();
		json_serial.randomval = new Date().getTime();
		if (formsend.debug) {
			alert(serial);
		}
		blockblack(formsend.msg);
		if (formsend.mod == "POST") {
			$.post(formsend.url, json_serial, function() { }, "script");
		} else {
			$.getScript(formsend.url);
		}
	}
}
function AddFavorite() {
	var SetHome = "http://www.walkin.com.tw/";
	var webname = "Walk-IN";
	if ($.browser.msie) {
		try {
			if (parseInt(jQuery.browser.version) < 8) {
				window.external.addFavorite(SetHome, webname);
			} else {
				window.external.addToFavoritesBar(SetHome, webname, 'slice');
			}
		}catch (e) {
			blockerr("加入「我的最愛」失敗，請選取工具列中的「我的最愛」進行操作", 3000);
		}
	} else if ($.browser.mozilla) {
		try {
			window.sidebar.addPanel(webname, SetHome, "");	
		}catch (e) {
			blockerr("加入「書籤」失敗，請選取工具列中的「書籤」進行操作", 3000);
		}
	} else {
		blockerr("目前本功能暫不支援您的瀏覽器，請使用IE或是Firefox，或是自行進行操作", 3000);
	}
}
function SetHome() {
	var SetHome = "http://www.walkin.com.tw/";
	if ($.browser.msie) {
		try {
			document.body.style.behavior='url(#default#homepage)';  
			document.body.setHomePage(SetHome);  
		}catch (e) {
			blockerr("設為首頁失敗，請選取工具列中的「工具」->[網際網路選項]進行操作", 3000);
		}
	} else if ($.browser.mozilla) {
		try {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e) {
				blockerr("此操作無法被瀏覽器接受！<br>請在瀏覽器網址列輸入about:config並送出<br>然後找到[signed.applets.codebase_principal_support]選項，並將之設定為true");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',SetHome); 
		} 
		catch (e) {
			blockerr("設為首頁失敗，請選取工具列中的「工具」->[選項]進行操作", 3000);
		}
	} else {
		blockerr("目前本功能暫不支援您的瀏覽器，請使用IE或是Firefox，或是自行進行操作", 3000);
	}
}
function UITB() {
	$("#StarUITB").remove();
	if (arguments.length < 2) {
		return false;	
	} else {
		var TBtitle = arguments[0];
		var url = arguments[1];
		var TBwidth = 710;
		if (typeof (arguments[2]) != "undefined") {
			var TBwidth = parseInt(arguments[2]);
		}
		var TBheight = $(window).height() - 120;
		if (typeof (arguments[3]) != "undefined") {
			var TBheight = parseInt(arguments[3]);
		}
		var js = function(){};
		if (typeof (url) == "function") {
			js = url;
			url = "";
		}
		$(".ui-dialog").remove();
		StarUITB = $('<iframe id="StarUITB" class="StarUITB" name="StarUITB" src="' + url + '" ></iframe>').dialog({
			title: TBtitle,	
			autoOpen: true,
			zIndex: 500,
			width: TBwidth,
			height: TBheight,
			modal: true,
			resizable: true,
			autoResize: true,
			open: js
		}).width(TBwidth - 30).height(TBheight - 45);
		var position = $(".ui-dialog").position();
		$.scrollTo((position.top - 60) + "px");
	}
}
function CHECKUITB() {
	if (arguments.length < 2) {
		return false;	
	} else {
		var TBtext = arguments[0];
		var ObjectData;
		var LOADtext = arguments[2];
		if (typeof (LOADtext) == "undefined" || LOADtext == "") {
			LOADtext = "刪除中，請稍後...";
		}
		if (typeof(arguments[1]) != "function") {
			if (typeof(arguments[3]) == "boolean" && arguments[3] == true) {
				var url = "ajax/Typedel.php?tid=" + arguments[1];
			} else {
				var url = "ajax/del.php?id=" + arguments[1];
			}
			eval("ObjectData = function() { $(this).dialog('close');blockblack(LOADtext);$.getScript('" + url + "'); }");
		} else {
			ObjectData = arguments[1];
		}
		var TBwidth = 600;
		var TBheight = 170;
		$(".ui-dialog").remove();
		StarUITB = $('<div id="StarUITB" class="StarUITB">' + TBtext + '</div>').dialog({
			title: 'Message',	
			autoOpen: true,
			zIndex: 500,
			width: TBwidth,
			height: TBheight,
			modal: true,
			resizable: true,
			autoResize: true,
			buttons: {
				'OK': ObjectData,
				'Cancel': function() {
					$(this).dialog('close');
				}
			}
		}).width(TBwidth - 30).height(TBheight - 45);
		var position = $(".ui-dialog").position();
		$.scrollTo((position.top - 60) + "px");
	}
}
