function $(d){
	return document.getElementById(d);
}

// set or get the current display style of the div
function dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
	//debugger;
}

// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(dsp(d)!='none'&& dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=20;
t=1;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially. *********
function ct(d){
	d = $(d);
	if(sh(d)>0){
		v = Math.round(sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		v = 0;               //Code changed to avoid the flickering
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
		
	}else{
		sh(d,0);
		dsp(d,'none');
		clearInterval(d.t);
		
}
	//
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	d = $(d);
	if(sh(d)<d.maxh){
		v = Math.round((d.maxh-sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)+v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
	}
}

// Collapse Initializer
function cl(d){
	
	if(dsp(d)=='block'){
	    //dsp(d,'none');
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('et("'+d.id+'")',t);
	}
	
}

// Removes Classname from the given div.
function cc(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc){
    
    var get_opendiv;
	//Array to store the number of clicks on each header
	var pathName = document.location.pathname;
	var clicked = new Array(13);
	for(i=0;i<13;i++)   //Initialize the array to 0
	{
	    clicked[i] = 0;
	}
	
	// get all the elements that have id as content
	l=$(d).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	sel=null;
	
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=$(h.substr(0,h.indexOf('-'))+'-content');
			
			var isCollapse = checkMenu(pathName,(h.substr(0,h.indexOf('-'))+'-content'));
			if(isCollapse == true)
			    d.style.display='none';
            else
            {
                
            }
//			//if(isCollapse == false)
//		    {
//			   d.style.display = 'block';
//			   ex($(h.substr(0,h.indexOf('-'))+'-content'));
//			   n=$(h);
//			   cc(n,'__');
//			   n.className=n.className+' '+n.tc;
//			   get_opendiv=n.id;
//			}
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=$(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.
			h.onclick = function()
			{
		
				//debugger;
				for(i=0;i<this.c.length;i++)
				{
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					
					if((n+'-header')==this.id)
					{
						
						clicked[i]++;
						if(clicked[i] == 2) //Check whether continuously 2 times clicked on the same header
					    {
					        clicked[i]=0;
					        
					        cl($(n+'-content'));
					        cc($(n+'-header'),'');
					        continue;
					    }
						//$(n+'-content').style.display='block';
						ex($(n+'-content'));
						n=$(n+'-header');
						cc(n,'__');
						n.className=n.className+' '+n.tc;
						get_opendiv=n.id;
						
						
					}
					else
					{
						    
						    clicked[i] = 0;
						   
						   	cl($(n+'-content'));
							cc($(n+'-header'),'');						
					}
                    
				
				}//end of for
			} //end of function onclick
			
			if(h.className.match(/selected+/)!=undefined)
			{ 
			    sel=h; 
			}
                
		}//end of if
	}//end of for
	if(sel!=undefined)
	{
	    sel.onclick();
	}
}




//function added to keep the menu open depending on the selected page
function checkMenu(path, tab)
{
    if(path == "/payment/prop_payonline.asp" && tab == "test-content")//for online property tax
    {
        var linkOPT = document.getElementById('lnkOPT'); 
        linkOPT.outerHTML = "<LABEL id=lnkOPT><u>Online Property Tax</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/OnlineBuildingSanction.aspx" && tab == "test-content")//for online building sanctions
    {
        var linkOBS = document.getElementById('lnkOBS'); 
        linkOBS.outerHTML = "<LABEL id=lnkOBS><u>Online Building Sanctions</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/gen_comp/reg_complaint.asp" && tab == "test1-content")//for register complaint
    {   
        var linkRegComp = document.getElementById('lnkRegComp');
        linkRegComp.outerHTML = "<LABEL id=lnkRegComp><u>Register your Complaint</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/gen_comp/comp_status.asp" && tab == "test1-content")//for comaplint status
    {
        var linkStatus = document.getElementById('lnkStatus');
        linkStatus.outerHTML = "<LABEL id=lnkStatus><u>Complaint Status</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/publicopn.aspx" && tab == "test2-content")//for feedback
    {
        var linkFeedback = document.getElementById('lnkFB');
        linkFeedback.outerHTML = "<LABEL id=lnkFB><u>Post your Feedback</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/rti.aspx" && tab == "test11-content")//for right to information
    {
        var linkRTI = document.getElementById('lnkRTI');
        linkRTI.outerHTML = "<LABEL id=lnkRTI><u>Right to Information</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/kalyanwarta.aspx" && tab == "test10-content")//for kalyan warta
    {
        var linkKW = document.getElementById('lnkKW');
        linkKW.outerHTML = "<LABEL id=lnkKW><u>Kalyan-Warta</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/about_us.aspx" && tab == "test5-content")//for overview
    {
        var linkOvr = document.getElementById('lnkOvr');
        linkOvr.outerHTML = "<LABEL id=lnk><u>Overview</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/infrapmc.aspx" && tab == "test5-content")//for PMC Infrastructure
    {
        var linkPMCI = document.getElementById('lnkPMCI');
        linkPMCI.outerHTML = "<LABEL id=lnk><u>PMC Infrastructure</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/loccommitee.aspx" && tab == "test5-content")//for committee decisions
    {
        var linkCD = document.getElementById('lnkCD');
        linkCD.outerHTML = "<LABEL id=lnk><u>Committee Decisions</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/kiosk_loc.aspx" && tab == "test5-content")//for Kiosks in pune
    {
        var linkKIP = document.getElementById('lnkKIP');
        linkKIP.outerHTML = "<LABEL id=lnk><u>Kiosks in Pune</u></LABEL>";
        return false;
    }
    else if(path == "/pmcwebn/contact_us.aspx" && tab == "test13-content")//for contact us
    {
        var linkCU = document.getElementById('lnkCU');
        linkCU.outerHTML = "<LABEL id=lnk><u>Contact Details</u></LABEL>";
        return false;
    }
    return true; 
}














































var onloading = 0;
//Accordian Initializer right
function Accordian_right(d,s,tc){
	var get_opendiv;
	//Array to store the number of clicks on each header
	var clicked = new Array(13);
	for(i=0;i<13;i++)   //Initialize the array to 0
	{
	    clicked[i] = 0;
	}
	
	// get all the elements that have id as content
	l=$(d).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content_right'){c.push(h);}
	}
	sel=null;
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header_right'){
			d=$(h.substr(0,h.indexOf('-'))+'-content_right');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=$(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.
			h.onclick = function(){
		
				//debugger;
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					
					if((n+'-header_right')==this.id){
						
						clicked[i]++;
						if(clicked[i] == 2) //Check whether continuously 2 times clicked on the same header
					    {
					        clicked[i]=0;
					        //alert("Clicked"+ this.id);
					        cl($(n+'-content_right'));
					        cc($(n+'-header_right'),'');
					        continue;
					    }
						
						ex($(n+'-content_right'));
						n=$(n+'-header_right');
						cc(n,'__');
						n.className=n.className+' '+n.tc;
						get_opendiv=n.id;
					
						
						
						}else{
						    
						    clicked[i] = 0;
						   
						   	cl($(n+'-content_right'));
							cc($(n+'-header_right'),'');						
					}
                    
				
				}
			} 
			//Code changed to expand the right menu by default on page load
			if(onloading == 0)
			{
				n = "test2" ;
				clicked[i] ++;
				onloading = 1;
				ex($(n+'-content_right'));
				n=$(n+'-header_right');
				cc(n,'__');
				n.className=n.className+' '+n.tc;
				get_opendiv=n.id;
			}

			
			if(h.className.match(/selected+/)!=undefined){ sel=h; }
		}
	}
	if(sel!=undefined){sel.onclick();}
}
