function set_cookie(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 get_cookie(name) {

    var name_eq = 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(name_eq) == 0) return c.substring(name_eq.length,c.length);
    }
    return null;

}

// a function that manages the process of setting the top values of the divs
// when the text size is changed
function set_divs()
{
	// an array of div ids
	var id_array = ["sl", "learn", "ks", "tr", "jo", "dp", "sb", "ot", "cu"];
	var top;
	var page_size = get_cookie("page_size");
	var height;
	
	// if the current size isn`t null then process set the div top value
	if(page_size != null && page_size != "1")	{
		// if text size of 1.3
		if(page_size == "1.1")
		{
			if( -1 != navigator.userAgent.     //bloody ie doesnt like -ve top values
			indexOf ("MSIE") )
			{    top = 0;   }
			else { top = 5; }
			height = 250;
		}
		else
		{
			// if text size is 1.7
			top = 10;
			height = 300;
		}
		
		// for each div id
		for ( var id in id_array )
		{
			// set the position of the div
			if(id == 5 && page_size == "1.1")
			{
				top = top + 7;
			}
			else if(id == 5 && page_size == "1.3")
			{
				top = top + 7;
			}
			
			if (top == 10) {
			set_div(id_array[id], top + "px", height + "px");
				}
			else {
			set_div(id_array[id], top + "px", height + "px");
			}
		} 
	}
}

// a function that sets the divs location by its top value
// it takes 2 arguments, a div id and a top value e.g. -10px
function set_div(id, top, height)
{
	// get the div by its id
	var div = document.getElementById(id);
	// set its position to relative
	div.style.position = "relative";
	// set the top value for the div
	div.style.top =top;
	//div.style.min-height = height;
}

if(get_cookie("page_size") != null){

    document.write('<style>');
    document.write('body{');
    document.write('font-size:'+ get_cookie("page_size") + 'em');
    document.write('}');
    document.write('</style>')
}else{

    document.write('<style>');
    document.write('body{');
    document.write('font-size: 1em');
    document.write('}');
    document.write('</style>')  

}
