var url = document.URL;
var dirArray = url.split("/");
var lcdir = dirArray[6];
var subjectdir = dirArray[7];
dirArray.reverse();
var page = dirArray[0];
var pageArray = page.split(".");
var pagename = pageArray[0];
var qArray = url.split("?");
if (qArray[1].match(/.[a-zA-Z0-9\=\/]$/) && (qArray[1].match(/^http/) != 'http')){
	var qInfo = qArray[1];
	}
else if (qArray[1].match(/.[a-zA-Z0-9\:\/]$/) && qArray[1].match(document.location.hostname)){
	var qInfo = qArray[1];
	}
else{
	 window.alert("Security error");
}
if (lcdir=='lc_two') {
	var path = '/student/testing/sat/lc_two/'+subjectdir+'/prac/';
}
else {if (lcdir=='prep_one') {
	var path = '/student/testing/sat/prep_one/'+subjectdir+'/prac/'
}
else {
	var path = '';
};};

//button preload
function preloadButtons() {
	btns = new Array('testing','plan','csearch','apply','pay','myorg');
	if (document.images) {
		for (i=0;i<btns.length;i++) {
			btn = btns[i];btn = new Image;
			btn.src = '/prod_images/navigation/but_' + btns[i] + '_on.gif';
		}
	}
}

function goto_content(selection) {
	var which = selection.selectedIndex;
	var url = selection[which].value;
	if (url == 'http://www.collegeboard.com/sat/html/admissions/indx001.html') {
			window.open(url,'newwin')
		}
	else if (url == '/clep') {
			window.open(url,'newwin')
		}
	else {
		document.URL = url;
	}		
}

function SubmitQuiz(url) {
	if (ValidQuiz()) {
		var winTwo = window.open(url,'result','top=100,left=100,toolbar=0,width=540,height=420,resizable=no,scrollbars=yes');
		winTwo.focus();
		return false;
	} else {
		return false;
	}
}

// function to check the validity of a quiz
function ValidQuiz() {
	// if it's a pulldown, the answer is the value of the pulldown
	if (document.quizform.rdQuizAnswers.type == "select-one") {
		ans = document.quizform.rdQuizAnswers.selectedIndex;
	} else {
		ans=0;
		for (var i=0; i < document.quizform.rdQuizAnswers.length; i++) {
			// if it's radio buttons, the answer is the checked one
			if (document.quizform.rdQuizAnswers[i].checked) {	
				ans=i+1;
			}
		}
	}
	if (ans > 0) {retval = true} else {retval = false}
	if (retval == false) {
		alert('Cat got your tongue?  You need to make a selection before hitting the "Submit" button.');
	}
	
	return retval;
}

//learning center functions
function shortcut(newURL) {
	var winTwo=window.open(newURL,'newWin','status=no,scrollbars=yes,width=600,height=400');
	winTwo.focus();
	return false;
}

function hint(newURL) {
	var winTwo=window.open(newURL,'newWin','status=no,scrollbars=yes,width=600,height=400');
	winTwo.focus();
	return false;
}

function getAnswer(newURL,formName,correct) {
	if (newURL) {
		var theAnswers= eval('document.forms.'+formName+'.answer');
		var yourAnswer = '';
		var urlAnswer = '';
		for (i=0;i<theAnswers.length;i++) {
			if (theAnswers[i].checked) {
				yourAnswer = theAnswers[i].value;
			}
		}
		if (yourAnswer!='') {
			if (yourAnswer == correct) {
				urlAnswer = newURL + '?a=r';
			}
			else {
				urlAnswer = '/student/testing/sat/lc_two/pracWrong.html?'+newURL;
			}
		}
		else {
			urlAnswer = newURL;
		}
		var winTwo=window.open(urlAnswer,'answer','status=no,location=no,scrollbars=yes,width=600,height=400');
		winTwo.focus();
		return false;
	}
	else if (page.indexOf('?a=r')!=-1) {
		document.write('<p class="error"><b>CORRECT!</b></p> ')
	}
	else {
	}
}

function subNavLC() {
	//default number of questions
	var quest = 16;
	var tips = 'no';
	//get current question number from URL
	if (pagename.indexOf('Start')!=-1) {
		var current = 'Start';
	}
	else if (pagename.indexOf('Tips')!=-1) {
		var current = 'Tips';
	}
	else {
		var current = pagename.charAt(4).toString() + pagename.charAt(5).toString();
	}
	//list of all subjects
	var subjects = new Array('german','lit','hebrew','ital','koreanlist', 'histus', 'math1c', 'math2c', 'phys','span', 'latin','french', 'histworld','japanlist', 'japan', 'chinese', 'analogies', 'sent_comp', 'crit_read', 'multi_choice', 'quant_comp','spr', 'math_review_alg', 'math_review_geo');
	//number of questions in each subject
	var subjQuestions = new Array(5,10,7,7,2,16,8,7,16,4,6,7,10,4,8,9,3,3,7,6,8,5,4,7);
	//tips available for subject?
	var subjTips = new Array('no','yes', 'no','no','no','no','yes', 'yes', 'no','no','no','no','no','no','no', 'no','yes','yes','yes','yes','yes', 'yes', 'no', 'no');
	//user above arrays to find number of questions in this subject
	for (i=0;i<subjects.length;i++) {
		if (subjects[i] == subjectdir) {
			quest = subjQuestions[i];
			tips = subjTips[i];
		}
	}
	
	//Left and right corner "off" states
	var start = '<td width="58" height="24" class="cbDark"><a href="'+path+'pracStart.html"><img src="/prod_images/student/subnav_start.gif" width="51" height="15" border="0" alt="Start"></a></td>';
	var startLeft = 'subnav_left.gif';
	var subnavRight = "cbLight";

	//if start is "on", make left corner white
	if (current == 'Start') {
		var start = '<td width="58" height="24" class="white"><img src="/prod_images/student/subnav_start_on.gif" width="51" height="15" border="0" alt="Start"></a></td>';
		var startLeft = 'subnav_left_on.gif';
	}

	//if tips or last question is "on", make right corner white
	if ((current == 'Tips')||((current == quest)&&(tips ==' no'))) {
		var subnavRight = "white";
	}
	
	//calculate width of cells based on number of questions
	var cellWidth = Math.floor((300 - (quest - 1))/quest);

	var tableTop = '<table cellpadding="0" cellspacing="0" border="0" width="368">'
	+'<tr>'
	+'	<td width="6" rowspan="3" valign="top"><img src="/prod_images/student/'+startLeft+'" width="6" height="25" border="0" alt=""></td>'
	+'	<td colspan="2" height="1" class="cb"><img src="/prod_images/null_1x1.gif" width="2" height="1" border="0" alt=""></td>'
	+'	<td width="4" rowspan="2" class="'+subnavRight+'"><img src="/prod_images/student/subnav_right.gif" width="4" height="25" border="0" alt=""></td>'
	+'</tr>'
	+'<tr>'
	+	start
	+'	<td height="24" width="300" class="cbLight">'
	+'		<table cellpadding="0" cellspacing="0" border="0" width="100%">'
	+'		<tr>';
	
	var tableBottom = '</tr></table></td></tr>'
	+'<tr><td colspan="3" height="1" class="cb"><img src="/prod_images/null_1x1.gif" width="2" height="1" border="0" alt=""></td></tr>'
	+'</table>';
	
	document.write(tableTop);

	//loop through questions, applying color/white lines
	for (k=1;k<quest+1;k++) {
		if (k<10) {
			j = '0'+k;
		}
		else {
			j=k;
		}
		if ((k<quest)||((k==quest)&&(tips=='yes'))) {
			var url = path + 'prac' + j + '.html';
			//code for current question
			if (k==current) {
				document.write('<td class="white" align="center" width="'+cellWidth+'"><span class="subNavOn">'+k+'</span></td><td width="1" align="center"><img src="/prod_images/white.gif" width="1" height="24" border="0" alt=""></td>');
			}
			//code for all other questions
			else {
				document.write('<td align="center" width="'+cellWidth+'"><a href="'+url+'" class="subNav">'+k+'</a></td><td width="1" align="center"><img src="/prod_images/white.gif" width="1" height="24" border="0" alt=""></td>');
			}
		}
		//code for last question if no tips
		else if ((k==quest)&&(tips='no')) {
			var url = path + 'prac' + j + '.html';
			if (k==current) {
				document.write('<td class="white" align="center" width="'+cellWidth+'"><span class="subNavOn">'+k+'</span></td>');
			}
			else {
				document.write('<td align="center"><a href="'+url+'" class="subNav">'+k+'</a></td>');
			}
		}
	}

	//code for Tips cell
	if (tips == 'yes') {
		if (current == 'Tips') {
			document.write('<td class="white" align="center">&nbsp;<span class="subNavOn">Tips</span>&nbsp;</td>');
		}
		else {
			document.write('<td align="center">&nbsp;<a href="'+path+'pracTips.html" class="subNav">Tips</a>&nbsp;</td>');
		}
	}
	
	document.write(tableBottom);
}


function popup(url,title,w,h,r,s,m,t) {
	//if vars aren't provided, use these defaults
	if (title==null) {
		title = 'popup';
	} if (w==null) {
		w=600;
	} if (h==null) {
		h=400;
	} if (r==null) {
		r='yes';
	} if (s==null) {
		s='yes';
	} if (m==null) {
		m='no';
	} if (t==null) {
		t='no';
	}
	vars = 'width='+w+',height='+h+',resizable='+r+',scrollbars='+s+',menubar='+m+',toolbar='+t;
	var newWin = window.open(url,title,vars);
	newWin.focus();
	return false;
}
