﻿// JScript File

/*
DezinerFolio.com Simple Accordians.

Author  : G.S.Navin Raj Kumar
Website : http://dezinerfolio.com

Modifications: Internet Content Team - Automobile Club of Southern California - 4/2008

*/

/*
* The Variable names have been compressed to achive a higher level of compression.
*/

// Prototype Method to get the element based on ID
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;
	}
}

// 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=7;
t=15;

//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);
		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'){
		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){
	// 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');
			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;
			if(i==0){
			ex(d);
			}
			// set the onclick function for each header.
			h.onclick = function(){
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					if((n+'-header')==this.id){
						b=$(n+'-content');
						setTimeout("ex(b)",t*15);
						n=$(n+'-header');
						cc(n,'__');
						n.className=n.className+' '+n.tc;
						m=$('homePic'+i);
						m.style.display='block';
					}else{
						cl($(n+'-content'));
						cc($(n+'-header'),'');
						m=$('homePic'+i);
						m.style.display='none';
					}
				}
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}

//End of Accordian functions


//Tooltip Functions

function imgSwap(oImg)
{
   var strOver  = "_on"    // image to be used with mouse over
   var strOff = "_off" 
    // normal image
   var strImg = oImg.src
  
   if (strImg.indexOf(strOver) != -1) 
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}
function PNGswap(myID)
{
   var strOver  = "_on"
   var strOff = "_off"
   var oSpan = document.getElementById(myID)
   var currentAlphaImg = oSpan.filters(0).src
   if (currentAlphaImg.indexOf(strOver) != -1)
      oSpan.filters(0).src = currentAlphaImg.replace(strOver,strOff)
   else
      oSpan.filters(0).src = currentAlphaImg.replace(strOff,strOver)
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
var prevTooltip;
function getWindowWidth() {
    
    if(window.innerWidth) {
        return window.innerWidth;
    } 
    
    return document.body.clientWidth
}

function mouseX(e) {

    if(e.pageX) {
        return e.pageX;
    }
    
    return e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
}

function mouseY(e) {
   
   if(e.pageY) {
        return e.pageY;
    } 
    
    return e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);    
}

function tooltip(e, o, z, tt, w) {

    var windowWidth = getWindowWidth();

    o = document.getElementById(o);

	//Check to see if there is a rollover state
	if(tt){
	
	 	if ((version >= 5.5) && (document.body.filters) && (version <= 6.0)) {
			//png rollover for IE6
			
			PNGswap(w);
	 	}else{
			
			//normal image rollover for all other browsers
			
			imgSwap(z);
	 	}
	}
    
    if(prevTooltip && prevTooltip != o) {
        prevTooltip.style.visibility = 'hidden';
    }

    if(o.style.visibility == 'visible') {

        o.style.visibility = 'hidden';
    } else {
    
        if(o.offsetWidth) {
            ew = o.offsetWidth;
        } else if(o.clip.width) {
			alert(ew);
            ew = o.clip.width;
        }
    
        y = mouseY(e) - 50;
        x = mouseX(e) + (ew / 25);
        
        if (x < 2) {
            x = 2;
        } else if(x + ew > windowWidth) {
            x = windowWidth - ew - 4;
        }
        
        o.style.left = x + 'px';
        o.style.top = y + 'px';    
        
        o.style.visibility = 'visible';
        
        prevTooltip = o;
		
    }
}


//End Image Swap Functions

//click tooltips
function bwsr(x,w){

}
function valSmog(e){
	
		var Schk = $('ctl00_ContentPlaceHolder1_SearchFilter1_dlSearchFilter_ctl03_chkServiceItem');
		var GSGR = $('ctl00_ContentPlaceHolder1_SearchFilter1_dlSearchFilter_ctl04_chkServiceItem');
		if (Schk.checked&&GSGR.checked){
			alert("AAR facilities can be either 'Smog Check' facilities or 'Test-Only Smog/GSGR' but not both.");
			$(e.id).checked=false;
		}	
		
}

function showTip(e, tipID){
	ansID = $('ans'+tipID);	
	ifrm=$('iframeshim');

		y = mouseY(e) - (20 + ansID.offsetHeight);
        x = 210;
		
        ansID.style.left = ifrm.style.left  = x + 'px';
        ansID.style.top = ifrm.style.top = y + 'px';   
		ifrm.width=ansID.offsetWidth;
		ifrm.height=ansID.offsetHeight;
	var parentDiv = $("ttAnswers");
	var divCollection = parentDiv.getElementsByTagName("div");  
	for (i=0;i<divCollection.length;i++){

	if(divCollection[i].id!="" && divCollection[i].id!='ans'+tipID){
		divCollection[i].style.visibility='hidden';
	}
   		
	}
	
	if(ansID.style.visibility!='visible'){
		ifrm.style.display='block';
		ansID.style.visibility='visible';
	}else{
		ifrm.style.display='none';
		ansID.style.visibility='hidden';
	}
}

function hideTip(id){
	ifrm.style.display='none';
	ansID = $(id);	
	ansID.style.visibility='hidden';
}
//end click tooltips

// show card


function memberToggle(){
x = $("member");
Toggle(x);

}
function cardToggle(){
x = $("card");
Toggle(x);

}
function Toggle(w){
display=w.style.display;
if(display=="block"){
w.style.display="none";
}else {
w.style.display="block";
}

}

// End show card

function newWin( url, params ) {
		window.open( url, '', params );
	}
