/*  ******************************************/
/*  **  Configuration  **/

var MHLN_FLASH_LINK_DIRECT = true; //calls the swf file directly instead of its html
var	MHLN_FLASH_MARGIN_WIDTH = 18;
var	MHLN_FLASH_MARGIN_HEIGHT = 25;

/*	Javascript functions  */

// Scripts

function parse_qs()
{
	var getitem = new Array();
	if(location.search.length > 2) 
	{
		var qs = location.search.substring(1).split('&');
		for(var i=0;i<qs.length;i++)
		{
			qsitem = qs[i].split('=');
			if(qsitem.length == 2)
				getitem[unescape(qsitem[0])] = unescape(qsitem[1]);
		}
	}
	return getitem;	
}

function strim(s)
{
	return (s.replace(/^\s+|\s+$/g,''));
}

function embed_flash(src,width,height,params)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ');
	
	//document.write('width="' + width + '" height="' + height + '">\n');
	document.write('width="' + '100%' + '" height="' + '100%' + '">\n');
    
	document.write('<param name="movie" value="' + escape(src) + '" />\n');
    document.write('<param name="quality" value="high" />\n');
	for(param in params)
		document.write('<param name="' + param + '" value="' + params[param] + '" />\n');
    document.write('<embed src="' + escape(src) + '" ');
	for(param in params)
		document.write(param + '="' + params[param] + '" ');
	document.write(' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
	
	//document.write('type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>\n</object>');
	document.write('type="application/x-shockwave-flash" width="' + '100%' + '" height="' + '100%' + '"></embed>\n</object>');
}

/**** To Popup assets in external sites like MHLN ****/
function pop_mhln_asset(url,type)
{
	if(MHLN_FLASH_LINK_DIRECT)
	{
		if(url.match(/showpage.htm$/)) {marginw = 20; marginh = 20;}
		else
		{
			url = url.replace(/\.html?$/,'.swf');
			marginw = 0; marginh = 0;
		}
	}
	else
	{
		marginw = MHLN_FLASH_MARGIN_WIDTH;
		marginh = MHLN_FLASH_MARGIN_HEIGHT;
	}
	
	if(url.match(/mhln\.com\/ob\//))
	{
		if(type=='game'){width = 800; height=600;}
		else{width = 640; height=480;}
	}
	else if( url.match(/mhln\.com\/lng\//)){width = 625; height=500;}
	else{width = 640; height=480;}
	
	popext = window.open(url,'_blank','width=' + (width + marginw) + ',height='+ (height + marginh) + ',status=no,scrollbars=no,resizable=no');
}

/**** To Popup FactDash ****/
function popFactDash()
{
	popfd = window.open('http://www.mhschool.com/math/2009/ca/assets/factdash.html','_blank','width=640,height=480,status=no,scrollbars=no,resizable=no')
}


function get_asset_info(asset_id,asset_type)
{
	var asset_info = new Array();
	asset_info['type'] = asset_type;
	asset_info['title'] = '';
	
	switch(asset_info['type'])
	{
		case 'ANI':
			asset_info['path'] = 'animation/' + asset_id + '.swf';
			asset_info['title'] = 'Animation';
			asset_info['width'] = 600;
			asset_info['height'] = 435; //635;
			asset_info['params'] = null;
			break;


		case 'PT':
			asset_info['path'] = 'pt/' + asset_id + '.swf';
			asset_info['title'] = 'Personal Tutor';
			asset_info['width'] = 801;
			asset_info['height'] = 670; //635;
			asset_info['params'] = null;
			break;
		
		case 'CIM':
			asset_info['path'] = 'cim/' + asset_id + '.swf';
			asset_info['title'] = 'Concepts in Motion';	
			asset_info['width'] = 550;
			asset_info['height'] = 400;	
			asset_info['params'] = null;		
			break;
			
		case 'CIMF':
			asset_info['path'] = 'cim/' + asset_id + '/Start.swf';
			asset_info['title'] = 'Concepts in Motion';	
			asset_info['width'] = 909;
			asset_info['height'] = 639;	
			asset_info['params'] = {
				'base': 'CIM/' + asset_id,
				'allowScriptAccess': 'sameDomain'				
				};			
			break;			
			
		case 'BSS':
			asset_info['title'] = 'Blip\'s Satellite Service';
						  
		case 'BF':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Bugle Farms';
				
		case 'CJ':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Critter Junction';
				
		case 'MF':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Mount Frost';
				
		case 'NV':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Number Voyage';
				
		case 'RW':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Robo Works';
				
		case 'SEC':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Scrambled Egg City';
				
		case 'ST':
			if(asset_info['title'] == '')
				asset_info['title'] = 'Starfish Theater';
				
			asset_info['path'] = 'Activity.swf';
			asset_info['width'] = 800;
			asset_info['height'] = 600;	
			asset_info['params'] = {
				'FlashVars': 'webData=' + asset_id.replace(/_/g,','),
				'allowScriptAccess': 'sameDomain'
			};		
			break;
			
		default:
			asset_info['path'] = '/' + asset_id + '.swf';
			asset_info['title']  = 'Lesson Asset';
			asset_info['width'] = 640;
			asset_info['height'] = 480;
			asset_info['params'] = null;		
			break;
	}
	
	return asset_info;
	
}

function pop_commingsoon()
{
	w=300;
	h=300;
	wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;	
	popw = window.open('../comingsoon.html','_blank','width=' + w + ', height=' + h + ', left=' + wleft + ', top=' + wtop + ', ' + 'status=no,scrollbars=no,resizable=no');		
}


function popEGlossary()
{
	popw = window.open('http://www.glencoe.com/apps/eglossary/grade.php','_blank','width=680,height=480,status=no,scrollbars=no,resizable=no');		
}

function popMathToolChest()
{
	popw = window.open('http://www.mhschool.com/math/mathtoolchest/mtc_online/','_blank','width=780,height=523,status=no,scrollbars=no,resizable=no');			
}

function popVocabReview(url)
{
	popw = window.open(url,'_blank','width=800,height=650,status=no,scrollbars=no,resizable=no');		
}


function pop_asset(src,atype)
{
	inf = get_asset_info(src,atype);
	popw = window.open('../assets/asset_view.html?s=' + escape(src) + '&type=' + atype,'_blank',
		'width='+ inf['width'] + ',height=' + inf['height'] + ',status=no,scrollbars=no,resizable=no');	
}

function pop_animation(src,atype)
{
	inf = get_asset_info(src,atype);
	popw = window.open('../assets/asset_view.html?s=' + escape(src) + '&type=' + atype,'_blank',
		'width='+ inf['width'] + ',height=' + inf['height'] + ',status=no,scrollbars=no,resizable=yes');	
}


function pop_mathadv_asset(src)
{
	atype = src.split('_')[0];
	inf = get_asset_info(src,atype);
	popw = window.open('../assets/asset_view.html?s=' + escape(src) + '&type=' + atype,'_blank',
		'width='+ inf['width'] + ',height=' + inf['height'] + ',status=no,scrollbars=no,resizable=no');			
}

function pop_vm()
{
	popw = window.open('http://www.glencoe.com/sites/common_assets/mathematics/ebook_assets/vmf/VMF-Interface.html');			
}

function pop_url(src)
{
	popw = window.open(src);			
}

function setExternalLinkWarnings()
{
	a = document.getElementsByTagName('a');
	
	for(i=0;i<a.length;i++) {

		if(a[i].className == 'externalLink'){
			a[i].onclick=function(){alert('You are leaving a MGH website!');}
		}	
	}
	
	
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function markStudentPage()
{
	if(location.href.match('^.*?sg.*?.html$')){
		createCookie('LastStudentPage',location.href,1);
	} else if (location.href.match('^.*index_(teacher|family).html$')) {
		eraseCookie('LastStudentPage');
	}
	
}

function goStudentPage()
{
	sp = readCookie('LastStudentPage');
	if(sp) {
		location.href = sp;	
	} else {
		up = location.href.split('/');
		d = up[up.length-2];
		location.href = 'sg' + (d.substr(d.length-1)) + 'c1lesson1.html';
	}
}


function init()
{
	//setExternalLinkWarnings();
	markStudentPage();
	
}

window.onload = init;

