// JavaScript Document for Visual Torah

function init(){
	
	ajaxpage('vt_content_panel.asp', 'contentBody');

}

function setHTML(pageToLoad, container, panelID, panelName) {

	//load the contents of the html page
	ajaxpage(pageToLoad.replace(".php",".asp"), container);


}

function submitform(whichform,whichdiv){
	theqs = "";
	if(document.forms[whichform]){
		
		for (i=0; i<document.forms[whichform].elements.length; i++) {
         if (document.forms[whichform].elements[i].tagName == "INPUT") {
            if (document.forms[whichform].elements[i].type == "text" || document.forms[whichform].elements[i].type == "hidden") {
               theqs += document.forms[whichform].elements[i].name + "=" + document.forms[whichform].elements[i].value + "&";
            }
            if (document.forms[whichform].elements[i].type == "checkbox") {
               if (document.forms[whichform].elements[i].checked) {
                  theqs += document.forms[whichform].elements[i].name + "=" + document.forms[whichform].elements[i].value + "&";
               } else {
                  theqs += document.forms[whichform].elements[i].name + "=&";
               }
            }
            if (document.forms[whichform].elements[i].type == "radio") {
               if (document.forms[whichform].elements[i].checked) {
                  theqs += document.forms[whichform].elements[i].name + "=" + document.forms[whichform].elements[i].value + "&";
               }
            }
         }   
         if (document.forms[whichform].elements[i].tagName == "SELECT") {
            var sel = document.forms[whichform].elements[i];
            theqs += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         if (document.forms[whichform].elements[i].tagName == "TEXTAREA"){
			 theqs += document.forms[whichform].elements[i].name + "=" + document.forms[whichform].elements[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(theqs);
	//alert(document.forms[whichform].action);
	ajaxpage(document.forms[whichform].action + "?" + theqs, whichdiv);
}

function centerondiv(whichdiv){
	//alert(document.getElementById(whichdiv).offsetLeft);
	//alert(document.getElementById(whichdiv).offsetTop);
	//alert(document.getElementById(whichdiv).offsetWidth);
	//alert(document.getElementById(whichdiv).offsetHeight);
	//alert(document.getElementById(whichdiv).offsetLeft + ((document.getElementById(whichdiv).offsetWidth / 2) - (document.getElementById("msgdiv").offsetWidth / 2)));
	//alert(document.getElementById(whichdiv).offsetTop + ((document.getElementById(whichdiv).offsetHeight / 2) - (document.getElementById("msgdiv").offsetHeight / 2)));
	document.getElementById('msgdiv').style.left = (document.getElementById(whichdiv).offsetLeft + ((document.getElementById(whichdiv).offsetWidth / 2) - (document.getElementById("msgdiv").offsetWidth / 2))) + "px";
	document.getElementById('msgdiv').style.top = (document.getElementById(whichdiv).offsetTop + ((document.getElementById(whichdiv).offsetHeight / 2) - (document.getElementById("msgdiv").offsetHeight / 2))) + "px";
	//alert(document.getElementById('msgdiv').style.left);
	//alert(document.getElementById('msgdiv').style.top);
}

function pause(thetime){
	//for strange ie bug
	for(x=0;x<=thetime;x++){
		//pause loop
	}
}

function mytest(whichform){
	for (i=0; i<document.forms[whichform].elements.length; i++) {
		alert(document.forms[whichform].elements[i].name);
	}
}

function addell(thediv){
	var el = document.createElement('div');
	counter = parseInt(document.getElementById(thediv + "counter").value);
	counter = 1 + counter;
	document.getElementById(thediv + "counter").value = counter;
	el.innerHTML = "Rank <input type=text size=3 name=item" + counter + "rank> Graphic <input type=text name=item" + counter + "graphic><br>";
	el.id = thediv + "div" + counter;
	document.getElementById(thediv).appendChild(el);
	
}

function remel(thediv,theel){
	myel = document.getElementById(theel);
	document.getElementById(thediv).removeChild(myel);
}

function changeimg(whichway,whichdiv){
	//alert(imgcounter + " " + maximg);
	if(whichdiv == "div2" || whichdiv == "div1"){
		hilight = "#f0ac2c"
		nohilight = "#000000"
		arrowon = "#000000"
		arrowoff = "#ffffff"
	}else{
		hilight = "#000000"
		nohilight = "#ffffff"
		arrowon = "#ffffff"
		arrowoff = "#8b8b8b"
	}

	document.getElementById(whichdiv + 'num' + eval(whichdiv + "imgcounter")).style.color = nohilight;
	//dontdoit = 0;
	if(whichway == 'next' && eval(whichdiv + "imgcounter") < eval(whichdiv + "maximg")){
		eval(whichdiv + "imgcounter += 1");
		//dontdoit = 1;
		//alert("hit next")
	}else if(whichway == 'prev' && eval(whichdiv + "imgcounter") > 0){
		eval(whichdiv + "imgcounter -= 1");
		//dontdoit = 1;
		//alert("hit prev")
	}else if(whichway != "next" && whichway != "prev"){
		//alert("hit");
		eval(whichdiv + "imgcounter = whichway");
	}
	if(rashiflag == 1){
		document.getElementById(whichdiv + 'multimg').src = "images/rashi/" + eval(whichdiv + "imgarray[" + whichdiv + "imgcounter]");
	}else{
		document.getElementById(whichdiv + 'multimg').src = "images/items/" + eval(whichdiv + "imgarray[" + whichdiv + "imgcounter]");
	}
	document.getElementById(whichdiv + 'num' + eval(whichdiv + "imgcounter")).style.color = hilight;
	if(eval(whichdiv + "imgcounter") == 0){
		//document.getElementById('prevdiv').style.display = 'none';
		document.getElementById(whichdiv + 'prevlink').style.color = arrowoff;
	}else{
		//document.getElementById('prevdiv').style.display = 'inline';
		document.getElementById(whichdiv + 'prevlink').style.color = arrowon;
	}
	if(eval(whichdiv + "imgcounter") == eval(whichdiv + "maximg")){
		//document.getElementById('nextdiv').style.display = 'none';
		document.getElementById(whichdiv + 'nextlink').style.color = arrowoff;
	}else{
		//document.getElementById('nextdiv').style.display = 'inline';
		document.getElementById(whichdiv + 'nextlink').style.color = arrowon;
	}
}

function changeform(whichone){
	if(whichone == 8){
		document.getElementById("contentdiv").style.display = "none";
		//document.getElementById("footnotediv").style.display = "inline";
		document.getElementById("titletitle").innerHTML = "Source Text: ";
	}else{
		document.getElementById("contentdiv").style.display = "inline";
		//document.getElementById("footnotediv").style.display = "none";
		document.getElementById("titletitle").innerHTML = "Title: ";
	}
}