/**
 * Utils.
 *  
 * @author Jim Huang
 */
 
 // open url in a new customized window.
 function popMe(action,width,height)
 {
 	var url = "";
 	url = action;
 	var window_top = (screen.availHeight - height)/2;
	var window_left = (screen.availWidth - width)/2;
 	window.open (url, "newwindow", ("top=" +window_top+ ",left = " +window_left+ +",height=" + height + ", width=" + width + ", toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no"))
 }
 
 function popMe(action)
 {
 	popMe(action, 640, 480);
 }
 
 /**
 *  
 * @author DuanMeiLan
 */
 
 // check input words invalidation and delete the invalid words.
 
function checkForm(str) {
return RemoveBad(str); 
}
function RemoveBad(strTemp) {
var html = strTemp;
html = html.replace(/\<script/gi,"&lt;script");
html = html.replace(/\<\/script/gi,"&lt;\/script");
html = html.replace(/\<iframe/gi,"&lt;iframe");
html = html.replace(/\<\/iframe/gi,"&lt;\/iframe");
html = html.replace(/\<frameset/gi,"&lt;frameset");
html = html.replace(/\<\/frameset/gi,"&lt;\/frameset");
html = html.replace(/\<input/gi,"&lt;input");
html = html.replace(/\<\/input/gi,"&lt;\/input");
html = html.replace(/\<textarea/gi,"&lt;textarea");
html = html.replace(/\<\/textarea/gi,"&lt;\/textarea");
html = html.replace(/\<select/gi,"&lt;select");
html = html.replace(/\<\/select/gi,"&lt;\/select");
html = html.replace(/\<option/gi,"&lt;option");
html = html.replace(/\<\/option/gi,"&lt;\/option");
html = html.replace(/\<html/gi,"&lt;html");
html = html.replace(/\<\/html/gi,"&lt;\/html");
html = html.replace(/\<htm/gi,"&lt;htm");
html = html.replace(/\<\/htm/gi,"&lt;\/htm");
html = html.replace(/\<body/gi,"&lt;body");
html = html.replace(/\<\/body/gi,"&lt;\/body");
html = html.replace(/\<head/gi,"&lt;head");
html = html.replace(/\<\/head/gi,"&lt;\/head");
html = html.replace(/\<meta/gi,"&lt;meta");
html = html.replace(/\<\/meta/gi,"&lt;\/meta");
html = html.replace(/\<title/gi,"&lt;title");
html = html.replace(/\<\/title/gi,"&lt;\/title");
html = html.replace(/\<link/gi,"&lt;link");
html = html.replace(/\<\/link/gi,"&lt;\/link");
html = html.replace(/\<form/gi,"&lt;form");
html = html.replace(/\<\/form/gi,"&lt;\/form");
return html;

}

function RemoveBad_old(strTemp) {
var html = strTemp;
html = html.replace(/\<p>/gi,"[$p]");
html = html.replace(/\<\/p>/gi,"[$\/p]");
html = html.replace(/\<br>/gi,"[$br]");
html = html.replace(/\<[^>]*>/g,"");
html = html.replace(/\[\$p\]/gi,"<p>");
html = html.replace(/\[\$\/p\]/gi,"<\/p>");
html = html.replace(/\[\$br\]/gi,"<br>");
return html;

}

function _open(url) {
	var window_width = 640;
	var window_height = 480;
	var window_top = (screen.availHeight - window_height) /2;
	var window_left = (screen.availWidth -window_width)/2;
	var window_dimensions = 'top='+window_top+',left='+window_left+',height='+window_height+',width='+window_width+',toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=yes';
	var loginWin = window.open(url, 'RMS', window_dimensions);
	if (loginWin)
		loginWin.focus();
}
function _formReset(formName) {
	var fields = document.getElementById(formName).elements;
	if (!fields) return; 
	for (var i =0; i<fields.length; i++) {
		if (fields[i].type != 'submit' && fields[i].type != 'button' && fields[i].type != 'reset')
			fields[i].value = '';
	}

}

/**********************************************************************
*JavaScript Code: zhuyouhong
***********************************************************************/

function setSelectedItem(selectBox_name,selected_value) {   
	//??? ???????
    box = document.getElementsByName(selectBox_name)[0];

    n=box.options.length;
    for(i=0;i<n;i++)
    {
        if(box.options[i].value==selected_value)
        {
            box.options[i].selected=true;
        }
    }
}

function findSelections(boxname) { 
        //checkbox radio ???????? 
        var returnAry = new Array();                        
        box = document.getElementsByName(boxname);
        
        for (k=0; k < box.length; k++) {
            if(box[k].checked) {
                returnAry.push(box[k].value);
            }
        }
                
        return returnAry;                
}
function findSelection(boxname) {     
	var returnAry = findSelections(boxname);
	if(returnAry==null || returnAry.length<1) {
		return null;
	}
	return returnAry[0];
}

function showRefrenceWindow(url,features,contextPath)
{
	    //????????????URL
        window_url =contextPath+ "/jsp/admin/common/framesetInModeDialog.jsp";              
         
        //????????????????              
        window_arguments = new Array();
        window_arguments.push(url);

		//??????????????
        if(features== null) {
	        features="status:0;dialogHeight:600px;dialogWidth:800px;dialogTop: "+event.screenY+"px; dialogLeft: "+event.screenX+"px";       
		}
		
        return window.showModalDialog(window_url,window_arguments,features);	
	
}

function Jtrim(str)  //?????
{
	var i = 0;
	var len = str.length;
	if ( str == "" ) return( str );
	j = len -1;
	flagbegin = true;
	flagend = true;
	while ( flagbegin == true && i< len)
	{
		if ( str.charAt(i) == " " )
		{
			i=i+1;
			flagbegin=true;
		}
		else
		{
			flagbegin=false;
		}
	}

	while  (flagend== true && j>=0)
	{
		if (str.charAt(j)==" ")
		{
			j=j-1;
			flagend=true;
		}
		else
		{
			flagend=false;
		}
	}

	if ( i > j ) return ("")

	trimstr = str.substring(i,j+1);
	return trimstr;
}
