  	// Input  : Object
  	// Output : Value of the Object -> Will be use only 0-9, a-z, A-Z and _
  	// Purpose: Remove unwanted characters
  	// For example:
  	// Input: abc~%123 -> will be replaced to abc123  	
  	function trimSpace(obj)
	{
		var nonValidChar=/[^0-9,a-z,A-Z,_]/gi;
		obj.value = obj.value.replace(nonValidChar, "");
		return true;
	}
	
	function trimString (str) 
	{
		str = this != window? this : str;
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	
	
	function SpotLight(pOn, pObj)
    {
        if (pOn) {
            pObj.style.backgroundColor      = "silver";
            pObj.style.cursor               = "hand";
            pObj.borderColor                = "#9C9A9C";
        }
        else {
            pObj.style.backgroundColor      = "#E7E7E7";
            pObj.style.cursor               = "default";
            pObj.borderColor                = "#E7E7E7";
        }
    }
	
	function GetXY(aTag)
	{
		var p=[0,0];
		while(aTag!=null){
  			p[0]+=aTag.offsetLeft;
  			p[1]+=aTag.offsetTop;
  			aTag=aTag.offsetParent;
		}
		return p;
	}
	
	function ViewFrame(objHandler, iFrameID, pSrc, iFrameWidth, iFrameHeight)
	{
		var objFrame = document.getElementById(iFrameID);
		objFrame.src    = pSrc;
		var p=GetXY(objHandler);
		with (objFrame.style) {
			width=iFrameWidth;
			height=iFrameHeight;
			left=p[ 0 ]+1;
			top =p[ 1 ]+objHandler.offsetHeight+1;
			visibility="visible";
		}

	}

	function ViewRFrame(objHandler, iFrameID, pSrc, iFrameWidth, iFrameHeight)
	{
		var objFrame = document.getElementById(iFrameID);
		
		objFrame.src    = pSrc;
		var p=GetXY(objHandler);
		with (objFrame.style) {
			width=iFrameWidth;
			height=iFrameHeight;
			left=(p[ 0 ] + objHandler.offsetWidth) - (iFrameWidth + 1);
			top =p[ 1 ]+objHandler.offsetHeight+1;
			visibility="visible";;
		}
	}

	function ViewTLFrame(objHandler, iFrameID, pSrc, iFrameWidth, iFrameHeight)
	{
		var objFrame = document.getElementById(iFrameID);
		
		objFrame.src    = pSrc;
		var p=GetXY(objHandler);
		with (objFrame.style) {
			width=iFrameWidth;
			height=iFrameHeight;
			left=p[ 0 ]+1;
			top =p[ 1 ]-(objHandler.offsetHeight+iFrameHeight) + 16;
			visibility="visible";
		}
	}
	
	function ShowIframe(iFrameID, pSrc)
	{
		var objFrame = document.getElementById(iFrameID);
		
		objFrame.src = pSrc;
		with (objFrame.style) {
			width  = "250px";
			height = "120px";
  			left   = 50;
			top    = 100;
			visibility="visible";
		}
	}
	
	// obj1 => target object
	// obj2 => button
	function showCalendar(obj1, obj2) 
	{
		gfPop.fPopCalendar(obj1);
		if (obj2.value == "...") {
			obj2.value = "X";
			obj2.title = "Close";
		}	
		else {
			obj2.value = "...";
			obj2.title = "Browse Date";
		}	
	}
	
	function showAvailableDate(obj) 
	{
		gfPop.fPopCalendar(obj.form.txtAvailableDate);
		if (obj.value == "...") {
			obj.value = "X";
			obj.title = "Close";
		}	
		else {
			obj.value = "...";
			obj.title = "Browse Date";
		}	
	}
	
	function showDeletedDate(obj) 
	{
		gfPop.fPopCalendar(obj.form.txtDeletedDate);
		if (obj.value == "...") {
			obj.value = "X";
			obj.title = "Close";
		}	
		else {
			obj.value = "...";
			obj.title = "Browse Date";
		}	
	}
	
	// ----------------- Clear All
	function clearAll(pObj)
	{
		for (var iCount=0; iCount < pObj.length; iCount++)
			pObj[ iCount ].selected = false;
	}

	// ----------------- Select All
	function selectAll(pObj)
	{
		for (var iCount=0; iCount < pObj.length; iCount++)
			pObj[ iCount ].selected = true;
	}

	function SwapUp(pObj, pIndex)
	{
		if (pIndex > 0) {
			var tempVal	= pObj[ pIndex ].value;
			var tempText	= pObj[ pIndex ].text;
			
			pObj[ pIndex ].value = pObj[ pIndex - 1 ].value;
			pObj[ pIndex ].text  = pObj[ pIndex - 1 ].text;
			pObj[ pIndex - 1 ].value = tempVal;
			pObj[ pIndex - 1 ].text  = tempText;
		}
	}

	function SwapDown(pObj, pIndex)
	{
		if (pIndex < pObj.length) {
			var tempVal	= pObj[ pIndex ].value;
			var tempText	= pObj[ pIndex ].text;
			
			pObj[ pIndex ].value = pObj[ pIndex + 1 ].value;
			pObj[ pIndex ].text  = pObj[ pIndex + 1 ].text;
			pObj[ pIndex + 1 ].value = tempVal;
			pObj[ pIndex + 1 ].text  = tempText;
		}
	}

	function moveUp(pObj)
	{
		var firstIndex = -1;
		// --------------- Save current selected values
		var sIndex = "";
		for (var iCount=0; iCount<pObj.length; iCount++) {
			if (pObj[ iCount ].selected) {
				if (firstIndex == -1) firstIndex = iCount;
				if (sIndex == "") sIndex = pObj[ iCount ].value;
				else sIndex += "," + pObj[ iCount ].value;
			}
		}
		
		if (firstIndex > 0) {

			// --------------- Order Process
			for (iCount=0; iCount<pObj.length; iCount++) {
				if (pObj[ iCount ].selected) {
					SwapUp(pObj, iCount);
				}
			}
		
			// --------------- Clear all selected item
			clearAll(pObj);
		
			// --------------- Restore the selected values
			for (iCount=0; iCount<pObj.length; iCount++) {
				var arrValue = sIndex.split(",");
				var bFound = false;
				for (var iCount2=0; iCount2 < arrValue.length && !bFound; iCount2++) {
					iItem = arrValue[ iCount2 ];		
					if (parseInt(iItem) == parseInt(pObj[ iCount ].value)) bFound = true;
				}
				if (bFound) pObj[ iCount ].selected = true;
			}
			
		}	
	}

	function moveDown(pObj)
	{
		var lastIndex = -1;
		// --------------- Save current selected values
		var sIndex = "";
		for (var iCount=0; iCount<pObj.length; iCount++) {
			if (pObj[ iCount ].selected) {
				if (lastIndex < iCount) lastIndex = iCount;
				if (sIndex == "") sIndex = pObj[ iCount ].value;
				else sIndex += "," + pObj[ iCount ].value;
			}
		}
		
		if (lastIndex < pObj.length-1) {

			// --------------- Order Process
			for (iCount=pObj.length-1; iCount>=0; iCount--) {
				if (pObj[ iCount ].selected) {
					SwapDown(pObj, iCount);
				}
			}
		
			// --------------- Clear all selected item
			clearAll(pObj);
		
			// --------------- Restore the selected values
			for (iCount=0; iCount<pObj.length; iCount++) {
				var arrValue = sIndex.split(",");
				var bFound = false;
				for (var iCount2=0; iCount2 < arrValue.length && !bFound; iCount2++) {
					iItem = arrValue[ iCount2 ];		
					if (parseInt(iItem) == parseInt(pObj[ iCount ].value)) bFound = true;
				}
				if (bFound) pObj[ iCount ].selected = true;
			}
		}	
	}
	
	//-- Remove Item from multiple select box
	function removeIt(pObj)
	{
	    if (pObj) {
    		if (pObj.selectedIndex != -1) {
    		    var iCount = 0;
    		    var bDone  = 0;
    		    
    		    while (iCount < pObj.length) {
    		        if (pObj[ iCount ].selected) {
    		            pObj[pObj.selectedIndex] = null;
    		            iCount = 0;
    		        }
    		        else iCount++;
    		    }
    		}	
        }    		    
	}

	
	// ----- ADD IMAGE TO TEXT BOX | Credit: Peter Sunardi
	// Form name has to be form1
	// Additional hidden type has to exist -> name: txtImage
        function addImage()
	{
		popup('/cmsadmin/include/imgLib_to_box.asp', 600, 250)
	}
	
	// ----- REMOVE IMAGE FROM TEXT BOX | Credit: Peter Sunardi
	function removeImage()
	{
		document.form1.imgID.value      = 0;
		document.form1.txtImage.value   = ""; 
		document.form1.txtCaption.value = ""; 
	}
	
	function copyToList(from,to)
    {
      //fromList = eval('document.forms[0].' + from);
      //toList = eval('document.forms[0].' + to);
      fromList  = from;
      toList    = to;

      var sel = false;
      for (i=0;i<fromList.options.length;i++)
      {
        var current = fromList.options[i];
        if (current.selected)
        {
          sel = true;
          txt = current.text;
          val = current.value;
          toList.options[toList.length] = new Option(txt,val);
          fromList.options[i] = null;
          i--;
        }
      }
      if (!sel) alert ('You haven\'t selected any options.');
    }
    
    function copyToList2(from,to)
    {
      //fromList = eval('document.forms[0].' + from);
      //toList = eval('document.forms[0].' + to);
      fromList  = from;
      toList    = to;

      selectAll(fromList);

      var sel = false;
      for (i=0;i<fromList.options.length;i++)
      {
        var current = fromList.options[i];
        if (current.selected)
        {
          sel = true;
          txt = current.text;
          val = current.value;
          toList.options[toList.length] = new Option(txt,val);
          fromList.options[i] = null;
          i--;
        }
      }
      if (!sel) alert ('You haven\'t selected any options.');
    }
    
    function IsNumeric(sText)
	{
		var ValidChars = "0123456789";
		var IsNumber   = true;
		var Char;
	
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
			Char = sText.charAt(i); 
			if ((i == 0) && (Char == "-")) { 	// check first character for minus sign
				IsNumber = false;
			}	
			else if (ValidChars.indexOf(Char) == -1) IsNumber = false;
		}
		return IsNumber;
	}
	
	function doCleanCode(code) {    
	
	    	// removes all Class attributes on a tag eg. '<p class=asdasd>xxx</p>' returns '<p>xxx</p>'
		//code = code.replace(/<([\w]+) class=([^ |>]*)([^>]*)/gi, "<$1$3")
		code = code.replace(/<[p|P] class=([^ |>]*)([^>]*)/gi, "<$1$3")

		// removes all style attributes eg. '<tag style="asd asdfa aasdfasdf" something else>' returns '<tag something else>'
		code = code.replace(/<([\w]+) style="([^"]*)"([^>]*)/gi, "<$1$3")
		
		// gets rid of all xml stuff... <xml>,<\xml>,<?xml> or <\?xml>
		code = code.replace(/<\\?\??xml[^>]>/gi, "")
		
	    	// get rid of ugly colon tags <a:b> or </a:b>
		code = code.replace(/<\/?\w+:[^>]*>/gi, "")
		
		// removes all empty <p> tags
		code = code.replace(/<p([^>])*>(&nbsp;)*\s*<\/p>/gi,"")
		
		// removes all empty span tags
		code = code.replace(/<span([^>])*>(&nbsp;)*\s*<\/span>/gi,"")
		
		return code
	}
	
	//-- Page Property (Add - Edit)
	function objReset(pParam)
	{
		var obj = document.form1;
	
		if (pParam == 1) {	
			obj.txtPublishUntil.value		          = "";
			obj.txtPublishUntil.disabled		      = true;
			obj.txtPublishUntil.style.backgroundColor = "#D4D0C8";
			obj.buCalExpire.disabled		          = true;
			obj.buUntilRemove.disabled		          = true;
			obj.sel_untilHour.disabled		          = true;
			obj.sel_untilMinute.disabled		      = true;
		}
		else {
			obj.txtPublishUntil.disabled		      = false;
			obj.txtPublishUntil.style.backgroundColor = "#FFFFFF";
			obj.buCalExpire.disabled		          = false;
			obj.buUntilRemove.disabled		          = false;
			obj.sel_untilHour.disabled		          = false;
			obj.sel_untilMinute.disabled		      = false;
		}
	}
	
	//-- Page Property (Delete)
	function objReset_delete(pParam)
	{
		var obj = document.form1;
	
		if (pParam == 1) {	
			obj.txtPublishUntil.value		          = "";
			obj.txtPublishUntil.disabled		      = true;
			obj.txtPublishUntil.style.backgroundColor = "#D4D0C8";
			obj.sel_untilHour.disabled		          = true;
			obj.sel_untilMinute.disabled		      = true;
		}
		else {
			obj.txtPublishUntil.disabled		      = false;
			obj.txtPublishUntil.style.backgroundColor = "#FFFFFF";
			obj.sel_untilHour.disabled		          = false;
			obj.sel_untilMinute.disabled		      = false;
		}
	}