/* ----------------------------------------------------------------------------------------
File Name: General_Functions.js

	This file handles general functions.
 ----------------------------------------------------------------------------------------*/
var _gGroup = 0;
var first_time2 = true;
var last_item	= "";
//var printObj;
function openLink(url)
{
	popUpWin = open(url, 'popUpWin');
	popUpWin.focus();
}
function popUpWindow(URLStr, left, top, width, height)
{
	var popUpWin=0;
	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus();
}

function limit(El)
{
	if(El.value.length >= 40)
		El.value = El.value.substring(0,40);
}

//--------------------------------------------------------------------------------

function GroupIt(El)
{
	if (El.state !== "down")
	{
		if(first_time2)
		{
			last_item = El.id;
			first_time2 = false;
		}
		else
		{
			if(document.getElementById(last_item))
			{
				document.getElementById(last_item).state = "";
				document.getElementById(last_item).style.cursor = "hand";
				document.getElementById(last_item).src =  "images/" + last_item + "_normal.gif";
			}
			last_item = El.id;
		}
				
		El.style.cursor = "normal";
		El.src = "images/" + El.id + "_over" + ".gif";
		El.state = "down";
	}
} 
function OverIt(El)
{
	if (El.state !== "down")
	{
		El.src = "images/" + El.id + "_over" + ".gif";
		El.state = "over";
	}	
}
function OutIt(El)
{
	if (El.state == "over")
	{
		El.state = "";
		El.src = "images/" + El.id + "_normal" + ".gif";
	}	
	else if (El.state !== "over" && El.state !== "down")
			El.src = "images/" + El.id+ "_normal" + ".gif";
}

function PrintData(type)
{
	/*switch(type)
	{
		case 1:
			printObj = document.getElementById("content");
			break;
	}*/
	
	printWin = open("includes/printWin.html", 'printWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=0,height=0,left=2000, top=2000');
}

//------------ CONTACT FUNCS ---------------------------//
function resetForm(frm)//gets frm form object and clears all data in texts areas and inputs
{
	var allFormEl = new Array();
	allFormEl = frm.getElementsByTagName("INPUT");
	//alert(allFormEl.length)
	
	for(var i=0; i<allFormEl.length; i++)
		if(allFormEl[i].type == "text")
			allFormEl[i].value = "";
	
	allFormEl = frm.getElementsByTagName("INPUT");
	//alert(allFormEl.length)
	
	frm.Comments.value = "";
}

// --------- LEFT MENU SELECTED -------------
/*This function compares current url with the a href attribute in each link in the main menu
and heighlights the selected link*/
function selectedMenuItem(module)
{	
	if(module == "home" || module == "contact")
	{
	    var td = document.getElementById("menu_item_" + module);
	    linkName = td.getElementsByTagName("A");
	    td.innerHTML = "<img src='images/menu_element.gif'><span class='sideMenu_selected'>" + linkName[0].innerHTML + "</span>";
	}
	else //dynamic-pages module
	{
	    var tblMainMenu = document.getElementById("tblMainMenu");
	    var aTDs = new Array();
	    aTDs = tblMainMenu.getElementsByTagName("TD");
    	
	    for(var i=0; i<aTDs.length; i++)
	    {        
	        aHrefs = aTDs[i].getElementsByTagName("A");
	        linkName = aHrefs[0].innerHTML;
	        href = aHrefs[0].href;
	        //alert(aHrefs[0])
	        url = window.location;
	        //alert(linkName+"\n"+url)
	        if(href == url)
	        {
	            aTDs[i].innerHTML = "<img src='images/menu_element.gif'><span class='sideMenu_selected'>" + linkName + "</span>";
	        }
	        else
	        {
                //alert(href+"\n"+url)
                bcDiv = document.getElementById("divBreadCrumbs");
                var aBCs = new Array();
                aBCs = bcDiv.getElementsByTagName("A")
                //alert(aBCs[1].href+" "+href);
                if(aBCs.length > 1 && href == aBCs[1].href)
                {
                    aTDs[i].innerHTML = "<img src='images/menu_element.gif'><span class='sideMenu_selected'>" + linkName + "</span>";
                }
            }
	    }
	}
}


/* ----- DARK SCREEN FOR SLIDESHOW -----*/
function darkScreen(vis,divID, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=1;//zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= '1400';//pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
  
  if (vis)
	document.getElementById(divID).style.display = 'block';
  else
	document.getElementById(divID).style.display = 'none';
}
