// these scripts are to be available to all pages on the site

//place gloabal variables here
var d = document;


// based on script by Paul Bellows; mod. by Avid Technology, Inc.
function evenColumns() {
	if (d.getElementById) { // determine if browser uses DOM
		var contentHeight = d.getElementById('ContentBody'); //middle column
		var rightHeight = d.getElementById('Rightside'); //right column
		var leftHeight = d.getElementById('Leftside'); //left column
		if (rightHeight != null) { //check if right column exists; set heights to largest
			//alert('I detect three columns/nNow, which one is the highest?');
			if ((contentHeight.offsetHeight >= rightHeight.offsetHeight) && (contentHeight.offsetHeight >= leftHeight.offsetHeight)) {
				//alert('content div is the highest');
				leftHeight.style.height = (contentHeight.offsetHeight) + 'px';
				rightHeight.style.height = (contentHeight.offsetHeight) + 'px';
				contentHeight.style.height = (contentHeight.offsetHeight) + 'px';
			} else if ((rightHeight.offsetHeight >= contentHeight.offsetHeight) && (rightHeight.offsetHeight >= leftHeight.offsetHeight)) {
				//content not the hightest; checking others...
				//alert('right div is the highest');
				leftHeight.style.height = (rightHeight.offsetHeight) + 'px';
				rightHeight.style.height = (rightHeight.offsetHeight) + 'px';
				contentHeight.style.height = (rightHeight.offsetHeight) + 'px';
			} else { //ok, only one column left to be the highest (yup, the left one)
				//alert('left div is the highest');
				leftHeight.style.height = (leftHeight.offsetHeight) + 'px';
				rightHeight.style.height = (leftHeight.offsetHeight) + 'px';
				contentHeight.style.height = (leftHeight.offsetHeight) + 'px';
			}
				
		} else if (leftHeight !=null) { //assume only two columns; set heights to largest
			if (contentHeight.offsetHeight >= leftHeight.offsetHeight) {
				leftHeight.style.height = (contentHeight.offsetHeight) + 'px';
			} else { //left nav taller than content (bad design *yeesh*
				contentHeight.style.height = (leftHeight.offsetHeight) + 'px';
				}
		}
	}
}

function evenColumnsHP() {
	if (d.getElementById) { // determine if browser uses DOM
		var newsHeight = d.getElementById('NewsEventsTable'); 
		var showHeight = d.getElementById('ShowcaseTable'); 
		var downHeight = d.getElementById('Down_Tut'); 
		var promoHeight = d.getElementById('PromoTable');
		
		if ((newsHeight.offsetHeight >= showHeight.offsetHeight) && (newsHeight.offsetHeight >= downHeight.offsetHeight) && (newsHeight.offsetHeight >= promoHeight.offsetHeight)) {
			showHeight.style.height = (newsHeight.offsetHeight) + 'px';
			downHeight.style.height = (newsHeight.offsetHeight) + 'px';
			promoHeight.style.height = (newsHeight.offsetHeight) + 'px';
			newsHeight.style.height = (newsHeight.offsetHeight) + 'px';
		} else if ((showHeight.offsetHeight >= downHeight.offsetHeight) && (showHeight.offsetHeight >= promoHeight.offsetHeight)) {
				newsHeight.style.height = (showHeight.offsetHeight) + 'px';
				downHeight.style.height = (showHeight.offsetHeight) + 'px';
				promoHeight.style.height = (showHeight.offsetHeight) + 'px';
				showHeight.style.height = (showHeight.offsetHeight) + 'px';
		} else if (downHeight.offsetHeight >= promoHeight.offsetHeight) {
				newsHeight.style.height = (downHeight.offsetHeight) + 'px';
				showHeight.style.height = (downHeight.offsetHeight) + 'px';
				promoHeight.style.height = (downHeight.offsetHeight) + 'px';
				downHeight.style.height = (downHeight.offsetHeight) + 'px';
		} else {
				newsHeight.style.height = (promoHeight.offsetHeight) + 'px';
				showHeight.style.height = (promoHeight.offsetHeight) + 'px';
				downHeight.style.height = (promoHeight.offsetHeight) + 'px';
				promoHeight.style.height = (promoHeight.offsetHeight) + 'px';
		}
		
	}
}



//openVideoWin('LOTR_Production1',135)
function openVideoWin(token,videoID) {
  var vidWin;
  winWidth='450';
  winHeight='422';
  theURL = '/video/video_window.asp?vidName='+token+'&videoID='+videoID;
  vidWin = window.open(theURL,'videoWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+winWidth+',height='+winHeight+'');
  vidWin.focus();
}
//this one passes in different data
//openVideoWindow('/video/video_window.asp?vidName=mca_overview&videoID=89', 422, 450)
function openVideoWindow(theURL,wH,wW) {
  var vidWin;
  winWidth=wW;
  winHeight=wH;
  vidWin = window.open(theURL,'videoWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+winWidth+',height='+winHeight+'');
  vidWin.focus();
}

function openFLVWin(flash,fWidth,fHeight) {
	var flashWin;
	var winWidth;
	var winHeight;
	winWidth = fWidth + 250;
	winHeight = fHeight + 250;
	flashWin = window.open('/video/FLVOnlyPlayer.asp?video='+flash+'&width='+fWidth+'&height='+fHeight,'flashWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+winWidth+',height='+winHeight+'');
	flashWin.focus();
}

function jumpMenu(selectObj){
   eval("parent.location='"+selectObj.options[selectObj.selectedIndex].value+"'");
}

//for opening up VNAB window
function openVNABWin () {
   var myWinVar;
   myWinVar = window.open('/nab2005/nab2005.html','myWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=950,height=700');
   myWinVar.focus();
}

//opens up a flash piece in a new window; pass in flash piece url (swf only), width and height
function openFlashDemo(flash,fWidth,fHeight) {
	var flashWin;
	flashWin = window.open('/flash/flashWindow.asp?flash='+flash+'&width='+fWidth+'&height='+fHeight,'flashWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+fWidth+',height='+fHeight);
	flashWin.focus();
}

//opens content in new window
function openBrWindow(theURL,winName) {
  brWidth=900;
  brHeight=680;
  features = 'scrollbars=yes,resizable=yes,width='+brWidth+',height='+brHeight;
  newWin = window.open(theURL,winName,features);
}
function openBcastAnim(theURL) {
  bcastWidth=1010;
  bcastHeight=740;
  features = 'toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,status=0,width='+bcastWidth+',height='+bcastHeight;
  newWin = window.open(theURL,'BcastAnim',features);
}

//share function to open new windws
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function maximizeWindow() {
	/***********************************************
	* Auto Maximize Window Script- © Dynamic Drive (www.dynamicdrive.com)
	* This notice must stay intact for use
	* Visit http://www.dynamicdrive.com/ for this script and 100's more.
	***********************************************/

	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
		top.window.outerHeight = screen.availHeight;
		top.window.outerWidth = screen.availWidth;
		}
	}
}



//country site list pulldown
function siteSelect(subDomain){
	subDomain = subDomain.value;
	//var expireDate = new Date();
	//expireDate.setFullYear(expireDate.getFullYear()+1);
	//document.cookie = 'siteSelect=' + subDomain + '; expires=' + expireDate.toGMTString();
	switch(subDomain) {
		case 'kr': {
			location.href = 'http://www.avid.co.kr/';
			break;
		}
		case 'www': {
			location.href = 'http://www.avid.com/';
			break;
		}
		case 'cn': {
			location.href = 'http://www.avid-china.com/';
			break;
		}
		case 'fr': {
			location.href = 'http://fr.avid.com/';
			break
		}
		case 'de': {
			location.href = 'http://de.avid.com/';
			break;
		}
		case 'jp': {
			location.href = 'http://www.avid.co.jp/';
			break;
		}
		case 'es': {
			location.href = 'http://es.avid.com/';
			break;
		}
		case 'uk': {
			location.href = 'http://uk.avid.com/';
			break;
		}
		case 'au': {
			location.href = 'http://www.avidaustralia.com.au/';
			break;
		}
		case 'at': {
			location.href = 'http://www.avid.at/';
			break;
		}
		case 'be': {
			location.href = 'http://www.avid.be/';
			break;
		}
		case 'nl': {
			location.href = 'http://www.avid.nl/';
			break;
		}
		case 'dk': {
			location.href = 'http://www.avid.dk/';
			break;
		}
		case 'fi': {
			location.href = 'http://www.avid.fi/';
			break;
		}
		case 'it': {
			location.href = 'http://www.avid.it/';
			break;
		}
		case 'no': {
			location.href = 'http://www.avid.no/';
			break;
		}
		case 'se': {
			location.href = 'http://www.avid.se/';
			break;
		}
		case 'nxn': {
			location.href = 'http://www.alienbrain.com/';
			break;
		}
		case 'digi': {
			location.href = 'http://www.digidesign.com/';
			break;
		}
		case 'si': {
			location.href = 'http://www.softimage.com/';
			break;
		}
		case 'maudio': {
			location.href = 'http://www.m-audio.com/';
			break;
		}
		case 'pinn': {
			location.href = 'http://www.pinnaclesys.com/';
			break;
		}
		case 'ap': {
			location.href = 'http://www.avid-asia.com/';
			break;
		}
		default:{
			break;
		}
	}
}

//event firings
if (homepage) {
	window.onload = function() {
		evenColumnsHP();
	}
	window.onresize = function() {
		evenColumnsHP();
	}
} else {
	window.onload = function() {
		evenColumns();
	}
	window.onresize = function() {
		evenColumns();
	}
}

// stuff for hosted website survey 2005

function takeSurvey(){
	surveyCookie = getCookieS('siteSurvey2005');
	if(surveyCookie==null){
		// first time thru, set cookie so we don't prompt them again
		expiresDate = new Date();
		expiresDate.setMonth(expiresDate.getMonth()+2);
		setCookieS('siteSurvey2005',true, expiresDate)
		popup_window();
	}	
}

function popup_window() {
            // Create the popup
            var w = window.open('', 'Survey_Invite', 'width=300, height=250, menubar=no, scrollbars=no, toolbar=no, location=no, resizable=yes, top=50, left=50');
            if(w){
		    //setCookieS('siteSurvey2005',true, expiresDate)
		    var d = w.document;

		    //d.write('<link href="/stylesheets/Default.css" type="text/css" rel="stylesheet" />');

		    // Create the popup's html
		    d.write("<head><title>We invite you to take the 2005 Avid Web Site Visitor survey</title></head>");
		    d.write("<style type='text/css'>body {font-family: Arial, Verdana, Helvetica, sans-serif;font-size: 0.8em;color: #000000;}</style>");
		    d.write("<body>");

		    // BEGINNING OF POPUP TEXT CONTENT
		    d.write("<div align='left'><p>We invite you to take the 2005 Avid Web Site Visitor Survey.</p>");
		    d.write("<p>Please help us to improve your experience with Avid.com.</p>");
		    d.write("<p>Take a few minutes and complete this brief survey.  Your opinions are important to us.</p>");
		    d.write("<p>Would you like to take the survey now?</p></div>");
		    // END OF POPUP TEXT CONTENT

		    // Finish creating popup's html
		    d.write("<form onSubmit=\"window.open('http://survey.perseus.com/116396be.htm');self.close();\">");
		    d.write("<div align='right'>");
		    d.write("<input type='submit' value=' Yes '>&nbsp;");
		    d.write("<input type='button' value=' No ' onclick='self.close();'>");
		    d.write("</div>");
		    d.write("</form>");
		    d.write("</body>");
            }
}

function setCookieS(name, value, expire) {
	document.cookie = name + "=" + escape(value) + "; path=/" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookieS(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search);
		if (offset != -1) { // if cookie exists
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

//takeSurvey();

// delete cookie, for testing
//setCookieS('siteSurvey2005','',new Date(1999,1,1));


// end of hosted survey stuff
