
/* generate css to show submenu for this section */

var currMenu = null;

function displayMenu( sectionPath ) {    
    if( ! sectionPath ) {
        var currPath = new String( top.location.pathname ).split( '/' );        
        sectionPath = ( currPath[ 2 ] ? currPath[ 2 ] : '' );
    }
//    alert( "sectionPath = " + sectionPath );
//	alert( "currMenu = " + currMenu );
    if( sectionPath != currMenu ) {
        var currDiv = document.getElementById( 'submenu-' + currMenu );
        if( currDiv ) {
//            currDiv.style.visibility = 'hidden';   
            currDiv.style.display = 'none';   
        }
        var newDiv = document.getElementById( 'submenu-' + sectionPath );
        if( newDiv ) {

//			alert( "Make Visible: " + 'submenu-' + sectionPath );
//            newDiv.style.visibility = 'visible';   
            newDiv.style.display = 'block';   
        }
        currMenu = sectionPath;
    }
}

onload = function() { displayMenu(); }

/* sms service popup window */

var smsWin = null;

function openSMS( theUrl ) {
    
    if( smsWin ) {
        if( ! smsWin.closed ) {
            smsWin.close();
            smsWin = null;
        }
    }
    var w = 350;
    var h = 250;
    var l = ( screen.width - w ) / 2;
    var t = ( screen.height - h ) / 2;
    smsWin = window.open( theUrl, 'smsWin', 'status=yes,width=' + w + ',height=' + h + ',left=' + l + ',top=' + t );
    return false;
}

var photoWin = null;

function viewPhoto( imgSrc, imgTitle ) {

    if( photoWin ) {
        if( ! photoWin.closed ) {
            photoWin.close();
            photoWin = null;
        }
    }

    var w = 100
    var h = 100;
    var l = ( screen.width - w ) / 2;
    var t = ( screen.height - h ) / 2;

    photoWin = window.open( '', 'photoWin', 'width=100,height=100,left=' + l + ',top=' + t );

    var htm = '<html>' + 
        '<head>' + 
        '<title>' + imgTitle + '</title>' +
        '<meta http-equiv="imagetoolbar" content="false" />' +
        '</head>' + 
        '<body style="margin: auto; padding: auto; overflow: hidden;" onload="document.getElementById(\'theDiv\').style.visibility=\'visible\';window.resizeTo(document.images[ \'theImage\' ].width+10,document.images[ \'theImage\' ].height+28);window.moveTo((screen.width - document.images[ \'theImage\' ].width)/2,(screen.height - document.images[ \'theImage\' ].height)/2);">' +
        '<p style="font: 11px Verdana,sans-serif; position: absolute; top: 10px; left: 10px;">Loading...</p>' +
        '<div id="theDiv" style="visibility: hidden; position: absolute; top: 0; left: 0;"><img src="' + imgSrc + '" border="0" id="theImage" alt="' + imgTitle + '" /></div>' +
        '</body>' +
    '</html>';

    photoWin.document.write( htm );
    photoWin.document.close();
}




function validateForm() {
//  generic form validation function
//  pass a list of form field objects, and each will be checked for a value
//  tim@saltstonemedia.co.uk

    var flds = validateForm.arguments;
    var val = true;
    var err = '';
    
    for( var i = 0; i < flds.length; i++ ) {
        if( typeof( flds[ i ].type ) != 'undefined' ) {
            switch( flds[ i ].type ) {
                case 'select-one' : {
                    // select box - check that the selected item has a value
                    if( ! flds[ i ].options[ flds[ i ].selectedIndex ].value ) val = false;
                    break;
                }
                case 'checkbox' : {
                    // checkbox - should be checked
                    if( ! flds[ i ].checked ) val = false;
                    break;
                }
                default : {
                    // text, textarea, hidden - check that it has a value
                    if( ! flds[ i ].value ) val = false;
                }
            } 
        } else {
            // type is not defined, so it's probably a group of radio buttons
            var chk = false;
            for( var btn = 0; btn < flds[ i ].length; btn++ ) {
                // step through each item in the group and see if any are checked
                if( flds[ i ][ btn ].type == 'radio' ) {
                    if( flds[ i ][ btn ].checked ) chk = true;
                }
            }
            if( ! chk ) val = false;
        }
    } 
    if( ! val ) alert( 'Please complete all required fields.' );
    return val;
}
