//default font-size var.  used to keep track of font-size when we increase and decrease via tools menu
var fontSize;
fontSize = 11;

//clears out all values from form.  (different than reset which resets back to what the form looked like when loaded)
function clearForm() {
    var theForm = document.forms[0];
    for(i=0; i<theForm.length; i++)
    {
        switch(theForm.elements[i].type)
        {
            case 'text': theForm.elements[i].value = "";
                break;
            case 'select-one': theForm.elements[i].selectedIndex = 0;
                break;
            case 'checkbox': theForm.elements[i].checked = false;
        }
    }
}   

//bookmark function
function bookmarksite(title,url){
    if (window.sidebar) {
        // firefox
	    //window.sidebar.addPanel(title, url, "");  however when clicking on the new bookmank, the site opens is the left column only
	    alert('Press Ctrl + D to add bookmark.');
	}
    else if(window.opera && window.print){ // opera
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
    } 
    else if(document.all)// ie
	    window.external.AddFavorite(url, title);
}

//font tools menu actions
function setFont(action)
{
    var newFontSize;
    switch(action)
    {
        case '+':
            if (fontSize < 16) {
            fontSize ++;
            newFontSize = fontSize + 'px';
            setStyleByTag('p','fontSize',newFontSize,1);
            setStyleByTag('td','fontSize',newFontSize,1);
            setStyleByClass('div','text','fontSize',newFontSize);
            setStyleByClass('div','contentArea','fontSize',newFontSize);
            };
            break;
        case '-':
            fontSize --;
            newFontSize = fontSize + 'px';
            setStyleByTag('p','fontSize',newFontSize,1);
            setStyleByTag('td','fontSize',newFontSize,1);
            setStyleByClass('div','text','fontSize',newFontSize);
            setStyleByClass('div','contentArea','fontSize',newFontSize);
            break;
        case 'black':
            setStyleByTag('body','color','black',1);
            break;
        case 'red':
            setStyleByTag('body','color','red',1); 
            break;   
    }
}

//debug function to view array members
function viewArrayMembers(arrayToView)
{
    var arrayVars = "";
    for(key in arrayToView)
    {
        arrayVars += "\r\n";
        arrayVars += key;
        arrayVars += ":";
        arrayVars += arrayToView[key];
    }
    alert(sourceVars);
}

//external link popup and focus
function popitup(url)
{
    var newwindow = '';
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,'name');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

//When an ECP clicks on Canadian link on the TWW home page
function disp_confirm(urlCA)
{
    var name=confirm("You are heading to the Canadian Eyecare Professional site," + '\n' + "is this where you want to go?")
    if (name==true)
    {
        //for open in new window 
        //window.open(urlCA); 
        //for open in the same window
        window.location.href = urlCA; 
    }
}

function popUp(url){
    //window.open( url, "Experience", "height = 500, width = 720, resizable = 0" )
    popUpSize(url, 500, 720);
}

function popUpSize(url, ppHeight, ppWidth){
    var newwindow = '';
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open( url, "name", "height = " + ppHeight + ", width = " + ppWidth + ", resizable = 0" );
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
}

function openNewWindow(url){
    window.open(url, "_blank");
}