// JScript File

function Get_Height() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		//alert('ht1');
		return window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		//alert('ht2b');
		return document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		//alert('ht3');
		return document.body.clientHeight;
	}
}


var up,down;
var min1,sec1;
var cmin1,csec1,cmin2,csec2;

function GetByID(IDName){
	if (document.getElementById) { 
		var t = document.getElementById(IDName);
		return t;
	} else if (document.layers) {
		var tLayer = eval('document.'+IDName);
		return tLayer;
	} else {
		var t = document.all[IDName];
		return t;
	}
}

function WriteDiv(DName, DVal){
	if (document.getElementById) { 
		var t = document.getElementById(DName);
		t.innerHTML = DVal;
	} else if (document.layers) {
		var tLayer = eval('document.'+DName);
		tLayer.document.open();
		tLayer.document.write(DVal);
		tLayer.document.close();
		RightAlignDiv(DName);
	} else {
		var t = document.all[DName];
		t.innerHTML = DVal;
	}
	return true;
}

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function keepCharsInBag(sstr, bag){
	var i;
	var c;
	var sret = '';
	// Search through string's characters one by one.
	// If character is in bag, append to returnString.
	for (i = 0; i < sstr.length; i++){   
		c = sstr.charAt(i);
		if (bag.indexOf(c) >= 0) sret += c;
	}
	return sret;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function button_mouseover(x) {
	x.style.textDecoration='none';
	x.style.backgroundColor='#5580EE';
	x.style.color='#FFEE00';
	x.style.cursor='pointer';
}

function button_mouseout(x) {
	x.style.textDecoration='none';
	x.style.backgroundColor='#FFFFFF';
	x.style.color='#787878';
}

function button_link(t) {
	if (document.Exam_Form){
		if (document.Exam_Form.ExamFinished){
			alert('Please use the "grade" button to continue.');
		} else {
			location.href = t
		}
	} else if (document.IDVer_Form){
		if (document.IDVer_Form.VerifyID){
			alert('Please use the "submit" button to continue.');
		} else {
			location.href = t
		}
	} else {
		location.href = t
	}
	if (document.getElementById && document.all) window.event.cancelBubble = true;
	return false;
}

function Minutes(data) {
	for(var i=0;i<data.length;i++){
		if(data.substring(i,i+1)==":") break;
	}
	return(data.substring(0,i)); 
}

function Seconds(data) {
	for(var i=0;i<data.length;i++){
		if(data.substring(i,i+1)==":") break;
	}
	return(data.substring(i+1,data.length)); 
}

function Display(min,sec) {

	var disp;

	if(min<=9) disp=" 0";
	else disp=" ";

	disp+=min+":";

	if(sec<=9) disp+="0"+sec;
	else disp+=sec;

	return(disp); 
}

function Up() {

	cmin1=0;
	csec1=0;

	min1=0+Minutes(document.sw.beg1.value);
	sec1=0+Seconds(document.sw.beg1.value);

	UpRepeat(); 
}

function UpRepeat() {

	csec1++;

	if(csec1==60) { 
		csec1=0; cmin1++; 
	}

	WriteDiv("Timer", Display(cmin1,csec1));

	if((cmin1==min1)&&(csec1==sec1)){
		// alert("Stopwatch Stopped");
		if (document.forms[1]) {
			if (document.forms[1].ExamFinished) {
				document.forms[1].ExamFinished.click();
			} else if (document.forms[1].VerifyID) {
				document.forms[1].VerifyID.click();
			} else {
				document.forms[1].submit();
			}
		} else {
			document.forms[0].submit();
		}
	} else {
		up=setTimeout("UpRepeat()",1000); 
	}
}

function Down() {

	if (document.sw){
		if (document.sw.beg2){
			cmin2=1*Minutes(document.sw.beg2.value);
			csec2=0+Seconds(document.sw.beg2.value);
			if ((cmin2 > 0) || (csec2 > 0)) {
				DownRepeat(); 
			}
		}
		if (document.sw.maxsecs){
			if (document.sw.maxsecs.value){
				cmin1=0;
				csec1=0;

				min1=1*Minutes(document.sw.maxsecs.value);
				sec1=0+Seconds(document.sw.maxsecs.value);
				if ((min1 > 0) || (sec1 > 0)) {
					UpRepeat(); 
				} 
			} 
		} 
	}
}

function DownRepeat() {

	if ((csec2 > 0) || (cmin2 > 0)){
		csec2--;
	} else {
		return true;
	}
	
	if(csec2==-1) { 
		csec2=59; cmin2--; 
	}
	WriteDiv("Timer", Display(cmin2,csec2));

	if ((cmin2) || (csec2)){
		down=setTimeout("DownRepeat()",1000); 
	} else {
		var mike=null;
	}
}

function checktime() {
	var x = parseInt(cmin2);
	var y = parseInt(csec2);
	if ((x) || (y)){
		if (x + y != 0) {
			alert("You must stay on this page an additional " + Display(cmin2, csec2) + " before you can continue.");
			try {
				cancelBubble;
			}
			catch (error) {
				// Nothing
				x = 0;
			}
			return false;
		} else {
			if (document.Exam_Form){
				if (document.Exam_Form.ExamFinished){
					alert('Please use the "grade" button to continue.');
				} else if (document.sw.nexturl){
					window.location.href=document.sw.nexturl.value;
				}
			} else if (document.IDVer_Form){
				if (document.IDVer_Form.VerifyID){
					alert('Please use the "submit" button to continue.');
				} else if (document.sw.nexturl){
					window.location.href=document.sw.nexturl.value;
				}
			} else if (document.sw.nexturl){
				window.location.href=document.sw.nexturl.value;
			}
		}
	} else {
		if (document.sw){
			if (document.Exam_Form){
				if (document.Exam_Form.ExamFinished){
					alert('Please use the "grade" button to continue.');
				} else if (document.sw.nexturl.value){
					window.location.href=document.sw.nexturl.value;
				}
			} else if (document.IDVer_Form){
				if (document.IDVer_Form.VerifyID){
					alert('Please use the "submit" button to continue.');
				} else if (document.sw.nexturl.value){
					window.location.href=document.sw.nexturl.value;
				}
			} else if (document.sw.nexturl.value){
				window.location.href=document.sw.nexturl.value;
			}
		}
	}
	return true;
}


function Align_Footer() {
	var ht = Get_Height();
	sht = document.documentElement.scrollHeight;
	var maxHt = 2000;
	if (ht > maxHt) ht = maxHt;
	var gutter = 0;

	// alert('here 1');

	if (document.getElementById) { 
		var BodBot = document.getElementById("Body_Bottom");
		var Foot = document.getElementById("footer");
		var BSpace = document.getElementById("BSpacer");
		var Container = document.getElementById("container");
		var MainContent = document.getElementById("maincontent");
		var theImportant = document.getElementById("BottomText");
		var BottomLinks = document.getElementById("LinkB");
		var Header = document.getElementById("header");
		
		if (Header) {
			HeadHt = Header.scrollHeight;
			HeadTop = Header.scrollTop;
		} else {
			HeadHt = 0;
			HeadTop = 0;
		}


		var i = 0;
		if (theImportant) i = theImportant.offsetHeight;

		if ((MainContent)) { 
			mHt = MainContent.offsetHeight;
			if (MainContent.scrollHeight > MainContent.offsetHeight) {
				// alert('10: MainContent.offsetHeight=' + MainContent.offsetHeight + ' MainContent.scrollHeight=' + MainContent.scrollHeight);
				MainContent.style.height = MainContent.scrollHeight + 'px';
				mHt = MainContent.scrollHeight;
			}
			if (Foot) {
				// alert('11: ht=' + ht + '\nMainContent.offsetTop=' + MainContent.offsetTop +'\nMainContent.offsetHeight=' + MainContent.offsetHeight +'\nMainContent.scrollHeight=' + MainContent.scrollHeight +'\nBodBot.offsetTop=' + BodBot.offsetTop + '\nFoot.offsetTop=' + Foot.offsetTop + '\nFoot.scrollHeight=' + Foot.scrollHeight + '\nBSpace.height='  + BSpace.height + '\nFoot.scrollTop=' + Foot.scrollTop + '\nFoot.scrollHeight=' + Foot.scrollHeight);
				if (ht > Foot.offsetTop + Foot.scrollHeight + gutter){
					n = ht - Foot.offsetTop - Foot.scrollHeight - gutter;
					// alert('Setting BodyBot Height to ' + n);
					mHt = mHt + n - 1;
					if (mHt > 0) MainContent.style.height = mHt + 'px';
					if (n > 0) BodBot.style.height = n + 'px';
				} else if (BodBot.offsetTop + BodBot.offsetHeight < MainContent.offsetHeight) {
					mHt = MainContent.scrollHeight;
					n = ht - MainContent.offsetTop - mHt - Foot.scrollHeight - gutter;
					if (n > 0) mHt = mHt + n - 1;
					// alert('11b: MainContent.offsetHeight=' + MainContent.offsetHeight + '\nMainContent.scrollHeight=' + MainContent.scrollHeight + '\nsetting BodBot.style.height = ' + n + '\nsetting MainContent.style.height = ' + mHt);
					if (n > 0) BodBot.style.height = n + 'px';
					if (mHt > 0) MainContent.style.height = mHt + 'px';
				}
			}
			if ((MainContent.scrollHeight > MainContent.offsetHeight) || (MainContent.offsetHeight < mHt)) {
				// alert('12: MainContent.offsetHeight=' + MainContent.offsetHeight + ' MainContent.scrollHeight=' + MainContent.scrollHeight);
				if (mHt > 0) MainContent.style.height = mHt + 'px';
			}
			if (theImportant){
				if (BottomLinks){
//alert('setting theImportant.style.top to ' + findPos(BottomLinks)[1] + ' + ' + EleHt(BottomLinks) + 'px');
					theImportant.style.top = findPos(BottomLinks)[1] + EleHt(BottomLinks) + 'px';
				} else {
					if (Foot) {
						theImportant.style.top = findPos(Foot)[1] + EleHt(Foot) + 'px';
					}
				}
			}
			if (Container){
				//alert('30: Container.offsetHeight=' + Container.offsetHeight + ' Container.scrollHeight=' + Container.scrollHeight);
				if (Container.scrollHeight > Container.offsetHeight) {
					//alert('31: Container.offsetHeight=' + Container.offsetHeight + ' Container.scrollHeight=' + Container.scrollHeight);
					Container.style.height = Container.scrollHeight + 'px';
				} else if (Container.scrollHeight < Container.offsetHeight) {
					//alert('32: Container.offsetHeight=' + Container.offsetHeight + ' Container.scrollHeight=' + Container.scrollHeight);
					Container.style.height = Container.scrollHeight + 'px';
				}
			}
		}
	} else if (document.layers) {
		var t = eval('document.BSpacer');
		ht = ht - t.pageY;
		t.height = ht - gutter; 
	} else {
		var t = document.all['BSpacer'];
		ht = ht - t.y;
		t.height = ht - gutter; 
	}
	return true;
}

function GreaterValue(Val1, Val2)
{
	if (Val1 > Val2) return Val1;
	else return Val2;
}

function EleHt(Ele)
{
	y = Ele.style.height ? Ele.style.height : 0;
	y = GreaterValue(y, Ele.offsetHeight);
	y = GreaterValue(y, Ele.scrollHeight);
	return y;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function MM_CheckFlashVersion(reqVerStr,msg){
	with(navigator){
		var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
		var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
		if (!isIE || !isWin){  
			var flashVer = -1;
			if (plugins && plugins.length > 0){
				var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
				desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
				if (desc == "") flashVer = -1;
				else{
					var descArr = desc.split(" ");
					var tempArrMajor = descArr[2].split(".");
					var verMajor = tempArrMajor[0];
					var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
					var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
					flashVer =  parseFloat(verMajor + "." + verMinor);
				}
			}
			// WebTV has Flash Player 4 or lower -- too low for video
			else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;
			var verArr = reqVerStr.split(",");
			var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
			if (flashVer < reqVer){
				if (confirm(msg))
				window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
			}
		}
	}
}


function SetStatus(Tx){
	window.status=Tx;
	return true;
}

function openChild(file, window, width, height, options, loadingPage) {
	if (options){
		opts = options
	} else {
		opts = 'resizable=1'
	}

	if (loadingPage){
		loading = loadingPage
	} else {
		loading = ''
	}

	var childWindow;
	//alert(childWindow.name);
	//if (childWindow) childWindow.close;
	
	try {
		childWindow=open(loading,window,opts+',width=' + width + ',height=' + height,false);
		childWindow.focus();
	}
	catch(err) {
		//Handle errors here
	}
	//return false;
		
	childWindow=open(file,window,opts+',width=' + width + ',height=' + height,false);

	try {
		childWindow.focus();
	}
	catch(err) {
		//Handle errors here
	}
	return false;
}

function LoadParent(url, closeSelf){
	var opnr = self.opener;
	if (! opnr) opnr = self;
	if (url) {
		try {
			opnr.location = url;
		}
		catch(err) {
			//Handle errors here
			//alert('problem going to [' + eurl + ']');
		}
	}
	opnr.focus();
	if ((closeSelf) && (opnr != self)) { 
		self.close(); 
	}
}

function confirmDelete(e) 
{
	var targ; 
	var nodetype;
	if (!e) var e = window.event;
	targ = (e.target) ? e.target : e.srcElement;
	if(nodetype != null) {
		if (targ.nodeType == 3) targ = targ.parentNode;
	}
	if(targ.id)	{
		// alert('here I am. target=[' + targ.id + ']');
		if (targ.id.toLowerCase().indexOf("delete") >= 0) {        
			return confirm("Do you want to delete this item?");
		} else {
			if (document.getElementById && document.all) window.event.cancelBubble = true;
			else e.stopPropagation();   
		}
	}
}

document.onclick = confirmDelete;


var LinkClicked = false;
var OtherClicked = false;
var EnableRedir = false;
var HandlersEnabled=false;
var NavRef = 'http://www.fastandstressfreetrafficschool.com/';

function ClickTrack(e) {
	var targ; 
	var nodetype;
	if (!e) var e = window.event;
	targ = (e.target) ? e.target : e.srcElement;
	if(nodetype != null) {
		if (targ.nodeType == 3) targ = targ.parentNode;
	}
	//alert('target.nodeType = ' + targ.nodeType);
	if (targ.href) LinkClicked = true;
	else OtherClicked = true;

	//alert('LinkClicked='+LinkClicked + '\nOtherClicked='+OtherClicked);
//alert('1');
}

function BackHandler(e) {
	if (!e) var e = window.event;
	EnableRedir=false;
	if (LinkClicked || OtherClicked) {
		EnableRedir=false;
	} else {
		// Set Other Clicked to prevent this from firing more than once.
		OtherClicked=true;
		EnableRedir=true;
		//location.href = NavRef;
		// stop event propagation
		//return 'We\'d like a chance to change your mind.  Please read this before you go.';
	}
//alert('2');
}

function NavHandler() {
//alert('3' + EnableRedir);
	if (EnableRedir) {
//alert('4');
//		OtherClicked=true;
		location.href = NavRef;
		//return false;
	}
	return true;
}
