if ( document.getElementById ){
	if (!document.getElementById('home')){
		var num = genRand(4);
		document.write("<style type=\"text/css\" media=\"all\">");
		document.write("#titlebar {background-image: url(../img/s-titlebar-bg"+num+".gif)}");	
		document.write("</style>");		
	}
}

if (location.search == '?g'){
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../inc/glossary.css\" media=\"all\" />")
}

function initialize(){
	if ( document.getElementById ){
		if (!document.getElementById('home')){
			if (document.getElementById('glossary') && location.search == '?g'){
				initGlossaryPage();
			}
			if (document.all) sfTarget();
			initSubnav();
			initGlossary();
			initPDFWindow(); 
			initPopup();
			if (document.getElementById("testimonial")) initTestimonial();
			if (document.getElementById("alltestimonials")) initAllTestimonial();
			if (document.getElementById('Photo')) {
				document.getElementById('Photo').onload = initFade;
				loadAPI();
			}
		} else {
			initHPh();
		}
	}
}

function addAnEvent( target, eventName, functionName){
   eval('target.on'+eventName+'=functionName');
}

function initSubnav(){
	var nav = document.getElementById('nav');
	var navas = nav.getElementsByTagName('a');
	for (var a=0; a<navas.length; a++){
		var currenthref=String(navas[a].href);
		var currentloc=String(document.location);
		if (unescape(currenthref)==unescape(currentloc)){
			navas[a].className="current"
		}
	}
}

function initGlossary() {
	var mc = document.getElementById('content');
	var gas = mc.getElementsByTagName('a');
	for ( var z=0; z<gas.length; z++ ){            
  		if ( gas[z].className == "glossary" ){
			gas[z].setAttribute("title", "Define this term");
			addAnEvent(gas.item(z),'click',glossary);
		}
   }
}

function glossary(){
	var u = this.href;
	u = u.split("#");
	u = u[0]+"?g#"+u[1];
 	GlossaryWindow = window.open (u,"glossaryWindow","width=360,height=260,scrollbars=1,resizable=1");
	GlossaryWindow.focus ();
	return false;        
}

function initPDFWindow(){
	var links=document.getElementsByTagName("a");
	var linky;
	for(var i=0;i<links.length;i++){
		linky = links[i];
		if(linky.href.indexOf(".wpd") > 0 || linky.href.indexOf(".pdf") > 0 || linky.href.indexOf(".doc") > 0 || linky.href.indexOf("getdoc.aspx?dl=0") > 0){
			linky.title = "This document will open in a new window.";
			linky.innerHTML += "<img src=\"../img/ic-newwin.gif\" width=\"23\" height=\"13\" alt=\"\" />";
			addAnEvent(linky,'click',PDFWindow);
		}
	}
}

function PDFWindow(){
 		appWindow = window.open (this.href,"appWindow","width=600,height=400,toolbar=0");
		appWindow.focus ();
		return false;        
}

function initPopup(){
	var links=document.getElementsByTagName("a");
	var linkp;
	for(var i=0;i<links.length;i++){
		linkp = links[i];
		if(linkp.className == "popup"){
			linkp.title = "This document will open in a new window.";
			linkp.innerHTML += "<img src=\"../img/ic-newwin.gif\" width=\"23\" height=\"13\" alt=\"\" />";
			addAnEvent(linkp,'click',Popup);
		}
	}
}

function Popup(){
 		appWindow = window.open (this.href,"appWindow","width=600,height=400,toolbar=1,scrollbars=1,resizable=1");
		appWindow.focus ();
		return false;        
}

function sfTarget () {
	var sfEls=document.getElementsByTagName("div");
	var aEls = document.getElementsByTagName("a");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i]; aEls[j].onclick = function() {
					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget"; document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}

function initGlossaryPage(){
	var dl = document.getElementsByTagName("dl");
	var divs = dl[0].getElementsByTagName("div");
	for (var d=0; d<divs.length; d++){
		if (divs[d].className == "rtt"){
			divs[d].innerHTML = "<a href=\"javascript:window.close();\">close window</a>";
			divs[d].className = "close";
		}
	}
}

function initHPh(){
	var nav = document.getElementById('nav')
	var num = genRand(4);
	nav.innerHTML += "<img src=\"img/h-ph"+num+".jpg\" width=\"273\" height=\"180\" alt=\"\" id=\"photo\" />";
}

function genRand(x) {
 var range = x;
 return Math.floor(Math.random() * range) + 1;
}

//tesimonials
var testimonials = [
	['I am thankful the California Dentists&rsquo; Guild came to our central coast. They showed us how we could start making a step toward out future. Elizabeth Clark of the Guild and Bob Gajewski of Comerica both have given me tremendous guidance in preparing for my retirement.','Hobert E. Herber, DDS<br />Pismo Beach, CA'],
    ['Our practice has been a participant in the profit sharing plan from many years now. Participants have always seen a level of growth even in a down economy. The Annual Meeting provides any participant the ability to speak directly to the various fund managers. Elizabeth Clark and her team are effective managers. Our relationship with CDG is terrific!','Virginia Hughson-Otte, DDS, Inc.<br />Santa Clarita, CA'],
	['The CDG quite simply gives me peace of mind with the wild fluctuations of the market causing day traders ulcers; I can sleep at night and concentrate on dentistry (which I do best). They have proven themselves time and time again.','Richard Hoedt, Jr., DDS<br />San Francisco, CA'],
	['The California Dentists&rsquo; Guild is always there for you! They provide a cost effective way of saving for retirement with protections built in.','William A. Hall, DDS<br />Salinas, CA'],
	['CDG is your one stop shop for all your no load, no fee retirement funds. Everyone at the Guild is knowledgeable and so friendly. They always remember me and solve all my problems very efficiently!','Tiffany Lee, DDS<br />Torrance, CA'],
	['The Guild truly belongs to its members. Whenever I call I get a real human voice as well as personal service to answer my questions. I&rsquo;ve had a very satisfactory relationship for 40 years.','Ken Fat, DDS<br />Sacramento, CA'],
	['For over 20 years the Guild has been making money (lots!) for me. And now that I&rsquo;m no longer practicing, the returns are paying for most of my bills. Thanks!','Robert D. Abeloff, DDS<br />Beverly Hills, CA'],
	['I really like the programs and options that California Dentists&rsquo; Guild has.','Rodney Chew, DDS<br />Fremont, CA'],
	['For those who, like me, don&rsquo;t enjoy dealing with the administration of your retirement plan, California Dentists&rsquo; Guild is the answer. I have been very pleased with how CDG has kept me current and safe with respect to government requirements.','Richard Cohrs, DDS<br />Covina, CA']
]

function initTestimonial(){
    var n=genRand(testimonials.length);
    var testimonial = document.getElementById("testimonial");
	var content = "<h4 id=\"hdtestimonial\"><a href=\"/about/testimonials.htm\">Client Testimonials</a></h4>"
    content += "<p class=\"quote\">&ldquo;"+testimonials[n-1][0]+"&rdquo;</p>\n";
    content += "<p class=\"attr\">"+testimonials[n-1][1]+"</p>\n";
    content += "<p class=\"more\"><a href=\"/about/testimonials.htm\">Read more testimonials.</a></p>\n";
    testimonial.innerHTML = content;
}

function initAllTestimonial(){
    var testimonial = document.getElementById("alltestimonials");
	var content = "";
	for (var n = 0; n < testimonials.length; n++){
    	content += "<p class=\"quote\">&ldquo;"+testimonials[n][0]+"&rdquo;</p>\n";
    	content += "<p class=\"attr\">"+testimonials[n][1]+"</p>\n";
    	content += "<hr />\n";
	}

    testimonial.innerHTML = content;
}

window.onload=initialize;
