function PopupImage(url,width,height,title)
{
    var windowheight = height+40;
    var windowwidth = width+20;

    var left = (screen.width - windowwidth)/2;
    var top = (screen.height - windowheight)/2 - 18;

    var scrollbars = "no";

    if (left<0) { scrollbars = "yes"; left = 32; windowwidth = screen.width - 2*left; }
    if (top<0) { scrollbars = "yes"; top = 32; windowheight =  screen.height - 2*top - 18; top = top - 18; }

    var num = Math.round(Math.random()*10000000);
    var str = new String(num);
    var win = window.open("",str,"toolbar=no,location=no,directories=no,"+
        "status=no,menubar=no,scrollbars=" + scrollbars + ",resizable=no,"+
        "copyhistory=no, width="+windowwidth+",height="+windowheight+",left=" + left + ",top=" + top);
    win.document.write("\<HEAD\>\<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/style.css\"\/\>\<meta http-equiv=\"pragma\" content=\"no-cache\"\>\<TITLE\>"+title+"\<\/TITLE\>");
    win.document.write("\<link rel=\"STYLESHEET\" type=\"text/css\" href=\"/style.css\"\>");
//    win.document.write("\<meta content=\"text\/html; charset=UTF-8\" http-equiv=\"Content-Type\"\>");
    win.document.write("\<\/HEAD\>");
    win.document.write("\<BODY style=\"margin:5px;background:#D7C9C9\"\>\<center\>\<a href=\"javascript:window.close();\"\>\<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" border=\"0\"\ title=\""+title+"\">\<BR\>\<\/a\>\<\/center\>\<\/BODY\><\/HTML\>");
}
function PopupPhoto(url,width,height,title) {
    var num = Math.round(Math.random()*10000000);
    var str = new String(num);
    var windowheight = height+40;
    var windowwidth = width+20;
    var left = (screen.width - windowwidth)/2;
    var top = (screen.height - windowheight)/2 - 18;

    var win = window.open(url,str,"toolbar=no,location=no,directories=no,"+
        "status=no,menubar=no,scrollbars=yes,resizable=yes,"+
        "copyhistory=no, width="+windowwidth+",height="+windowheight+",left=" + left + ",top=" + top);
}


function wordCounter(_field, _msg, _count)
{
	var _form = _field.form;
 	var _string="";
	var _wordCount=0;
	var _IsSpace=false;
	var _WasSpace=false;
  for (var _x=0;_x<_field.value.length;_x++)
  {
    _WasSpace=_IsSpace;
    //_IsSpace=(/\.|\!|\?|\s/.test(_field.value.charAt(_x)));
    _IsSpace=(/\b/.test(_field.value.charAt(_x)));
    if(_IsSpace && ! _WasSpace)
      _wordCount++;
    if (_wordCount >= _count)
    	_msg.className="wordCount enought"
    else
    	_msg.className="wordCount"
  }
  _msg.value=_wordCount;
}

function hopBacktoResourceScreen (key)
{

        var mySplitResult = key.split("-");

        var courseID = mySplitResult[0];
        var lessonID = mySplitResult[1];
        var activityID = mySplitResult[2];

        if (courseID=='0')
        {
            alert("Please choose a valid Course, Lesson or Activity to view the matching resources.");
            return false;
        }

        var path = "/resources/list.xml?courseID="+courseID;

        if (activityID != '0')
        {
            path += "&path=/courses/l"+lessonID+".xml&query=activity_id="+activityID;
        }
        else if (activityID=='0' && lessonID!='0')
        {
            path += "&path=/courses/l"+lessonID+".xml";
        }
    window.location.assign(path);
}


function expandBookImage ()
{
    document.getElementById("right").style.width="170px;";
    document.getElementById("right").style.display="block";
}

function shrinkBookImage ()
{
    document.getElementById("right").style.width="0px;";
    document.getElementById("right").style.display="none";
}
