var statusText = '';
var statusCount = 0;
var selectedAll = false;

//Function to add the code to the message for the smileys
function addEmo(emoType) {

        var txtarea = document.getElementById('message');
        emoType = '' + emoType + '';
        if (txtarea.createTextRange && txtarea.caretPos) {
                var caretPos = txtarea.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? emoType + ' ' : emoType;
                txtarea.focus();
        } else {
                txtarea.value  += emoType;
                txtarea.focus();
        }


}


function addEmoImage(){
        var ImgUrl= prompt("Enter address of image:", "http://");
        if (ImgUrl != null && ImgUrl != "" && ImgUrl != "null"){
                var imgtext = '[img]' + ImgUrl + '[/img]';


                var txtarea = document.getElementById('message');
                if (txtarea.createTextRange && txtarea.caretPos) {
                        var caretPos = txtarea.caretPos;
                        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? imgtext + ' ' : imgtext;
                        txtarea.focus();
                } else {
                        txtarea.value  += imgtext;
                        txtarea.focus();
                }
        }



}

function addEmoLinky(){
        var sUrl= prompt("Enter your URL:", "http://");
        if (sUrl != null && sUrl != "" && sUrl != "null"){
                var linktext = '[url]' + sUrl + '[/url]';

                var txtarea = document.getElementById('message');
                if (txtarea.createTextRange && txtarea.caretPos) {
                        var caretPos = txtarea.caretPos;
                        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? linktext + ' ' : linktext;
                        txtarea.focus();
                } else {
                        txtarea.value  += linktext;
                        txtarea.focus();
                }

        }
}

function goUrl(myUrl){
        window.location.href=myUrl;
}

function PopUpWindow(mypage, myname, w, h, scroll) {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,status=yes'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function openViewAllEmos()
{
        PopUpWindow('vallemos.php', 'AllEmoticons', 350, 240, 'yes');
}

function defStatus(sText){
        defaultStatus = ' ';
        statusText = sText;
        setTimeout('blinkStatus();',200);
}

function blinkStatus(){
        if(defaultStatus == ' '){
                defaultStatus = statusText;
        }else{
                defaultStatus = ' ';
        }

        statusCount = statusCount + 1;

        if(statusCount > 20){
                setTimeout('resetStatus();',1000);
                statusCount = 0;
        }else{
                setTimeout('blinkStatus();',400);
        }
}

function resetStatus(){
        defaultStatus='Done - ' + statusText + ' -';
}

function getSigValue(sText)
{
        sTextTwo = '';
        sTextTwo = sText.split('\n').join('[sigBr]');
        return sTextTwo;
}

function enableSaveButton(fields,savebuttonname)
{
        // split array
        myFields = fields.split(";");
        var x=0;
        bEnable = true;
        for(x=0;x<myFields.length;x++)
        {
                oField = document.getElementById(myFields[x]);
                if(oField.type == 'checkbox')
                {
                        if(oField.checked == false)
                        {
                                bEnable = false;
                        }
                }
                else
                {
                        if(oField.value == '')
                        {
                                bEnable = false;
                        }
                }
        }

        if(bEnable)
        {
                oSubmit = document.getElementById(savebuttonname);
                oSubmit.disabled = false;
        }
        else
        {
                oSubmit = document.getElementById(savebuttonname);
                oSubmit.disabled = true;
        }
        return true;
}

function createCaret(cursorPos) {
         if (cursorPos.createTextRange) cursorPos.caretPos = document.selection.createRange().duplicate();
}


function CheckAllAT() {
  for (var i = 0; i < document.markidsasread.elements.length; i++) {
    if(document.markidsasread.elements[i].type == 'checkbox'){
      document.markidsasread.elements[i].checked =         !(document.markidsasread.elements[i].checked);
    }
  }
}
function CheckAllPM_old() {
	delpms = document.getElementsByName('delpmids');
  for (var i = 0; i < delpms; i++) {
    if(delpms[i].type == 'checkbox'){
      delpms[i].checked =         !(delpms[i].checked);
    }
  }
}


function CheckAllPM(){
	//var checkall=document.getElementById("checkall");
	var checks=document.getElementsByTagName("input");
	//var ischecked=checkall.checked;
	for(var i=0;i<checks.length;i++){
		//alert(checks[i].type);
		if(checks[i].type == 'checkbox'){
			checks[i].checked=!(checks[i].checked);
		}
	}
}