/* 
========================================================================================================= CREDITS
Copyright 	: Copyright (c) 2008 JPL & HARSCO. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com 
Date    	: 12/2/2008 
Notes     	: JavaScript file for handling various events ... onLoad, onClick, etc
========================================================================================================= CHANGE LOG
Date		Name			Desc
---			---				---
========================================================================================================= BEGIN JAVASCRIPT
*/
/* ====================================================================================================== MULTIPLE ONLOAD HANDLER */
/* this code won't overwrite windows.onload like the other one does */
function addEvent(obj, evType, fn, useCapture) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent('on' + evType, fn);
        return r;
    } else {
        //alert("Handler could not be attached");
    }
}

/* ====================================================================================================== CALL FUNCTIONS TO BE LOADED */

addEvent(window, 'load', loadModals, false);
addEvent(window, 'load', loadFlash, false);
addEvent(window, 'load', checkLang, false);

/* ====================================================================================================== LOAD MODALS */
function loadModals() {
	/* 
	* AUTOMATED
	* init_modal() SEARCHES FOR ALL MODALS AND ATTACHES EVENT LISTENERS 
	*/
	init_modal();

	/* 
	* MANUAL
	* USE THE EXAMPLE BELOW TO ATTACH EVENT LISTENERS MANUALLY, INCREMENT THE COUNTER FOR EACH ADDITION
	* THE SECOND PARAMETER SHOULD BE SET TO TRUE ONLY IF YOU NEED TO DYNAMICALLY DETERMINE THE HEIGHT/WIDTH
	*/
	modal_manual0 = document.getElementById('modal0_manual_open');
	if (modal_manual0 != null) {
		modal_manual0.onclick = function() {
			new_modal_manual0 = new modal('modal0_manual',true);
			new_modal_manual0.activate();
			return false;
		}
	}
}

/* ====================================================================================================== LOAD FLASH FILES */
function loadFlash() {
	if (document.getElementById('flash0') != null) {
        var flashvars = {};
        var params = { wmode: "opaque" };
        var attributes = {};

		swfobject.embedSWF("lib/swf/flash0.swf", "flash0", "800", "200", "9.0.0", "lib/swf/expressInstall.swf", flashvars, params, attributes);
		if (document.getElementById('flash0-alt') != null) {
			document.getElementById('flash0-alt').style.visibility = "visible";
		}
	}
	if (document.getElementById('flash1') != null) {
        var flashvars = {};
        var params = { wmode: "opaque" };
        var attributes = {};

		swfobject.embedSWF("lib/swf/flash1.swf", "flash1", "500", "500", "9.0.0", "lib/swf/expressInstall.swf", flashvars, params, attributes);
	}
}

function checkLang() {
	if(window.location.href.indexOf("/fr") != -1) {
		document.getElementById("language").innerHTML = "Fran&ccedil;ais";
		document.getElementById("languageurl").href = "/";
		document.getElementById("languageurl").innerHTML = "(Changement)";
	}
	else {
		document.getElementById("language").innerHTML = "English";
		document.getElementById("languageurl").href = "/fr";
		document.getElementById("languageurl").innerHTML = "(Change)";
	}
}

function GetLabel(id) {
    var labels = document.getElementsByTagName('label');

    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            return labels[i];
        }
    }

    return null;
};

function ClearModalField(inFieldName) {
    var objId = idPrefix + '_' + inFieldName
    var obj = GetObject(objId);
    obj.value = '';
    
	var label = GetLabel(objId);
    if (label) {
        if (label.defaultClass) {
            label.className = label.defaultClass;

            var test = label.className;
        }
    }
}

function ClearModalForm() { 
    ClearModalField('txtFirstName');
    ClearModalField('txtLastName');
    ClearModalField('txtIndustry');
    ClearModalField('txtCompany');
    ClearModalField('txtPhone');
    ClearModalField('txtEmail');

    var pnlWarning = GetObject('pnlWarning');
    pnlWarning.innerHTML = '';
}

function jsNewWin() {
    if(typeof modal == 'function') 
    {
		ClearModalForm();
        new_modal = new modal('modal0',true);
        new_modal.activate();
        
        var modalimage = document.getElementById('modal-banner');
        
        modalimage.src = '/lib/img/logo2.gif';
        modalimage.className = 'modal-logo2';
		
		document.getElementById('modal0').className = 'signup';
        
        var modalsubtitle = document.getElementById('modal-subtitle');
        modalsubtitle.className = 'modal-subtitle-show';
		
		var modalpdf = document.getElementById('modal-pdf-1');
        modalpdf.className = 'modal-subtitle-hidden';
        
        var hiddenfield = document.getElementById('access-hidden-field').childNodes[0];
        if (hiddenfield != null) 
        {
            hiddenfield.value = 'Product Samples';
        }
    }
}

function jsOldWin() {
    if(typeof modal == 'function') 
    {
		ClearModalForm();
        new_modal = new modal('modal0',true);
        new_modal.activate();
        
        var modalimage = document.getElementById('modal-banner');
        
        modalimage.src = '/lib/img/logo.gif';
        modalimage.className = 'modal-logo';
		
		document.getElementById('modal0').className = 'signup';
        
        var modalsubtitle = document.getElementById('modal-subtitle');
        modalsubtitle.className = 'modal-subtitle-hidden';
		
		var modalpdf = document.getElementById('modal-pdf-1');
        modalpdf.className = 'modal-subtitle-hidden';
        
        var hiddenfield = document.getElementById('access-hidden-field').childNodes[0];
        if (hiddenfield != null) 
        {
            hiddenfield.value = 'Stay Informed';
        }
    }
    return false;
}
        
        
function jsWin3() {
    if(typeof modal == 'function') 
    {
	    ClearModalForm();
        new_modal = new modal('modal0',true);
        new_modal.activate();
        
        var modalimage = document.getElementById('modal-banner');
        
        modalimage.src = '/lib/img/logo.gif';
        modalimage.className = 'modal-logo';
		
		document.getElementById('modal0').className = 'signup';
        
        var modalsubtitle = document.getElementById('modal-subtitle');
        modalsubtitle.className = 'modal-subtitle-hidden';
		
		var modalpdf = document.getElementById('modal-pdf-1');
        modalpdf.className = 'modal-subtitle-hidden';
        
        var hiddenfield = document.getElementById('access-hidden-field').childNodes[0];
        if (hiddenfield != null) 
        {
            hiddenfield.value = 'Fortis-Zd Webinar';
        }
    }
    return false;
}

function jsWin4() {
    if(typeof modal == 'function') 
    {
	    ClearModalForm();
		
		document.getElementById('modal0').className = 'signup signup-pdf-1';		
		
        new_modal = new modal('modal0',true);
        new_modal.activate();
        
        var modalimage = document.getElementById('modal-banner');
        
        modalimage.src = '/lib/img/logo.gif';
        modalimage.className = 'modal-logo';
        
        var modalsubtitle = document.getElementById('modal-subtitle');
        modalsubtitle.className = 'modal-subtitle-hidden';
		
		var modalpdf = document.getElementById('modal-pdf-1');
        modalpdf.className = 'modal-subtitle-show';
        
        var hiddenfield = document.getElementById('access-hidden-field').childNodes[0];
        if (hiddenfield != null) 
        {
            hiddenfield.value = 'Insight';
        }
    }
    return false;
}
