// 	/root/js/forum.js
	
// 	Updated : 31 January 2007
//	Author : Richard Adams
//		 (function emoticon is adapted from phpBB)

var blockmsg = "This function is currently unavailable to you.";
var blockThreadmsg ="This thread is closed. No further posts will be accepted.";

function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.forms['post'].message.createTextRange && document.forms['post'].message.caretPos) {
		var caretPos = document.forms['post'].message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.forms['post'].message.focus();
	} else {
		document.forms['post'].message.value  += text;
		document.forms['post'].message.focus();
	}
	hideEmoticons();
}

function showEmoticons() {
	obj = document.getElementById("emoticons");
	
	if (obj.style.display == "block") {
		hideEmoticons();
	} else {
		obj.style.display = "block";
	}
}

function hideEmoticons() {
	obj = document.getElementById("emoticons");
	
	obj.style.display = "none";
}

function updateSending(value) {
	obj = document.getElementById("sending");

	obj.innerHTML = "Sending to : " + value;
}

function validateProfile() {

		return true;

}
function validateGallery() {
	gt = document.getElementById("gallery_teaser");
	
	if (gt.value == "") {
		alert("Please add a title to your story.");
		return false;
	} else {
		return true;
	}
}

function validateUpload() {
	obj = document.getElementById("member_avatar_upload");
	
	if (obj.value == "") {
		alert("You have not selected a file to upload.");
		return false;
	} else {
		return checkFileType();
		//return true;
	}
}

function checkFileType () {
	  ext = document.getElementById("member_avatar_upload").value;
	  ext = ext.substring(ext.length-3, ext.length);
	  ext = ext.toLowerCase();
	  if((ext != 'jpg') && (ext != 'gif')) {
		 alert('You selected a .'+ext+' file, please select a .jpg or .gif file instead.');
	 	 return false; 
	  } else {
   	 	 return true; 
	  }
}

function showMoreInfo() {
	obj = document.getElementById("moreinfo");
	
	if (obj.style.display == "block") {
		hideMoreInfo();
	} else {
		obj.style.display = "block";
	}
}

function hideMoreInfo() {
	obj = document.getElementById("moreinfo");
	
	obj.style.display = "none";
}

function showCaption(id) {
	obj = document.getElementById("avatarcaption");
	
	if (obj.style.display == "block") {
		hideCaption();
	} else {
		obj.style.display = "block";
	}
	
	if (id == 1) {
		obj.style.top = "260px";
	} else if (id == 2) {
		obj.style.top = "410px";
	} else if (id == 3) {
		obj.style.top = "560px";
	}

	obj2 = document.getElementById("caption_pid");
	obj2.value = id;
}

function hideCaption() {
	obj = document.getElementById("avatarcaption");
	
	obj.style.display = "none";
}


function showRemoveDialog(info, link_url)
{
	// Show the div
	obj = document.getElementById("removeDialog");
	obj.style.display = "block";
	
	// Show the title
	info_obj = document.getElementById("info");
	info_obj.innerHTML = info;
	
	// Setup the link.
	link = document.getElementById("removeLink");
	link.href = link_url;
	
	return false;
}

function hideRemoveDialog()
{
	obj = document.getElementById("removeDialog");
	obj.style.display = "none";
}

function nu_create_window(w,h,url)
{

var options = "width=" + w + ",height=" + h + ",resizable=no";
var new_window = window.open(url, "new_window", options);

}

function popup(theURL,winName,width,height,features) {
  
var window_width = width;
var window_height = height;
var newfeatures= features;
var window_top = (screen.height-window_height)/2;
var window_left = (screen.width-window_width)/2;
newWindow=window.open(''+ theURL + '',winName,'width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',' + newfeatures + '');
newWindow.focus();
}

var validNums = '0123456789.';
var validInt = '0123456789';
var validLetters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

function nu_validateKeyPress(e, validSet)
{
    var key;
    var keychar;
    //alert(e.keyCode);
    if(window.event || !e.which) // IE
        key = e.keyCode; // IE
    else if(e)
        key = e.which;   // Netscape
    else
        return true;     // no validation
     if(key<32 || key == 37 || key==46 || key==39)
        return true;
    keychar = String.fromCharCode(key);
    validSet += String.fromCharCode(8);
    var ind = validSet.indexOf(keychar);
    if (validSet.indexOf(keychar) < 0)
      return false;

    return true;
}

        function highlightSearch(search)
        {
                // Split into words
                arrSearch = search.split(" ");

                // Make sure we can find the text of the body
                if (!document.body || typeof(document.body.innerHTML) == "undefined")
                {
                        return false;
                }

                //var body = document.body.innerHTML;
                var body = document.getElementById("mainBox").innerHTML;
                for (var i = 0; i < arrSearch.length; i++) {
                        body = highlight(body, arrSearch[i]);
                }

                document.getElementById("mainBox").innerHTML = body;
                //document.body.innerHTML = body;
                return true;
        }

        function highlight(body, search)
        {
                start = "<span style='color: #f00; background-color: #ff0; font-size: 15px; padding: 2px;'>";
                end   = "</span>";

                var i       = -1;
                var bodyL   = body.toLowerCase();
                var searchL = search.toLowerCase();
                var newBody = "";

                while (body.length > 0)
                {
                        i = bodyL.indexOf(searchL, i+1);
                        if (i < 0)
                        {
                                newBody += body;
                                body = "";
                        }
                        else
                        {
                                // Skip out HTML
                                if (body.lastIndexOf(">",i) >= body.lastIndexOf("<", i))
                                {
                                        // and JS
                                        if (bodyL.lastIndexOf("/script>", i) >= bodyL.lastIndexOf("<script", i))
                                        {
                                                newBody += body.substring(0, i) + start + body.substr(i, search.length) + end;
                                                body	 = body.substr(i + search.length);
                                                bodyL 	 = body.toLowerCase();
                                                i	 = -1;
                                        }
                                }
                        }
                }

                return newBody;
        }
//delete pm
function SubmitForm(){

	var SelectedEmail = document.selectemails.emailid;

	isSelected = -1;
	if(SelectedEmail.length)
	{
		for (i=0; i<SelectedEmail.length; i++) {
			if (SelectedEmail[i].checked) {
				isSelected = 1;
			}
		}

		if(isSelected > -1){
			var dm = confirm ("Are you sure you want to delete the selected messages?");
			if(dm==true){
				return true;
			}
			else{return false;}
		}

		else{
			alert("You have not selected any messages to delete.")
			return false;
		}

	}
}

function Reply(){
	r = document.getElementById('showReply').style;
 	r.display='block'
}
