/**
@description opens spidersmart popups
url must have http://
@name openSSPopup
@author Rafael Guarinon
@since 11/08/06
@param string url
@param string params
@param string open_method
TODO: check if theres an http:// in the url, if not put it.
	  get array instead of string params
**/
function openSSPopup(url, open_method, params) {		
	/**
	* checking parameters 
	**/
	if (!url) return false;
	if (!open_method) return false;
	if (!params) return false;			
	/**
	* opens poup
	**/
	window.open(url,open_method,params);
}

/**
to come
**/
function spidersmart_fillDatabases()
{
	feed = document.getElementById("databases");
	return_databases = document.getElementById("return_databases");
	
	return_databases.value = "";
				
	for (i=0;i<feed.length;i++) {		
		if(feed.options[i].selected == true)
		{				
			return_databases.value += feed.options[i].value + ",";
		}		
	}	
}

function spidersmart_showNewCountry(value , style)
{
	if (!style) style = "block";
	
	country_div = document.getElementById("new_country");
				
	if (value == 6)
	{	
		country_div.style.display = style;				
	} 
	else
	{		
		country_div.style.display = "none";		
	}
}

function showDrills(father_node)
{
	if (father_node)
	{
		drills_div = document.getElementById(father_node);
		more_icon  = document.getElementById(father_node+"_more_icon");
		less_icon  = document.getElementById(father_node+"_less_icon");
		
		if (drills_div)
		{
			if (drills_div.style.display == "none") {
				drills_div.style.display = "block";
				more_icon.style.display  = "none";
				less_icon.style.display  = "inline";
			}
			else if (drills_div.style.display == "block") {
				drills_div.style.display = "none";
				less_icon.style.display  = "none";
				more_icon.style.display  = "inline";
			}
		} else
		{
			return false;
		}
	}
}

function showErrors(id)
{
	if (id)
	{
		div_error = document.getElementById(id);
		
		if (div_error.style.display == "none")		
			div_error.style.display = "block";		
		else if(div_error.style.display == "block")
			div_error.style.display = "none";
	}
	else
	{
		return false;
	}
}

function sortResults(sort_option, page, parameters, site)
{
	sort_fields = document.getElementById("sort");	
	spidersmart_extLoadContent(site, 'superadmin/print_assignment_report_ajax.php', 'print_assignment_report', parameters+'&sort='+sort_fields[sort_option].value);
	
}

function gotoPage(page_option, parameters, site)
{
	page_dd = document.getElementById("page");	
	spidersmart_extLoadContent(site, 'superadmin/print_assignment_report_ajax.php', 'print_assignment_report', parameters+'&page='+page_dd[page_option].value);
}

/*function viewEbook()
{	
	var ebook   = document.getElementById('ebook').value;
	var rwlevel = document.getElementById('rwlevel').value;

	if (!rwlevel)
	{
		alert("Select a R&W Level.");	
	}
	else
	{
		if (!ebook)
		{
			alert("Select an e-book.");
		}
		else
		{
			alert("Showing up ebook: " + ebook);	
		}
	}
}*/

function changeIcon(func, span_id)
{	
	var span_block = document.getElementById(func+"_"+span_id);	
	span_block.style.display = "none";
	
	if (func == "less")
	{
		var show_block = "more_" + span_id;
	}
	else if (func == "more")
	{
		var show_block = "less_" + span_id;
	}
	else
	{
		return false;
	}
	
	document.getElementById(show_block).style.display = "inline";
}

function gscToggleAllBooks()
{
	var book_count = document.gsc_review.elements['completed[]'].length;
									
	if (!book_count) {
		document.gsc_review.elements['completed[]'].checked = true;
	}
	else {
		for (var i = 0; i < book_count; i++) {
			document.gsc_review.elements['completed[]'][i].checked = true;
		}		
	}
}

function gscToggleNoneBooks()
{
	var book_count = document.gsc_review.elements['completed[]'].length;
		
	if (!book_count) {
		document.gsc_review.elements['completed[]'].checked = false;
	}
	
	for (var i = 0; i < book_count; i++) {
		if (document.gsc_review.elements['completed[]'][i].checked)
			document.gsc_review.elements['completed[]'][i].checked = false;
	}		
}

function filterReviews()
{
	gscToggleNoneBooks();	
	document.gsc_review.filter.value = "yes";
	document.gsc_review.submit();
}

function addCategory(id, node)
{	
	seed = document.getElementById("category");
	feed = document.getElementById("categories");
	
	text = seed.options[node].text;
				
	var flag=true;
	for (i=0;i<feed.length;i++)
		if (feed.options[i].value==id)
			flag=false;
	
	
	if(text && id && flag){
		feed.options[feed.length] = new Option(text, id);
		alert('Category "'+text+'" successfully added!');
	} else {
		if (!flag) alert('This category was already inserted');
		else alert('Please, select a valid category');
	}
}

function removeCategory()
{
	feed = document.getElementById("categories");
	if (feed.selectedIndex >= 0) feed.remove(feed.selectedIndex);
}

function showScreenInstructions(screen_id)
{
	var screen_instructions_value = document.getElementById("screen_instructions_" + screen_id).value;
	var screen                    = document.getElementById("show_screen_instructions");
	
	if (screen && screen_instructions_value)
	{
		screen.style.display = "block";
		screen.innerHTML 	 = "Screen Instructions: <span style=\"font-weight: normal;\">" + screen_instructions_value + "</span>";
	}
	
	return true;
}


function controlLoginValues(obj, value, event, password) {
    if (password) {
        obj.type = 'password';
    }
    if (event == 'onfocus') {
        obj.value = obj.value == value ? '' : obj.value;
    }
    if (event == 'onblur') {
        if (password) obj.type = obj.value == '' ? 'text' : 'password';
        obj.value = (obj.value != value && obj.value != '') ? obj.value : value;
    }
}

function switchTestimonial(testimonial) {
	
	var title;
	var signature;
	var text;
	var imageHolder;
	var titleSize = "18px";
	var textSize  = "16px";
	var signSize  = "16px";
	var divSize   = "283px";
	
	if (testimonial == 'eric')
	{ 
		title 	    = "Promoting Good Reading Habits for 20 Years.";
		signature   = "- Eric C's mom";
		text	    = "My son started SpiderSmart in second grade as a reluctant reader.  Gradually, through this program he has become a book lover. He is now in fifth grade and an avid reader.";
		imageHolder = "interface/images/img_eric.jpg";
		titleSize	= "16px";		
	}
			
	else if(testimonial == 'leonard')
	{
		title 	    = "Teaching Reading & Writing for Over 20 Years.";
		signature   = "- Leonard Bumbaca, President, Fairfax Education Association";
		text	    = "SpiderSmart is consistently about growth and meeting individualized needs.  At  SpiderSmart Learning Center I have seen students master reading & writing skills in an environment that is supportive and task-oriented.  I am glad that my own son attends something that he looks forward to each week.";
		imageHolder = "interface/images/img_leonard.jpg";
		titleSize	= "16px";
		textSize  	= "12px";		
		signSize  	= "12px";
	}
	
	else if(testimonial == 'youlim')
	{
		title 	    = "Teaching Excellence, One Student at a Time.";
		signature   = "- Youlim Y, Wellesley College";
		text	    = "I have taken my lessons from SpiderSmart and employed them at school where they helped me tremendously in my English classes.  The continual practice of writing well thought out and well written essays paid off when it was time for college applications and college essays.";
		imageHolder = "interface/images/img_youlim.jpg";
		titleSize	= "16px";
		textSize  	= "13px";		
		signSize  	= "13px";		
	}
	
	else if(testimonial == 'ami')
	{
		title 	    = "Building Confidence with Consistent Guidance.";
		signature   = "- Ami J's mom";
		text	    = "Ami came to the US five years ago.  About a year ago, she started SpiderSmart. Since then her English grades shot up.  For those students exposed to two different languages at home, this is a perfect program.";
		imageHolder = "interface/images/img_ami.jpg";
		titleSize	= "16px";
		textSize  	= "14px";		
		signSize  	= "14px";		
	}
	
	else if(testimonial == 'christine')
	{
		title 	    = "Building Confidence in Writing for Over 20 Years.";
		signature   = "- Christine L, 7th grade";
		text	    = "My teacher says that my writing is so good. I think SpiderSmart helped me become an excellent writer.  Thank you, SpiderSmart!";
		imageHolder = "interface/images/img_christine.jpg";
		titleSize	= "16px";		
	}
	
	else if(testimonial == 'michelle')
	{
		title 	    = "Teaching Success, One Student at a Time.";
		signature   = "- Michelle, 5th grade";
		text	    = "I think SpiderSmart is fun. I get to read a lot of good books. My reading level went up two grades in four months.";
		imageHolder = "interface/images/img_programs.jpg";		
	}
	
	document.getElementById('title').innerHTML 	   			   = title;
	document.getElementById('signature').innerHTML 			   = signature;
	document.getElementById('text').innerHTML	   			   = text;
	document.getElementById('imageHolder').src	   			   = imageHolder;
	document.getElementById('title').style.fontSize	   		   = titleSize;
	document.getElementById('text').style.fontSize	   		   = textSize;
	document.getElementById('signature').style.fontSize	   = signSize;
	document.getElementById('testimonialBox').style.height	   = divSize;
}

function showTestimonial(testimonial) {
	
	var text;
	
	if (testimonial == 'youlim')
	{
		text = "I had to analyze questions and be able to write about the books effectively. With the help of the teachers, I learned and strengthened my skills in basic grammar, organization, and composition of an essay.  I have taken my lessons from SpiderSmart and employed them at school where they helped me tremendously in my English classes.  The continual practice of writing well-written essays paid off when it was time for college applications and college essays. I had mastered techniques and was ready to woo the colleges.&quot;<br><br>Youlim Y. Wellesley College";
		document.getElementById('youlimText').innerHTML = text;
		
		if (document.getElementById('youlimText').style.display == "block")
		{
			document.getElementById('youlimText').style.display = "none";
		}
		else
		{
			document.getElementById('youlimText').style.display = "block";	
		}		
	}
	else if (testimonial == 'leonard')
	{
		text = "As a teacher in the Fairfax County Public Schools system, I am glad that my own son attends something that he looks forward to each week.  Sometimes it is hard to make him stop reading.&quot;<br><br>Leonard Bumbaca,<br>President, Fairfax Education Association";
		document.getElementById('leonardText').innerHTML = text;
		
		if (document.getElementById('leonardText').style.display == "block")
		{
			document.getElementById('leonardText').style.display = "none";
		}
		else
		{
			document.getElementById('leonardText').style.display = "block";	
		}		
	}
	else if (testimonial == 'eric')
	{
		text = "He always has a book in his hand.  Sometimes it is hard to make him stop reading.&quot;<br><br>Eric C's mom";
		document.getElementById('ericText').innerHTML = text;
		
		if (document.getElementById('ericText').style.display == "block")
		{
			document.getElementById('ericText').style.display = "none";
		}
		else
		{
			document.getElementById('ericText').style.display = "block";	
		}		
	}	
	else if (testimonial == 'patricia')
	{
		text = "Patricia deeper understanding of themes and topics.  Through participating in SpiderSmart, Patricia has made significant progress with her reading and writing skills.&quot;<br><br>Patricia M's mom";
		document.getElementById('patriciaText').innerHTML = text;
		
		if (document.getElementById('patriciaText').style.display == "block")
		{
			document.getElementById('patriciaText').style.display = "none";
		}
		else
		{
			document.getElementById('patriciaText').style.display = "block";	
		}		
	}
}