////////////////////////////////////////////////////////////////////////////////
//
// Public Javascript Functions
//
// Revision: $Id: casalemediaDotCom-public.js,v 1.1.2.2 2007/05/23 17:07:01 matt Exp $
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright @ 2007 Casale Media
// All Rights Reserved.
//
// ---------------------------------------------------------------------------
//
// Legal Notice
//
// The information contained within this document is confidential,
// coyprighted and or trade secret. No part of this document may be
// reproduced or distributed in any form or by any means, in whole
// or in part, without the prior written permission of Casale Media.
//
////////////////////////////////////////////////////////////////////////////////

function displayTextField(fieldName, formName) {

	var field = eval('document.'+ formName + '.' + fieldName);
	if (field.value=='other') {
	  if (document.getElementById) {
		document.getElementById('other').style.display='inline';
		document.getElementById('other').value="enter your text here";
		document.getElementById('other').focus();
	  }
	  else {
		/*document.layers['other'].style.display='inline';
		document.layers['other'].value="enter your text here";
		document.layers['other'].focus();*/
	  }
	}	
	else {
	  if (document.getElementById) {
		document.getElementById('other').style.display="none";
 	  }
	  else {
		//document.layers['other'].style.display="none";
	  }
	}
}

var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;

function getElement(id) {
  if (NS4) {return eval("document." + id)}
  else if (IE4) {return eval("document.all." + id)}
  else if (IE5 || N6) {return document.getElementById(id)};
}

function gotoURL(page) {
	window.open(page, 
'_blank',"height=600,width=480,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,top=80"); 
}

function printablePage(page) {
        window.open(page,
'_blank',"height=600,width=670,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,top=80");
}

function emailPage(page) {
        window.open(page,'_blank',"height=448,width=490,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,top=80");
}

function popupPage(page) {
        window.open(page,'_blank',"height=380,width=380,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,top=80");
}
function jumptoURL(form, obj){
  if (eval('document.'+ form +'.' + obj +'.options[document.'+form+'.'+obj+'.selectedIndex].value') != "none") 
   {
     window.document.location = eval('document.'+form+'.'+ obj +'.options[document.'+form+'.'+obj+'.selectedIndex].value');
   }
}
function openPresentation(page){
	window.open(page,'_blank',"height=460,width=610,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,top=80");
}

var PopupWindow;
function popWin( url, name, width, height, scroller ) {
        if (PopupWindow && name!='') {
                PopupWindow.close();
        }
        var outStr = 'height=' + height + ',width=' + width;
        if (scroller != 'true') {
                outStr += ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes';
        } else {
                outStr += ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars,resizable=yes';
        }
        eval( name + " = window.open(\"" + url + "\", \"" + name + "\", \"" + outStr + "\");" );
        eval( name + ".focus();" );
        PopupWindow = eval(name);
}

function KW(){
setTimeout('window.close();',50);
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);

   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

var W3CDOM = (document.createElement && document.getElementsByTagName);
function spanishFormInit() {
	if (!document.spanishForm) return;
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/images/browse-button-spanish2.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].getAttribute('noscript')) continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		if (x[i].value)
			x[i].onchange();
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

