// JavaScript Document
String.prototype.trim = function()
{
   return this.replace(/(^\s+)|\s+$/g,"");
}
//关闭全部Windows
function CloseAll()
{
window.parent.location.reload();
//window.close();   
	//form_data.closeAll();
}

//从这里开始第一步
//targetUrl:页面转到路径 如果targetUrl为空代表不需要转到页面 只是判断是否登陆 
//info:是否需要ajaxWindows Bool类型 [True代表需要ajaxWindow] [False代表location.href]
//Width:宽度 Height:高度 Title:弹出页面标题
//closeInfo:判断是否需要叶面右上角的关闭按钮 0：没有 1：有
//Request:传入参数 例如：id=1&type=1
var cookie="0";
function NeedCookieExam(targetUrl,info,Title,Width,Height,closeInfo,Request)
{
	//首先读取Cookie 如果为0 证明Cookie为空
	var request = "random="+Math.random();
	new Ajax.Request(
		'/common/ajaxCookie.aspx',
		{
			method: 'post',
			postBody: request,
			onComplete: function(response) 
			{
				cookie=response.responseText;
				if (cookie=="0") 
				{
					ajax_login_Exam(false, targetUrl,'登陆界面',info,Title,Width,Height,closeInfo,Request);
				} 
				else 
				{
					if (info == false)//如果不需要AjaxLogin 直接转到该页面
					{
						location.href = targetUrl;
					}
					else
					{
						Windows.closeAll();
						ajaxOpenDialogExam(targetUrl,Title,Width,Height,closeInfo,Request) 
					}
				}
			}
		}
	);
}

//此方法是为了调用登陆页面
var loginDialog = null;
var redirectUrl = '';
var userinfo;
var userTitle;
var userwidth;
var userheight;
var RequestString;
var usercloseInfo;
function ajax_login_Exam(force, targetUrl, ajaxtitle,info,title,width,height,closeInfo,Request) 
{
	loginDialog = new Window(
		{
			className: "bluelighting",
			title: ajaxtitle || "该页面需要登录",
			parent: document.body,
			width: 850,
			height: 470,
			destroyOnClose: true,
			recenterAuto: true,
			closable: !force,
			maximizable: false
		}
	);
	loginDialog.getContent().update('<div class="working-img"></div>');
	loginDialog.showCenter(true);
	new Ajax.Request(
		'/common/loginExam.aspx',
		{
			method: 'post',
			onSuccess: function(transport) {
				loginDialog.getContent().innerHTML = transport.responseText;
				
				if (targetUrl) {
					redirectUrl = targetUrl;
					userinfo = info;
					userTitle = title;
					userwidth = width;
					userheight = height;
					usercloseInfo = closeInfo;
					RequestString = Request;
				} else {
					windows.location.reload();
				}
			}
		}
	);
}

//此方法调用转到页面的按钮事件[登陆按钮 后台进行代码处理判断]
function doLoginExam()
{
	new Ajax.Request('/common/ajaxdo.aspx',
	{
		method: 'post',
		parameters: Form.serialize('login-form'),
		//parameters: request,
		onSuccess: function(request)
		{
			var data = request.responseText;
			if(data != "-1")// true 代表通过
			{
				//Windows.closeAll();
				if (redirectUrl!="")
				{
					if (userinfo==true)
					{
							ajaxOpenDialogExam(redirectUrl,userTitle,userwidth,userheight,usercloseInfo,RequestString);
						}
					else
					{	
						location.href = redirectUrl;
						location.reload();
						}
				}
				else
				{
					Windows.closeAll();
				}
			} 
			else 
			{
				displayError('login-error', '无法登录，请检查您的输入');
			}
		}
	}
	);
}

//根据已经弹出的AJAX对话框（登陆界面） 直接转到Url[目前专为TutorOrder编写]
function ajaxOpenDialogExam(url,title,width,height,closeInfo,Request) 
{

	if (Request!='')
	{	url = url + "?" + Request; }
	
	var c = true;//closable
	var m = false;//maximizable
	if (closeInfo=="0")//判断如果不需要关闭按钮的话
	{

		c = false;m=false;	
	}
	var dialog = new Window(
		{
			url: url, 
			className: "bluelighting",
			title: title,
			parent: document.body,
			width:width,
			height:height,
			destroyOnClose: true,
			recenterAuto: true,
			closable: c,
			minimizable: false,
			maximizable: false,
			//top:100, left:100,  width:300, height:200, zIndex:150, opacity:1, 
			resizable: true
		}
	);
	dialog.setDestroyOnClose();
    dialog.showCenter(true);

}