function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

String.prototype.Trim = function(){ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

//jQuery 弹出层
var dialogFirst=true;
function dialog(title,content,width,height,cssName){

	if(dialogFirst==true){
		var temp_float=new String;
		temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
		temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
		temp_float+="<div class=\"title\"><h4></h4><span>关闭</span></div>";
		temp_float+="<div class=\"content\"></div>";
		temp_float+="</div>";
		$("body").append(temp_float);
		dialogFirst=false;
	}
	
	$("#floatBox .title span").click(function(){
		$("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
		$("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();}); 
	});
	
	$("#floatBox .title h4").html(title);
	contentType=content.substring(0,content.indexOf(":"));
	content=content.substring(content.indexOf(":")+1,content.length);
	switch(contentType){
		case "url":
			var content_array=content.split("?");
			$("#floatBox .content").ajaxStart(function(){
				$(this).html("loading...");
			});		
			$.ajax({
				type:content_array[0],
				url:content_array[1],
				data:content_array[2],
				error:function(){
					$("#floatBox .content").html("error...");
				},
				success:function(html){
					$("#floatBox .content").html(html);
				}
			});
		break;
		case "text":
			$("#floatBox .content").html(content);
		break;
		case "id":
			$("#floatBox .content").html($("#"+content+"").html());
		break;
		case "iframe":
			$("#floatBox .content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
	}
	
	$("#floatBoxBg").show();
	$("#floatBoxBg").animate({opacity:"0.5"},"normal");
	$("#floatBox").attr("class","floatBox "+cssName);
	$("#floatBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
	$("#floatBox").animate({top:($(document).scrollTop()+50)+"px"},"normal"); 
}


//分页回车提交
function pagekeydown(){
    if(document.addEventListener){//如果是Firefox
         document.addEventListener("keypress",fireFoxHandler, true);
    }else{  //如果是 IE
          document.attachEvent("onkeypress",ieHandler);
    }
}

function fireFoxHandler(evt){
    if(evt.keyCode == 13){   //  Enter 的keycode 是 13
        document.getElementById("adminForm").submit();//如果是回车键，使用代码触发提交按钮的点击事件。
    }
}

function ieHandler(evt){
	if(evt.keyCode==13){
		if(event.keyCode == 13)// 侦测到按下键盘的按钮，13代表回车键  
		{   
			event.returnValue=false; // 是当前事件的返回值为false  
			event.cancel = true;  // 停止当前时间继续运行  
			document.getElementById("adminForm").submit();//如果是回车键，使用代码触发提交按钮的点击事件。  
			return false;  
		}
	}
}

