//******************************************************************************
// ********************** DO NOT DELETE ****************************************
//
// COPYRIGHT NOTICE: Copyright 2001 Harris Susanto, ID 50496269.
//
// This code is not for non-commercial use. Any commercial usage or 
// duplication requires a licensing agreement from the author who may be 
// contacted at the following email address: harris78@yahoo.com
//
// The author assumes no responsibility for any damage caused by the 
// proper or inproper use of this code.
// 
// Revision History: Sep 17, 2001
// Revision History: April 06, 2004
//
// ********************** DO NOT DELETE ****************************************
//******************************************************************************

function confirmDelete(){
var isDelete = window.confirm('Are you sure to delete this record !');
	if (!isDelete) return false;
	return true;
}

function confirmPromote(){
var isDelete = window.confirm('Promote this user to maintenance groups !');
	if (!isDelete) return false;
	return true;
}

function mailThis() {
	strSelection = document.selection.createRange().text
	if (strSelection == "") document.fInputText.tTextEditor.focus()
	strMail = prompt("Enter the email address you want to link :","your@yourmail.com")
	if (strMail == null) return;
	document.selection.createRange().text = "<a href=\"mailto:" + strMail + "\">" + strSelection + "</a>"
	return;
}


function ahrefThis() {
	strSelection = document.selection.createRange().text
	if (strSelection == "") document.fInputText.tTextEditor.focus()
	strHref = prompt("Enter the URL you want to link to:","http://")
	if (strHref == null) return;
	document.selection.createRange().text = "<a href=\"" + strHref + "\">" + strSelection + "</a>"
	return;
}

function boldThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") {		
		document.fInputText.tTextEditor.focus()
		if (from == 2) document.fInputText.tTextEditor.select()
		strSelection = document.selection.createRange().text
		document.selection.createRange().text = strSelection + "<b></b>"
	}	
	else document.selection.createRange().text = "<b>" + strSelection + "</b>"
	return;
}

function imgThis() {
	strSelection = document.selection.createRange().text
	if (strSelection == "") document.fInputText.tTextEditor.focus()
	strImage = prompt("Enter image name you want to add :","sample.jpg")
	if (strImage == null) return;
	document.selection.createRange().text = "<img src=\"" + strImage + "\">" + strSelection + "</a>"
	return;
}

function allThis(from,val) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") document.fInputText.tTextEditor.focus()
	strHref = prompt("Enter the Url Name you want to link to:",val)
	if (strHref == null) return;
	document.selection.createRange().text = "<a href=\"" + val + "\">" + strHref + "</a>"
	return;
}

function flashThis(from,val) {	
	strSelection = document.selection.createRange().text
	
	if (strSelection == "") {		
		document.fInputText.tTextEditor.focus()
		strHref = prompt("Enter the Url Name you want to link to:",val)
		if (strHref == null) return;
			document.selection.createRange().text = "<!--flashTag src=\"" + val + "\"-->" + strHref + "<!--flashTag-->"
		return;

		if (from == 2) document.fInputText.tTextEditor.select()
		strSelection = document.selection.createRange().text
		document.selection.createRange().text = "<!--flashTag src=\"" + val + "\"-->" + strSelection + "<!--flashTag-->"
	}	
	else document.selection.createRange().text = "<!--flashTag src=\"" + val + "\"-->" + strSelection + "<!--flashTag-->"
						      
	return;
}


function pdfThis(from,val) {	
	strSelection = document.selection.createRange().text
	
	if (strSelection == "") {
		document.fInputText.tTextEditor.focus()
		strHref = prompt("Enter the Url Name you want to link to:","http://")
		if (strHref == null) document.selection.createRange().text = "<a href=\"" + val + "\">" + strHref + "</a>"

	}else 
		document.selection.createRange().text = "<img src=\"/image/icon-pdf.gif\" height=\"15\" width=\"15\" border=\"0\"><a href=\"" + val + "\">" +  strSelection  + "</a>"
	return;
}


function excellThis(from,val) {	
	strSelection = document.selection.createRange().text
	
	if (strSelection == "") {
		document.fInputText.tTextEditor.focus()
		strHref = prompt("Enter the Url Name you want to link to:","http://")
		if (strHref == null) document.selection.createRange().text = "<a href=\"" + val + "\">" + strHref + "</a>"

	}else 
		document.selection.createRange().text = "<img src=\"/image/icon-excel.gif\" height=\"15\" width=\"15\" border=\"0\"><a href=\"" + val + "\">" +  strSelection  + "</a>"
	return;
}




function italicThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		document.fInputText.tTextEditor.focus()
		if (from == 2) document.fInputText.tTextEditor.select()
		strSelection = document.selection.createRange().text
		document.selection.createRange().text = strSelection + "<i></i>"
	}
	else document.selection.createRange().text = "<i>" + strSelection + "</i>"
	return;
}

function brThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		document.fInputText.tTextEditor.focus()
		if (from == 2) document.fInputText.tTextEditor.select()
		strSelection = document.selection.createRange().text
		document.selection.createRange().text = strSelection + "<br>"
	}	
	return;
}

function deleteWordThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection != "") {
		document.selection.createRange().text = ""
	}
	return;
}


function paragraphThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") document.fInputText.tTextEditor.focus()
	strPosition = prompt("Enter the paragraph position (Left, Right, Center):","left")
	if (strPosition == null) return;
	document.selection.createRange().text = "<p align=\"" + strPosition + "\">" + strSelection + "</p>"
	return;
}

function underlineThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		document.fInputText.tTextEditor.focus()
		if (from == 2) document.fInputText.tTextEditor.select()
		strSelection = document.selection.createRange().text
		document.selection.createRange().text = strSelection + "<u></u>"
	}
	else document.selection.createRange().text = "<u>" + strSelection + "</u>"
	return;
}
function previewThis(from) {
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		document.fInputText.tTextEditor.focus()
		if (from == 2) document.fInputText.tTextEditor.select()
		strSelection = document.selection.createRange().text
		document.selection.createRange().text = strSelection + "<preview><preview>"
	}
	else document.selection.createRange().text = "<preview>" + strSelection + "<preview>"
	return;
}

function clearAll()
{
  var e = document.fUser.elements;
  for (var i=0; i < e.length; i++) 
    if (e[i].name == "msgid")
      e[i].checked = false;
}

function checkAll()
{
  var e = document.fUser.elements;
  for (var i=0; i < e.length; i++)
    if (e[i].name == "msgid")
      e[i].checked = true;
}

function validFile(filespec){
   var fso, s
   fso = new ActiveXObject("Scripting.FileSystemObject");
   s = fso.GetExtensionName(filespec);
   if (s != "txt") {
	alert("Incorrect File");
   }	

}

function checkRange(){
   if(fRumah.golongan.values > fRumah.golongan1.values) {
	alert('invalid range');
	return false;
   }
return true		
}


function PopUp(imgfile,imgname){
if((myImage.width!=0)&&(myImage.height!=0)){
		popup(imgfile,myImage.width,myImage.height,imgname);
	}
	else{
		funzione="PopUp('"+imgfile+"','"+imgname+"')";
		intervalo=setTimeout(funzione,20);
	}
}

function openImage(imgfile,imgname){
	myImage = new Image;
	myImage.src = imgfile;
	PopUp(imgfile,imgname);
}

function openUrl(url,items) {
	var go;
	go = items.list.value; 
	window.location.href= url +'?fid=' + go + '&method=open&module=forum';   
}


function simpleTag(tag) {
	strSelection = document.selection.createRange().text	
	
	if (tag=="img" || tag=="email" || tag=="url"){
		strSelection = document.selection.createRange().text
		document.fInputText.tTextEditor.focus()
		strPrompt = prompt("Enter the url or email address you want to link :","your value")
		if (strPrompt == null) return;	
			document.selection.createRange().text = "[" + tag + "=" + strPrompt + "]" + strSelection + "[/" + tag + "]"
			
	}else {	
		if (strSelection == "" && tag.length == 1) {		
			document.fInputText.tTextEditor.focus()		
			strSelection = document.selection.createRange().text
			document.selection.createRange().text = strSelection + "[" + tag +"][/"+ tag +"]"
		}	
		else document.selection.createRange().text = "[" + tag +"]" + strSelection + "[/" + tag +"]"		
	}
	return;
}


function emoticon(theSmilie)
{
	doInsert(" " + theSmilie + " ", "", false);
}

function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.fInputText.tTextEditor;
	var myAgent   = navigator.userAgent.toLowerCase();
	var myVersion = parseInt(navigator.appVersion);
	var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
	var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

	var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));

	if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
	{
		if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else{
			if(isSingle)
				isClose = true;
	
			obj_ta.value += ibTag;
		}
	}
	else
	{
		if(isSingle)
			isClose = true;

		obj_ta.value += ibTag;
	}

	obj_ta.focus();
	
	return isClose;
}	


function printPopUp(url,width,height,top,left){
	sHeight = screen.height;
	sWidth = screen.width
	var boxWidth, boxHeight, boxLeft, boxTop;
	boxWidth = width;
	boxHeight = height;
	boxLeft = (screen.width - boxWidth) / 2;
	boxTop = (screen.height - boxHeight) / 2;

	window.open(url,'_blank','height='+ boxHeight+',width=' + boxWidth + ',top=' + boxTop + ',left=' + boxLeft + ',toolbars=0,statusbar=0,scrollbars=1,resizable=1',false); 
		
}

