<!--

var B_open = 0;
var I_open = 0;
var U_open = 0;
var QUOTE_open = 0;
var CODE_open = 0;
var HTML_open = 0;

var bbtags   = new Array();

var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_opera = (myAgent.indexOf("opera") != -1);
var is_ie   = ((myAgent.indexOf("msie") != -1)  && (is_opera==false));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (is_opera==false)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac    = (myAgent.indexOf("mac")!=-1);



function stacksize(thearray) {
    for (i = 0 ; i < thearray.length; i++ ) {
        if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') ) {
            return i;
        }
    }
    return thearray.length;
}

function pushstack(thearray, newval) {
    arraysize = stacksize(thearray);
    thearray[arraysize] = newval;
}

function popstack(thearray) {
    arraysize = stacksize(thearray);
    theval = thearray[arraysize - 1];
    delete thearray[arraysize - 1];
    return theval;
}

function closeall() {
    if (bbtags[0]) {
        while (bbtags[0]) {
            tagRemove = popstack(bbtags)
            document.editor.ta.value += "[/" + tagRemove + "]";
            if ( (tagRemove != 'FONT') && (tagRemove != 'SIZE') && (tagRemove != 'COLOR') ) { 
                eval("document.editor." + tagRemove + ".value = ' " + tagRemove + " '");
                eval(tagRemove + "_open = 0");
            }
        }
    }
    document.editor.tagcount.value = 0;
    bbtags = new Array();
    document.editor.ta.focus();
}


function add_code(NewCode) {
    document.editor.ta.value += NewCode;
    document.editor.ta.focus();
}

function alterfont(theval, thetag) {
    if (theval == 0)
        return;
    if(doInsert("[" + thetag + "=" + theval + "]", "[/" + thetag + "]", true))
        pushstack(bbtags, thetag);
    document.editor.ffont.selectedIndex  = 0;
    document.editor.fsize.selectedIndex  = 0;
    document.editor.fcolor.selectedIndex = 0;
}

function simpletag(thetag) {
    var tagOpen = eval(thetag + "_open");

    if (tagOpen == 0) {
        if(doInsert("[" + thetag + "]", "[/" + thetag + "]", true))
        {
            eval(thetag + "_open = 1");
            eval("document.editor." + thetag + ".value += '*'");

            pushstack(bbtags, thetag);
        }
    }
    else {
        // Find the last occurance of the opened tag
        lastindex = 0;

        for (i = 0 ; i < bbtags.length; i++ )
        {
            if ( bbtags[i] == thetag )
            {
                lastindex = i;
            }
        }

        // Close all tags opened up to that tag was opened
        while (bbtags[lastindex])
        {
            tagRemove = popstack(bbtags);
            doInsert("[/" + tagRemove + "]", "", false)


            if ( (tagRemove != 'FONT') && (tagRemove != 'SIZE') && (tagRemove != 'COLOR') ) {
                eval("document.editor." + tagRemove + ".value = ' " + tagRemove + " '");
                eval(tagRemove + "_open = 0");
            }
        }
    }
}


function tag_list() {
    var listvalue = "init";
    var thelist = "";
    while ( (listvalue != "") && (listvalue != null) ) {
        listvalue = prompt(list_prompt, "");
        if ( (listvalue != "") && (listvalue != null) ) {
            thelist = thelist+"[*]"+listvalue+"\n";
        }
    }
    if ( thelist != "" ) {
        doInsert( "[LIST]\n" + thelist + "[/LIST]\n", "", false);
    }
}

function tag_url() {
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_url, "http://");
    var enterTITLE = prompt(text_enter_url_name, "My Webpage");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (!enterTITLE) {
        FoundErrors += " " + error_no_title;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    doInsert("[URL="+enterURL+"]"+enterTITLE+"[/URL]", "", false);
}


function tag_image() {
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_image, "http://");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    doInsert("[IMG]"+enterURL+"[/IMG]", "", false);
}

function tag_email() {
    var emailAddress = prompt(text_enter_email, "");
    if (!emailAddress) {
        alert(error_no_email);
        return;
    }
    doInsert("[EMAIL]"+emailAddress+"[/EMAIL]", "", false);
}

function doInsert(ibTag, ibClsTag, isSingle) {
    var isClose = false;
    var obj_ta = document.editor.ta;
    // Ensure it works for IE4up / Win only
    if ((myVersion >= 4) && is_ie && is_win) {
        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.collapse;
            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 {
        // this should work with Mozillas
        if ( (myVersion >= 4) && is_win && !is_opera) {
            var length = obj_ta.textLength;
            var start = obj_ta.selectionStart;
            var end = obj_ta.selectionEnd;
            var head = obj_ta.value.substring(0,start);
            var rng = obj_ta.value.substring(start, end);
            var tail = obj_ta.value.substring(end, length);
            if( start != end ){
                if (ibClsTag != "" && length > 0)
                    ibTag += rng + ibClsTag;
                else if (isSingle)
                    isClose = true;
                rng = ibTag;
                obj_ta.value = head + rng + tail;
                start = start + rng.length;
            }
            else{
                if(isSingle)
                    isClose = true;
                obj_ta.value = head + ibTag + tail;
                start = start + ibTag.length;
            }
            obj_ta.selectionStart = start;
            obj_ta.selectionEnd = start;
        }
        else {
            if(isSingle)
                isClose = true;
            obj_ta.value += ibTag;
        }
    }
    obj_ta.focus();
    return isClose;
}

function getObj(name)
{
  if (document.getElementById)
  {
    if(document.getElementById(name))
      return document.getElementById(name);
    else
      return false;
  }
  else if (document.all)
  {
	if (document.all[name])
      return document.all[name];
    else
      return false;
  }
  else if (document.layers)
  {
    if (document.layers[name])
      return document.layers[name];
    else
      return false;
  }
}

function makeRequest(url,id) {
	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				http_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function()
    {
      if (http_request.readyState == 4 && http_request.status == 200)
      {
      	document.body.style.cursor = 'auto';
      	getObj(id).innerHTML = http_request.responseText;
      }
    }
	http_request.open('POST', 'index.php?ind=ajax&cach='+Math.floor(89999999*Math.random()+10000000), true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", url.length);
    http_request.setRequestHeader("Connection", "close");
	http_request.send(url);
}

function sendPost(id) {
	var bid = 'b'+id;
	document.body.style.cursor = 'wait';
	getObj(id).style.display = '';
	getObj(bid).innerHTML = 'wiat';
	var sendpost = "mod=trans&lang=" + encodeURI(getObj("lang").value ) + "&text=" + encodeURI(getObj("trans").value);
	makeRequest(sendpost,id);
}

function weather(id, c) {
if (getObj("code").value == "none") return false;
	document.body.style.cursor = 'wait';
	getObj(id).style.display = '';
	getObj(id).innerHTML = '<p class="ajax"><img src="vb/images/misc/progress.gif" alt="" /> ÇáÑÌÇÁ ÇáÅäÊÙÇÑ</p>';
	var weather = "mod=weather&code=" + getObj("code").value;
	makeRequest(weather, id);
}

function Sweather() {
	document.body.style.cursor = 'wait';
	getObj("weather").style.display = '';
	getObj("weather").innerHTML = '<p class="ajax"><img src="vb/images/misc/progress.gif" alt="" /> ÇáÑÌÇÁ ÇáÅäÊÙÇÑ</p>';
	var sweather = "mod=weather&code=MECA";
	makeRequest(sweather, "weather");
}
function Translate() {
	document.body.style.cursor = 'wait';
	getObj("result").style.display = '';
	getObj("result").innerHTML = '<p class="ajax"><img src="vb/images/misc/progress.gif" alt="" /> ÇáÑÌÇÁ ÇáÅäÊÙÇÑ</p>';
    var trans = "mod=trans&lang=" + encodeURI(getObj("lang").value) + "&text=" + encodeURI(getObj("text").value);
	makeRequest(trans, "result");
}
function Gsthread(f) {
	if (!f) m = 'mod=newthread&forum=';
	else m = 'mod=newthread&forum=' + f;
	document.body.style.cursor = 'wait';
	getObj('t1').innerHTML = '<p class="ajax"><img src="vb/images/misc/progress.gif" alt="" /> ÇáÑÌÇÁ ÇáÅäÊÙÇÑ</p>';
	makeRequest(m,'t1');
}
function archive(a){
	if(getObj(a).style.display == "none"){
		getObj(a).style.display = '';
	}else{
		getObj(a).style.display = 'none';
	}
}
function Textdir() {if (getObj('lang').value == 'ar|en') {getObj('text').dir="rtl"} else {getObj('text').dir="ltr"}}
function sure(m){if(confirm(m)){return true}else{return false}}
function selChd(d) {if (getObj("d").value == "none") return false;location.href='index.php?ind=site&op=submit_file1=' + getObj("d").value;}
function sel(d){var idx = d.selectedIndex;var sel = d.options[idx].value;if (sel == "none") return false;location.href='index.php?ind=site&op=add2&evento='+sel;}
function copysel(a){obj=getObj(a).createTextRange();obj.select();obj.execCommand('copy')}
function favorite(){var url = window.location;var title = document.title;if (window.sidebar)window.sidebar.addPanel(title, url, "");else if(window.opera && window.print){var elem = document.createElement('a');elem.setAttribute('href',url);elem.setAttribute('title',title);elem.setAttribute('rel','sidebar');elem.click();}else if(document.all)window.external.AddFavorite(url, title);}

//-->
