  	// 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 popup3(URL, pWidth, pHeight)
  	{
		window.open(URL,'_blank','width=' + pWidth + ',height=' + pHeight + ',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
		return true;
  	} 	
  	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 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 IsNumeric2(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 IsReal(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 IsValidYear(sText)
	{		
		if(sText > 2050 || sText < 1910 ) {
			return false 
		} else {
			return true
		}
	}
	
	function KeyCheck(e)
	{
		var KeyID = (window.event) ? event.keyCode : e.which;
		if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) ||
		   (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
		{
			return false;
		}
		return true;
	}
	
	function SpotLight(pOn, pObj)
    {
        if (pOn) {
            pObj.style.backgroundColor      = "silver";
            pObj.style.cursor               = "hand";
            pObj.borderColor                = "#9C9A9C";
        }
        else {
            pObj.style.backgroundColor      = "#EDEDED";
            pObj.style.cursor               = "default";
            pObj.borderColor                = "#EDEDED";
        }
    }
	
	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;
			}
		}	
	}
	
	// ----- 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', 800, 250)
	}
	
	// ----- REMOVE IMAGE FROM TEXT BOX | Credit: Peter Sunardi
	function removeImage()
	{
		document.form1.imgID.value      = 0;
		document.form1.txtImage.value   = ""; 
		document.form1.txtCaption.value = ""; 
	}
	
	//-- Remove Item from multiple select box
	function removeIt(pObj)
	{
		if (pObj.selectedIndex != -1) {
			for (var iCount=0; iCount<pObj.length; iCount++) {
				if (pObj[iCount].selected) {
					pObj[pObj.selectedIndex] = null;
					iCount = 0;
				}	
			}	
		}	
	}
	
	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
	}
	
	//-- Remove all HTML tags
	function stripHTML(oldString) {

	   	return oldString.replace(/<[^>]*>/g, "");
	}	
	
	//-- 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_untilHour.selectedIndex			  = 0;
			obj.sel_untilMinute.disabled		      = true;
			obj.sel_untilMinute.selectedIndex		  = 0;
		}
		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		      = true;
			obj.txtPublishUntil.style.backgroundColor = "#FFFFFF";
			obj.sel_untilHour.disabled		          = true;
			obj.sel_untilMinute.disabled		      = true;
		}
	}
	
	//-- For meta tag only --------------------------------------------------
	
	function fillSearchTitle(pValue)
	{
		document.form1.txtSearchTitle.value = pValue;
	}
	
	function fillMetaDescription(sContent)
	{
		var sText = "";
		var sChar = "";
		var bExit = false;
		
		//-- get 200 characters from content
		sContent = replace(sContent, "<br>", " ");
		sContent = replace(sContent, "<BR>", " ");
		sContent = trimString(stripHTML(sContent));
		sContent = replace(sContent, "\n", "");
		sContent = replace(sContent, "\r", "");
		sContent = replace(sContent, "&nbsp;", " ");
		
		if (sContent.length > 200) {
			for (i=0; i < 250 && !bExit; i++) {
				sChar = sContent.charAt(i);
				if (i >= 200) {
					if (sChar == " ") {
						bExit = true;
					}
					else sText += sChar;
				}
				else sText += sChar;
			}
		}
		else sText = sContent;
		
		return sText;
	}
	
	function inMetaAuthorList(pList, pName)
	{
		if (pList != "") {
			sArray = pList.split(", ");
			iNum   = 0;
			iFound = 0;
			
			while ((iNum < sArray.length)) 
			{
				if (sArray[iNum] == unescape(pName)) {
					iFound = 1;
				}
				++iNum;
			}
			return iFound	
		}
		return 0
	}
	
	function updateSearchAuthor()
	{
		var sAuthorList    = "";
		
		var objSearch      = document.form1.txtAuthor;
		
		var objAuthor      = document.form1.sel_author;
		var objOtherAuthor = document.form1.txtAuthorOther;
		
		var objEditor      = document.form1.sel_editor;
		var objOtherEditor = document.form1.txtEditorOther;
		
		selectAll(objAuthor);
		selectAll(objEditor);
		
		//-- Author
		if (objAuthor.length > 0) {
			for (i=0; i < objAuthor.length; i++) {
				if (inMetaAuthorList(sAuthorList, objAuthor[i].text) == 0) {
					if (sAuthorList == "") {
						sAuthorList = objAuthor[i].text;
					}
					else sAuthorList += ", " + objAuthor[i].text;
				}
			}
		}
		
		//-- Other Author
		if (objOtherAuthor.value != "") {
			if (inMetaAuthorList(sAuthorList, objOtherAuthor.value) == 0) {
				if (sAuthorList == "") {
					sAuthorList = objOtherAuthor.value;
				}
				else sAuthorList += ", " + objOtherAuthor.value;
			}	
		}
		
		//-- Editor													
		if (objEditor.length > 0) {
			for (i=0; i < objEditor.length; i++) {
				if (inMetaAuthorList(sAuthorList, objEditor[i].text) == 0) {
					if (sAuthorList == "") {
						sAuthorList = objEditor[i].text;
					}
					else sAuthorList += ", " + objEditor[i].text;
				}	
			}
		}
		
		//-- Other editor
		if (objOtherEditor.value != "") {
			if (inMetaAuthorList(sAuthorList, objOtherEditor.value) == 0) {
				if (sAuthorList == "") {
					sAuthorList = objOtherEditor.value;
				}
				else sAuthorList += ", " + objOtherEditor.value;
			}	
		}
		
		clearAll(objAuthor);
		clearAll(objEditor);
		
		objSearch.value = sAuthorList;
	}
	
	function center()
	{
		var leftX = (screen.width - self.document.body.offsetWidth) / 2;
		var topY  = (screen.height - self.document.body.offsetHeight) / 2;
		moveTo(leftX, topY);
	}
	
	//------------------------------------------------------------------------------------------------------------