// JavaScript Document

Formstyle.prototype.path = "";
Formstyle.prototype.checkboxup = "Images/check_up.gif";
Formstyle.prototype.checkboxclick = "Images/check_click.gif";
Formstyle.prototype.checkupdisabled = "Images/check_updis.gif";
Formstyle.prototype.checkclickdisabled = "Images/check_clickdis.gif";

function Formstyle()
{
	
	this.dynapi();
	this.tablearray = new Array();
	this.callbackCheckbox;
	
	/* this.path = "";
	this.checkboxup = "Images/check_up.gif";
	this.checkboxclick = "Images/check_click.gif";
	this.checkupdisabled = "Images/check_updis.gif";
	this.checkclickdisabled = "Images/check_clickdis.gif";
	*/
	
	//if(typeof this.path != "undefined")
	this.path ="../../App_Themes/ExternalTheme/" ;
	
	var version = parseInt(navigator.appVersion)
	
	if(this.isIE && version < 7)
	{	this.radioup = "Images/radio_up.gif";
		this.radioclick = "Images/radio_click.gif";
		this.radioupdisabled = "Images/radio_updis.gif";
		this.radioclickdisabled = "Images/radio_clickdis.gif";
	}
	else
	{	this.radioup = "Images/radio_up.png";
		this.radioclick = "Images/radio_click.png";
		this.radioupdisabled = "Images/radio_updis.png";
		this.radioclickdisabled = "Images/radio_clickdis.png";
	}
	
	var tobj = document.getElementsByTagName('table');
	
	for(var t=0; t<tobj.length; t++)
	{
	    if(tobj[t].className =="dyntable")
	    { //this.applytableeffect(tobj[t].id);
			this.applytableeffect(tobj[t]);
		}
		else if(tobj[t].className =="rowstyle")
		{
		  this.applyrowtableeffect(tobj[t]);
		}
	}
	
	
	
	for(var i=0; i<document.forms.length; i++)
	{
		this.formelem = document.forms[i].elements;
		
		for(var j=0; j<this.formelem.length; j++)
		{
			if(this.formelem[j].nodeName == "INPUT" && (this.formelem[j].type == "text" || this.formelem[j].type == "password" || this.formelem[j].type == "button" || this.formelem[j].type == "submit" ))
			{ this.applytexteffect(j);}
			if(this.formelem[j].nodeName == "TEXTAREA")
			{ this.applytextareaeffect(j);}
			if(this.formelem[j].nodeName == "INPUT" && this.formelem[j].type == "radio")
			{ this.applyradioeffect(j,"radio",i);}
			if(this.formelem[j].nodeName == "INPUT" && this.formelem[j].type == "checkbox")
			{ this.applycheckboxeffect(j,"checkbox",i);}
		}

	}

}


Formstyle.prototype.applyrowtableeffect = function(tobj)
{
	var allrows = tobj.rows;
	
	for(t=0; t<allrows.length; t++)
	{
		var num = t%2;
		
		//alert(typeof num)
		
		 if(num == 0)
		{	allrows[t].className = "up1"; }
		else if(num == 1)
		{	allrows[t].className = "up"; }
		/*else
		{	break;}
		*/
	}
}

Formstyle.prototype.applytableeffect = function(obj)
{
	this.table = obj;//(this.isIE)? document.all(txt) : document.getElementById(txt);
	
	if(this.table != null)
	{	
		this.tableid = this.table.id;
		this.tablearray[this.tableid] = this.tableid;
		
		var trows = this.table.tBodies[0].rows;
		
		for(var i=0; i<trows.length; i++)
		{
			var checkstatus = this.loopthrough(trows[i]);
			if(typeof checkstatus != "undefined")
			{ 
				this.alternaterows(trows[i]);
			
				if(checkstatus)
				{ this.detachevent(trows[i]);}
				else
				{ this.attachevent(trows[i]);}
			}
		}
	}
}

Formstyle.prototype.alternaterows = function(obj)
{
	var theCells = obj.cells;
	for(var i=0; i<theCells.length; i++)
	{	
		if(obj.sectionRowIndex%2 == 0)
		{theCells[i].className = "outstate";}
		else
		{theCells[i].className = "outstate1";}
	}
}


Formstyle.prototype.detachevent = function(obj)
{
	obj.onmouseover = this.activestate;
	obj.onmouseout = this.activestate;
}

Formstyle.prototype.attachevent = function(obj)
{
	obj.onmouseover = this.overstate;
	obj.onmouseout = this.outstate;
}

Formstyle.prototype.applyactivestate = function(obj)
{
	var theCells = obj.cells;
	for(var i=0; i<theCells.length; i++)
	{	theCells[i].className = "activestate";	}
}

Formstyle.prototype.activestate = function()
{
	var theCells = this.cells;
	for(var i=0; i<theCells.length; i++)
	{	theCells[i].className = "activestate";	}
}

Formstyle.prototype.overstate = function()
{
	var theCells = this.cells;
	for(var i=0; i<theCells.length; i++)
	{	theCells[i].className = "overstate";
	}
}

Formstyle.prototype.outstate = function()
{
	var theCells = this.cells;
	for(var i=0; i<theCells.length; i++)
	{	
		if(this.sectionRowIndex%2 == 0)
		{theCells[i].className = "outstate";}
		else
		{theCells[i].className = "outstate1";}
	}
}

Formstyle.prototype.loopthrough = function(obj)
{
	var inputcell = obj.getElementsByTagName('input')
	for(var i=0; i<inputcell.length; i++)
	{	if(inputcell[i].type=="checkbox" || inputcell[i].type=="radio")
		return (inputcell[i].checked);
	}
}

Formstyle.prototype.applycheckboxeffect = function(val,type,rootval)
{
	var thisobj = this;
	
	this.formelem = document.forms[rootval].elements;
	this.checkbox = this.formelem[val];
	
	if(this.checkbox.type == type && (this.getCSSDisplay(this.checkbox) != "none"))
	{
		var imgobj = document.createElement('IMG');
		imgobj.className = "img";
		
		if(this.checkbox.checked)
		{ 	  		  
				  if(!this.checkbox.disabled)
				  {imgobj.setAttribute('src',this.path+this.checkboxclick); }
				  else
				  {imgobj.setAttribute('src',this.path+this.checkclickdisabled); }

		  var tr = this.getTR(this.checkbox)
		  var table = this.getTable(this.checkbox)
		  
		  /*if(this.tablearray[table.id] != null )
		  { if(this.tablearray[table.id] == table.id)
		     {	this.applyactivestate(tr); }
		  }*/
		  if(table.className == "dyntable")
		  {	this.applyactivestate(tr);}

		}
		else if(!this.checkbox.checked)
		{
			
			if(!this.checkbox.disabled)
				  {imgobj.setAttribute('src',this.path+this.checkboxup); }
				  else
				  {imgobj.setAttribute('src',this.path+this.checkupdisabled); }
		}
		
		this.checkbox.parentNode.insertBefore(imgobj, this.checkbox);
		this.checkbox.style.display = "none";
		
		imgobj.onclick = function()
		{
			
		    if(!this.nextSibling.disabled)
		    {this.nextSibling.click();}
		
			if(thisobj.checkboxstatus(this.nextSibling) && thisobj.checkboxstatus(this.nextSibling) != 'undefined')
			{ 	
		 		this.src = thisobj.path+thisobj.checkboxclick;
			  
			  	var tr = thisobj.getTR(this.nextSibling)
				var table = thisobj.getTable(this.nextSibling)
		  		
		  		/*if(thisobj.tablearray[table.id] != null )
		            { if(thisobj.tablearray[table.id] == table.id)
		                {	thisobj.detachevent(table.rows[tr.sectionRowIndex]); }
		            }
				*/
				
				if(table.className == "dyntable")
				{	thisobj.detachevent(table.rows[tr.sectionRowIndex]); }
				
			} 
			else if(thisobj.checkboxstatus(this.nextSibling)==false && thisobj.checkboxstatus(this.nextSibling) != 'undefined')
			{ 
			  this.src = thisobj.path+thisobj.checkboxup;

				  var tr = thisobj.getTR(this.nextSibling)
				  var table = thisobj.getTable(this.nextSibling)
				 // if(thisobj.tablearray[table.id] != null )
		           // { if(thisobj.tablearray[table.id] == table.id)
		             //   {	thisobj.attachevent(table.rows[tr.sectionRowIndex]); }
		     	// }
				if(table.className == "dyntable")
				{	thisobj.attachevent(table.rows[tr.sectionRowIndex]); }
				  
			}
			
			//if(this.nextSibling.type == "checkbox")
			//{	this.nextSibling.checked = !this.nextSibling.checked}
		}
	}
}

Formstyle.prototype.checkboxstatus = function(obj)
{	
	
	if(obj.checked && !obj.disabled)
	{return true}
	else if(!obj.disabled)
	{return false}
	
}

Formstyle.prototype.getTR = function(obj)
{
	objp = obj.parentNode;	
	while(objp.nodeName != "TR")
	{	objp = objp.parentNode;	}
	 return objp;
}

Formstyle.prototype.getTable = function(obj)
{
	objp = obj.parentNode;	
	while(objp.nodeName != "TABLE")
	{	objp = objp.parentNode;	}
	
	//alert(objp.nodeName);
	return objp;
}

Formstyle.prototype.applytexteffect = function(val)
{
	//alert(this.formelem[val].type)
	if((this.formelem[val].type=="text") && this.formelem[val].readOnly)
	{	this.formelem[val].className = "disabled"; }
	else if((this.formelem[val].type=="button" || this.formelem[val].type=="submit") && this.formelem[val].className == "")
	{ this.formelem[val].className = "submit";}
	else
	{
		if(!this.formelem[val].disabled)
		{	
		this.formelem[val].className = "up";
		this.formelem[val].onfocus = function(){ this.className="over";}
		this.formelem[val].onblur = function(){ this.className = "up";}
		}
		else
		{	this.formelem[val].className = "disabled";}
	}
}

Formstyle.prototype.applytextareaeffect = function(val)
{
	//alert(this.formelem[val].disabled)
	 if((this.formelem[val].type=="textarea") && this.formelem[val].readOnly)
	{	this.formelem[val].className = "disabled"; }
	else
	{
		if(!this.formelem[val].disabled)
		{	
		this.formelem[val].className = "up";
		this.formelem[val].onfocus = function(){ this.className="over";}
		this.formelem[val].onblur = function(){ this.className = "up";}
		}
		else
		{	this.formelem[val].className = "disabled";}
	}
}

Formstyle.prototype.applyradioeffect = function(val,type,rootval)
{
	var thisobj = this;
	
	this.formelem = document.forms[rootval].elements;
	this.radio = this.formelem[val];
	
	if(this.radio.type == type && (this.getCSSDisplay(this.radio) != "none"))
	{ 
		var imgobj = document.createElement('IMG');
		imgobj.className = "img";
		
		if(this.radio.checked && !this.radio.disabled)
		{	imgobj.setAttribute('src',this.path+this.radioclick); }
		else if(this.radio.checked && this.radio.disabled)
		{	imgobj.setAttribute('src',this.path+this.radioclickdisabled); }
		else if(!this.radio.checked && this.radio.disabled)
		{	imgobj.setAttribute('src',this.path+this.radioupdisabled);}
		else if(!this.radio.checked && !this.radio.disabled)
		{	imgobj.setAttribute('src',this.path+this.radioup);}
		
		 if(this.radio.checked)
		{ 	  var tr = this.getTR(this.radio)
		 	  var table = this.getTable(this.radio)
		 	  if(table.className == "dyntable")
		 	  {	this.applyactivestate(tr); }
		}
		
		this.radio.parentNode.insertBefore(imgobj, this.radio);
		this.radio.style.display = "none";
		
		imgobj.onclick = function()
		{
			var robj = document.forms[rootval].elements[this.nextSibling.name] // because of mulitple forms
			this.nextSibling.click()
			
			if(typeof robj.length != "undefined")
			{thisobj.applyradioimg(robj) }
			else if(typeof robj.length == "undefined")
			{	thisobj.callbackRadio(robj);}
		}
	}
}

Formstyle.prototype.findlabel = function(obj)
{
	var labels = document.getElementsByTagName('label')	
	for(var i=0; i<labels.length; i++)
	{
		if(labels[i].htmlFor == obj.id)
		{	return (labels[i]) }
	}
}

Formstyle.prototype.applyradioimg = function(obj)
{
	for(var i=0; i<obj.length; i++)
	{
		
		var tr = this.getTR(obj[i]) // retrieve row
		var table = this.getTable(obj[i]) // retrieve table
		
		if(obj[i].checked && !obj[i].disabled)
		{obj[i].previousSibling.src = this.path+this.radioclick;
		  
		 if(table.className == "dyntable") 	// apply detachevent  if(table.id == tr.parentNode.parentNode.id  && table.id != "")
		 {	this.detachevent(table.rows[tr.sectionRowIndex]);}
				  
		}
		else if(!obj[i].checked && !obj[i].disabled)
		{obj[i].previousSibling.src = this.path+this.radioup;

			if(table.className == "dyntable")	// apply attachevent if(table.id == tr.parentNode.parentNode.id && table.id != "")
			{	this.attachevent(table.rows[tr.sectionRowIndex]); 
				  
				var theCells = table.rows[tr.sectionRowIndex].cells; // reset row color very important
				for(var k=0; k<theCells.length; k++)
				{ if(tr.sectionRowIndex%2 == 0)
					{theCells[k].className = "outstate"; }
					else
					{theCells[k].className = "outstate1"; }
				}
			}
		}
	}	
}

Formstyle.prototype.getCSSDisplay = function(obj)
{	
	if(window.currentStyle)	
	{	return obj.currentStyle.display;}
	else if(window.getComputedStyle)
	{	return document.defaultView.getComputedStyle(obj,'').getPropertyValue('display');}
	else if(document.body.style)
	{	return obj.style.display;}
}

Formstyle.prototype.dynapi = function()
{
	this.isCSS = (document.body && document.body.style)? true : false;
	this.isIE = (this.isCSS && document.all)? true : false;
	this.isDOM = (this.isCSS && document.getElementById)? true : false;
	this.isNN4 = (document.layers)? true : false;
	this.isOpera = (navigator.userAgent.indexOf('opera') != -1)? true : false;
}

function callbackCheckbox(obj)
{
	var table = Formstyle.prototype.getTable(obj);
	var tr;
	
	var inputobjs = table.getElementsByTagName('input');
	for(i=0; i<inputobjs.length; i++)
	{
		if(inputobjs[i].nodeName == "INPUT" && inputobjs[i].type == "checkbox" && inputobjs[i].id != obj.id)
		{	
			if(obj.checked && !obj.disabled)
			{	
				if(!inputobjs[i].disabled)
				{	inputobjs[i].checked = true;
					inputobjs[i].previousSibling.setAttribute('src',Formstyle.prototype.checkboxclick)
					tr = Formstyle.prototype.getTR(inputobjs[i]);
					Formstyle.prototype.detachevent(table.rows[tr.sectionRowIndex]);
					Formstyle.prototype.callbackRowstyle(tr,true)
				}
			}
			else if(!obj.checked && !obj.disabled)
			{	
				if(!inputobjs[i].disabled)
				{	inputobjs[i].checked = false;
					inputobjs[i].previousSibling.setAttribute('src',Formstyle.prototype.checkboxup)
					tr = Formstyle.prototype.getTR(inputobjs[i]);
					Formstyle.prototype.attachevent(table.rows[tr.sectionRowIndex]);
					Formstyle.prototype.callbackRowstyle(tr,false)
				}
			}
		}
	}
	
	Formstyle.prototype.callbackRowstyle(table,obj.checked);
}

Formstyle.prototype.callbackRowstyle = function(obj,bool)
{
	
		var theCells = obj.cells;
		for(var k=0; k<theCells.length; k++)
		{	if(bool)
			{theCells[k].className = "activestate";}
			else
			{	var num = obj.sectionRowIndex%2;
		 		if(num == 0)
				{	theCells[k].className = "outstate1"; }
				else if(num == 1)
				{	theCells[k].className = "outstate"; }
			}
		}
}

Formstyle.prototype.callbackRadio = function(obj)
{
	var thisobj = this;	
    var table = this.getTable(obj);
	var inputobjs = table.getElementsByTagName('input');

	var tr; // retrieve row
	var table = this.getTable(obj) // retrieve table
	
	for(i=0; i<inputobjs.length; i++)
	{
		if(inputobjs[i].nodeName == "INPUT" && inputobjs[i].type == "radio" && inputobjs[i].id != obj.id)
		{
			inputobjs[i].checked = false;
			inputobjs[i].previousSibling.src = this.path+this.radioup;
			tr = this.getTR(inputobjs[i])
			
			if(table.className == "dyntable")	// apply attachevent if(table.id == tr.parentNode.parentNode.id && table.id != "")
			{	this.attachevent(table.rows[tr.sectionRowIndex]); 
				  
				var theCells = table.rows[tr.sectionRowIndex].cells; // reset row color very important
				for(var k=0; k<theCells.length; k++)
				{ if(tr.sectionRowIndex%2 == 0)
					{theCells[k].className = "outstate"; }
					else
					{theCells[k].className = "outstate1"; }
				}
			}
		}
	}
	
	obj.checked = true;
	obj.previousSibling.src = this.path+this.radioclick;
	tr = this.getTR(obj)
	if(table.className == "dyntable") 	// apply detachevent  if(table.id == tr.parentNode.parentNode.id  && table.id != "")
	{	this.detachevent(table.rows[tr.sectionRowIndex]);}
}


/* -------------------------------------------------- other ---------------------------------------*/
function activate(obj)
{
	var disp = Formstyle.prototype.getCSSDisplay(document.getElementById(obj.rel));
	resetall()
	if(disp == "block")
	{ document.getElementById(obj.rel).style.display = "none"; }
	else
	{ document.getElementById(obj.rel).style.display = "block"; }
} 

function resetall()
{
	var i=1;
	while(document.getElementById('div'+i))
	{	document.getElementById('div'+i).style.display = "none";
		i++;
	}
}

