/* *******************************************************
Software: Web Wiz Forums
Info: http://www.webwizforums.com
Copyright: ©2001-2007 Web Wiz. All rights reserved
******************************************************* */

//function to change page from option list
function linkURL(URL) {
	if (URL.options[URL.selectedIndex].value != "") self.location.href = URL.options[URL.selectedIndex].value;
	return true;
}

//function to open pop up window
function winOpener(theURL, winName, scrollbars, resizable, width, height) {

	winFeatures = 'left=' + (screen.availWidth-10-width)/2 + ',top=' + (screen.availHeight-30-height)/2 + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height + ',toolbar=0,location=0,status=1,menubar=0'
  	window.open(theURL, winName, winFeatures);
}

//Show drop down
function showDropDown(parentEle, dropDownEle, dropDownWidth, offSetRight){

	parentElement = document.getElementById(parentEle);
	dropDownElement = document.getElementById(dropDownEle)

	//position
	dropDownElement.style.left = (getOffsetLeft(parentElement) - offSetRight) + 'px';
	dropDownElement.style.top = (getOffsetTop(parentElement) + parentElement.offsetHeight + 3) + 'px';

	//width
	dropDownElement.style.width = dropDownWidth + 'px';

	//display
	hideDropDown();
	dropDownElement.style.visibility = 'visible';


	//Event Listener to hide drop down
	if(document.addEventListener){ // Mozilla, Netscape, Firefox
		document.addEventListener('mouseup', hideDropDown, false);
	} else { // IE
		document.onmouseup = hideDropDown;
	}
}

//Hide drop downs
function hideDropDown(){
	hide('div');
	hide('iframe');
	function hide(tag){
		var classElements = new Array();
		var els = document.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)dropDown(.*\)');

		for (i = 0, j = 0; i < elsLen; i++){
			if (pattern.test(els[i].className)){
				els[i].style.visibility='hidden';
				j++;
			}
		}
	}
}


//Top offset
function getOffsetTop(elm){
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

//Left offset
function getOffsetLeft(elm){
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

//AJAX
var xmlHttp;
var xmlHttpResponseID;

//create XMLHttpRequest object
function createXMLHttpRequest(){
	if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		if (! xmlHttp){
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
}

//XMLHttpRequest event handler
function XMLHttpResponse(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState=='complete'){
		if (xmlHttp.status == 200){
			xmlHttpResponseID.innerHTML = xmlHttp.responseText;
		}else {
			xmlHttpResponseID.innerHTML = '<strong>Error connecting to server</strong>';
		}

	}
}

//Get AJAX data
function getAjaxData(url, elementID){
	xmlHttpResponseID = document.getElementById(elementID);
	xmlHttpResponseID.innerHTML = '<strong>Loading...</strong>';
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = XMLHttpResponse;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function ShowMySubMenu(menuID){
        var menuDivID = '';
        document.getElementById('AboutUsMenuDiv').style.display='none';
        document.getElementById('NewsMenuDiv').style.display='none';
        document.getElementById('SadnaotMenuDiv').style.display='none';
        document.getElementById('forumsMenuDiv').style.display='none';
        if(menuID=='AboutUs')
        {
            menuDivID = 'AboutUsMenuDiv';
        }
        else
        {
            if(menuID=='News'){
                HideBigTable();
                menuDivID = 'NewsMenuDiv';
            }
            if(menuID=='Sadnaot'){
                HideBigTable();
                menuDivID = 'SadnaotMenuDiv';
            }
            if(menuID=='forums')
            {
                HideBigTable();
                menuDivID = 'forumsMenuDiv';                
            }
        }
        
        if(document.getElementById(menuDivID))
        {
            if(document.getElementById(menuDivID).style.display=='none')
            {
                document.getElementById(menuDivID).style.display='';
            }
            else
            {
                document.getElementById(menuDivID).style.display='none';
            }
        }
    }
    function HideBigTable(){
        if(document.getElementById('subCatTable'))
        {
            if(document.getElementById('subCatTable').style.display=='none')
            {
                document.getElementById('subCatTable').style.display='';
            }
            else
            {
                document.getElementById('subCatTable').style.display='none';
            }
        }
    }
    
function doClientSearch(txtBox)
{
    if(document.getElementById(txtBox))
    {
        var srchTerm = document.getElementById(txtBox).value
        window.location = '../SearchResults.aspx?' + escape(srchTerm);
    }
}
function checkSearchField(elemID)
{
    var oObj = document.getElementById(elemID);
    if(oObj)
    {
        var s = oObj.value;
        if(s)
        {
            s = s.replace('Please type here the word you wish to find.', '');
            oObj.value = s;
			doClientSearch(elemID);
        } else
		{
			oObj.value = 'Please type here the word you wish to find.';
			
		}
    }
    
}