function roll_acer_product_menu(ele_id){
	var ele = $(ele_id);
	if(!ele) return;
	if(ele.style.display == 'none')
		Effect.BlindDown(ele_id, {duration: 0.5}); 
	else
		Effect.BlindUp(ele_id, {duration: 0.5}); return false;
	return false;
}

function rollUp(ele_id){
	var ele = $(ele_id);
	if(!ele) return true;
	var ele2 = ele.parentNode;
	var ele3 = ele.nextSibling;
	while (ele3) {
		if(ele3.nodeType=="3")
    		ele3 = ele3.nextSibling;
    	else
    		break;
  	}
	if(!(ele2 && ele3)) return true;
	setTimeout(function(){
		Effect.BlindUp(ele_id, {duration: 0.5});
		//ele2.style.position = 'absolute';
		//ele2.style.width = '100%';
		ele3.getElementsByTagName('li')[0].onclick = function(evt){
			roll_acer_product_menu(ele_id);
		};
	},1);
	return true;
}

function _bookmark(title,url){
	if (window.sidebar)
    	window.sidebar.addPanel(title, url, "");
	else if(document.all)
    	window.external.AddFavorite(url, title);
}

function _makeBorder(obj,bColor,_top,_right,_bottom,_left){
	var obj = _gEl(obj);
	if(obj==null) return;
	if(_top)
		obj.style.borderTop = "1px solid "+bColor;
	if(_left)
		obj.style.borderLeft = "1px solid "+bColor;
	if(_right)
		obj.style.borderRight = "1px solid "+bColor;
	if(_bottom)
		obj.style.borderBottom = "1px solid "+bColor;
}

function _addClass(obj,className){
	var obj = _gEl(obj);
	if(obj==null) return;
	obj.className += (' '+className);
}

function _removeClass(obj,className){
	var obj = _gEl(obj);
	if(obj==null) return;
	className = new RegExp(className,"ig");
	obj.className = obj.className.replace(className,'');
}

function _flipColor(obj,color1,color2){
	var obj = _gEl(obj);
	if(obj==null) return;
	var t = obj.style.backgroundColor;
	if(t==null || _compareColor(t,color2))
		obj.style.backgroundColor=color1;
	else
		obj.style.backgroundColor=color2;
}

function _flipAllRow(obj,color1,color2){
	var obj = _gEl(obj);
	if(obj==null) return;
	if(obj.tagName!="TR" && obj.parentNode!=null)
		_flipAllRow(obj.parentNode,color1,color2);
	else{
		var childs = obj.childNodes;
		if(childs==null) return;
		for(var i=0;i<childs.length;i++){
			if(childs[i].tagName=="TD")
				_flipColor(childs[i],color1,color2);
		}	
	}
}

function _borderBottomAllRow(obj,size,color){
	var obj = _gEl(obj);
	if(obj==null) return;
	if(obj.tagName!="TR" && obj.parentNode!=null)
		_borderBottomAllRow(obj.parentNode);
	else{
		var childs = obj.childNodes;
		if(childs==null) return;
		for(var i=0;i<childs.length;i++){
			if(childs[i].tagName=="TD"){
				if(size!=0)
					childs[i].style.borderBottom = size+'px solid '+color;
				else
					childs[i].style.borderBottom = '0px';
			}
		}	
	}
}

function _compareColor(color1,color2){
	if((color1.indexOf("#") != -1 && color2.indexOf("#") != -1) || 
      (color1.indexOf("rgb") != -1 && color2.indexOf("rgb") != -1)){
      return color1.toLowerCase() == color2.toLowerCase()
    } else{
      var xCol_1 = color1;
      var xCol_2 = color2;
      if(xCol_1.indexOf("#") != -1) xCol_1 = _toRGBcolor(xCol_1);
      if(xCol_2.indexOf("#") != -1) xCol_2 = _toRGBcolor(xCol_2);
      return xCol_1.toLowerCase() == xCol_2.toLowerCase()
    }
}

function _toRGBcolor(color1){
    varR = parseInt(color1.substring(1,3), 16);
    varG = parseInt(color1.substring(3,5), 16);
    varB = parseInt(color1.substring(5,7), 16);
    return "rgb(" + varR + ", " + varG + ", " +  varB + ")";
  }

function _changeDisplay(obj){
	var obj = _gEl(obj);
	if(obj==null) return;
	if(obj.style.display==null || obj.style.display=="" || obj.style.display!="none")
		obj.style.display="none";
	else{
		try {	
			obj.style.display="table-row";
		} catch(err) {obj.style.display="block"; }		
	}		
}

function _changeVisibility(obj){
	var obj = _gEl(obj);
	if(obj==null) return;
	if(obj.style.visibility==null || obj.style.visibility=="" || obj.style.visibility=="visible")
		obj.style.visibility="hidden";
	else{
		obj.style.visibility="visible";		
	}		
}

/*function _changeDisplay(obj){
	var obj = _gEl(obj);
	if(obj==null) return;
	if(obj.style.display==null || obj.style.display=="" || obj.style.display!="block")
		obj.style.display="none";
	else{
		obj.style.display="block";		
	}		
}*/

function _changeImageOpposite(obj){
	var obj = _gEl(obj);
	if(obj==null) return;
	var sImage = obj.src;

	if(sImage==null || sImage=="") return;
	if(sImage.indexOf('.')!=-1){
		var t = sImage.substring(sImage.lastIndexOf('.'));
		sImage = sImage.replace(t,"");
		if(sImage.match(/_over$/g)!=null){
			obj.src = sImage.replace(/_over$/g,"")+t;
		}else{
			obj.src = sImage+"_over"+t;
		}
	}
}

function _goToURL(linkURL,newWin) {
	var openNew = false;
	if(newWin)
		openNew = newWin;
	if(linkURL==null || linkURL=="") return;
	if(openNew==true || openNew=="true")
		window.open(linkURL);
	else
		window.location.href = linkURL;
}

function _changeClass(objId,cName) {
	if(objId==null||cName==null||cName=="") return;
	var o = _gEl(objId);
	if(o==null)return;
	o.className = cName;
}

function _changeClassByObj(obj,cName) {
	if(obj==null || cName==null || cName=="") return;
	obj.className = cName;
}

function _swapClassByObj(obj,oldCName,newCName) {
	if(obj==null || oldCName==null || oldCName=="" || newCName==null || newCName=="") return;
	obj.className = obj.className.replace(oldCName,newCName);
}

function _getXY(obj) {
	if(obj == null) return;
	for (var sumTop=0,sumLeft=0;obj!=document.body;sumTop+=obj.offsetTop,sumLeft+=obj.offsetLeft,obj=obj.offsetParent);
	return {left:sumLeft,top:sumTop}
}

function _getXY_relative(obj,toEleId){
	if(obj==null) return;
	var toEle = _gEl(toEleId);
	if(toEle==null) return;
	for (var sumTop=0,sumLeft=0;obj!=toEle;sumTop+=obj.offsetTop,sumLeft+=obj.offsetLeft,obj=obj.offsetParent);
	return {left:sumLeft,top:sumTop}
}

function _preventEvent(e){
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function _gEl(objRef) {
	var theObj=null;
	if (objRef) {
		if (typeof objRef != 'object')
			theObj = document.getElementById(objRef);
		else
			theObj = objRef;
		return theObj;
	} else
		return false;
}

function _addError(ulId,propertyName){
	var theObj = _gEl(ulId);
	if(theObj==null) return;
	var li = document.createElement("li");
	_changeClassByObj(li,"error");
	li.innerHTML = propertyName;
	theObj.appendChild(li);	
}

function _checkAllMultiEntry(unit, index) {
	var key = multiChoiceMap[unit + index];
	var fields = document.getElementsByName(unit + 'Checked');
	if(fields == null) return;
	for(var i=0; i < fields.length; i++){
		if (key == "all" && fields[i].id.substring(0,fields[i].id.indexOf('_')) == index )
			fields[i].checked = true;
		else if (key == "none" && fields[i].id.substring(0,fields[i].id.indexOf('_')) == index )
			fields[i].checked = false;
	}
	if(key == "all") key = "none";
    else key = "all";
    multiChoiceMap[unit + index] = key;
    return false;
}

function _removeRowMultiEntry(unitID, rowID){
	if((unitID+"[0]")==rowID) return;
	var lastIndex = multiEntryMap[unitID + 'LastIndex'];
	var lastID = unitID + '[' + lastIndex + ']'; 
	var row = document.getElementById(rowID);
	var ds = document.getElementById(unitID + 'DataSize');
	if(row==null || ds==null) return;
	var size = parseInt(ds.getAttribute('value'));		
	if(size > 1){
		var pRow = row.previousSibling;
		if(pRow == null) return;

		row.parentNode.removeChild(row);
	    size--;
		ds.setAttribute('value', size);		
	} 
	multiEntryMap[unitID + 'LastIndex'] = lastIndex;
}

function _addRowMultiEntry(unitID,cols,rowID){
	var currentRow = document.getElementById(rowID);
	if(currentRow==null || currentRow.parentNode==null )return;
	var lastIndex = multiEntryMap[unitID + 'LastIndex'];
	lastIndex = (lastIndex==-1 || lastIndex==0)?1:++lastIndex;
	var newRowId = unitID + '[' + lastIndex + ']';
	var temp = currentRow.innerHTML;
	while(temp.indexOf(rowID) > 0){
		temp = temp.replace(rowID, newRowId);
	}
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id',newRowId);
	newDiv.innerHTML = temp;
	
	var nextRow = currentRow.nextSibling;
	if(nextRow)
		currentRow.parentNode.insertBefore(newDiv,nextRow);
	else
		currentRow.parentNode.appendChild(newDiv);	
		
	var ds =  document.getElementById(unitID + 'DataSize');
	var size = parseInt(ds.getAttribute('value')) + 1;
	ds.setAttribute('value',size);
	if(size >= 2 && cols!=null){
		var colsId = cols.split(",");
		for(var i=0;i<colsId.length;i++){
			var header = document.getElementById(newRowId + '_Header_'+colsId[i]);				
			if(header) {
	    		header.style.display='none';
	    	}
	    }
	}
	var inputs = newDiv.getElementsByTagName('input'); 
	if(inputs != null){
		for(var i=0; i < inputs.length; i++){
	        var input = inputs.item(i);
	        if(input.getAttribute('name').indexOf(newRowId) > -1){
	        	input.setAttribute('value','');
	    	}
		}
	}	  
	multiEntryMap[unitID + 'LastIndex'] = lastIndex;
}
