var CONTROL = {};	//控制类
//用户必须登录
CONTROL.u_must_login = function(str) {
	alert(str);
	return window.location = '?controller=Login&action=LoginForm';
}

$(function() {
	//双击层关闭
	$('#PBW_show_box').dblclick(function() {
		$(this).hide();
		$(this).prev().remove();
	});
})

//获取滚动条y座标
function getScrollTop() {
	var scrollPos;
 	if (typeof window.pageYOffset != 'undefined') {
		scrollPos = window.pageYOffset; 
	} 
	else if (typeof document.compatMode != 'undefined' && 
		  document.compatMode != 'BackCompat') { 
		scrollPos = document.documentElement.scrollTop; 
	} 
	else if (typeof document.body != 'undefined') { 
		scrollPos = document.body.scrollTop; 
	}
	return scrollPos;	
}

//设置容器定位
function setBoxPos() {
	var scrollPos;
 	if (typeof window.pageYOffset != 'undefined') { 
		scrollPos = window.pageYOffset; 
	} 
	else if (typeof document.compatMode != 'undefined' && 
		  document.compatMode != 'BackCompat') { 
		scrollPos = document.documentElement.scrollTop; 
	} 
	else if (typeof document.body != 'undefined') { 
		scrollPos = document.body.scrollTop; 
	}
	$('#PBW_show_box').css({left:(screen.width-$('#PBW_show_box').width()) / 2, 'top':scrollPos + 100 + 'px'});
//	alert(scrollPos);
}

//隐藏容器
function hideBox() {
	$('#PBW_show_box').hide();
	$('.shadow').remove();
}

//更改某控件的值
function CtlV(c, v) {
	$(c).val($.trim(v));
}

//设置信息提示框的位置(全屏遮档)
function setWposition() {
	var height = document.body.scrollHeight;
	var pad = height/2 - 50;
	$('#PBW_warning').css({top:0,width:screen.width-18, height:height, 'padding-top': pad});
}

//选中下拉菜单某项
function OptV(c, v) {
	$(c).find('option').each(
		function() {
			if($(this).text().toLowerCase().indexOf(v.toLowerCase())>=0) this.selected = true;
		}
	);
//	alert($(c)[0].selectedIndex);
//	alert($(c).text().contains(v));
}

//变成textbox
function toTextbox(_this) {
}

//禁用#PBW_inner_box里面，除了class为className的控件
function disableExcept(className) {
	$('#PBW_inner_box').find("input[@class!='" +className+ "'], select").each(function() {
		this.disabled = true;
	})
}

//toggle某元素
function toggle(el) {
	$(el).toggle();
	return false;
}

//AJAX提示框1
function loading(str) {
	if(str) {
		$('#PBW-LOADING').css({'top':getScrollTop()+screen.height / 2-200, 'left':screen.width / 2 - $('#PBW-LOADING').width()/2}).show();
	}
	else {
		$('#PBW-LOADING').hide();
	}
	$('#PBW-LOADING').bgiframe();
}

//AJAX提示框2
function setW(str, container) {
	if(!container) container = '#PBW_warning';
	setWposition();
	if(str) {
		$(container).html('<span class="warning_text">' +str+ '</span>').show();
	}
	else {
		$(container).hide();
	}
	$('.PBW_window').dblclick(function() {$(this).remove();});
}

//AJAX调用
/*
类型		参数			解释		例子
------------------------------------------
object 	options		键值对	{id:1, type:0}
string	container	容器		#PBW_show_box
string  action		动作		?controller=A&action=B
string 	U			地址		http://jobpo.com
*/
function loadByAction(options, container, action, U, txt, func, hidden) {
	var ref = '';
	if(U != undefined) {
		ref = U;
	}
	else {
		ref = URL;
	}
	
	if (txt) setW(txt);

	$.post(ref + action, options, function(data) {
		if(!func) {
			if(container) {
				if(!hidden) {
					$(container).html(data).show();
				}
				else {
					$(container).html(data);
				}
				shadow(container);
			}
		}
		else {
			func(data, this);
		}

		setW();
	});	
}

//背影容器exp：shadow('#PBW_show_box');
function shadow(container) {
	if(container == '#PBW_show_box' || container == '#PBW_inner_box') {
		var width = screen.width - 15;
		var height = document.body.scrollHeight;
		$(container).before('<div class="shadow hand" onclick="$(this).remove();$(\''+container+'\').hide();" style="width:'+width+'px;height:'+height+'px;"></div>');
		$(container + ', #PBW_warning').bgiframe();
	}
}

//关闭窗口exp: cancelShowBox('#PBW_show_box', false);
function cancelShowBox(container, remove) {
	if(remove) {
		$(container).remove();
		$(container).prev().remove();
	}
	else {
		if(container == undefined) {
//			alert(container);
			$('#PBW_inner_box').hide();
			$('#PBW_inner_box').prev().remove();		
		}
		else {
			$(container).hide();
			$(container).prev().remove();
		}
	}
}
