// JavaScript Document
/***********modified by pratik panchal*****/
var vari = document.URL;
var segments = new Array();
segments = vari.split("/");
var webpath="";
for(var i=0;i<4;i++)
{    
        if(i==0)
        {
            webpath = segments[i]+"/";     
        }
        else
        {
            webpath += segments[i]+"/";  
        }
}

//var end = vari.indexOf('Reports');
//var webpath = vari.substring(0,end+1);
Formstyle.prototype.path = webpath;
/*****************************************/
//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;

	
	//if(typeof this.path != "undefined")
	//this.path ="../../../";
	
	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]);
		}
		else if(tobj[t].className =="tableholder")
		{
			this.applytableholdereffect(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);}
		}
		
		//this.findlabel();
	}
}


Formstyle.prototype.applytableholdereffect = function(tobj)
{
	var allrows = tobj.rows;
	 for(var t=0; t<allrows.length; t++)
	{
		var allcells = allrows[t].cells;
		
		 for(var k=0; k<allcells.length; k++)
		{
			if(allcells[k].className == "" && this.getInputObj(allcells[k]) && allcells[k].nodeName != "TH")
			{	allcells[k].className = "fieldcell";
			}
			else if(allcells[k].className == "" && !this.getInputObj(allcells[k]))
			{	allcells[k].className = "txtcell";	}
		}
	}
}

Formstyle.prototype.getInputObj = function(obj)
{
	if(obj.hasChildNodes())	
	{
		for(var o=0; o<obj.childNodes.length; o++)
		{
			if(obj.childNodes[o].nodeName == "INPUT" || obj.childNodes[o].nodeName == "SELECT" || obj.childNodes[o].nodeName == "TEXTAREA")
			{	return true;}
			//else{	return false;			}
		}
		return false;
	}
}

Formstyle.prototype.applyrowtableeffect = function(tobj)
{
	var allrows = tobj.rows;
	
	for(t=0; t<allrows.length; t++)
	{
		var num = t%2;
		
		if(allrows[t].className != "pagerstyle") // pager style
		{
		 if(num == 0)
		{	allrows[t].className = "up1"; }
		else if(num == 1)
		{	allrows[t].className = "up"; }
		}
	}
}

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" && (!inputcell[i].disabled))
		{return (inputcell[i].checked);}
		else
		{return '';}
	}
}

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(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";
		
		
		if(this.checkbox.nextSibling && this.checkbox.nextSibling.nodeName == 'LABEL' && (this.checkbox.id == this.checkbox.nextSibling.htmlFor))
		{ var labelobj = this.checkbox.nextSibling;
		    
		   /*    this.checkbox.onclick = function() // Enable image if person click on the label
		    {  var chobj = this.previousSibling;
		       if(!this.disabled)
		       {   thisobj.applycheckboximg(chobj) }
		    }
		  */   
		   
		    if(this.checkbox.onclick != null)
			{	var clickaction = this.checkbox.onclick.toString();
				var clickobj =clickaction.substring(clickaction.indexOf('{')+1, clickaction.lastIndexOf('}'));
			}
		
			 this.checkbox.onclick = function()
			{ 	
			    var chobj = this.previousSibling;
		       if(!this.disabled)
		       {   thisobj.applycheckboximg(chobj) }
			
			    if(typeof clickobj != "undefined")
			    eval(clickobj); 
			}   
		}
		
		
		imgobj.onclick = function()
		{   
            var chobj = this; 
            
		    if(!this.nextSibling.disabled)
		    {this.nextSibling.click();}
		    
		    
		
		    if(!this.nextSibling.disabled)
			{thisobj.applycheckboximg(chobj) }
			
			/* if(thisobj.checkboxstatus(this.nextSibling) && (thisobj.checkboxstatus(this.nextSibling) != 'undefined') && !this.nextSibling.disabled)
			{ 	
		 		this.src = thisobj.path+thisobj.checkboxclick;
			    
			  	var tr = thisobj.getTR(this.nextSibling)
				var table = thisobj.getTable(this.nextSibling)

				if(table.className == "dyntable")
				{	thisobj.detachevent(table.rows[tr.sectionRowIndex]); }
				
			} 
			else if(thisobj.checkboxstatus(this.nextSibling)==false && (thisobj.checkboxstatus(this.nextSibling) != 'undefined') && !this.nextSibling.disabled)
			{ 
			  this.src = thisobj.path+thisobj.checkboxup;
				  var tr = thisobj.getTR(this.nextSibling)
				  var table = thisobj.getTable(this.nextSibling)
				
				if(table.className == "dyntable")
				{	thisobj.attachevent(table.rows[tr.sectionRowIndex]); }	  
			}*/
			
		}
	}
}


Formstyle.prototype.applycheckboximg = function(obj)
{       
    var thisobj = this;
  
   if(this.checkboxstatus(obj.nextSibling) && (this.checkboxstatus(obj.nextSibling) != 'undefined') && !obj.nextSibling.disabled)
			{ 	
		 		obj.src = this.path+this.checkboxclick;
			    
			  	var tr = this.getTR(obj.nextSibling)
				var table = this.getTable(obj.nextSibling)

				if(table.className == "dyntable")
				{	this.detachevent(table.rows[tr.sectionRowIndex]); }
				
			} 
			else if(this.checkboxstatus(obj.nextSibling)==false && (this.checkboxstatus(obj.nextSibling) != 'undefined') && !obj.nextSibling.disabled)
			{ 
			  obj.src = this.path+this.checkboxup;
				  var tr = this.getTR(obj.nextSibling)
				  var table = this.getTable(obj.nextSibling)
				
				if(table.className == "dyntable")
				{	this.attachevent(table.rows[tr.sectionRowIndex]); }	  
			}
	return;
}

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)
{
	var defaultclass=""; // to access style which is applied for an individual element.
    
    if(this.formelem[val].className != "")
    {   defaultclass = " "+this.formelem[val].className; }
	
	// reset the class Names
	this.formelem[val].className == "";

    	
	if((this.formelem[val].type=="text" || this.formelem[val].type=="password") && (this.formelem[val].readOnly || this.formelem[val].disabled))
	{	this.formelem[val].className = "disabled"+defaultclass;}
	else if(this.formelem[val].type=="text" || this.formelem[val].type=="password")
	{
		this.formelem[val].className = "up"+defaultclass;
		this.applyevents(this.formelem[val],defaultclass);
		//this.formelem[val].onfocus = function(){ this.className="over"+defaultclass;}
		//this.formelem[val].onblur = function(){ this.className = "up"+defaultclass;}
	}

	
	if(this.formelem[val].type=="button" || this.formelem[val].type=="submit")
	{ this.formelem[val].className = "submit"+defaultclass;}
	
}


Formstyle.prototype.applyevents = function(obj,defaultclass)
{
		if(obj.onfocus != null)
			{	var focusaction = obj.onfocus.toString();
				var focusobj =focusaction.substring(focusaction.indexOf('{')+1, focusaction.lastIndexOf('}'));
			}
		
			if(obj.onblur != null)
			{	var bluraction = obj.onblur.toString();
				var blurobj =bluraction.substring(bluraction.indexOf('{')+1, bluraction.lastIndexOf('}'));
			}
		
			obj.onfocus = function()
			{ 	if(typeof focusobj != "undefined")
				eval(focusobj); 
				this.className="over"+defaultclass;
			}
		
			obj.onblur = function()
			{ 	if(typeof blurobj != "undefined")
				eval(blurobj); 
				this.className = "up"+defaultclass;
			}
			
}


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 && !this.radio.disabled)
		{ 	  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";
		
		 if(this.radio.nextSibling && this.radio.nextSibling.nodeName == 'LABEL' && (this.radio.id == this.radio.nextSibling.htmlFor))
		{ 
		            if(this.radio.onclick != null)
		            {	var clickaction = this.radio.onclick.toString();
				       var clickobj =clickaction.substring(clickaction.indexOf('{')+1, clickaction.lastIndexOf('}'));
			        }
			            
			            
		            this.radio.onclick = function()
			        { 	
			               
		                      var robj = document.forms[rootval].elements[this.name] // because of mulitple forms
			                if(typeof robj.length != "undefined" && !this.disabled)
		        	        {   thisobj.applyradioimg(robj) }
			                else if(typeof robj.length == "undefined" && !this.disabled)
			                 {	thisobj.callbackRadio(robj);}
			            
			                 if(typeof clickobj != "undefined")
			                 eval(clickobj);
			        } 

		
		}
		imgobj.onclick = function()
		{   
			var robj = document.forms[rootval].elements[this.nextSibling.name] // because of mulitple forms
			
			
			if(!this.nextSibling.disabled) 
			{this.nextSibling.click();
			}
			
			
			if(typeof robj.length != "undefined" && !this.nextSibling.disabled)
			{thisobj.applyradioimg(robj) }
			else if(typeof robj.length == "undefined" && !this.nextSibling.disabled)
			{	thisobj.callbackRadio(robj);}
		}
	}
}

/* Formstyle.prototype.findlabel = function(rootval)
{

	 var labels = document.getElementsByTagName('label');	
	for(var i=0; i<labels.length; i++)
	{   if(labels[i].htmlFor != "")
		   {    
		    labels[i].onclick = function(){
		   
		        //if((document.getElementById(this.htmlFor).type == "radio") && (document.getElementById(this.htmlFor).previousSibling.nodeName))
		         //   {  document.getElementById(this.htmlFor).previousSibling.onclick(); }   
		         
		         return false;
		         
		        }
		    }
	} 
}*/

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;
			    if(!inputobjs[i].disabled)
			    {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]);}
}


/* -------------------------------------------------- new window ---------------------------------------*/

function newwindow(url,w,h)
{
	
	var topy = parseInt((window.screen.availHeight/2)-(h/2));
	var leftx = parseInt((window.screen.availWidth/2)-(w/2));

	if(typeof win != "undefined")
	{win.close();}

	
	win = window.open(url,'win1','width='+w+',height='+h+',top='+topy+',left='+leftx+',screenX='+leftx+',screenY='+topy+', scrollbars=yes ');
	win.focus();
}
