﻿$ = jQuery ;
$j = jQuery ;

var m_isPopupIntention = false;

//from common
var m_stdEmpty = "";
var m_mhFixed = false;
var isReady = false;
var m_crumbs;
var m_pnlinks ;
var m_isHome = true;
function sReady()
{
    $j(document).ready (
        function (){isReady = true; $j(document).triggerHandler( 'sReady');}
    );
    aitd();
}
function addsReady ( fn )
{
    jQuery(document).bind ( 'sReady' , fn);
}
function aitd ()
{   
    if ( m_isPopupIntention )
    {
        try{
       jQuery.each(document.body.childNodes, function(i, val) {
        if ( $j(val).is('table'))$j(val).css('width','100%');
        });
        }
        catch(e){}
    }  
}

function RenderFlash()
{
	var flashObjects = ParseDivObjects( "flashContentDiv" );
	var flashObject;
	for( var flashIdx = 0; flashIdx < flashObjects.length; flashIdx++ )
	{
	    var jscriptTxt  = unescape(flashObjects[flashIdx].innerHTML).replace( /&amp;/gi, "&");
	    if ( jscriptTxt.indexOf("new FlashLibraryActivate") > -1 )
	    {
	        try
	        {
	        	var flashObj = eval(jscriptTxt);
	            var fullscreen = getQueryVariable( "~lt" );
	            if( fullscreen == "flash_fullscreen" )
	            {
	                document.body.style.margin = 0;
	                document.body.style.padding = 0;
	                document.body.innerHTML = flashObj.getPluginTag();
	            }
	            else
	            {
		            flashObjects[flashIdx].innerHTML = flashObj.getPluginTag();
		            flashObjects[flashIdx].style.display = "block";
		        }
		    }
		    catch(e){}
	    }
	}
}

function FlashLibraryActivate( swfFile, width, height, bgcolor, ver, altFormat, params, movieName, quality, scaleMode, allowFS, wMode, menu, contentFile  )
{
	var t = this;
	var activeX = false;
	t.ieAutoInstall = false;
	
	
	if( quality == undefined || quality == "" )
	{
		quality = "high";
	}
	if( scaleMode == undefined || scaleMode == "")
	{
		scaleMode = "noscale";
	}
	if( wMode == undefined || wMode == "" )
	{
		wMode = "opaque";
	}
	if( allowFS == undefined || allowFS == "" )
	{
		allowFS = "true";
	}
	if( menu == undefined || menu == "" )
	{
		menu = "true";
	}
	if( ver == undefined || ver == "" )
	{
		ver = "7";
	}
	
	t.hasVersion = function( ver )
	{
		t.swf = false;
		if( !ver ) ver = 0;
		var n = navigator;
		if(n.plugins && n.plugins.length > 0)
		{
			var m,tp,d,v;
			m = n.mimeTypes;
			tp = 'application/x-shockwave-flash';
			if(m && m[tp] && m[tp].enabledPlugin && m[tp].enabledPlugin.description)
			{
				d = m[tp].enabledPlugin.description;
				v = d.charAt(d.indexOf('.')-1);
				t.swf = (v >= ver) ? true : false;
			}
		}
		else if ( n.appVersion.indexOf("Mac") == -1 && window.execScript )
		{
			ieFlashObj = null;
			activeX = true;
			for(var i=ver; i<=10&&i!=1&& ieFlashObj!=true; i++)
			{
				execScript('on error resume next: ieFlashObj=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash'+((i==0)?'':'.'+i)+'"))','VBScript');
				if ( ieFlashObj == true )
				{
					t.swf = true;
					break;
				}
			}
		}
		else
		{
			t.swf = false;
		}
		return t.swf;
	}
	
	t.getPluginTag = function()
	{
		var fixedVer = ver;		
			var cmHack= swfFile.indexOf ( "cmhack" )> -1;
		if ( cmHack )
		{
			if ( document.location.href.indexOf ( "~bandwidth=Modem" ) == -1 && !t.hasVersion( parseInt( ver ) ) )
			{
				document.location.href = document.location.href + "&~bandwidth=Modem";
			}
		}
	
		if ( swfFile.indexOf ( "autoinstall" ) > -1 )
		{
			t.ieAutoInstall = true;
		}
		
		params = " " + params + " ";
		var s = "";
		var win = ( navigator.appVersion.toLowerCase().indexOf( "win" ) != -1 );
		var ie = ( navigator.appName == "Microsoft Internet Explorer" );
		
		
		if( ( t.hasVersion( parseInt( ver ) ) && swfFile ) || ( win && ie && swfFile && t.ieAutoInstall ) )
		{
			
			var additionalParams = '';
			var qPos = swfFile.indexOf ( "?" )
			var fVars = swfFile.substr( qPos + 1, swfFile.length );

			if ( ( qPos > -1 ) && ( qPos + 1 < swfFile.length ) && ( parseInt( fixedVer ) > 5 ) )
			{
				var ta = 'FlashVars';
				var v = swfFile.substring ( qPos + 1 );
				v += "&containerURL=" + encodeURIComponent( location.href );
				v += "&id=" + movieName;
				additionalParams += ( activeX ) ? '\t<param name="' + ta + '" value="' + v + '" />\n': ' '+ ta + '="' + v + '"';
			}
			else
			{
				var ta = 'FlashVars';
				var v = "";
				v += "containerURL=" + encodeURIComponent( location.href );
				v += "&id=" + movieName;
				additionalParams += ( activeX ) ? '\t<param name="' + ta + '" value="' + v + '" />\n': ' '+ ta + '="' + v + '"';
			}
			if( qPos > -1 )
			{
				swfFile = swfFile.substr( 0, qPos );
			}
	
			if( activeX )
			{
				s = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + fixedVer + '" id="' + movieName + '" width="' + width + '" height="' + height + '" >\n';
				s += '\t<param name="movie" value="' + swfFile + '" />\n';
				s += '\t<param name="allowFullScreen" value="' + allowFS + '" />\n';
				s += '\t<param name="quality" value="' + quality + '" />\n';
				s += '\t<param name="menu" value="' + menu + '" />\n';
				s += '\t<param name="wmode" value="' + wMode + '" />\n';
				s += '\t<param name="allowScriptAccess" value="always">\n';			
				s += '\t<param name="bgcolor" value="' + bgcolor + '" />\n';
				s += '\t<param name="scale" value="' + scaleMode + '" />\n';
				s += additionalParams;
				s += params;
				s += altFormat;
				s += '</object>\n\n';
	
				// create the <iframe> IF the contentfile attribute is present
				try
				{
					if( contentFile != undefined && contentFile != "" )
					{
						s += '<iframe id="" name="" src="' + contentFile + '" style="display:none" title="" align="left" frameborder="0" height="1" weight="1" longdesc="" marginheight="0" marginwidth="0" scrolling="no" ></iframe>';
					}
					else
					{
					}
				}
				catch(e)
				{
					
				}
				return s;
			}
			else
			{
				// EMBED
				s = '<embed src="' + swfFile + '" quality="' + quality + '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" allowScriptAccess="always" wmode="' + wMode + '" allowFullScreen="' + allowFS + '" type="application/x-shockwave-flash" name="' + movieName + '" id="' + movieName + '" width="' + width + '" height="' + height + '" bgcolor="' + bgcolor + '"'+ additionalParams+params + '" menu="' + menu + '" scale="' + scaleMode + '" ></embed>\n';
				
				
				try
				{
					if( contentFile != undefined && contentFile != "" )
					{
						s += '<iframe id="" name="" src="' + contentFile + '" style="display:none" title="" align="left" frameborder="0" height="1" weight="1" longdesc="" marginheight="0" marginwidth="0" scrolling="no"></iframe>';
					}
				}
				catch(e)
				{
					
				}
				return s;
			}
		}
		else
		{
			return altFormat;
		}
	}
}

function getQueryVariable(variable)
{
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++)
      {
            var pair = vars[i].split("=");
            if (pair[0] == variable)
            {
                  return pair[1];
            }
      }
}

function ParseDivObjects( targetName )
{
   
	var objs = document.getElementsByName( targetName );
	if( objs.length == 0 )
	{
		var targets = document.getElementsByTagName( "DIV" );
		var tmpObj;
		objs = new Array();
		for( var targetidx = 0; targetidx < targets.length; targetidx++ )
		{
			tmpObj = targets[targetidx];
			if( tmpObj.name == targetName )
			{
				objs.push( tmpObj );
			}
		}
	}
	return objs;
}

function stormModalObj()
{
    this.Inited= false;
}

stormModalObj.prototype.init = function ()
{
   if ( this.Inited )
   {
        return;
   }
   
   var standardModel = '<div class="jqmWindow" id="standardModel"><div class="jqmWinHeader jqDrag" ><div class="jqmClose" onclick="stormModal.close()"><image src="' + m_imgPfx + '/images/global/brand/icons/modal_close_btn.gif" border="0" /></div><div class="jqmWinTitle"></div></div><div class="jqmContent"></div><div class="jqmFooter"><div class="jqmFooterButtons"></div><div class="jqmFooterStatus"></div></div></div>';
   $j(standardModel).appendTo('body');
   
   $j('#standardModel').jqm( );
   this.InternalModal= $j('#standardModel') ;
   this.DefaultProps = { defaultTitle: "&nbsp;"  , width : this.InternalModal.width() };
   this.AbsoluteHeight = 0;
   this.Title  = this.InternalModal.find( '.jqmWinTitle');
   this.Footer  = this.InternalModal.find( '.jqmFooter');
   this.FooterStatus  = this.Footer.find( '.jqmFooterStatus');
   this.FooterButtons  = this.Footer.find( '.jqmFooterButtons');
   
   this.Content = this.InternalModal.find( '.jqmContent');
   this.DummbyAnchor = $j('<div href=foo  ><div>');
   this.Inited=true;
}
stormModalObj.prototype.addclick = function ( t )
{
    t.each  ( function (){ 
        
        $j(this).click ( function ()
            { 
            var map= {};
            map.href = $j(this).attr ('href');
            stormModal.show ( map );
            $j(this).blur();
	        return false;
            }
        )}
        );
}

stormModalObj.prototype.positionModal = function()
{

var scrollTop = (document.all)? ( truebody().scrollTop) : window.pageYOffset;
var scrollLeft = (document.all)? ( truebody().scrollLeft) : window.pageXOffset;
var clientHeight = (document.all)? ( truebody().clientHeight) : document.body.clientHeight;
var clientWidth = (document.all)? ( truebody().clientWidth) : document.body.clientWidth;

var elm = this.InternalModal;
var left=0, top=0;
top  = scrollTop + clientHeight/2 - elm.height()/2;
left = scrollLeft + clientWidth/2 ;

var cssObj = {
        left: left+"px",
        top: top+"px"
      };
elm.css(cssObj);

}

var stormModal = new stormModalObj();
function clientPageInit ()
{
    stormModal.addclick  ($j('a[@n_modal]'));
}
$j(document).ready( clientPageInit );

addsReady( InitDocumentLoad );
function InitDocumentLoad()
{
    InitClueTip();
    InitToolTips();
    RenderFlash();
}

function InitToolTips()
{
   $j("span[@glid]").livequery(function(){ 
        var gdeco = $j(this).attr("glnodeco");
        var gtitle = $j(this).attr("gltitle");
        if ( typeof(gdeco) == "undefined" )
        {
            $j(this).addClass('glossaryitem'); 
        }
        else
        {
            $j(this).addClass('glossaryitem_nodecoration'); 
        }
        var requestUrl = m_requestURLBase + "&~ttmode=html&~ttid=" + escape( this.attributes.glid.value );
        if ( this.attributes.glmoredetails )
        {
            var ref = src.attributes.glmoredetails.value;
            ref = ref.replace ( /:/g, "~" );
            requestUrl += "&~ttref=" + ref;
        }
        $j(this).attr('rel', requestUrl );
        $j(this).cluetip({arrowHPosition:'offset',delayedClose:typeof(m_containerTimeout)!='undefined'?m_containerTimeout:500,delayedOpen:typeof(hoverovertime)!='undefined'?hoverovertime:500,positionBy:'topBottom',width:'400px',cluetipClass: 'jtip',arrows: true,arrowSize: 'lg',hoverIntent: false,showTitle: false,dropShadow: true,waitImage:false,mouseOutClose:true,sticky:true,closeText:'',onActivate:function(e) {$j("#cluetip-inner").show();return true; },
        onShow:function(e) {
            $j(".itemCloseContainer").click(function() {
                $j("#cluetip").hide();
                return false;});
             var title = $j(".itemContainerTitle").html();
             if( title == null || title.length == 0 || title == "&nbsp;" )
             {
                $j(".itemContainerTitle").html(gtitle);
             }
            return true; }
        });
    });
}

function InitClueTip()
{
    $j(".hv_cluetip") 
    .livequery(function(){  
    $j(this).cluetip({ positionBy:'auto',width:'251px', cluetipClass: 'jtip',arrows: true, hoverIntent: false,showTitle: false,waitImage:false,onActivate:       function(e) {$j("#cluetip-inner").show();return true; } });
    });
    
     $j(".ic_cluetip")
    .livequery(function(){  
        $j(this).cluetip({width:'160px',topOffset:'10',splitTitle: '|', dropShadow: false,arrowSize:'sm', arrows:true,cluetipClass: 'jtip', showTitle: false,positionBy: 'bottomTop',hoverIntent: false,   cursor: 'default', onActivate:       function(e) { $j(this).attr('title', ''); return true; }});
    });
}

