
function changeIMG(sObjID,sImgPath)
{
	var sObj;
	
	sObj = document.getElementById(sObjID).src = sImgPath;
	
	sObj = null;
}	

function changeBgColor(sTID,sBgColor)
{
	var sObj;
	
	sObj = document.getElementById(sTID);
	sObj.style.backgroundColor = sBgColor;
	
	sObj = null;
}



function visLayer(loadName,vis)
{
	var sObj;
	
	sObj = document.getElementById(loadName);
	sObj.style.visibility = vis;
	
	sObj = null;
}

function displayObj(objName,objDisplay)
{
	var sObj;
	
	//alert(objName + " " + objDisplay);
	sObj = document.getElementById(objName);
	sObj.style.display = objDisplay;
	
	sObj = null;	
}	



function setValue(objName,objValue)
{
	var sObj;
	
	sObj = document.getElementById(objName);
	sObj.value = objValue;
	
	sObj = null;
}

function getElText(formName,elName)
{
	return document.forms[formName].elements[elName].options[document.forms[formName].elements[elName].selectedIndex].text;
}

function getElValue(formName,elName)
{
	return document.forms[formName].elements[elName].options[document.forms[formName].elements[elName].selectedIndex].value;
}

function getOptionText(sName)
{
	var sObj;
	var sText = "";
	
	sObj = document.getElementById(sName);
	sText = sObj.options[sObj.selectedIndex].text;
	sObj = null;	
	
	return sText;
}

function getOptionValue(sName)
{
	var sObj;
	var sText = "";
	
	sObj = document.getElementById(sName);
	sText = sObj.options[sObj.selectedIndex].value;
	sObj = null;	
	
	return sText;
}

function setElObjText(sObjName,sObjText)
{
	var sObj;
	
	sObj = document.getElementById(sObjName);
	sObj.text = sObjText;
	sObj = null;
}

function setElObjValue(sObjName,sObjValue)
{
	var sObj;
	
	sObj = document.getElementById(sObjName);
	sObj.value = sObjValue;
	sObj = null;
}

function setElObj_src(sObjName,sObj_src)
{
	var sObj;
	
	sObj = document.getElementById(sObjName);
	sObj.src = sObj_src;
	sObj = null;
}

function setElObjInnerHTML(sObjName,sObjHtml)
{
	var sObj;
	
	sObj = document.getElementById(sObjName);
	sObj.innerHTML = sObjHtml;
	//sObj.document.write(sObjHtml);
	sObj = null;
}

function setElObjDisable(sObjName,st)
{
	var sObj;
	//alert(sObjName);
	sObj = document.getElementById(sObjName);
	sObj.disabled = st;
	sObj = null;
}

function setElObjChecked(sObjName,sChk)
{
	var sObj;
	
	sObj = document.getElementById(sObjName);
	sObj.checked = sChk;
	sObj = null;	
}	

function getElObjCheck(sObjName)
{
	var sObj;
	var sCheck;
	
	sObj = document.getElementById(sObjName);
	sCheck = sObj.checked;
	sObj = null;
	
	return sCheck;
}

function getElObjText(sObjName)
{
	var sObj;
	var sText;
	
	sObj = document.getElementById(sObjName);
	sText = sObj.text;
	sObj = null;
	
	return sText;
}

function getElObjValue(sObjName)
{
	var sObj;
	var sValue;
	
	sObj = document.getElementById(sObjName);
	sValue = sObj.value
	sObj = null;
	
	return sValue;	
}	

function removeOp(opName)
{
	while( document.getElementById(opName).options.length > 0 )
		document.getElementById(opName).remove(0);
}

function addOp(opName,opText,opValue)
{	
	document.getElementById(opName).options.add( new Option(opText,opValue) );//option(text,value)
}

	// Create a DHTML layer
function createLayer(name, inleft, intop, width, height, visible, content, sAlpha, sBgColor, sAlign, sOverFlow) 
{
	  var layer;
	  var sValue;
	 /*
	  if (!document.all) 
	  {
		document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width +
				 ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  
				 ' -moz-opacity:' + (sAlpha / 100) + ' background-color:' + sBgColor + 
				 ' align="' + sAlign + '">');
			document.writeln(content);
		document.writeln('</layer>');
	  } 
	  else */
	  {
	  	sValue = (sAlpha / 100);
		document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' +
				 intop + 'px; width:' + width + 'px; height:' + height + 'px;' + 
				 ';visibility:' + (visible ? 'visible;' : 'hidden;') +  ';filter:alpha(Opacity=' + sAlpha + ')' + 
				 ';-moz-opacity:' + sValue + ';opacity:' + sValue +'; background-color:' + sBgColor + 
				 ';overflow:' + sOverFlow + ';" align=' + sAlign + '>');
			document.writeln(content);
		document.writeln('</div>');
	  }
}

function clipLayer(name, clipleft, cliptop, clipright, clipbottom) 
{		
	  var layer = getLayer(name);
	  
	if (!isIE) 
	{
		layer.clip.left   = clipleft;
		layer.clip.top    = cliptop;
		layer.clip.right  = clipright;
		layer.clip.bottom = clipbottom;
	}	  
	else 
	{
		var newWidth = clipright - clipleft;
		var newHeight = clipbottom - cliptop;
		
		layer.height = newHeight;
		layer.width	= newWidth;
		layer.top	= cliptop  + "px";
		layer.left	= clipleft + "px";
	}
	layer = null;
}

function setLayerIndex(layerName,sZindex)
{
	document.getElementById(layerName).style.zIndex = sZindex;
}	

// get the layer object called "name"
function getLayer(name) 
{
	 /* if (!isIE)
		return(document.layers[name]);
	  else */
	  {
		var theObj = document.getElementById(name);
		return theObj.style;
	  }
}
		
// move layer to x,y
function moveLayer(name, x, y) 
{		
  	var layer = getLayer(name);
  			
  	if (!isIE)
    		layer.moveTo(x, y);
	 else 
	 {
		layer.left = x + "px";
   		layer.top  = y + "px";
  	}
}
		
// set layer background color
function setObjBackgroundColor(name, color) 
{		
  	var layer = getLayer(name);
  			
 	if (!isIE)
    		layer.bgColor = color;
	else
    		layer.backgroundColor = color;
    	
    	layer = null;	
}

// toggle layer to invisible
function hideLayer(name) 
{		
  	var layer = getLayer(name);
  			
  	if (!isIE)
    		layer.visibility = "hide";
	else
   		layer.visibility = "hidden";
}

// toggle layer to visible
function showLayer(name) 
{		
  	var layer = getLayer(name);		
  	
  	if (!isIE)
    		layer.visibility = "show";
	else
		layer.visibility = "visible";
}



function panClipLayer(name, clipleft, cliptop, clipright, clipbottom) 
{		
	  var layer = getLayer(name);
	  
	  if (!isIE) 
	  {
		    layer.clip.left   = clipleft;
		    layer.clip.top    = cliptop;
		    layer.clip.right  = clipright;
		    layer.clip.bottom = clipbottom;
	  }	  
	  else 
	  {
		    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	  }

}



function drag(obj,e)
{
	var _x;
	var _y;


	if(!e) 
		e = window.event;
		
	_x = e.clientX - parseInt(obj.style.left);
	_y = e.clientY - parseInt(obj.style.top);
	
	if(document.addEventListener)//FireFox
	{
		document.addEventListener("mousemove",move,true);
		document.addEventListener("mouseup",up,true);
	}
	else if(attachEvent)//IE
	{
		document.attachEvent("onmousemove",move);
		document.attachEvent("onmouseup",up);
	}	
	
	function move(e)
	{
		//document.getElementById("long").value=_x;
		//document.getElementById("lat").value=_y;
		
		if(!e)
			e = Window.event;
		
		obj.style.left = e.clientX - _x + "px";
		obj.style.top = e.clientY - _y + "px";	

		
	}
	function up(e)
	{
		if(!e)
			e = Window.event;
		
		if(document.removeEventListener)
		{
			document.removeEventListener("mousemove",move,true);
			document.removeEventListener("mouseup",up,true);
		}	
		else if(document.detachEvent)
		{
			document.detachEvent("onmousemove",move);
			document.detachEvent("onmouseup",up);	
		}	

	}			
}


function getLineColor()
{
	var sColor = "";
	var sColorObj;
	
	sColorObj = document.getElementsByName("LineColor");
	
	if(sColorObj[0].checked)
		sColor = "0,0,0";
	else if(sColorObj[1].checked)
		sColor = "255,0,0";
	else if(sColorObj[2].checked)
		sColor = "255,127,50";	
	else if(sColorObj[3].checked)
		sColor = "0,255,0";
	else if(sColorObj[4].checked)
		sColor = "0,0,255";
	else if(sColorObj[5].checked)
		sColor = "255,0,255";	
	else if(sColorObj[6].checked)
		sColor = "255,255,0";
	
	sColorObj = null;
	
	return sColor;	
}

function colorMenu()
{
	var colorArray = new Array("black","red","orange","green","blue","pink","yellow");
	
	
	for(var i = 0; i < colorArray.length; i++)
	{
		if( i == 0)
			document.writeln('<input id="LineColor" name="LineColor" type="radio" value="0" checked>');
		else
			document.writeln('<input id="LineColor" name="LineColor" type="radio" value="' + i + '">');
			
				document.writeln('<span class="' + colorArray[i] + '">Line</span>');
			//document.writeln('<span class="' + colorArray[i] + '">¡½</span>');
	}
	colorArray = null;

}

function getFormatTime(now)
{
	var s;
	var y,m,d,hh,mm,ss;
	
	y = now.getFullYear();
	m = now.getMonth() + 1;
	d = now.getDate();
	hh = now.getHours();
	mm = now.getMinutes();  
	ss = now.getSeconds();
	
	s = y + "/" + m + "/" + d + " " + hh + ":" + mm + ":" +ss;
	return s;
}

function setLastLogoutTime(sUID,sJetLag,sDTime,sCID,sUserIP,sWebServer)
{
	var xmlHttp;
	var urlStr = "";
	var sFormatTime;
	var now;
	
	//alert(sJetLag + " , " + sDTime);
	now = new Date( ((sJetLag * 60 * 60 * 1000) + sDTime ));
	sFormatTime = getFormatTime(now);
	//alert(sFormatTime);
	urlStr += "setLastLogoutTime=true&UserID=" + sUID + "&LastLogoutTime=" + sFormatTime + "&CID=" + sCID + "&UserIP=" + sUserIP + "&WebServer=" + sWebServer;
	//alert(urlStr);
	xmlHttp = createXmlHttpRequest(xmlHttp);
	xmlHttp.open("POST", "setItem.jsp", true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(urlStr);	
	

}

function setObjVisibility(objName,objStatus)
{
	var sObj;
	
	sObj = document.getElementById(objName);
	sObj.style.visibility = objStatus;	
	sObj = null;
}	

function setObjPosition(objName,objPosition,sValue)
{
	var sTxt;
	
	sTxt = "document.getElementById('" + objName + "').style." + objPosition + "='" + sValue + "px';"
	eval( sTxt );	
	//alert(sTxt);
	//document.getElementById(objName ).style.objPosition  = sValue + "px";	
}
	

function checkEventCode(e)
{
	var charCode;
	var ev;
	
	if(window.event)
	{
		charCode = e.keyCode;
		ev = window.event;
	}
	else
	{
		charCode = e.which;;
		ev = e;
	}
	
	if ((charCode < 48 && charCode != 45 && charCode != 42 && charCode != 36)|| 
		(charCode > 57 && charCode < 65) || (charCode > 90 && charCode < 97)|| 
		charCode > 122) 
	{
		ev = false;
	} 	
}

function getKeyCode(e)
{
	var charCode;
	
	if(window.event)
		charCode = e.keyCode;
	else
		charCode = e.which;	
	
	return charCode;	
}	

/*
function checkTextLength(obj)
{
	var sValue;
	var sb = true;
	
	sValue = obj.value;

	if( sValue.trim().length <= 0)
	{
		alert("");
		sb = false;
	}	
	//alert(sValue);	

	return sb;	
}
*/	

function checkNumber(obj)
{
	var sValue;
	var charCode;
	var sb = true;
	
	sValue = obj.value;
	
	for(var i = 0; i < sValue.length; i++)
	{
		charCode = sValue.charCodeAt(i); 

		//if ( (charCode < 48 || charCode > 57) && charCode != 45 )
		if ( charCode < 48 || charCode > 57 )		
		{
			alert("Please input number");
			obj.value = "";
			sb = false;
			break;
		} 		       
	}		

	return sb;		
}	
	
	

function checkKeyWord(obj)
{
	var sValue;
	var sb = true;
	
	sValue = obj.value;
	
	if( sValue.indexOf("insert") != -1 || sValue.indexOf("update") != -1|| sValue.indexOf("delete") != -1 ||
	  sValue.indexOf("drop") != -1 || sValue.indexOf("select") != -1 || sValue.indexOf("from") != -1 ||
	  sValue.indexOf("--") != -1 || sValue.indexOf("'") != -1)
	{
		alert(" don\'t accept insert,update,delete,drop,select,from,--,' ");
		obj.value = "";
		sb = false;

	}	

	return sb;	
}	

function checkInputText(obj)
{
	var sb = true;
	
	//if( !checkNumber(obj) || !checkKeyWord(obj) )
	if( !checkKeyWord(obj) )
		sb = false;
	
	return sb;	
}	

function checkFormAllTextCurrent(sFormName)
{
	var sForm;
	var sObj;
	var sb = true;
	
	sForm = document.getElementById(sFormName);
	sObj = sForm.elements;
	
	for(var i = 0; i < sObj.length; i++)
	{
		if(sObj[i].type == "text" || sObj[i].type == "password")	
		{

			if( !checkInputText(sObj[i]) )
			{
				//alert("test");
				sb = false;
				break;	
			}	
		
		}	
	}	
	sForm = null;	
	
	return sb;	
}	



function checkFormAllTextLength(sFormName)
{
	var sForm;
	var sObj;
	var sb = true;
	
	sForm = document.getElementById(sFormName);
	sObj = sForm.elements;
	
	for(var i = 0; i < sObj.length; i++)
	{
		if(sObj[i].type == "text" || sObj[i].type == "password")	
		{
			//alert(sObj[i].id + ": " + sObj[i].style.display);
			if(sObj[i].style.display != "none")
			{
				if( sObj[i].value.trim().length <= 0)
				{
					alert("No Data");
					sb = false;
					break;	
				}	
			}
		}	
	}	
	
	sForm = null;
	return sb;
}


function addOption(opName,sText,sValue)
{
	var sObj;
	var sOption;
	
	sOption =  new Option(sText,sValue);
	sObj = document.getElementById(opName);
	sObj.options.add( sOption );
	
	sOption = null;
	sObj = null;
}

function removeAllOption(opName)
{
	var sObject = null;
	
	sObject = document.getElementById(opName);
	
	if(sObject.options.length > 0)
	{
		while( sObject.options.length > 0 )
			sObject.remove(0);
	}
	sObject = null;
}

function changeMileage_Speed(sUnit,oSpeed)
{
	var nSpeed = "";
	
	if(sUnit == "mile")	
		nSpeed = oSpeed * CHANGEOVER_SPD_Mile;
	else
		nSpeed = oSpeed * CHANGEOVER_SPD_KM;
		
	return nSpeed;			
}	

function redirect(sUrl,sFrame)
{
	location.href=sUrl;target=sFrame;
}	



