includeFile('/simages/scripts/js/lib/sugar.js');
includeFile('/simages/scripts/js/lib/simpleajax.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','noticeForm'];
	for(var j=0;j<frms.length;j++) {
		var frm = document[frms[j]];
		
		if(frm && !window.NOSHAD) {
	

			EFX.BSHAD.applyForm(frm);
		
		}
	}
	for(var i=0;i<nones.length;i++) {
		nones[i].style.display = 'none';
	}
	
});

function showLowPriceInfo() {
	var info = '<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>'+
	'<p>All requests and price adjustments must be made prior to course payment and will require verification by TrafficSchoolOnline.com</p>' + 
	'<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>';
	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;
			}
		}
	}
}


function titleBotTT(ele,t,tt) {
	if(!ele.ttip) {
		ele.ttip = makeEle('div',{className:'titleTT_bot',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)+Math.round(bs[0]/2)-320)+'px';
		ele.ttip.style.top = (findPosY(ele)+bs[1]+10)+'px';
		document.getElementsByTagName('body')[0].appendChild(ele.ttip);
		ele.onmouseout = function() {
			if(ele.ttip) {
				ele.ttip.parentNode.removeChild(ele.ttip);
				ele.ttip = null;
			}
		}
	}
}


function titleOTTT(ele,t,otid) {
	if(!ele.isopen) {
		ele.isopen = true;
		if(!ele.ttip) {
			ele.ttip = makeEle('div',{className:'titleTT_bot',dom:[
				makeEle('div',{className:'titleTT_cont',dom:[
					makeEle('div',{className:'titleTT_title',html:t}),
					makeEle('div',{id:'otDesc'+otid,className:'titleTT_tt',html:''})
				]})
			]});
			var bs = getBoxSize(ele);
			ele.ttip.style.left = (findPosX(ele)+Math.round(bs[0]/2)-320)+'px';
			ele.ttip.style.top = (findPosY(ele)+bs[1]+10)+'px';
			document.getElementsByTagName('body')[0].appendChild(ele.ttip);
			ele.ttip.cont = eID('otDesc'+otid);
			simpleAjax('/simages/scripts/ajax/otdesc.cgi?otID='+otid,function(resp) {
				ele.ttip.cont.innerHTML = resp;
			});
		} else {
			document.getElementsByTagName('body')[0].appendChild(ele.ttip);
		}
		ele.onmouseout = function() {
			if(ele.ttip) {
				ele.ttip.parentNode.removeChild(ele.ttip);
				//ele.ttip = null;
				ele.isopen = false;
			}
		}
	}
}

function showPricing() {
	var mode = arguments[0]||'list';
	createOverlay('Price Check','loading...');
	simpleAjax('/simages/scripts/ajax/stateprices.cgi?mode='+mode,function(resp) {
		createOverlay('Price Check',document.createTextNode('<div style="overflow:auto;">'+resp+'</div>'));
		document.getElementById('overlayMain').focus();
	});
	return false;
}

function showReg() {
	var state = arguments[0]||0;
	createOverlay('Register','loading...');
	simpleAjax('/simages/scripts/ajax/stateprices.cgi?mode=reg&stateID='+state,function(resp) {
		createOverlay('Register',document.createTextNode(resp+'<br style="clear:both;"/>'));
		eID('actualoverlaytext').parentNode.style.maxWidth='970px';
	});
	return false;
}

