var UserCookie = new Array(30);
var CookieValid = false, SSO_Cookie = false, SSO_Cookie_Id = '';
var CookieUsername = 1, CookieUser_Id = 2, CookieGroup_Id = 3, CookiePerson_Id = 4, 
    CookieName = 5, CookieEmail = 6, CookiePrefs = 7, CookiePrivs = 8;

function getCookie( name )
{
  var arg = name + '=';
  if ( document.cookie && document.cookie.length != 0 )
  {
  	var cstart = document.cookie.indexOf( arg );
    if ( cstart == -1 )
      return null;
    else
    {
      var tmpStr = document.cookie.substring( cstart, ( document.cookie.length + 1 ) );
    	var cend = tmpStr.indexOf( ';' );
      if ( cend == -1 ) cend = tmpStr.length + 1;
	  	tmpStr = unescape( tmpStr.substring( arg.length, cend ) );
      return tmpStr;
    }
  }
  else
    return null;
}

function ReadCookie()
{
	CookieValid = false;
  var j=1, i=0;
  var str = getCookie( 'Marketbright_Cookie' );
  
// TRANSLATE( Value, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*~][!?', 
//                   '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/:-=_@' );

	if ( str == null || str == "" ) return false;
  
	if ( str.indexOf( "/" ) != -1 )
  {
		while ( str.substring( i, str.length ).indexOf( "/" ) != -1 && j < 50 )
    {
      cStr = "";
      for ( var i; str.substring( i, i + 1 ) != "/"; i++ ) cStr += str.charAt(i);
      i++;
      UserCookie[j] = cStr;
      j++
		}
	}
 	UserCookie[j] = str.substring( i, str.length );
 	UserCookie[0] = j-1;
	CookieValid = true;

  SSO_Cookie = false;
  SSO_Cookie_Id = '';
  
  if ( document.location.href.indexOf( SSO_Secure_Domain ) > -1 )
  {
    var SSO_Str = getCookie( SSO_Cookie_Name );
    if ( SSO_Str ) 
    {
      SSO_Cookie = true;
      SSO_Cookie_Id = SSO_Str.substring( 0, SSO_Str.indexOf( '-' ) );
    }
  }
  
  if ( typeof( cacheCheckId ) != 'undefined' && cacheCheckId )
  {
    if ( cacheCheckId.indexOf( UserCookie[2] + '/' + UserCookie[3] + '-' ) == -1 )
    {
      var URL = mbWebsiteURL + '/pages/admin-marketbright/error_page.html?cacheCheckId=' + cacheCheckId + '&Cookie=' + UserCookie[2] + '/' + UserCookie[3] +
                '&p_URL=' + escape( document.location.href );
      var logCacheIssue = new Image(); 
      logCacheIssue.src = URL;
    }
  }

  return true;
}

function drawWelcome()
{
  var Str = '<SPAN class="HelpTextG">welcome';
  
  if ( CookieValid && UserCookie[CookieUser_Id] != '1' )    
  {
    Str += ' <b>' + UserCookie[CookieName];
    Str += '</b>, </SPAN> <A class="HelpTextG" href="/services/web/Update_Users.Logout?Action=/index.html" class="HelpText">sign out</A>&nbsp;' +
           '<SPAN CLASS="HelpTextG">|</SPAN>&nbsp;<A class="HelpTextG" href="/pages/account/edit.html" class="HelpText">my account</A>&nbsp;';
  }
  else
    Str += ',</SPAN> <A class="HelpTextG" href="/pages/account/login.html?Action=edit.html" class="HelpText">sign in</A>&nbsp;';
  
//  Str += '<SPAN CLASS="HelpTextG">|</SPAN>&nbsp;<a class="HelpTextG" href="javascript:getHelp()" class="HelpText" onmouseover="window.status=\'Get Help for this Screen\'" onmouseout="window.status=\'\'" >help</A>&nbsp';

//  if ( CookieValid && UserCookie[CookieGroup_Id] != '1' )    
//  {
//    var URL = document.location.pathname;
//    if ( document.location.search ) URL += document.location.search;
//    URL = escape( URL.replace( /\/pages/, '' ) );
//    Str += '|&nbsp;<a class="HelpTextG" href="javascript:helpPopup(\'/pages/help/support.html?p_Type=Feedback&p_Title=Online%20Support&p_URL='+URL+'\');" class="HelpText" onmouseover="window.status=\'Get Online Support\'" onmouseout="window.status=\'\'">support</A>&nbsp';
//  }
  if ( CookieValid && UserCookie[CookieGroup_Id] == '0' && ( UserCookie[CookieEmail].indexOf( '@'+'marketbright.com' ) > -1 ) )
  {
    var thisPageDebug = window.location.href;
    if ( thisPageDebug.indexOf( 'Debug=Y' ) > -1 ) thisPageDebug = thisPageDebug.replace( /Debug\=Y/, 'Debug=N' );
    else if ( thisPageDebug.indexOf( '?' ) > -1 ) thisPageDebug += '&Debug=Y';
    else thisPageDebug += '?Debug=Y';
    Str += '|&nbsp;<A class="HelpTextG" href="'+thisPageDebug+'" class="HelpText">debug</A>&nbsp;';

//    var thisPageEdit = window.location.href;
//    if ( thisPageEdit.indexOf( 'Edit=Y' ) > -1 ) thisPageEdit = thisPageEdit.replace( /Edit\=Y/, 'Edit=N' );
//    else if ( thisPageEdit.indexOf( '?' ) > -1 ) thisPageEdit += '&Edit=Y'; 
//    else thisPageEdit += '?Edit=Y';
//    Str += '|<A class="HelpTextG" href="'+thisPageEdit+'" class="HelpText">edit</A>';
  }
  document.write( Str );
  document.close();
}
	
	
	
	
	
	
	
	
	
	
	
	/// Legacy scripts
	/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;


/// Legacy Script
function getHTTPObject() {
	var http = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
	return http;
}

function changeTab(name, id){
	var http = getHTTPObject();
//	var params = 'column='+id+'&name='+name;
	var params = '';
//	http.open("POST", "includes/ajax.html", true);
	http.open("GET", "/includes/widgets/" + name + ".html", true);
	
	var tabs = document.getElementById('tabs'+id);
	var tagArray = tabs.getElementsByTagName("a");
	
	for(var x=0; x<tagArray.length; x++){
		if(name != tagArray[x].id){
			//tagArray[x].style.backgroundColor = '#eaf3ef';
			tagArray[x].className = "normalTab";
		}else{
			//tagArray[x].style.backgroundColor = '#fff';
			tagArray[x].className = tagArray[x].className + " selected";
		}
	}
	
	//Send the proper header infomation along with the request
//	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-type", "text/html");
//	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Content-length", params.length );
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function(){
		switch(http.readyState){
			case 4:
				if(http.status == 200){
					if(name != "solutions-sol"){
						document.getElementById('contentArea'+id).innerHTML = http.responseText;
					}else{
						var array = Array("<div style='font-size: 11px;'><span style='width: 100%; display: block; text-align: center;'><a href='/solutions/customer-success/conde-nast.html'><img src='/images/logos/conde_nast.gif' alt='' border='0'></a></span><div class='contentAreaItem'><a href='/solutions/customer-success/conde-nast.html'>'DatAdvantage showed us the existing access permissions and gave us visibility into who is really using the data, how often and in what way.'<span style='display: block; width: 100%; text-align: right; color: rgb(102, 102, 102); padding-top: 3px;'>-Jerry Anzano, Manager, Conde Nast</span></a></div></div>", "<div style='font-size: 11px;'><span style='width: 100%; display: block; text-align: center;'><a href='/solutions/customer-success/m_systems.html'><img alt='' src='/images/logos/m_systems.gif'></a></span><div class='contentAreaItem'><a href='/solutions/customer-success/m_systems.html'>'The fast-turnaround of our business and our rapidly changing organization made us choose DatAdvantage.'<span style='display: block; width: 100%; text-align: right; color: rgb(102, 102, 102); padding-top: 3px;'>-Udi Weinstein, CIO, M-Systems</span></a></div></div>", "<div style='font-size: 11px;'><span style='width: 100%; display: block; text-align: center;'><a href='/solutions/customer-success/moma.html'><img alt='' src='/images/logos/moma.gif'></a></span><div class='contentAreaItem'><a href='/solutions/customer-success/moma.html'>'With Varonis DatAdvantage we were able to establish effective data authorization processes.'<span style='display: block; width: 100%; text-align: right; color: rgb(102, 102, 102); padding-top: 3px;'>-Steve Peltzman, CIO, MoMA</span></a></div></div>");
					
					var randNum = Math.round(Math.random() * (2-0));
					document.getElementById('contentArea'+id).innerHTML = array[randNum];
					}
				}else{
					document.getElementById('contentArea'+id).innerHTML = 'An error occurred.';
				}
			break;
			case 3:
				document.getElementById('contentArea'+id).innerHTML = 'Loading...';
			break;
		}
	}
	http.send(params);
}


//// funcs
var BASEURL = '/';


function openWin(url, width, height){
	if(width == null){
		width = 600;
	}
	if(height == null){
		height = 400;
	}
	var newWindow = window.open(url, 'newWin', 'width='+width+',height='+height+',status=no,scrollbars=1,resizable=yes');
	if(window.focus) newWindow.focus();
	return false;
}
function flashObject(id, swf, width, height){
	var so = new SWFObject(swf, 'flash_' + id, width, height, '8');
	so.addParam('quality', 'best');
	so.addParam('menu', 'false');
	so.addParam('allowScriptAccess', 'sameDomain');
	so.write(id);
}
function changeNavTab(section){
	var navString;
	var subNav = document.getElementById('subnav');
	/*
	// change to selected tab
	var parent = document.getElementById(section).parentNode;
	parent.className = 'current';
	*/
	switch(section){
		case 'Products':
			navString = '<ul><li><a href="' + BASEURL + 'products/overview.html">Overview</a></li><li><a href="' + BASEURL + 'products/datadvantage/index.html">DatAdvantage</a></li><li><a href="' + BASEURL + 'products/dataprivilege/index.html">DataPrivilege</a></li><li><a href="' + BASEURL + 'products/architecture/index.html">Architecture</a></li></ul>';
		break;
		case 'Solutions':
			navString = '<ul><li><a href="' + BASEURL + 'solutions/customer-success/index.html">Customer Success</a></li><li><a href="' + BASEURL + 'solutions/industries/index.html">Industries</a></li><li><a href="' + BASEURL + 'solutions/whyvaronis/index.html">Why Varonis</a></li></ul>';
		break;
		case 'Partners':
			navString = '<ul><li><a href="' + BASEURL + 'partners/programs.html">Programs</a></li><li><a href="' + BASEURL + 'pages/partners/registration_intro.html">Become a Partner</a></li><li><a href="' + BASEURL + 'pages/account/login.html">Partner Login</a></li></ul>';
		break;
		case 'Support':
			navString = '<ul><li><a href="' + BASEURL + 'support/overview.html">Overview</a></li><li><a href="' + BASEURL + 'support/programs.html">Programs</a></li><li><a href="' + BASEURL + 'support/resources.html">Resources</a></li></ul>';
		break;
		case 'News':
			navString = '<ul><li><a href="' + BASEURL + 'news/industry-buzz/index.html">Industry Buzz</a></li><li><a href="' + BASEURL + 'news/press-releases/index.html">Press Releases</a></li><li><a href="' + BASEURL + 'news/awards/index.html">Awards</a></li><li><a href="' + BASEURL + 'news/events/index.html">Events</a></li></ul>';
		break;
		case 'Company':
			navString = '<ul><li><a href="' + BASEURL + 'company/overview.html">Overview</a></li><li><a href="' + BASEURL + 'Company/management.html">Management Team</a></li><li><a href="' + BASEURL + 'company/investors.html">Investors</a></li><li><a href="' + BASEURL + 'company/board-of-directors.html">Board of Directors</a></li><li><a href="' + BASEURL + 'company/contact.html">Contact</a></li></ul>';
		break;
	}
	navString += '<div class="clear"></div>';
	subNav.innerHTML = navString;
}

function toggleBox(id,el){
	var element = document.getElementById(id);
	if(element.style.display == 'none'){
		element.style.display = 'block';
		el.style.backgroundImage = "url(/images/right_module_images/static/down_arrow.gif)";
	}else{
		element.style.display = 'none';
		el.style.backgroundImage = "url(/images/right_module_images/static/arrow.gif)";
	}
}
