SITEURL = "http://"+window.location.hostname;

// BASIC AJAX HANDLER
function GetXmlHttpObject(handler){ 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0){
		xmlHttp=new XMLHttpRequest();
		xmlHttp.onload=handler
		xmlHttp.onerror=handler
		return xmlHttp;
	}
	if (navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP"
		} try	{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} catch(e) { 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}

function insertquote(code) {
	
	 var textarea = document.getElementById("frm_comment");
	 var scrollPos = textarea.scrollTop;
	 var open = "[quote]";
    // our close tag
   var close = "[/quote]";
	 
	 var text = open+code+close;
 
	    if(document.selection) { 
	        textarea.focus(); 
	        var orig = textarea.value.replace(/\r\n/g, "\n"); 
	        var range = document.selection.createRange(); 
	 
	        if(range.parentElement() != textarea) { 
	            return false; 
	        } 
	 
	        range.text = text; 
	         
	        var actual = tmp = textarea.value.replace(/\r\n/g, "\n"); 
 
	        for(var diff = 0; diff < orig.length; diff++) { 
	            if(orig.charAt(diff) != actual.charAt(diff)) break; 
	        } 
	 
	        for(var index = 0, start = 0;  
	            tmp.match(text)  
	                && (tmp = tmp.replace(text, ""))  
	                && index <= diff;  
	            index = start + text.length 
	        ) { 
	            start = actual.indexOf(text, index); 
	        } 
	    } 
			else if(textarea.selectionStart) { 
	        var start = textarea.selectionStart; 
	        var end   = textarea.selectionEnd; 
	 
	        textarea.value = textarea.value.substr(0, start)  
	            + text  
	            + textarea.value.substr(end, textarea.value.length); 
	    } 
	     
    if(start != null) { 
	       setCaretTo(textarea, start + text.length); 
	  } 
		else { 
	     textarea.value += text; 
	  }
		var textarea = document.getElementById("frm_comment");
		caretPos(textarea,scrollPos);
		parent.location='#LastComment';		
} 
function caretPos(textEl,scrollPos) {
	var i=textEl.value.length+1;
	if (!textEl.setSelectionRange){
		theCaret = document.selection.createRange().duplicate();
			while (theCaret.parentElement()==textEl && 
theCaret.move("character",1)==1) --i;
			return i;
	}
	else {
		textEl.focus();
		//var scrollPos = textEl.scrollTop;
		textEl.scrollTop = scrollPos;
	}
	return -1;
}
	
	
function insertcode(tag,text_field) {
	// our textfiaseeld
	var textarea = document.getElementById(text_field);
	var scrollPos = textarea.scrollTop;
 // our open tag
	var open = "[" + tag + "]";
	// our close tag
	var close = "[/" + tag + "]";
	if(!textarea.setSelectionRange) {
		var selected="";
		if (window.getSelection) {
			selected = window.getSelection();
		}
		else if (document.getSelection) {
			selected = document.getSelection();
		}
		else if (document.selection) {
			selected = document.selection.createRange().text;
			
		}

		if(selected.length <= 0)    {
				// no text was selected so prompt the user for some text
				textarea.value += open + close;
		}
		else {
				// put the code around the selected text
			var text_box_text=document.getElementById(text_field).value;
			if(selected!=null)
			{
					if(text_box_text.indexOf(selected)!=-1)
					{	    
						document.selection.createRange().text = open + selected + close;		 
					}
			}
		}
	}
	else {
			// the text before the selection
			var pretext = textarea.value.substring(0, textarea.selectionStart);
			// the selected text with tags before and after
			var codetext = open + textarea.value.substring(textarea.selectionStart, textarea.selectionEnd) + close;
			// the text after the selection
			var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
			// check if there was a selection
			if(codetext == open + close) {
					//prompt the user
					codetext = open + close;
			}
			// update the text field
			textarea.value = pretext + codetext + posttext;
	}
	// set the focus on the text field

	var textarea = document.getElementById(text_field);
	caretPos(textarea,scrollPos);
	textarea.focus();
}




// inserts a link by prompting the user for a url
function insertlink(text_field)
{
	// our textfield
	var textarea = document.getElementById(text_field);
	var scrollPos = textarea.scrollTop;
 // our open tag
	if(!textarea.setSelectionRange) {
			//var selected = document.selection.createRange().text;
	 var selected="";
	 if (window.getSelection){
			selected = window.getSelection();
	 }
	 else if (document.getSelection) {
			selected = document.getSelection();
	 }
	 else if (document.selection) {
			selected = document.selection.createRange().text;
	 }

	 if(selected.length <= 0){
			// no text was selected so prompt the user for some text
			var url = prompt("Please enter the url", "http://");
			var open = "[link=" + url + "]";
			// our close tag
			var close = "[/link]";
			textarea.value += open + close;
		}
		else {
			var text_box_text=document.getElementById('frm_comment').value;
			if(selected!=null) {
				if(text_box_text.indexOf(selected)!=-1) {	    
					// put the code around the selected text
					var url = prompt("Please enter the url", "http://");
					var open = "[link=" + url + "]";
					// our close tag
					var close = "[/link]";
				
				
					document.selection.createRange().text = open + selected + close;
				}
			}
		}
	}
	else { 
		var url = prompt("Please enter the url", "http://");
    var open = "[link=" + url + "]";
		var close = "[/link]";
		// the text before the selection
		var pretext = textarea.value.substring(0, textarea.selectionStart);
		// the selected text with tags before and after
		var codetext = open + textarea.value.substring(textarea.selectionStart, textarea.selectionEnd) + close;
		// the text after the selection
		var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
		// check if there was a selection
		if(codetext == open + close) {
				//prompt the user
				codetext = open + close;
		}
		// update the text field
		textarea.value = pretext + codetext + posttext;
	}
	var textarea = document.getElementById(text_field);
	caretPos(textarea,scrollPos);
	// set the focus on the text field
	textarea.focus();
}

var cssmenuids=["menu"] //Enter id(s) of CSS Horizontal UL menus, separated by commas
var csssubmenuoffset=-1 //Offset of submenus from main menu. Default is 0 pixels.

function createcssmenu2(){
		//alert("menu2");
for (var i=0; i<cssmenuids.length; i++){
  var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
    	var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			spanref.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;"
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
    	ultags[t].parentNode.onmouseover=function(){
					this.style.zIndex=100
    	this.getElementsByTagName("ul")[0].style.visibility="visible"
					this.getElementsByTagName("ul")[0].style.zIndex=0
    	}
    	ultags[t].parentNode.onmouseout=function(){
					this.style.zIndex=0
					this.getElementsByTagName("ul")[0].style.visibility="hidden"
					this.getElementsByTagName("ul")[0].style.zIndex=100
    	}
    }
  }
	//alert("menu");
}




