/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 \
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 254 2010-07-23 05:14:44Z emartin24 $
 */

jQuery(function ($) {
	// Load dialog on page load
	//$('#basic-modal-content').modal();
/*
	// Load dialog on click
	$('#basic-modal .basic').click(function (e) {
		$('#basic-modal-content').modal();

		return false;
	});
*/
    var url = location.href;
    
    var nIdArray = $("[id^='n_']");

    if(window.location.search){
    //    alert(window.location.search);
    
        var questionMarkStr = window.location.search;
        arg = questionMarkStr.split("?");
    //    alert("questionMarkStr " +questionMarkStr);
        if(arg.length > 1 && arg[1].substring(0,1)=='n'){            
            popupNDA(arg[1].substr(1));
        }else{
        //    alert("Not sensitive popup!");
        }
    }
    
    if(window.location.hash){
    //    alert(window.location.hash);
        
        var poundSignStr = window.location.hash;
        arg = poundSignStr.split("#");
        if(arg.length > 1 && arg[1].substring(0,1)=='n'){
            var element = "n_"+ arg[1].substr(1);
            for(i=0; i< nIdArray.size(); i++){
                if(nIdArray[i].id== element){
                    popupNDA(arg[1].substr(1));
                    break;
                }
            }            
        }else{
        //    alert("Not sensitive popup!");
        }
    }

    $('#basic-modal').click(popup);

    for(i=0; i< nIdArray.size(); i++){
        $("#"+(nIdArray[i].id)).click(popupNDA);
    }
    
    function popupNDA(e) {
    
        var nda = "None";
        if(typeof e == 'object'){
        //    nda = e.target.innerHTML;            
            nda = $(this).html();
        }else{            
            nda = $("#n_"+e).html();
        }

        $("#reqFileDis").html(nda);
        $("#reqFileHid").val(nda);
        
		$("#basic-modal-content").modal({
            onOpen: function (dialog) {
                dialog.overlay.fadeIn('slow', function () {
                    dialog.data.hide();
                    dialog.container.fadeIn('slow', function () {
                        dialog.data.slideDown('slow');
                    });
                });
            },
            containerCss:{            
                height:465
            }
        });    
	}
	
    function popup() {
    
		$("#basic-modal-content").modal({onOpen: function (dialog) {
			dialog.overlay.fadeIn('slow', function () {
				dialog.data.hide();
				dialog.container.fadeIn('slow', function () {
					dialog.data.slideDown('slow');
				});
			});
		}});
    
	}
});
