//---------------------------
function navigationLeftClick(divs, navID)
//---------------------------
{
	var sElementLinkID = 'aLink'
	var sElementLIID = 'lilinks'
		
	//Hide them all - Lives in JSMenu.ascx
	hideJSMenu();
	
	var arrDivs = divs.split(",");
	for (var i=0; i <= arrDivs.length - 1 ;i++) {
	    //Make the DIVs on
	    var dv = document.getElementById(arrDivs[i]);
	    if (dv != null) dv.className = "disOn"; 
	}
	
	//Make the LI on
	var li = document.getElementById(sElementLIID + navID)
    if (li != null) li.className = "active"; 
}

//---------------------------
function openImageWindow(height, width, url, resize, title)
//---------------------------
{
    var features = 'height=' + height + ',width=' + width + ",left=" + left + ",top=" + top;
	var left = (window.screen.width - width) / 2;
	var top = (window.screen.height - height) / 2;
	    
	var sContent = '<html><head><title>'+title+'</title><link rel="stylesheet" href="/static/css/style.css" type="text/css" /></head><body>';
		sContent += '<img src="'+url+'" border="0" alt="'+ title +'" title="'+ title +'" />';
		sContent += '<div class="toolbox top"><a href="javascript:window.close();"><img width="100" border="0" title="Close Window" src="/upload/images/buttons/close_sm_off.gif"></a></div>';
	sContent += "</body></html>";

	var w = window.open('',title,features);
	wdoc = w.document;
	wdoc.open();
	wdoc.write(sContent) ;
	wdoc.close();
}


//---------------------------
function openWindow(height, width, url, resize)
//---------------------------
{
	var left = (window.screen.width - width) / 2;
	var top = (window.screen.height - height) / 2;
	var features = 'height=' + height + ',width=' + width + ",left=" + left + ",top=" + top;
	
	if (resize == true) {
	    features = features + ",resizable=yes";
	}
	
	winPopup = window.open(url,"",features);
	winPopup.document.write(sContent);
	winPopup.focus();
}


//---------------------------
function isValidEmail(str) {
//---------------------------
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//---------------------------------
function swapImage(me, image){
//---------------------------------
	me.src = image;
}

//---------------------------------
function MM_preloadImages() { //v3.0
//---------------------------------
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//---------------------------------
function MM_swapImgRestore() { //v3.0
//---------------------------------
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//---------------------------------
function MM_findObj(n, d) { //v4.01
//---------------------------------
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//---------------------------------
function MM_swapImage() { //v3.0
//---------------------------------
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//---------------------------------
function PreviousImage(value, id, count) {
//---------------------------------
	ResetImages(id, count)
	curImage = curImage - 1;
	
	if (curImage < 1) curImage = count;
	var imgID = id + curImage;
	document.getElementById(imgID).className='disOn';
}

//---------------------------------
function NextImage(value, id, count) {
//---------------------------------
	ResetImages(id, count)
	curImage = curImage + 1;
	
	if (curImage > count) curImage = 1;
	var imgID = id + curImage;
	    var image = document.getElementById(imgID);
	    if (image == null) return false;
		image.className='disOn';
}

//---------------------------------
function SelectImage(value, id, count) {
//---------------------------------
	ResetImages(id, count)
	curImage = value;
	
	if (curImage > count) return false;
	var imgID = id + curImage;
	
	var image = document.getElementById(imgID);
	if (image == null) return false;
	document.getElementById(imgID).className='disOn';
}

//---------------------------------
function ResetImages(id, count) {
//---------------------------------
	for (var i = 1; i<=count; i++){
		var imgID = id + i;
	    var image = document.getElementById(imgID);
	    if (image == null) return false;
		image.className='disOff';
	}
}

//---------------------------------
function vote(url, radioName, pollID) {
//---------------------------------
    if (url != ''){ 
        var voteValue = "";
        
        var e = document.getElementsByName(radioName);
        
        if (e == null){
            alert('There are no questions for this poll');
            return false;
        }
        
        for(var i=0; i<e.length; i++){
            //Get the radio Button
            cv = getCheckedValue(e);

            if (cv == '') {
            }else{
                voteValue = "?rdPoll=" + cv;
            }
        }
        var target  = url + voteValue
        window.location = target;
    }else{
        alert('Poll does not link anywhere');
    }
}

//---------------------------
function displayHiddenDiv(id, to, elementID){
//---------------------------
	var sDivID = elementID
	var sLIID = elementID
	var oElement = ""

	//Clear Results first
	for (var i=0; i<=to; i++){
		var sElementID = elementID + (i + 1);
		//alert(sElementID);
        var divElement = document.getElementById(sElementID);
        
        if (divElement != null){
		    divElement.className = 'disOff';
		}
	}	

    //alert("Show:" +elementID + id);
    var sDiv = elementID + id;
    var divShowElement = document.getElementById(sDiv);
	if (divShowElement != null){
	    divShowElement.className = 'disOn';
	}
}

//---------------------------------
function getCheckedValue(radioObj) {
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
//---------------------------------
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//---------------------------------
function KeyDownHandler(btn) {
//---------------------------------
     // process only the Enter key     
     if (event.keyCode == 13){
        
        // cancel the default submit 
        event.returnValue = false;        
        event.cancel = true;   
        var obj = document.getElementById(btn);   
        obj.click();
    }
}

//---------------------------------
        function AdjustHeight() {
//---------------------------------     

            // Change the height of the h3 tag if more than one line text
            var panelBoxes = document.getElementById('panelBoxes');
            if(panelBoxes != null)
            {
                var panelHeader = panelBoxes.getElementsByTagName('h3');

                if(panelHeader != null)
                {
                    var maximumHeight = 0;
                    var height = 0;            
                    for(i=0; i< panelHeader.length; i++)
                    {
                        height = panelHeader[i].offsetHeight;
                        if(maximumHeight < height)
                        {
                            maximumHeight = height;
                        }
                    }
                    for(i=0; i< panelHeader.length; i++)
                    {               
                        panelHeader[i].style.height = maximumHeight + "px";
                    }                                                    
                }
            }
        }
        window.onload = AdjustHeight;
