includeFile('/simages/scripts/js/lib/sugar.js');
includeFile('/simages/scripts/js/dshad.js');

// and for the onloadies
function addToOnload(func) {
  var oldonload = window.onload;
  if (typeof oldonload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	  oldonload();
	  func();
	}
  }
}


addToOnload(function() {
	// move the 'safe - simple - secure' message to pagehead
	var msg = eID('message');
	if(msg && msg.innerHTML.match(/Safe.+?Simple.+?Secure/)) {
		var divs = document.getElementsByTagName('div');
		var phead = null;
		for(var i=0;i<divs.length;i++) {
			if(divs[i].className == 'pagehead') {
				phead = divs[i];
				break;
			}
		}
		if(phead) {
			msg.innerHTML = msg.innerHTML.replace(/Safe.+?Simple.+?Secure/,'');
			phead.insertBefore(makeEle('span',{
				float:'right',
				fontSize:'110%',
				html:'Safe &bull; Simple &bull; Secure'
			}),phead.firstChild)
		}
	}


	// and now for something completely different...
	// add dropshadows to specified field elements
	var ds = document.getElementsByTagName('div');
	var nones = [];
	for(var i=0;i<ds.length;i++) {
		if(ds[i].style.display == 'none') {
			nones.push(ds[i]);
			ds[i].style.display = '';
		}
	}
	if(eID('theRegInfoBox')) EFX.BSHAD.apply(eID('theRegInfoBox'));
	
	var frms = ['registration','contactform','searchBox','info_form','reenterform','retrieveform'];
	for(var j=0;j<frms.length;j++) {
		var frm = document[frms[j]];
		
		if(frm && !window.NOSHAD) {
	
		var flds = frm.getElementsByTagName('input');
		for(var i=0;i<flds.length;i++) {
			if(flds[i].type != 'hidden') {
				EFX.BSHAD.apply(flds[i],{img:(parseInt(getCSSWidth(flds[i]),10)>550?'/simages/templates/tso_aff_2009/dropshad_big.png':'/simages/templates/tso_aff_2009/dropshad.png')});
			}
		}
		flds = [];
		flds = frm.getElementsByTagName('textarea');
		for(var i=0;i<flds.length;i++) {
			EFX.BSHAD.apply(flds[i],{img:(parseInt(getCSSWidth(flds[i]),10)>550?'/simages/templates/tso_aff_2009/dropshad_big.png':'/simages/templates/tso_aff_2009/dropshad.png')});
		}
		flds = [];
		flds = frm.getElementsByTagName('select');
		for(var i=0;i<flds.length;i++) {
			EFX.BSHAD.apply(flds[i],{img:(parseInt(getCSSWidth(flds[i]),10)>550?'/simages/templates/tso_aff_2009/dropshad_big.png':'/simages/templates/tso_aff_2009/dropshad.png')});
		}
		
		}
	}
	for(var i=0;i<nones.length;i++) {
		nones[i].style.display = 'none';
	}
	
});

function showLowPriceInfo() {
	var info = '<p><span class="error">**Please note</span> that in accordance with Arizona Defensive Driving code we are unable to offer price matching services for any Arizona Defensive Driving course.</p>' +
	'<h1>How it works</h1><p>We will match the price of any competitor!</p>' +
	'<ul>' +
	'<li><b>STEP 1:</b> Register for the course.  If you are not already registered, <a href="/reg_select.html">click here</a> to register</li>' +
	'<li><b>STEP 2:</b> Let us know where you found a lower price.  Please note the website and page where the price was found and then <a href="/help/contact.html">contact us</a> to let us know.</li>' +
	'<li><b>STEP 3:</b> After we have confirmed the competitor\'s price (including any hidden fees), we will change your course price to match it!</li>' +
	'</ul>';
	createOverlay('Low Price Guarantee',makeEle('div',{html:info}));
	return false;
}

function titleTT(ele,t,tt) {
	if(!ele.ttip) {
		ele.ttip = makeEle('div',{className:'titleTT',dom:[
			makeEle('div',{className:'titleTT_cont',dom:[
				makeEle('div',{className:'titleTT_title',html:t}),
				makeEle('div',{className:'titleTT_tt',html:tt})
			]})
		]});
		var bs = getBoxSize(ele);
		ele.ttip.style.left = (findPosX(ele)+bs[0])+'px';
		ele.ttip.style.top = (findPosY(ele)+Math.round(bs[1]/2))+'px';
		document.getElementsByTagName('body')[0].appendChild(ele.ttip);
		ele.onmouseout = function() {
			if(ele.ttip) {
				ele.ttip.parentNode.removeChild(ele.ttip);
				ele.ttip = null;
			}
		}
	}
}
