/**
 *
 * Moc 10 Media
 * http://www.moc10media.com/
 *
 * Script Name: scripts.js
 * Script Version: 1.0
 * Script Info: Basic Config/Load Scripts
 *
 */

// Function to preload images.

function preLoad() {
    aboutoff = new Image();
    aboutoff.src = "/img/nav/about_off.gif";
    servicesoff = new Image();
    servicesoff.src = "/img/nav/services_off.gif";
    newsoff = new Image();
    newsoff.src = "/img/nav/news_off.gif";
    publicationsoff = new Image();
    publicationsoff.src = "/img/nav/publications_off.gif";
    equipmentoff = new Image();
    equipmentoff.src = "/img/nav/equipment_off.gif";
    trainingoff = new Image();
    trainingoff.src = "/img/nav/training_off.gif";
    videooff = new Image();
    videooff.src = "/img/nav/video_off.gif";
    caseoff = new Image();
    caseoff.src = "/img/nav/case_off.gif";

    offshoreoff = new Image();
    offshoreoff.src = "/img/nav/offshore_off.jpg";
    inlandoff = new Image();
    inlandoff.src = "/img/nav/inland_off.jpg";
    roboticoff = new Image();
    roboticoff.src = "/img/nav/robotic_off.jpg";
    governmentoff = new Image();
    governmentoff.src = "/img/nav/government_off.jpg";

    abouton = new Image();
    abouton.src = "/img/nav/about_on.gif";
    serviceson = new Image();
    serviceson.src = "/img/nav/services_on.gif";
    newson = new Image();
    newson.src = "/img/nav/news_on.gif";
    publicationson = new Image();
    publicationson.src = "/img/nav/publications_on.gif";
    equipmenton = new Image();
    equipmenton.src = "/img/nav/equipment_on.gif";
    trainingon = new Image();
    trainingon.src = "/img/nav/training_on.gif";
    videoon = new Image();
    videoon.src = "/img/nav/video_on.gif";
    caseon = new Image();
    caseon.src = "/img/nav/case_on.gif";

    offshoreon = new Image();
    offshoreon.src = "/img/nav/offshore_on.jpg";
    inlandon = new Image();
    inlandon.src = "/img/nav/inland_on.jpg";
    roboticon = new Image();
    roboticon.src = "/img/nav/robotic_on.jpg";
    governmenton = new Image();
    governmenton.src = "/img/nav/government_on.jpg";

}

// Function to create dynamic pop up window, currently set to center window on screen.

function newWindow(url, name, wid, hgt, scr, res, stat, loc, mnu, tool, x, y) {
    if (screen) {
        widthOfScreen = screen.width;
        heightOfScreen = screen.height;
    }
    if ((x == null) || (y == null)) {
        midX = widthOfScreen / 2;
        midY = heightOfScreen / 2;
        midWid = wid / 2;
        midHgt = hgt / 2;
        x = midX - midWid;
        y = midY - midHgt;
    }
    windowOpts = "width=" + wid + ",height=" + hgt + ",scrollbars=" + scr + ",resizable=" + res + ",status=" + stat + ",location=" + loc + ",menubar=" + mnu + ",toolbar=" + tool + ",left=" + x + ",top=" + y;
    popUpWindow = window.open(url, name, windowOpts);
}

// Function to dynamically write out the flash code to work around the IE flash "white box" issue.

function flashMovie(name, width, height, bgcolor) {
    if (bgcolor == null) {
        bgcolor = '#ffffff';
    }

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="middle">');
    document.write('    <param name="allowScriptAccess" value="sameDomain" />');
    document.write('    <param name="movie" value="' + name + '" />');
    document.write('    <param name="quality" value="high" />');
    document.write('    <param name="bgcolor" value="' + bgcolor + '" />');
    document.write('    <embed src="' + name + '" quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" name="' + name + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('    </embed>');
    document.write('</object>');
}

// set the variable in the SWF
function loadSWF(str) {	
	if(window.stub) window.document["stub"].SetVariable("target", str);
	if(document.stub) document.stub.SetVariable("target", str);
}

function wipe(obj) {
/*
    ahrefs = document.getElementsByTagName('a');

    for (var i = 0; i < ahrefs.length; i++){
        var ahref = ahrefs[i];
        if (ahref.getAttribute('id') != undefined) {
            if ((ahref.getAttribute('id').indexOf('Link') != -1) && (ahref.getAttribute('id') != (obj + 'Link'))) {
                elm = document.getElementById(ahref.getAttribute('id'));
                if (elm.firstChild.nodeValue == "[-]") {
                    dojo.lfx.html.wipeOut(idName, 400).play();
		            elm.firstChild.nodeValue = "[+]";
                }
            }
        }
    }
*/
	idName = document.getElementById(obj + 'SubNav');
	elemName = document.getElementById(obj + 'Link');
    if (elemName.firstChild.nodeValue == "[+]") {
		dojo.lfx.html.wipeIn(idName, 400).play();
		elemName.firstChild.nodeValue = "[-]";
    } else {
		dojo.lfx.html.wipeOut(idName, 400).play();
		elemName.firstChild.nodeValue = "[+]";
    }	
}

// Checkbox validation

function removeCheckValidate(obj) {
    chk = document.getElementsByTagName("input");
    counter = 0;

    for (i = 0; i < chk.length; i++) {
        if (chk[i].type == "checkbox") {
            if (chk[i].checked) {
                counter++;
            }
        }
    }

    if (counter == 0) {
        alert("Please select " + obj + " to remove.");
        return false;
    } else {
        return true;
    }
}

// Convert URL

function convertURL(obj, subject, target) {

    formId = document.getElementById(obj);

    sub = eval('formId.' + subject);
    tar = eval('formId.' + target);

    if (tar.value == '') {
        str = sub.value.toLowerCase();
        str = str.replace(/\&/g, 'and');
        str = str.replace(/([^a-zA-Z0-9 \-\/])/g, '');
        str = str.replace(/ /g, '-');
        str = str.replace(/-*-/g, '-');

        tar.value = '/' + str; 

        return true;
    }

}

dojo.addOnLoad(preLoad);
dojo.addOnLoad(initLightBox);
