// JavaScript Document
//This file contains some function in javascript according to the customize-embedd box.

//NOTE: in this js file we have used the $D('element_name) to perform the functionality of 
//document.getElementById('element_name') function. This $D is defined in teh color picker file
//So i am just using that instead of defining the same here in this file.

function $D(v) { return(document.getElementById(v)); }
function display_box()
{
	if ($D("divBox").style.display=="none" || $D("divBox").style.display.length==0)
	{
		$D("divBox").style.display="block";
		
		//De-selecting the menu of Title, Background and Foreground color.
		change_color_area='1'; 
		select_change_color_area();
	}
	else
	{
		$D("divBox").style.display="none";
	}
}

//global variables for changing the generated code
var th_bgcolor='';
var th_bcolor='';
var th_fccolor='';

/*change_theme functions accepts the three parameters(color codes)
on the basis of these parameter the color (theme) of the quiz
box will be changed.*/
function change_theme(b_color, bg_color, fc_color)
{		
	if (bg_color.length != 0)
	{
		$D("tblquiz").style.backgroundColor = '#' + bg_color;
		th_bgcolor = bg_color;
	}
	
	if (b_color.length != 0)
	{
		$D("tblquiz").style.borderColor = '#' + b_color;
		$D("hlk_heading").style.color = '#' + b_color;

		$D("tblquiz").style.color ='#' +  b_color;
		th_bcolor = b_color;
		th_fccolor = b_color;
	}
	
	if (fc_color.length != 0)
	{
		$D("hlk_heading").style.color = '#' + fc_color;
		th_fccolor = fc_color;
	}
	
	$D("embed_code").value = update_embed_code();
    
    //Wildfire.initPost('107171', 'divWildfirePost', 665, 160, pconf);
    
}

function change_theme_def(b_color, bg_color, fc_color)
{		
	if (bg_color.length != 0)
	{
		$D("tblquiz").style.backgroundColor = '#' + bg_color;
		th_bgcolor = bg_color;
	}
	
	if (b_color.length != 0)
	{
		$D("tblquiz").style.borderColor = '#' + b_color;
		$D("hlk_heading").style.color = '#' + b_color;
		$D("tblquiz").style.color ='#' +  b_color;
		th_bcolor = b_color;
		th_fccolor = b_color;
	}
	
	if (fc_color.length != 0)
	{
		$D("hlk_heading").style.color = '#' + fc_color;
		th_fccolor = fc_color;
	}
}

function change_footer_firstime()
{
	$D("embed_code").value = $D("embed_code").value + footer_text;
}

var main_url = '';
var quiz_id = '';
var footer_text = '';
function update_embed_code()
{		
	var embed_code_text = "<iframe name='proprofs' id='proprofs' height='280' width='406' frameborder=0 marginwidth=0 marginheight=0 src='http://" + main_url + "/flashcards/cards_w.php?id=" + quiz_id + "&bgcolor=" + th_bgcolor + "&fcolor=" + th_bcolor + "&tcolor=" + th_fccolor + "'></iframe>"+ footer_text;
	
	return embed_code_text;
}
	
function set_quiz_details(site_url, qid, foot_text)
{
	main_url = site_url;
	quiz_id = qid;
	footer_text = foot_text;
}

function clearstyle(sel_theme)
{
	var frm=document.getElementsByTagName('a');
	for (var i=1; i< frm.length; i++)
	{
		if (('link_theme_' + i) == sel_theme)
		{
			$D('link_theme_' + i).className='theme_image_link selected';				
		}
		else
		{
			if ($D('link_theme_' + i) != null)
			{
				
				$D('link_theme_' + i).className='theme_image_link';
			}
		}
	}	
}

var change_color_area='';
function select_change_color_area()
{	
	$D("pick_color_0").className = "";//Title color
	$D("pick_color_1").className = "";//Background color
	$D("pick_color_2").className = "";//Foreground color
	
	if (change_color_area.length != 0)
	{
		$D("pick_color_" + change_color_area).className = "selected";
	}
}
