// -----------------------------------------------------------------------------------------------------------------
/* function definition
 
---- str ---- 
function trim( s )
function strShowCode(str)
function strElementPad(strSrc, strElement, intPadCount, intPos)

---- navigation ----
function openPage(strUrl, intWidth, intHeight)
function feedbackReturn(strFeedback, strJumpLink)

---- window ----
function openCenterWindow(strUrl, strName, intWndWidth, intWndHeight)
function openCenterWindow_wh_500(strUrl, strName)
function openWindow(strUrl)

---- parameter ----
function addParamLen(strParam, intDigit)
function getParamWithLen(strParam, intDigit)
ex: 
  addParamLen('12345', 3) will return '00512345'
  getParamWithLen('001a003xxx') will return array with array[0] = a, array[1] = xxx

---- cookie ----
function SetCookie(sName, sValue)
function GetCookie(sName)
function DelCookie(sName)

*/

// ---- str ----

function trim( s ){
	
	var nStart = -1;
	var nEnd;
	
	for( var i=0; i<s.length; i++ ){
		if( nStart == -1 )
			if( s.charAt(i) == ' ' ) continue;
			else nStart = nEnd = i;
		else
			if( s.charAt(i) != ' ' ) nEnd = i;	
	}
	
	if( nStart<0 ) return '';
	return s.substr( nStart, nEnd-nStart+1 );	
}

function strShowCode(str){	
	var i, strRet
	
	for(i=0, strRet=''; i<str.length; i++){
		strRet += str.charCodeAt(i)
	}
	
	return strRet
}

/*
' eg: strElementPad( '78', '0', 2, 0 ) = 0078
' intPos: 0 - from the beginning of strSrc; 1 - at the tail of strSrc*/
function strElementPad(strSrc, strElement, intPadCount, intPos){
	var strPad, i, strRet
	
	strRet = strSrc
	if(intPadCount > 0){
		for(i=0, strPad = '';i<intPadCount;i++) 
			strPad += strElement	
		
		if(intPos == 0) 
			strRet = strPad + strSrc
		else
			strRet = strSrc + strPad
	}	
	return strRet				
}

// ---- navigation ----

function openPage(strUrl, intWidth, intHeight){
	var objWin
	var strAttribute ='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no'
	
	strAttribute += ',width='+intWidth
	strAttribute += ',height='+intHeight
	
	objWin = Window.open(strUrl,  'popup', strAttribute);
}

function feedbackReturn(strFeedback, strJumpLink){
	if(strFeedback != '') alert(strFeedback);
	location.href = strJumpLink
}

// ---- window ----

function openCenterWindow(strUrl, strName, intWndWidth, intWndHeight){
	var intWndLeft = (window.screen.width - intWndWidth) / 2
	var intWndTop = (window.screen.height - intWndHeight) / 2
	
	var obj = window.open(strUrl, strName, 
		'channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0' + 
		',scrollbars=0,status=0,titlebar=0,toolbar=0' + 
		',left=' + intWndLeft + ',top=' + intWndTop + 
		',width=' + intWndWidth + ',height=' + intWndHeight, false
		)
	
	return obj	
}

function openCenterWindow_wh_500(strUrl, strName){
	return openCenterWindow(strUrl, strName, 540, 520)	
}

function openWindow(strUrl){
	return window.open(strUrl, '_blank', 'location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0')
}			

// ---- parameter ----

function addParamLen(strParam, intDigit){
	var str, str2
	
	str2 = (strParam.length).toString(10)
	str = strElementPad(str2, '0', intDigit-str2.length, 0)
	str = str + strParam
	
	return str 
}

function getParamWithLen(strParam, intDigit){
	if(strParam == null || strParam == '') return null
	
	var aryParam = new Array()
	var i = 0, j = strParam.length, k, m = 0
	
	while(i<j){
		k = parseInt(strParam.substr(i, intDigit), 10); i = i + intDigit
		aryParam[m++] = strParam.substr(i, k); i = i + k
	}
	
	return aryParam		
}	

// ---- cookie ----

function SetCookie(sName, sValue)
{
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function DelCookie(sName)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

