// JavaScript Document for Visual Torah

function init(){
	
	ajaxpage('vt_content_panel.php', 'contentBody');

}

function setHTML(pageToLoad, container, panelID, panelName) {

	//load the contents of the html page
	ajaxpage(pageToLoad, container);

	//setup the url for the tab
	var tabURL = "javascript:setHTML('vt_content_panel.php?pID="+panelID+"', 'contentBody', '"+panelID+"', '"+panelName+"')";
	
	//make all the tabs the same color
	var allTabs = JUNE.Dom.getByAttribute("name", "tab");
	for (var i=0; i < allTabs.length; i++)
	{
		JUNE.Dom.find(allTabs[i]).setAttribute("className", "navBtn");
		JUNE.Dom.find(allTabs[i]).setAttribute("class", "navBtn");
	}
		
	//if the tab clicked on is the standard welcome tab, then do nothing
	if (panelID == 'default') {
	
		JUNE.Dom.find('default').setAttribute("className", "navBtn_select");
		JUNE.Dom.find('default').setAttribute("class", "navBtn_select");

	//if the content tab does not exist in the navigation bar then		
	} else if ( !(JUNE.Dom.find('contentTab')) ) {
	
		//Create a new tab button element
		var contentTab = JUNE.Dom.createElement('a', panelName, 'contentTab', 'navBtn');
		
		//add the tab to the navigation bar
		JUNE.Dom.find('navBar').appendChild(contentTab);
		
		//create a simple reference to the newly added added
		var contentTab = JUNE.Dom.find('contentTab');
	
		//setup the href attribute of the tab
		contentTab.setAttribute("href", tabURL);
		
		//setup the name of the tab
		contentTab.setAttribute("name", "tab");
		
		//set the select style of the tab
		contentTab.setAttribute("className", "navBtn_select");
		contentTab.setAttribute("class", "navBtn_select");
		
	//if the content tab does exist, then remove it and start over
	} else if (JUNE.Dom.find('contentTab')) {
	
		//remove the current tab
		JUNE.Dom.removeChild(JUNE.Dom.find('contentTab'));
		
		//setup the html link
		setHTML(pageToLoad, container, panelID, panelName);
	
	}
	
	Effect.ScrollTo('content');

}

function submitform(whichform,whichdiv){
	theqs = "";
	if(document.forms[whichform]){
		
		for (i=0; i<document.forms[whichform].childNodes.length; i++) {
         //alert("test");
         if (document.forms[whichform].childNodes[i].tagName == "INPUT" || document.forms[whichform].childNodes[i].tagName == "input") {
            
            if (document.forms[whichform].childNodes[i].type == "text" || document.forms[whichform].childNodes[i].type == "hidden") {
               theqs += document.forms[whichform].childNodes[i].name + "=" + document.forms[whichform].childNodes[i].value + "&";
				
            }
            if (document.forms[whichform].childNodes[i].type == "checkbox") {
               if (document.forms[whichform].childNodes[i].checked) {
                  theqs += document.forms[whichform].childNodes[i].name + "=" + document.forms[whichform].childNodes[i].value + "&";
               } else {
                  theqs += document.forms[whichform].childNodes[i].name + "=&";
               }
            }
            if (document.forms[whichform].childNodes[i].type == "radio") {
               if (document.forms[whichform].childNodes[i].checked) {
                  theqs += document.forms[whichform].childNodes[i].name + "=" + document.forms[whichform].childNodes[i].value + "&";
               }
            }
         }   
         if (document.forms[whichform].childNodes[i].tagName == "SELECT") {
            var sel = document.forms[whichform].childNodes[i];
            theqs += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         if (document.forms[whichform].childNodes[i].tagName == "TEXTAREA"){
			 theqs += document.forms[whichform].childNodes[i].name + "=" + document.forms[whichform].childNodes[i].value + "&";
         }
         
      }

	}
	//alert(theqs.indexOf("&",theqs.length - 1) + " " + theqs.length);
	if(theqs.indexOf("&",theqs.length - 1) == theqs.length - 1){
		theqs = theqs.substring(0,theqs.length - 1)
	}
	
	//alert(document.forms[whichform].action);
	ajaxpage(document.forms[whichform].action + "?" + theqs, whichdiv);
}