/*for close the child window,if you want your child window close with the parent window,
 *add them to wArray array like this:
 * wArray[wArray.length]=window.open.....;	
*/
var wArray = new Array(); 
function closeChilds(){ 
		for(var i=0;i<wArray.length;i++)
			wArray[i].close();
		wArray.length=0;
}
	
function LTrim(str) { 
return str.replace(/^[ \t\n\r]+/g, "");
}

function RTrim(str) {
return str.replace(/[ \t\n\r]+$/g, "");
}

function Trim(str) {
    return RTrim(LTrim(str));
}

function confirmAndForward(message, forward, target)
{
    var go = confirm(message);
    if ( go ) {
        if (target == null) {
            window.location=forward;
        }
        else {
            targetWindow = window.open(forward, target);
        }
    }
}
function popSpeicalSizeWindow(url, name,width,height){
	popWindow = window.open(url, name, 'menubar=0,location=0,toolbar=0,personalbar=0,status=1, scrollbars=yes, left=0, top=0, resizable=yes, width='+width+', height='+height);
	wArray[wArray.length]=popWindow;
	popWindow.focus();
}
function popNewWindow(url, name){
	popWindow = window.open(url, name, 'menubar=0,location=0,toolbar=0,personalbar=0,status=1, scrollbars=yes, left=0, top=0, resizable=yes, width=750, height=400');
	wArray[wArray.length]=popWindow;
	popWindow.focus();
}
function popNewWindowNosizeLimit(url, name){
	popWindow = window.open(url, name, 'menubar=0,location=0,toolbar=0,personalbar=0,status=1, scrollbars=yes, left=0, top=0, resizable=yes');
	wArray[wArray.length]=popWindow;
	popWindow.focus();
}
 

function pickOpenWin(form, attribute, label, forward, callback)
{
    var newForward = forward + '?pickForm=' + form +'&pickLabel=' + label +'&pickAttribute=' + attribute + '&callback=' + callback;
    newWindow = window.open(newForward, 'Pick' , 'scrollbars=yes,menubar=0,location=0,personalbar=0, left=0, top=0, width=800, height=600');
    wArray[wArray.length]=newWindow;
}

function pickSetValue(form, attribute, label, attributeValue, labelValue, callback)
{
    for(var i=0; i<opener.document.forms.length; i++)
    {
        for (var j=0; j<opener.document.forms[i].elements.length; j++) 
        {
            if (opener.document.forms[i].elements[j].name == attribute)
            {
                opener.document.forms[i].elements[j].value = attributeValue;
                opener.document.forms[i].elements[j].blur();
            }
            if (opener.document.forms[i].elements[j].name == label)
            {
                opener.document.forms[i].elements[j].value = labelValue;
                opener.document.forms[i].elements[j].blur();
            }
        }
    }
    if(callback!=null)
    {
      eval(callback);
    }
    window.close();
}


//<%-- below is calendar js--%> 
function setCalendarField(fieldName,buttonName){  

		if(document.getElementById(fieldName) == null){ 
			try { 
			    document.getElementsByName(fieldName)[0].id = fieldName; 
			} catch(err) {
				alert(err);
				try{
			    	document.getElementsByName(fieldName).type='text';
			    	document.getElementsByName(fieldName).id = fieldName;			    	
			    	alert(document.getElementsByName(fieldName).id);
			    	//document.getElementsByName(fieldName).name = fieldName;	 
			    }catch(err1){
			    	alert('initial date input('+fieldName+') error');
			    }
			}
		} 
		Zapatec.Calendar.setup({
		showOthers        : true,
        firstDay          : 0,
        step              : 1,
        electric          : false,
        inputField        : fieldName,
        button            : buttonName,
        ifFormat          : "%Y-%m-%d",
        daFormat          : "%Y-%m-%d" 
      }); 
}
 
  
function setCalendarFieldWithDefault(fieldName,buttonName){ 
		if(document.getElementById(fieldName) == null){
			document.getElementsByName(fieldName)[0].id = fieldName;
		} 
		Zapatec.Calendar.setup({
		showOthers        : true,
        firstDay          : 0,
        step              : 1,
        electric          : false,
        inputField        : fieldName,
        button            : buttonName,
        ifFormat          : "%d-%b-%Y",
        daFormat	      : "%d/%b/%Y",
        setDefaultValue   : true 
      });  
}
//<%-- calendar js end--%> 

function rollover()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)
		{
			if(tables[i].className.indexOf('rollover')>=0)
			{
				var trs=tables[i].getElementsByTagName('tr');
				for(var j=0;j<trs.length;j++)
				{
					if(trs[j].parentNode.nodeName=='TBODY')
					{
						var oldclass;
						trs[j].onmouseover=function(){oldclass=this.className;this.className='rollover';return false}
						trs[j].onmouseout=function(){this.className=oldclass;return false}
					}
				}
			}
		}
	}
}

function setEntityValues (conid) {
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            if (elt.type == "radio") {
                if (elt.id == conid) {
                    elt.checked = true;
                }
            }
        }
    }
}
function retrieveFormName(form) {
    if (form.getAttributeNode) {
        if (form.getAttributeNode("id") &&
            form.getAttributeNode("id").value) {
            return form.getAttributeNode("id").value;
        } else {
            return form.getAttributeNode("name").value;
        }
    } else if (form.getAttribute) {
        if (form.getAttribute("id")) {
            return form.getAttribute("id");
        } else {
            return form.attributes["name"];
        }
    } else {
        if (form.id) {
            return form.id;
        } else {
            return form.name;
        }
    }
 }
 	function IsInt(objStr){
	    var reg =/^\+?[0-9]*[1-9][0-9]*$/;  
	    var r=objStr.match(reg); 
	    if(r==null){ 
	        return false;
	    }else{        
	        return true;  
	    }
	}
	 
function countCharactor(o,size){
	var toInput = size-o.value.length;
	if(toInput>=0){
		alert('目前总共有'+o.value.length+'字,您还可以输入'+toInput+'字');
	}else{
		alert('目前总共有'+o.value.length+'字,您最多可以输入'+size+'字');
	}
}
function moveOption(e1, e2){
 for(var i=0;i<e1.options.length;i++){
  if(e1.options[i].selected){
  	if(e1.options[i].value==''){
  		alert('您不可以添加此项！');
  		return;
  	}
	for(var j=0;j<e2.options.length;j++){
		if(e2.options[j].value==e1.options[i].value){
			e1.remove(i);
			i--;
			return;
		}
	}
   var e = e1.options[i];
   e2.options.add(new Option(e.text, e.value));
   e1.remove(i);
   i=i-1
  }
 }
}

function moveOptionWithLen(e1, e2,length){ 
clearEmptyItem(e2);
 for(var i=0;i<e1.options.length;i++){
  if(e2.options.length>=length && length>0){
  	alert('您最多可以选择'+length+'项!');
  	return;
  }
  if(e1.options[i].selected){
  	if(e1.options[i].value==''){
  		alert('您不可以添加此项！');
  		return;
  	}
	for(var j=0;j<e2.options.length;j++){
		if(e2.options[j].value==e1.options[i].value){
			e1.remove(i);
			i--;
			return;
		}
	}
   var e = e1.options[i];
   e2.options.add(new Option(e.text, e.value));
   e1.remove(i);
   i=i-1
  }
 }
}
function clearEmptyItem(s){
	for(var i=s.options.length-1;i>=0;i--){
		if(s.options[i].value==""){
			s.remove(i);
		}
	}
}
function selectAll(s){
	clearEmptyItem(s);
	if(s.options.length==0){
		s.options.add(new Option('','')); 
	}
	for(var i=0;i<s.options.length;i++){
		s.options[i].selected=true;
	}
}