var _selectBarId = '';

function popupHelperAction(fieldNames,mappingKeys,formName,action,postEvent,params,paramKeys,paramFields){
   
   p_link = action+"?ParentForm="+formName+"&ParentField="+fieldNames+"&MappingField="+mappingKeys;
   if(postEvent != "" && postEvent != "null"){
       p_link = p_link + "&PostAction="+postEvent; 
   }   
        
   if(params != "" && params != "null"){
       p_link = p_link + "&" + params;
   }
   
   if(paramKeys != "" && paramKeys != "null"){
        var _f = document.getElementById(formName);
        var _paramFieldAry = paramFields.split(',');
        var _paramKeyAry = paramKeys.split(',');
        var _paramStr = "";
        for(i=0;i<_paramKeyAry.length;i++){
           _fieldValue = eval('_f.'+_paramFieldAry[i]+'.value');      
           _paramStr = _paramStr + "&" +_paramKeyAry[i]+ "=" + encodeURIComponent(_fieldValue);
        }         
        p_link = p_link + _paramStr;
   }      
   
   popsinglewin(p_link);
         
}


function showSelectBar(sid){
   if(_selectBarId != ''){
       blurSelectBar(_selectBarId);
   }
   _selectBarId = sid;
   var element = document.getElementById(sid);
   element.style.display = "";
}

function blurSelectBar(sid){
   _selectBarId = '';	
   var element = document.getElementById(sid);
   element.style.display = "none";   
}

function clearSelectOption(form,name){
   var _field = eval('form.'+name);
   _field.length = 0;
}

function addSelectedOption(form,name,key){	
   var _field = eval('form.'+name);
   _field.options[_field.length]= new Option(key,key);
   _field.options[_field.length-1].selected = true;
   refreshSelectedView(form,name);
}

function refreshSelectedView(form,name){     
	var element =  eval('form.'+name);   
	var elementView = document.getElementById(name+'View');	
	if(elementView != null){
		elementView.innerHTML = "";
		for(i=0;i<element.options.length;i++){
			if(element.options[i].selected){
				if(elementView.innerHTML != ""){
					elementView.innerHTML = elementView.innerHTML+"<br>";
				}
				elementView.innerHTML = elementView.innerHTML + element.options[i].innerHTML;
			}
		}		
	}
}

function displaySubmitView()
{  
    var element = document.createElement('DIV');
    element.id = 'submit_view';
	element.className = 'submit_view';
	document.body.insertBefore(element,null);
}

function hiddenSubmitView()
{  
    document.body.removeChild($('submit_view')); 
}


function showMessage(sid)
{
    var element = document.getElementById(sid);
	alert(element.innerHTML);
}
      
function onMouseOver(element)
{
    element.className = 'table_row_selected';
}

function onMouseOut(element,clazz)
{ 
    element.className = clazz;
}


function previousListBody(sid){
	var t = document.getElementById(sid+"_BAR");
	currentBody = t.getAttribute('currentBody');
	totalBody = t.getAttribute('totalBody');
	if(currentBody > 1){
		document.getElementById(sid+"_"+currentBody).style.display="none";
		t.setAttribute('currentBody',(parseInt(currentBody)-1));
		document.getElementById(sid+"_"+(parseInt(currentBody)-1)).style.display="";	
		document.getElementById(sid+"_BAR_TEXT").innerHTML="&nbsp;("+t.getAttribute('currentBody')+"/"+totalBody+")&nbsp;";
	}else{
	}
}

function nextListBody(sid){
	var t = document.getElementById(sid+"_BAR");
	currentBody = t.getAttribute('currentBody');
	totalBody = t.getAttribute('totalBody');
	if(totalBody > currentBody){
		document.getElementById(sid+"_"+currentBody).style.display="none";
		t.currentBody = (parseInt(currentBody)+1);
		document.getElementById(sid+"_"+(parseInt(currentBody)+1)).style.display="";	
		document.getElementById(sid+"_BAR_TEXT").innerHTML="&nbsp;("+t.getAttribute('currentBody')+"/"+totalBody+")&nbsp;";
	}else{
	}
}
         
function hideElement(sid,img){
    if(document.all){
		eval('var t = '+sid+';');
		if(typeof t.length == 'number'){		
			for(i=0; i< t.length; i++){
				if(t[i].style.display == "none"){
					t[i].style.display = "";
					img.src = "/webresource/taglib/images/show.gif";
					img.setAttribute('title','Hide');
				}else{
					t[i].style.display = "none";
					img.src = "/webresource/taglib/images/hide.gif";
					img.setAttribute('title','Show');
				}
			}
		}else{
			if(t.style.display == "none"){
				t.style.display = "";
				img.src = "/webresource/taglib/images/show.gif";
				img.setAttribute('title','Hide');
			}else{
				t.style.display = "none";
				img.src = "/webresource/taglib/images/hide.gif";
				img.setAttribute('title','Show');
			}
		}
	}else{
		var t = document.getElementById(sid);
		if(t.style.display == "none"){
			t.style.display = "";
			img.src = "/webresource/taglib/images/show.gif";
			img.setAttribute('title','Hide');
		}else{
			t.style.display = "none";
			img.src = "/webresource/taglib/images/hide.gif";
			img.setAttribute('title','Show');
		}
	}
}



function popupdialog(p_link){        
    window.showModalDialog(p_link,'Dialog',"edge:Sunken;center:No;resizable:YES;dialogWidth:840px;dialogHeight:580px;dialogTop:150px;dialogLeft:150px");
}

function popsinglewin(p_link){
    win1=window.open(p_link,'Dialog',"menubar=no,scrollbars=yes,resizable=yes,width=840,height=580,top=50,left=50");
    win1.focus();
}

function popsinglewin(p_link,p_name){
    win1=window.open(p_link,p_name,"menubar=no,scrollbars=yes,resizable=yes,width=840,height=580,top=50,left=50");
    win1.focus();
}

function popnamewin(p_link,p_name,style){
    win1=window.open(p_link,p_name,style);
    win1.focus();
}

function popwin(p_link, p_scrollbar, p_width, p_height){
   win1=window.open(p_link,'_blank', 'toolbar=no,menubar=no, scrollbars='+p_scrollbar+', resizable=yes, width='+p_width+', height='+p_height+'');
   win1.focus();
}

function popsubmitwin(p_link){
   win1=window.open(p_link,'_blank', 'toolbar=no,menubar=no, scrollbars=no, resizable=no, width=10, height=10,left=2000,top=2000');
   win1.close();
}


function openfullwin(p_link) {
	new_win = window.open("","","scrollbars");
	if (document.all) {
		new_win.moveTo(0,0);
		new_win.resizeTo(screen.width,screen.height);
	}
	new_win.location = p_link;
}

function initDynamicBar(element,aryName){
    var e = document.getElementById(element);	
	e.innerHTML = eval(''+aryName+'[0]');
	e.currentIdx = '0';
	e.totalSize = eval(''+aryName+'.length');
	changeDynamicBarText(element,aryName);
}

function changeDynamicBarText(element,ary){
	var e = document.getElementById(element);	
	if(parseInt(e.currentIdx) >= parseInt(e.totalSize)){
		e.currentIdx = '0';
	}
    eval('e.innerHTML = '+ary+'['+e.currentIdx+'];');
    e.currentIdx = (parseInt(e.currentIdx)+1)+"";
    setTimeout("changeDynamicBarText('"+element+"','"+ary+"')",5000);
}

function popupDynamicSelection(sid,event){
   x = event.screenX-380;
   y = event.screenY-200;
   dialog=window.open("","Selection","menubar=no,scrollbars=no,resizable=no,locationbar=no,personalbar=no,statusbar=no,width=380,height=200,top="+y+",left="+x+"");
   dialog.focus();   
   dialog.document.writeln("<SCRIPT LANGUAGE=JavaScript>var _popupSid = '"+sid+"';</SCRIPT>");   
   dialog.document.writeln("<SCRIPT LANGUAGE=JavaScript SRC=\"/webresource/taglib/jscript/popupselect.js\"></SCRIPT>");
}

function changePageByField(formName,event,fieldId){
 var _field = document.getElementById(fieldId);	
 _pageNo = _field.value;
 if(_pageNo != ''){
     changePage(formName,event,_pageNo);
 }else{
     return;
 } 
}

function changePage(formName,event,pageNo){
 var _actionKey = document.forms[formName].action;
 params = "pageNo="+pageNo;
 if(_actionKey != ''){ 
   _actionKey = _actionKey.substr(0,_actionKey.indexOf('.'))+ '.' +event + _actionKey.substr(_actionKey.lastIndexOf('.'));  
   if(_actionKey.indexOf('?')> 0){  
      _actionKey = _actionKey.substr(0,_actionKey.indexOf('?')); 
   }  
   if(params != '' && ((params+"") != 'undefined')){ 
      _actionKey = _actionKey+"?"+params; 
   } 
 } 
 displaySubmitView();
 document.forms[formName].action = _actionKey; 
 document.forms[formName].submit();
}

function ajaxSubmitForm(action,formName,ajaxAction)
{    
	new Ajax.Request(action, { method: "post",
		parameters:Form.serialize(formName),		
		onSuccess: function(httpObj){
		    hiddenSubmitView();
		    ajaxText = httpObj.responseText;	  
            eval(ajaxAction+'(ajaxText)');     	    
		},
		onFailure: function(httpObj){
		    hiddenSubmitView(); 
		    alert(httpObj.statusText);
		}				
    });
	displaySubmitView();	
}

function ajaxUrl(action,formName,ajaxAction)
{    
	new Ajax.Request(action, { method: "post",
	    parameters:Form.serialize(formName),	    
		onSuccess: function(httpObj){
		    ajaxText = httpObj.responseText;	  
            eval(ajaxAction+'(ajaxText)');     	    
		},
		onFailure: function(httpObj){
		    alert(httpObj.statusText);
		}				
    });
}

function ajaxDefault(ajaxText){
   if(ajaxText != ''){
       alert(ajaxText); 
   }     
}
