// General javascript utilities


function roll(imageName, imageSrc){
  document[imageName].src=imageSrc;
}

function pop(url, name){
  newWindow = window.open(url, name);
  if (window.focus) {newWindow.focus()};

}

function nPop(linkID){
    var aName = 'newWindow';
    var url = linkID.href;
    if ( ! url ) {
        return true; // failed because no link to open!
    }
    thewindowobject = window.open(url,aName);
    
    if (window.focus) thewindowobject.focus();

    if ( thewindowobject )
        return false; // success!!
    else
        return true; // failed
    
}

function addSiteToFavourites(theName, theUrl){
  if (window.external && (!document.createTextNode || (typeof(window.external.AddFavorite)=='unknown'))){
    window.external.AddFavorite(theUrl, theName);
  } else if (window.sidebar) {
    window.sidebar.addPanel(theName, theUrl,"");
  }
}

function addPageToFavourites(){
	var theURL = document.URL;
	var theName = document.title;
	if (window.external && (!document.createTextNode || (typeof(window.external.AddFavorite)=='unknown'))){
    window.external.AddFavorite(theURL, theName);
  } else if (window.sidebar) {
    window.sidebar.addPanel(theName, theURL,"");
  }
}


function menuDrop(theMenu){
    var b = document.getElementById(theMenu);
    
    if (b.style.display == 'none'){
        b.style.display = 'block';
    } else {
        b.style.display = 'none';
    }   
    return;
}

function insMenuChangeState(menu){
    var menuID = 'insMenu' + menu;
    var element = document.getElementById(menuID);
    var arrow = document.getElementById('insMenu' + menu + 'Arrow');
    
    if (element.style.display == 'none'){
        arrow.src = 'img/ins_arrow_down.gif';
        element.style.display = 'block';
    } else {
        arrow.src = 'img/ins_arrow_right.gif';
        element.style.display = 'none';
    }
    return;
}

function insSetMenuStates(thePage){
    if (thePage == 'who'){
        insMenuChangeState('Partners');
        //insMenuChangeState('Insurers');
    } else if (thePage == 'Partners'){
        //insMenuChangeState('Insurers');
    } else if (thePage == 'Insurers'){
        insMenuChangeState('Partners');
    }
    return;
}


function sPop(link, width, height){
    return openPopupPos (link, width, height, 0, 0, "");
}


/* 
   openPopupPos creates a popup at (winnX, winnY)
*/
function openPopupPos (linkOb, thewidth, theheight, winnX, winnY, params) {
    var aname = 'popup';
    var url   = linkOb.href;

    if ( ! url ) {
        return true; // failed because no link to open!
    }
    
    if ( params ) {
        params = ',' + params;
    }

    str_WinParams = 'top=' + winnY+',left=' + winnX + params + ',width='+thewidth+',height='+theheight;

    thewindowobject = window.open(url,aname, str_WinParams);

    if (window.focus) thewindowobject.focus();

    if ( thewindowobject )
        return false; // success!!
    else
        return true; // failed
}







function setTextSize(newSize){
	document.body.style.fontSize = newSize;
	return;
}

function validateEmail(e){
    var emailFilter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var s = emailFilter.test(e);
    if (!(emailFilter.test(e))){
        return false;
    } else {return true;}
}


function validateForm(){
    var errorList = "";
    if (!(validateEmail(document.form1.contact_email.value))){
                errorList += "Please supply a valid email address\n";
            }
    
    if (errorList){
        window.alert(errorList);
        return false;
    } else {return true;}
}

