
//////////////// BROWSER DETECTION //////////////
var IE = (document.all) ? 1 : 0;
var NS = (document.layers) ? 1 : 0;

//////////////// WINDOW STATUS //////////////
window.defaultStatus = "";
function setWinStatus( msg )
{
	window.status = msg;
}

/////////////// JS ERROR CATCH ///////////
var debugJS = false;
function stopJSError() {
	if(!debugJS){
  		return true;
	}
}
window.onerror = stopJSError;


//////////////// ALERT ////////////////
function fsAlert( msg ) {
	if( msg != null && trim(msg) != "" ) {
		alert( msg );
	}
}

//////////////// WINDOW POPUP ////////////////
function popUp( loc, w, h, menubar, locationbar ) {
	if( w == null ) { w = 500; }
	if( h == null ) { h = 350; }
	if( menubar == null || menubar == false ) {
		menubar = "";
	} else {
		menubar = "menubar,";
	}
	if( locationbar == null || locationbar == false ) { 
		locationbar = "location=0,"; 
	} else {
		locationbar = "location=1,";
	}

	if( NS ) { w += 50; }
	// Need the var or else IE4 blows up not recognizing editorWin
	var editorWin = window.open(loc,'editorWin', menubar + locationbar + 'resizable,scrollbars,width=' + w + ',height=' + h);
	editorWin.focus();
}

function popUpLarge( loc, menubar ) {
	if( menubar == null ) { 
		menubar = false;
	}
	popUp( loc, 700, 500, menubar );
}


function closeMe() {
	//self.close();
	parent.close();
}


//////////////// FORM AND RELOAD ////////////////
function formSubmit() {
	parent.frames[0].document.forms[0].submit();
}

function openerReload() {
	if( parent.opener.name != null ) {
		parent.opener.location.reload();
	}
}

function delayReload() {
	self.setTimeout("selfReload()", 2000);
}
function selfReload(){
	self.location.reload();
}


//////////////// STRINGS ////////////////
function fsTrim( str ) {
	// Immediately return if no trimming is needed
	if( (str.charAt(0) != ' ') && (str.charAt(str.length-1) != ' ') ) { return str; }
	// Trim leading spaces
	while( str.charAt(0)  == ' ' ) {
		str = '' + str.substring(1,str.length);
	}
	// Trim trailing spaces
	while( str.charAt(str.length-1)  == ' ' ) {
		str = '' + str.substring(0,str.length-1);
	}

	return str;
}

function strReplace( entry, bad, good ) {
	temp = "" + entry; // temporary holder
	while( temp.indexOf(bad) > -1 ) {
		pos= temp.indexOf( bad );
		temp = "" + ( temp.substring(0, pos) + good + 
			temp.substring( (pos + bad.length), temp.length) );
	}
	return temp;
}


function ShowDialog(url, width, height, optValidate) {
	if (optValidate) {
		if (!validateMode()) return;
	}
	//eWebEditor.focus();
	var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
	//eWebEditor.focus();
}

function fPopUpNewsCategoryDlg(nameObj,IdObj)
{
	//alert("nameObj:"+nameObj);
	//alert("<%=request.getContextPath()%>/admin/newsCategoryList.jsp");
	showx = document.body.clientWidth/2-180;
	showy = document.body.clientHeight/2-280;
	if ((document.body.clientHeight/2-280)<0){showy = 180}
	//showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	//showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("categoryList.do", "", "dialogWidth:500px; dialogHeight:330px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		//alert(IdObj.value);
		nameObj.value = retval[1];
		IdObj.value = retval[0];
		//alert(IdObj.value);
	}else{
		//alert("canceled");
	}
}

function getEvent(){
	if(document.all) return window.event;//如果是ie
	func=getEvent.caller;
	while(func!=null){
	    var arg0=func.arguments[0];
	    if(arg0){if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){return arg0;}            }
	    func=func.caller;
	}
	return null;
}

function fPopUpNewsCategoryDlg1(nameObj,IdObj)
{
	var event=getEvent();//兼容火狐浏览器
	//alert("nameObj:"+nameObj);
	//alert("<%=request.getContextPath()%>/admin/newsCategoryList.jsp");
	showx = event.screenX - event.offsetX - 4 - 210 ; // + deltaX;
	showy = event.screenY - event.offsetY + 18; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	retval = window.showModalDialog("categoryList.do?showall=true", "", "dialogWidth:500px; dialogHeight:330px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "  );
	if( retval != null ){
		//alert(IdObj.value);
		nameObj.value = retval[1];
		IdObj.value = retval[0];
		//alert(IdObj.value);
	}else{
		//alert("canceled");
	}
}
