function Reload(img) {
	var dt = new Date();
	img.src = img.src + "?" + dt;
}

function OW(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
	var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";

	sF += "scrollbars=" + (SC ? SC : "NO") + ",";

	if (TYPE == "full") {
		sF += " Width=1010,";
		sF += " Height=750,";
		sF += " Top=0,";
		sF += " Left=0,";
		window.open(URL, "_blank", sF, false);
		return;
	}

	if (TYPE == "modal") {
		sF = "resizable:no; status:no; scroll:yes;";
		if (iW != undefined && iH != undefined) {
			sF += " dialogWidth=" + iW + "px;";
			sF += " dialogHeight=" + iH + "px;";
		} else {
			sF += " dialogWidth=800px;";
			sF += " dialogHeight=570px;";
		}

		if (parent.length < 2) {
			sF += "dialogTop:" + (parseInt(parent.dialogTop) + 25) + "px;";
			sF += "dialogLeft:" + (parseInt(parent.dialogLeft) + 25) + "px;";
		}

		var alpha = '?';
		var _URL = URL;
		var unique = (new Date()).getTime();
		// 如果没有参数
		if (_URL.indexOf(alpha) == -1) {
			_URL += "?time=" + unique;
		} else {
			// 如果带有参数，含有‘?’
			_URL += "&time=" + unique;
		}
		// alert(_URL.indexOf(alpha));alert(_URL);
		return window.showModalDialog(_URL, window, sF);
	} else if (TYPE == "modeless") {

		sF = "resizable:no; status:no; scroll:yes;";
		sF += " dialogWidth:800px;";
		sF += " dialogHeight:570px;";
		if (parent.length < 2) {
			sF += "dialogTop:" + (parseInt(parent.dialogTop) + 25) + "px;";
			sF += "dialogLeft:" + (parseInt(parent.dialogLeft) + 25) + "px;";
		}

		var alpha = '?';
		var _URL = URL;
		var unique = (new Date()).getTime();
		// 如果没有参数
		if (_URL.indexOf(alpha) == -1) {
			_URL += "?time=" + unique;
		} else {
			// 如果带有参数，含有??
			_URL += "&time=" + unique;
		}
		// alert(_URL.indexOf(alpha));alert(_URL);
		return window.showModelessDialog(_URL, window, sF);
	} else {
		if (iW != undefined && iH != undefined) {
			sF += " Width=" + iW + ",";
			sF += " Height=" + iH + ",";
		} else {
			sF += " Width=800,";
			sF += " Height=570,";
		}
		if (window.opener == null || window.opener == undefined) {
			if (TOP == undefined) {
				sF += " Top=0px,";
			} else {
				sF += " Top=50px,";
			}

			sF += " Left=50px,";
		} else {
			sF += "Top=" + (parseInt(window.screenTop) + 20) + "px,";
			sF += "Left=" + (parseInt(window.screenLeft) + 30) + "px,";
		}
		sF += " scrollbars=yes,"
		window.open(URL, "_blank", sF, false);

	}
}

/**
 * Sets a Cookie with the given name and value.
 * 
 * name Name of the cookie value Value of the cookie [expires] Expiration date
 * of the cookie (default: end of current session) [path] Path where the cookie
 * is valid (default: path of calling document) [domain] Domain where the cookie
 * is valid (default: domain of calling document) [secure] Boolean value
 * indicating if the cookie transmission requires a secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value)
			+ ((expires) ? "; expires=" + expires.toGMTString() : "")
			+ ((path) ? "; path=" + path : "")
			+ ((domain) ? "; domain=" + domain : "")
			+ ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 * 
 * name Name of the desired cookie.
 * 
 * Returns a string containing value of specified cookie, or null if cookie does
 * not exist.
 */
function getCookie(name, defaultvalue) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) {
			if (defaultvalue) {
				return defaultvalue;
			} else {
				return null;
			}
		}
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	var result = unescape(dc.substring(begin + prefix.length, end));
	return result;
}

/**
 * Deletes the specified cookie.
 * 
 * name name of the cookie [path] path of the cookie (must be same as path used
 * to create cookie) [domain] domain of the cookie (must be same as domain used
 * to create cookie)
 */
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "")
				+ ((domain) ? "; domain=" + domain : "")
				+ "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/** *************************************** */
/* 功能：回车焦点跳转 */
/*                                        */
/* 参数：无 */
/* 返回：无 */
/** *************************************** */
function jsCtrlBSKey(e) {
	var e = e ? e : (window.event ? window.event : null);
	// var e=window.event;
	var target = e.srcElement ? e.srcElement : e.target;

	if (e.keyCode == 13 && target.type != "button" && target.type != "submit"
			&& target.type != "textarea") {
		e.keyCode = 9;
		return;
	}
}

// window.document.onkeydown=jsCtrlBSKey;
// -->| x

// 添加收藏夹
function addFavorite(sURL, sTitle) {
	try {
		window.external.addFavorite(sURL, sTitle);
	} catch (e) {
		try {
			window.sidebar.addPanel(sTitle, sURL, "");
		} catch (e) {
			alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}

// 设置首页
function setHomepage(url) {
	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("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1']
				.getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', url);
	}
}

function fillName() {
	var lastname = getCookie("lastname");
	var rpswC = getCookie("lllltid");
	if (lastname != null) {
		$("input[name='loginName']").attr("value", lastname.toString());
		$("input[name='password']").focus();
	} else {
		$("input[name='loginName']").focus();
	}
	return true;
}

function relate2RememberCheckBox() {
	switch (this.name) {
	case "rememberMe": {
		if (this.checked == false) {
			$("input[name='rememberPsw']").attr("checked", "");
		}
		break;
	}
	case "rememberPsw": {
		if (this.checked) {
			$("input[name='rememberMe']").attr("checked", "checked");
		}
		break;
	}
	}

}

try {
	$(document).ready(
			function() {
				$("input[name='rememberPsw']").bind("click",
						relate2RememberCheckBox);
				$("input[name='rememberMe']").bind("click",
						relate2RememberCheckBox);
				fillName();
				var form = $("#captcha").parents("form");
				var loginUrl = $(location).attr("href")
				var loginParam = loginUrl.substring(loginUrl.indexOf('?'), loginUrl.length);
				var action = "/liantuo/manage/signon.in";
				action = action + loginParam;
				form.attr("action", action)
				//sso shut?
		    //close sso
	//	    if ($(location).attr("href").match("\\?sso=1")
				//open sso
				if (!$(location).attr("href").match("\\?sso=0")
						//not activityTenpay.in
						&& !$(location).attr("href").match("activityTenpay.in")
									) {
					ssosi();
				}
			});
} catch (e) {
}

function ssosi() {
	
	//$("#captcha").parentsUntil("tbody").hide();
	$("#captchaBox").hide();
	$("input[name='rememberMe']").attr("checked", true);
	$("input[name='rememberMe']").click(function() {
		this.checked = true;
	});
	$("#captcha").val("dddd");
	var form = $("#captcha").parents("form");

	var local_action = "http://192.168.7.17/sso/authorize";
	var pro_action = "http://sso.51book.com/sso/authorize";
	var return_suffix = "/liantuo/sso_port";
	var host = $(location).attr('host');

	// returnUrl
	form.append("<input type=hidden name=returnUrl value=\"http://" + host
			+ return_suffix + "\" />");
	form.append("<input type=hidden name=name />");
	form.append("<input type=hidden name=psw />");
	form.append("<input type=hidden name=appId value=\"1004\" />");
	// action
	if (host.match(/192\.168\./) != null && host.match(/192\.168\.20\./)==null) {
		form.attr("action", local_action);
	} else {
		form.attr("action", pro_action);
	}

	form
			.submit(function() {
				$("PasswordError").hide();
				$("NameError").hide();
				// rememberMe
				$("input[name='rememberMe']").attr("checked",
						$("input[name='rememberPsw']").attr("checked"));
				$("input[name='rememberPsw']").attr("checked", false);
				// uname
				$("input[name='name']").attr("value",
						$("input[name='loginName']").val());
				$("input[name='psw']").attr("value",
						$("input[name='password']").val());
				setCookie("lastname", $("input[name='loginName']").val(),
						new Date("2099-01-01"));
				// alert(form.serialize());
				return true;
			});
}


	try {
		$.fn.log = function(msg) {
			console.log("%s: %o", msg, this);
			return this;
		};
	} catch (err) {
		
	}


