
var isMozilla = navigator.userAgent.indexOf('Mozilla') != -1 && parseInt(navigator.appVersion.substring(0,1)) >= 5;
var isIE = navigator.userAgent.indexOf('MSIE') != -1;

systemDefine = new Object();
modalWindow.stack = [] 
modalWindow.current = false 

function modalWindow(width,height){
    var id = parseInt((Math.random()*100));    
    id = this.toString()+id;
    modalWindow.stack[id] = this;
    var win 
    var args 
	var LeftPosition=(screen.width-width)/2
	var TopPosition=(screen.height-height)/2 
	this.setPosition = function(left,top){
		LeftPosition = left

		TopPosition = top;
	}
    this._onclose = function(value){
        //window.onfocus = function(){ 
            
       // }
        modalWindow.current = false 
        this.onclose(value) 
    } 
    this.onclose = function(value){
        
    } 
    this.getDialogArguments = function(){
        return args
    } 
    this.currenfocu = function (){
        window.onfocus = function(){
               window.focus() 
        }
    }
    this.showModalDialog = function(url,_args,override){ 
        args = _args 
        if(!window.showModalDialog || override) { 
            modalWindow.current = win = window.open(url,'ModalWindow_'+id,'top='+TopPosition+',left='+LeftPosition+',width='+(width || 300)+',height='+ (height||180) +',modal,dialog,scrollbars,');
            window.onfocus = function(){
                modalWindow.current.focus() 
            }
        }else{ 
            var rv = window.showModalDialog( url , args , "dialogWidth:"+(width||300)+"px; dialogHeight: "+(height||180)+"px;dialogLeft:"+LeftPosition+"px;dialogTop:"+TopPosition+"px;status: no; help: no;unadorned:yes;resizable:yes;")  
            this.onclose( rv ) 
        } 
    }
}

// ============================FORM CORTROL============================

/**
 * Crawl the parents of an element up to finding a form.
 */
function forms_getForm(element) {
    while(element != null && element.tagName != "FORM") {
        element = element.parentNode;
    }
    return element;
}


//????????????
var selected = false;

//TODO when the mouse over the ListTable.TR

function hilite(theTR){
    if(theTR.className != "selected"){
        currentClassName = theTR.className;
        theTR.className = "mouseover";
    }
}
//TODO when the mouse out the ListTable.TR
function restore(theTR){
    if(theTR.className != "selected")
        theTR.className = currentClassName;
}

//TODO when the mouse down the ListTable.TR
function mousedownRow(theTR){
    if(selected){
        selectElement.className = selectClassName;
    }
    if(theTR.className != "selected"){
        selectID = theTR.rowIndex;
        //alert(theTR.cells[0].childNodes[0].checked=true);
        selectElement = theTR;
    }
}

//TODO when the mouse click the ListTable.TR
function clickRow(theTR){
    if(theTR.className != "selected"){
        selectClassName = currentClassName;
        theTR.className = "selected";
        selected = true;
        doSetButton();
    }
}
//TODO when the dbclick the ListTable.TR
function DblClickRow(theTR){
    clickRow(theTR);
    try{
        parent.frames[0].doDetail(theTR);    
    } catch (e) {
    	try{
	        parent.frames[0].doDetail();    
	    } catch (e) {
	    	
	    }
    }
}
//TODO setButton state plz rewrite 
function doSetButton(){
    
}

//TODO select all 
function selectAll(theBox){
    var state = theBox.checked;
    var element = theBox.form.elements;
    for(i=0;i<element.length;i++){
        if(element[i].type == "checkbox")
        element[i].checked = state;
    }   
}
//TODO STOR
function sortList(obj,key,sort,method){    
    var obj = forms_getForm(obj);
    if(sort.trim()=="default"){
        obj.sort.value="asc";
    }else if(sort.trim()=="asc"){
        obj.sort.value="desc";
    }else{
        obj.sort.value="asc";
    }
    obj.key.value=key;
    //obj.method.value = method;
    obj.submit();
}
//TODO STOR
function sortListStruts(obj,key,sort,method){    
    var obj = forms_getForm(obj);
    if(sort.trim()=="default"){
        obj._sort.value="asc";
    }else if(sort.trim()=="asc"){
        obj._sort.value="desc";
    }else{
        obj._sort.value="asc";
    }
    obj._key.value=key;
    //obj.method.value = method;
    obj.submit();
}
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function validateRowSetByForm(row,form){
    form.reset();
    for(var i=3;i<row.cells.length;i++){
        //alert("form."+row.cells(i).id+".value='"+row.cells(i).innerText+"'");
		try{
			eval("form."+row.cells(i).id+".value='"+row.cells(i).innerText+"'");
		}catch(e){}
    }
   return eval("validate"+form.name.substring(1,form.name.length)+"(form)");
}