/* This JS code is used by all modules in the online data processing system */
var tglFlag=0;
function ToggleBkg(cell)
{
   box=document.getElementById(cell);
   if (tglFlag == 0)
   	{
		tglFlag=1;
		box.style.backgroundColor="#F4FCFF";
	} else {
		tglFlag=0;
		box.style.backgroundColor="";
	}
}
function AdminClearForm() {
	var name=prompt("This process is for use only by MasterMind staff members. After one (1) test is taken, you may not change the company represented or your name.\n\nEnter password","")
	if (name!=null && name!="") {
    	if (name != 'startover' || name=='') {
			alert('That password is incorrect. Please continue.');
			return false;
		} else {
			//Delete cookie
			AdmDelete_Cookie('mminds','/','');
			window.location.reload();
		}
	} else {
		alert('That password is incorrect. Please continue.');
		return false;
	}
	return true;
}
function AdmDelete_Cookie( name, path, domain ) {
	document.cookie = "mminds=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

/*Vertical IFRAME resizer for a single iframe on a page.*/
function SetDspFrameSize(id) {

    var DspFrame = document.getElementById(id);
    if (DspFrame) {
        if (DspFrame.contentDocument && DspFrame.contentDocument.body.offsetHeight) {
            // FireFox, Mozilla, et. al. (W3C) syntax
            DspFrame.height = DspFrame.contentDocument.body.offsetHeight;    
        } else if (DspFrame.Document && DspFrame.Document.body.scrollHeight) {
            // MSIE syntax
            DspFrame.height = DspFrame.Document.body.scrollHeight;
        }
		/* For FF/NS class browsers (and possibly others) add some additional height
		to kill off the vertical scroll bar (shows up even if SCROLLING="NO"; go figure...)
		The next line casts the string to an integer, which may or may not be adjusted. */

		var adj=(DspFrame.height / 1); 
		if (!document.all)      /* Returns TRUE unless MSIE (inverted logic)*/
			adj+=16; 	       /* For any browser other than MSIE add 16 pixels to the height. Even
							      if it turns out that we end up overadjusting for a few browsers,
							      the likelihood that 16 pixels of space will cause a problem is
							      pretty remote. */
		DspFrame.height = adj;
		if (DspFrame.addEventListener) {
            DspFrame.addEventListener("load", adjDspFrame, false);
        } else {
			DspFrame.detachEvent("onload", adjDspFrame); //MSIE needs hand-holding...
            DspFrame.attachEvent("onload", adjDspFrame);
        }
   }
}
function adjDspFrame(evt) { //retaining the event (evt) for possible future expansion; not used
	SetDspFrameSize('DisplayFrame');
}
/* On page load the following is fall-through code that will always be executed
   This code binds similar event handlers to this page. This eliminates one
   setup step. Specifically, there is no need for an installer to include a
   "onload=..." statement in the <body tag.
*/
if (window.addEventListener) {
	window.addEventListener("load",adjDspFrame,false);
} else {
    window.attachEvent("onload", adjDspFrame);
}
/* Test population and display control */

function ResetFrame() {
    var obj = document.getElementById("TestInfo");
	obj.src="library/mstartup_empty.htm";
}
function WriteOptions(optlist) {

	if (optlist == "--SELECT--") {
		ResetFrame();
		return 0;
	}
	var opts = optlist.split("|", 10);
	var selOpts="<select size=1 name=TestName>";
	if (opts[1]=='Y')
		selOpts+="<option value='DriveMaster'>Drive Master</option>";
	if (opts[2]=='Y')
		selOpts+="<option value='RoleMaster'>Role Master</option>";
	if (opts[3]=='Y')
		selOpts+="<option value='TypeMaster'>Type Master</option>";
	if (opts[4]=='Y')
		selOpts+="<option value='ThoughtMaster'>Thought Master</option>";
	if (opts[5]=='Y')
		selOpts+="<option value='TraitMaster'>Trait Master</option>";
	if (opts[6]=='Y')
		selOpts+="<option value='TimedMath'>Timed Math</option>";
	if (opts[7]=='Y')
		selOpts+="<option value='TimedVerbal'>Timed Verbal</option>";
		selOpts+="</select>";
	var InsertCode='<form method=POST name=TestParms>';
	InsertCode+='<table border=0 width=100%>';
	InsertCode+='  <tr>';
   	InsertCode+='<td width=47% align=right><font face=Arial size=2>Select Test:</font></td>';
   	InsertCode+='<td width=1%></td>';
   	InsertCode+='<td width=52%><font face=Arial size=2>' + selOpts + '</font></td>';
   	InsertCode+='</tr>';
   	InsertCode+='<tr>';
   	InsertCode+='<td width=47% align=right valign=top><font face=Arial size=2>Referrer\'s Password (all tests):</font></td>';
   	InsertCode+='<td width=1%></td>';
   	InsertCode+='<td width=52%><font face=Arial size=2><input type=password name=TestPwd size=10></font><br><font face=Arial size=1 color=red>(Caution: Passwords are <i>case sensitive</i> and always entered in <i>lowercase</i> characters)</font></td>';
   	InsertCode+='</tr>';
	InsertCode+='  <tr>';
   	InsertCode+='<td width=47% align=right valign=top><img src=images/bullet.gif>&nbsp;<font face=Arial size=2>I have read and understand<br><a href=http://www.corp-regenesis.com/disclaimer.shtml target=_blank>the disclaimer</a> for these tests:</font></td>';
   	InsertCode+='<td width=1%></td>';
   	InsertCode+='<td width=52%><font face=Arial size=2><input type="checkbox" name="disclaimer" value=""></font></td>';
   	InsertCode+='</tr>';

   	InsertCode+='</table>';
   	InsertCode+='</form>';
    var testFrame = document.getElementById("TestInfo");
    var val;
    val = InsertCode;
    // now write out the new contents
    var doc = testFrame.contentDocument;
    if (doc == undefined || doc == null)
        doc = testFrame.contentWindow.document;
        doc.open();
        doc.write(val);
        doc.close();       
    document.all.myFrame.style.visibility="visible";
//	SetDspFrameSize('TestInfo');
	
}
function TestDispatch(form) {
	//Now, dig stuff out of the Iframe (AGAIN...)
	opts=form.MasterList.value;
	TestName=form.TestName.value;
	TestName=TestName.toLowerCase();
	var url = document.URL;
	var urlPath= url.split('/');
	var count=urlPath.length - 1;
	var newUrl='';
	for (var i=0;i<count - 1; i++) {
		newUrl+=urlPath[i] + '/';
	}
	var parms=opts.split('|');
	newUrl+=TestName + '/' + TestName + '.php?cid=' + parms[0] + '&rnm=' + parms[10] + '&co=' + form.Company.value + '&ln=' + form.LastName.value + '&fn=' + form.FirstName.value + '&tn=' + form.TelephoneNumber.value + '&ex=' + form.Extension.value + '&em=' + form.EmailAddress.value + '&dg=' + form.Degree.value + '&sh=' + form.SchoolLast.value + '&ch=' + form.CollegeLast.value + '&cp=' + form.CellPhone.value;
	//Setup and write cookie data	
	var ckdata=form.Company.value + '|' +form.LastName.value + '|' +form.FirstName.value + '|' + form.EmailAddress.value + '|' + form.TelephoneNumber.value + '|' + form.Extension.value + '|' + form.Degree.value + '|' + form.SchoolLast.value + '|' + form.CollegeLast.value + '|' + form.CellPhone.value;
	set_info(ckdata);
	//
	if (TestName == "traitmaster") {
		var foo=form.MasterList.value;
		var cparms = foo.split("|");
		var coid = cparms[0];
		var ptr=cparms.length - 1;
		var cname= cparms[ptr];
		newUrl+='&cdata=' + coid + '|' + cname;
	}
	window.location.href='#pgtop';
	window.location.href=newUrl;
}
function AltTestDispatch(form, TestName) {

	var url = document.URL;
	url = url.replace(/timedmath.php/ig, "timedmath1.php");
	window.location.href=url;

}
function TVTestDispatch(form, TestName) {

	var url = document.URL;
	url = url.replace(/timedverbal.php/ig, "timedverbal1.php");
	window.location.href=url;

}

//Do some cookie stuff
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}
function set_info(mInfo) {
	var expdate = new Date ();
	expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365 * 5));
	if (mInfo != "") 
		SetCookie ("mminds", mInfo, expdate);
}
