﻿//
// Main utility script
// v1.0

//
// Call 3rd party scripts
//
//document.write('<script type="text/javascript" src="Scripts/swfobject.js"><\/script>');
//document.write('<script type="text/javascript" src="Scripts/Scriptaculous/prototype.js"><\/script>');
//document.write('<script type="text/javascript" src="Scripts/Scriptaculous/scriptaculous.js"><\/script>');

// Test code
var lastDiv = 0;
function showDiv(name,effect) {
  if (lastDiv != name) {
   if(lastDiv != 0) {
     //hide last one
     if (effect) {
       //Effect.BlindUp(lastDiv);
       document.getElementById(lastDiv).style.display = 'none';
     }else{
       document.getElementById(lastDiv).style.display = 'none';
     }
   }
     lastDiv = name;
     //alert( "showDiv => " + lastDiv );
     if (effect) {
       //Effect.BlindDown(lastDiv);
       document.getElementById(lastDiv).style.display = 'block';
     }else{
       document.getElementById(name).style.display = 'block';
     }
  }
}
        
// Gets variable from URL
function getURLVar(name) {  
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if (results == null) {
      return "";
    }else{
      return results[1];
    }
}

// Checks if variable is populated with a value
function checkVar(what) {
    return Boolean(typeof what != 'undefined' && what);
}

//
// Begin client icon slide show
//
var slideShowSpeed = 5000; // Set slideShowSpeed (milliseconds)
var crossFadeDuration = 5; // Duration of crossfade (seconds)
var imagerootdir = "Images/Logos/";
var Pic = new Array();

Pic[0] = imagerootdir + 'ambev_sm.jpg'
Pic[1] = imagerootdir + 'sadia_sm.jpg'

var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();

for (i = 0; i < p; i++) {
	preLoad[i] = new Image();
	preLoad[i].src = Pic[i];
}

function runSlideShow() {
	if (document.all) {
	document.images.SlideShow.style.filter="blendTrans(duration=2)";
	document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
	document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[j].src;
	if (document.all) {
	document.images.SlideShow.filters.blendTrans.Play();
	}
	j = j + 1;
	if (j > (p - 1)) j = 0;
	t = setTimeout('runSlideShow()', slideShowSpeed);
}

//
// Begin disable right-click
//
var message = "Flateck © 2009. All Rights Reserved.";
function disableRightClick(e) {
  if(!document.rightClickDisabled) // initialize
  {
    if(document.layers) 
    {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all))
  {
    if (e.which==2||e.which==3)
    {
      alert(message);
      return false;
    }
  }
  else
  {
    alert(message);
    return false;
  }
}
disableRightClick();

//
//Character count for text area
//
var maxChars = 400;
function charsleft() {
    theInputBox = document.getElementById('messageText');
    theCountBox = document.getElementById('charsLeft');
    var currentChars = theInputBox.value.length;
    theCountBox.value = Math.max((maxChars - currentChars),0);
    if(currentChars > maxChars) {
        theInputBox.value = theInputBox.value.substring(0,maxChars);
    }
}

//
// Opens a new browser window
//
function NewWindow(page, name, w, h, scroll, resize) {
	var winl = 100;
	var wint = 100;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize
	OpenWin = window.open(page, name, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// Begin writing a new frame
function writeLayer(text) {
	document.frames['myFrame'].location.href = text;
	document.addrForm.location.value = text;
}

function onLoad(text) {
	if (text != "Microsoft Internet Explorer") {
	alert("netscape not supported");
	history.back();
}

return true;
}

//
// Macromedia utility functions
//
function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function FWOnLoad() {
    if (FwPrevHook) {
        FwPrevHook();
    }
    FWLoadInit();
}

function FWHookLoad() {
    var agent = navigator.userAgent;
    var hookPrev = true;
    if (agent.indexOf("MSIE") != -1 && agent.indexOf("Mac_") != -1) {
        hookPrev = false;
    }
    if (hookPrev) {
        FwPrevHook = window.onload;
    } else {
        FwPrevHook = false;
    }
    window.onload = FWOnLoad;
}
