<?php

if(! defined('OT_ROOT')) {
	exit('Access Denied');
}

class JS{
	public static function Diy($str){
		echo('<script language="javascript" type="text/javascript">'. $str .'</script>');
	}

	public static function DiyEnd($str){
		die('<script language="javascript" type="text/javascript">'. $str .'</script>');
	}


	public static function Href($str){
		echo('
		<script language="javascript" type="text/javascript">
		document.location.href="'. $str .'";
		</script>
		');
	}

	public static function HrefEnd($str){
		die('
		<script language="javascript" type="text/javascript">
		document.location.href="'. $str .'";
		</script>
		');
	}

	public static function HrefTimeout($str,$sec){
		echo('
		<script language="javascript" type="text/javascript">
		setTimeout("document.location.href=\''. $str .'\';",'. ($sec*1000) .');
		</script>
		');
	}

	public static function HrefTimeoutEnd($str,$sec){
		die('
		<script language="javascript" type="text/javascript">
		setTimeout("document.location.href=\''. $str .'\';",'. ($sec*1000) .');
		</script>
		');
	}


	public static function Write($str, $addiStr=''){
		echo('
		<script language="javascript" type="text/javascript">
		document.write("'. $str .'");'. $addiStr .'
		</script>
		');
	}

	public static function WriteEnd($str, $addiStr=''){
		die('
		<script language="javascript" type="text/javascript">
		document.write("'. $str .'");'. $addiStr .'
		</script>
		');
	}


	public static function Alert($str, $addiStr=''){
		echo('
		<script language="javascript" type="text/javascript">
		alert("'. $str .'");'. $addiStr .'
		</script>
		');
	}

	public static function AlertEnd($str, $addiStr=''){
		die('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");'. $addiStr .'
		</script>
		');
	}

	public static function AlertClose($str){
		echo('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");window.close();
		</script>
		');
	}

	public static function AlertCloseEnd($str){
		die('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");window.close();
		</script>
		');
	}


	public static function AlertBack($str){
		echo('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");history.back();
		</script>
		');
	}

	public static function AlertBackEnd($str){
		die('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");history.back();
		</script>
		');
	}

	public static function AlertBackHrefEnd($str,$url){
		die('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");
		if (document.referrer) {
			var prevPage = window.location.href;
			history.back();
			setTimeout(function(){
					if (window.location.href == prevPage) {
						window.location.href = "'. $url .'";
					}
				}, 800);
		}else{
			document.location.href="'. $url .'";
		}
		</script>
		');
	}

	public static function AlertBackCloseEnd($str){
		die('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");
		if (document.referrer) {
			var prevPage = window.location.href;
			history.back();
			setTimeout(function(){
					if (window.location.href == prevPage) {
						window.close();
					}
				}, 800);
		}else{
			window.close();
		}
		</script>
		');
	}


	public static function AlertHref($str,$url){
		echo('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");document.location.href="'. $url .'";
		</script>
		');
	}

	public static function AlertHrefEnd($str,$url){
		die('
		<script language="javascript" type="text/javascript">
		alert("'. self::AlertFilter($str) .'");document.location.href="'. $url .'";
		</script>
		');
	}

	public static function AlertHrefSelEnd($str, $url){
		die('
		<script language="javascript" type="text/javascript">
		if( confirm("'. self::AlertFilter($str) .'") ){
			document.location.href="'. $url .'";
		}
		</script>
		');
	}


	public static function ModeDeal($mode,$jud,$value='',$href=''){
		if ($mode=='jud'){
			return $jud;

		}elseif ($mode=='show'){
			die($value);

		}elseif ($mode=='get'){
			return $value;

		}elseif ($mode=='alert'){
			self::AlertEnd($value);

		}elseif ($mode=='alertBack'){
			self::AlertBackEnd($value);

		}elseif ($mode=='alertClose'){
			self::AlertCloseEnd($value);

		}elseif ($mode=='alertHref'){
			self::AlertHrefEnd($value,$href);

		}elseif ($mode=='alertStr'){
			die('alert("'. $value .'");');

		}elseif ($mode=='alertBackStr'){
			die('alert("'. $value .'");history.back();');

		}elseif ($mode=='alertHrefStr'){
			die('alert("'. $value .'");document.location.href="'. $href .'";');

		}
	}

	public static function AlertFilter($str){
		return str_replace(array("\n",'"'), array('\n','“'), $str);
	}

	public static function ParentHiddenEnd($id){
		die('
		<script language="javascript" type="text/javascript">
		parent.$id("'. $id .'").style.display="none";
		</script>
		');
	}

	public static function HiddenEnd($id){
		die('
		<script language="javascript" type="text/javascript">
		$id("'. $id .'").style.display="none";
		</script>
		');
	}

	public static function AlertUsersEnd($str='请先登录，该功能需要登录才能使用。', $webPathPart=''){
		die('
		<script language="javascript" type="text/javascript">
		if( confirm("'. self::AlertFilter($str) .'\n点【确定】跳转会员登录页。") ){
			document.location.href="'. Users::SysUrl('login','&force=1&isBack=1',$webPathPart) .'&backURL="+ encodeURIComponent(document.location.href);
		}
		</script>
		');
	}

}

?>