

function openWin() {
   newWindow = window.open("Terms&Conditions.html", "StreamCity", "menubar=no,width=520,height=550,toolbar=no,screenX=10,screenY=30,scrollbars=yes");
}

// forms functions
function sendContact() {
   var http_request = false;
   url = "procContact.asp";
   parameters = "name=" + escape(document.contactForm.name.value) + "&phone=" + escape(document.contactForm.phone.value) + "&email=" + escape(document.contactForm.email.value) + "&howhear=" + escape(document.contactForm.howhear.value) + "&comments=" + escape(document.contactForm.comments.value);
   if (window.XMLHttpRequest) {
      // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
         http_request.overrideMimeType('text/html');
         }
      }
   else if (window.ActiveXObject) {
      // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
         }
      catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
         catch (e) {
            }
         }
      }
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
      }
   http_request.onreadystatechange = function() {
      if(http_request.readyState == 4) {
         alert("Your message has been sent.");
         }
      }
   if(isValidEmail(document.contactForm.email.value)) {
      http_request.open('POST', "procContact.asp", true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
      }
   else {
      alert("Please provide a valid email address");
      }
   }


function sendTrialRequest() {
	
	var http_request = false;
   url = "procFreeTrial.asp";
   parameters = "name=" + document.demo.name_trial.value + "&phone=" + document.demo.phone_trial.value + "&email=" + document.demo.email_trial.value + "&company=" + document.demo.company_trial.value + "&zip=" + document.demo.zip_trial.value;
   if (window.XMLHttpRequest) {
      // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
         http_request.overrideMimeType('text/html');
         }
      }
   else if (window.ActiveXObject) {
      // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
         }
      catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
         catch (e) {
            }
         }
      }
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
      }
   http_request.onreadystatechange = function() {
      if(http_request.readyState == 4) {
         alert("Your trial request has been sent.");
         registerCancel();
         }
      }
	  

   if(validateAll()) {
	    http_request.open('POST', "procFreeTrial.asp", true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
      }else{
	
	}
	}
function isValidEmail(strEmail) {
  
   validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
   // search email text for regular exp matches
   if (strEmail.search(validRegExp) == - 1) {
      return false;
      }
   return true;
   }
   
function validateAll() {
	if ((validateEmail(document.forms.demo.email_trial, 'email_trial')==true)&(validatePhone(document.forms.demo.phone_trial, 'phone_trial')==true)&(validateName(document.forms.demo.name_trial, 'name_trial')==true)&(validateZip(document.forms.demo.zip_trial, 'zip_trial')==true)&(validateCompany(document.forms.demo.company_trial, 'company_trial')==true))
 {
		return true;
	}
		
}

// validating each element

var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

// --------------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// --------------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}


// --------------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}


// --------------------------------------------
//                  msg
// Display warn/error message in HTML element.
// commonCheck routine must have previously been called
// --------------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  var dispmessage;
  if (emptyString.test(message)) 
    dispmessage = String.fromCharCode(nbsp);    
  else  
    dispmessage = message;

  var elem = document.getElementById(fld);
  elem.firstChild.nodeValue = dispmessage;  
  
  elem.className = msgtype;   // set the CSS class to adjust appearance of message
}

// --------------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
// --------------------------------------------

var proceed = 2;  

function commonCheck(valfield, infofield) {  // true if required
	if (infofield == 'phone_trial') {
	infofield = 'phone number'	
	}
	if (infofield == 'name_trial') {
	infofield = 'your name is'	
	}
	if (infofield == 'email') {
	infofield = 'your email address is'	
	}
	if (infofield == 'company_trial') {
	infofield = 'your company name or a name under which you operate is'	
	}
	if (infofield == 'zip_trial') {
	infofield = 'your zip code is'	
	}
  if (emptyString.test(valfield.value)) {

      alert('ERROR: '+infofield+' required');  
      setfocus(valfield);
      return false;

  } else {
      
      return true;  
    }
  return proceed;
}

function validateName(valfield,   // element to be validated
                         infofield)
{
  var stat = commonCheck (valfield, infofield);
  if (stat != proceed) return stat;
  return true;
}

function validateZip(valfield,   // element to be validated
                         infofield)
{
  var stat = commonCheck (valfield, infofield);
  if (stat != proceed) return stat;
  return true;
}

function validateCompany(valfield,   // element to be validated
                         infofield)
{
  var stat = commonCheck (valfield, infofield);
  if (stat != proceed) return stat;
  return true;
}

function validateEmail(valfield,   // element to be validated
                         infofield)   // true if required
{
  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
	 alert('ERROR: the address provided is not a valid email');
	    setfocus(valfield);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
  if (!email2.test(tfld)) 
   alert('Unusual e-mail address - check if correct');
  else
      return true;
}

function validatePhone (valfield, infofield){
  //var stat = commonCheck (valfield, infofield);
  //if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-]+[0-9]$/  ;
  if (!telnr.test(tfld)) {
   alert('ERROR: not a valid telephone number. Characters permitted are digits, space ()- and leading +');
    setfocus(valfield);
    return false;
  } 
  return true;
}

// drop down menus:
var timeOut	= 500;
var closeTimer	= false;
var theMenu	= false;

function dropOpen(theId) {
	dropClose();
	stopTimer();
	theMenu = document.getElementById(theId);
	theMenu.style.visibility = 'visible';
}
function dropClose() {
		
	if (theMenu) {
		theMenu.style.visibility = 'hidden';
	}
}
function startTimer() {
	closeTimer = window.setTimeout(dropClose, timeOut);	
}
function stopTimer() {
	if (closeTimer) {
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}
function showcase() {
   var showcase = new SWFObject("showcase.swf", "alpha", "775", "486", "8", "#ffffff");
   //so.useExpressInstall('expressinstall.swf');
   //so.addParam("wmode", "transparent");
   showcase.addParam("allowScriptAccess", "Always");
   showcase.addParam("wmode", "transparent");
   showcase.write("showcasePlayerFlash");
}
function soWrite(which) {
  var so = new SWFObject(which, "alpha", "314", "350", "8", "#ffffff");
   so.addParam("allowScriptAccess", "Always");
   so.write("flashvideo");
}
function extractPageName(hrefString) {

	var arr = hrefString.split('/');
	var pageLoc =  (arr.length<1) ? hrefString : arr[arr.length-1];
	var arr2 = pageLoc.split('?');
	window.thisPage = arr2[0];
	window.subPage = arr2[1];	
	if (window.subPage == undefined) {
		window.subPage = '0';
	}
}
function setPage() {
	hrefString = document.location.href ? document.location.href : document.location;
	extractPageName(hrefString);
	showContent(window.thisPage, window.subPage);
}
var onlineVideo = 'http://magic.sc-streaming.com/player/shell.asp?campaignID=172_350';
var indexVideo = 'http://magic.sc-streaming.com/player/shell.asp?campaignID=172_349';
var productionVideo = 'http://magic.sc-streaming.com/player/shell.asp?campaignID=172_351';
var logoVideo = 'http://magic.sc-streaming.com/player/shell.asp?campaignID=172_354';
function showContent(thisPage, subPage) {
	
	var thisPageArr = thisPage.split('.html');
	var thisPageName = thisPageArr[0];	

	//showing the initial topNav for main 3:
	if (thisPageName == "index" || thisPageName == '' || thisPageName == 'about' || thisPageName == 'contact') {
		if (thisPageName == '') {
			thisPageName = "index";
		}
		var theTopNavName = thisPageName+'TopNav';
		var theTopNav = document.getElementById(theTopNavName);
		theTopNav.className = 'shown';
		window.lastTopNavName = theTopNavName;
	}
	
	//showing the initial page for main 3:
	if (thisPageName == "index" || thisPageName == '' || thisPageName == 'about' || thisPageName == 'contact') {
		if (thisPageName == '') {
			thisPageName = "index";
		}
		var thePage = document.getElementById(thisPageName);
		thePage.className = 'shown';
	}
	
	var navName = thisPageName+'Nav'+subPage;
	var theNav = document.getElementById(navName);
	//hideNavs(thisPageName);
	theNav.className = 'shown';

	var contentName = thisPageName+subPage;
	var theContent = document.getElementById(contentName);
	//hideContent(thisPageName);
	theContent.className = 'shown';	
	
	switch (thisPageName) {
		case 'contact':
			soWrite(indexVideo);
		break;
		case 'index':
			soWrite(indexVideo);
		break;
		case 'about':
			if (subPage == '1') {
				soWrite(logoVideo);
			} else {
				soWrite(indexVideo);
			}
			
		break;
		case 'online':
			soWrite(onlineVideo);
		break;
		case 'production':
			soWrite(productionVideo);
		break;
		case 'vidBriefings':
			soWrite(productionVideo);
		break;
		case 'showcase':
			showcase();
		break;
	}	
	window.lastPageName = thisPageName;
	window.lastNavName = navName;
	window.lastContentName = contentName;
	
	getFooters(thisPageName, subPage);
	
}
function getContent(mainPage, subPage) {

	var thisPageArr = mainPage.split('.html');
	var thisPageName = thisPageArr[0];
	// show the page for main 3:
	if (thisPageName != window.lastPageName) {
		
		var thePage = document.getElementById(thisPageName);
		hideDiv(window.lastPageName);
		thePage.className = 'shown';
		
		var theTopNavName = thisPageName+'TopNav';
		var theTopNav = document.getElementById(theTopNavName);
		hideDiv(window.lastTopNavName);
		theTopNav.className = 'shown';
		window.lastTopNavName = theTopNavName;
		
		if (window.lastPageName == 'about' && window.subPageStatus == '1') {
			soWrite(indexVideo);
		} else if (thisPageName == 'about' && subPage == '1') {
			soWrite(logoVideo);	
		}
	}
	if (thisPageName == 'about' && window.lastPageName == 'about') {
		if (subPage == '1') {
			soWrite(logoVideo);	
		} else if (window.subPageStatus == '1') {
			soWrite(indexVideo);	
		}
	} 

	window.lastPageName = thisPageName;	
	var navName = thisPageName+'Nav'+subPage;
	var theNav = document.getElementById(navName);
	var baseNav = thisPageName+'Nav0';
	hideDiv(window.lastNavName);
	hideDiv(baseNav);
	theNav.className = 'shown';
	
	var contentName = thisPageName+subPage;
	var theContent = document.getElementById(contentName);
	var baseContent = thisPageName+'0'
	hideDiv(window.lastContentName);
	hideDiv(baseContent);
	theContent.className = 'shown';	
	window.lastContentName = contentName;

	window.lastNavName = navName;
	getFooters(thisPageName, subPage);
}
function hideDiv(which) {
	document.getElementById(which).className = 'hidden';
}
function getFooters(thisPage, subPage) {
	//alert(thisPage+subPage)
	window.pageStatus = thisPage;
	window.subPageStatus = subPage;
		
	showFooters();
}
function showFooters() {
	switch (window.pageStatus) {
		case 'contact':
			hideVidFooters('showcaseVidFooter');
			showVidFooter('webTvVidFooter');
      		showVidFooter('publisherVidFooter');
      		showVidFooter('freeTrialVidFooter');
			document.getElementById("vidFooterSpacer").className = 'hidden';
		break;
		case 'index':
			hideVidFooters('webTvVidFooter');
			hideVidFooters('publisherVidFooter');
			hideVidFooters('freeTrialVidFooter');
			showVidFooter('newsVidFooter');
			showVidFooter('showcaseVidFooter');
			document.getElementById("vidFooterSpacer").className = 'shown';
		break;
		case 'about':
			document.getElementById("vidFooterSpacer").className = 'hidden';
			if (window.subPageStatus == '0' || window.subPageStatus == '1') {
				hideVidFooters('webTvVidFooter');
				hideVidFooters('publisherVidFooter');
				hideVidFooters('freeTrialVidFooter');

				showVidFooter('newsVidFooter');
				showVidFooter('showcaseVidFooter');
			}
			else {
				hideVidFooters('webTvVidFooter');
				hideVidFooters('publisherVidFooter');
				hideVidFooters('freeTrialVidFooter');
				hideVidFooters('newsVidFooter');
				showVidFooter('showcaseVidFooter');
			} 
		break;
		case 'online':
			showVidFooter('showcaseVidFooter');
			if (window.subPageStatus == '5') {
				hideVidFooter('publisher2VidFooter');
				hideVidFooters('liteVidFooter');
				hideVidFooters('freeTrialVidFooter');
				hideVidFooters('newsVidFooter');
			  	showVidFooter('webTvVidFooter');	
			  	showVidFooter('publisherVidFooter');
				
		  	} else if (window.subPageStatus == '4') {
				hideVidFooters('publisher2VidFooter');
				hideVidFooters('liteVidFooter');
			 	hideVidFooters('webTvVidFooter');
				hideVidFooters('freeTrialVidFooter');
				hideVidFooters('newsVidFooter');
				hideVidFooters('freeTrialVidFooter');
			  	hideVidFooters('publisherVidFooter');
		  	} else if (window.subPageStatus == '3') {
				hideVidFooters('publisher2VidFooter');
				hideVidFooters('liteVidFooter');
				hideVidFooters('publisherVidFooter');
				hideVidFooters('newsVidFooter');
				showVidFooter('freeTrialVidFooter');
			 	showVidFooter('webTvVidFooter');
		  	} else if (window.subPageStatus == '2') {
				hideVidFooters('webTvVidFooter');
				hideVidFooters('freeTrialVidFooter');
				hideVidFooters('newsVidFooter');
			  	hideVidFooters('publisherVidFooter');
				showVidFooter('publisher2VidFooter');
				showVidFooter('liteVidFooter');
		  	} else if (window.subPageStatus == '1') {
				hideVidFooters('publisher2VidFooter');
				hideVidFooters('liteVidFooter');
				hideVidFooters('webTvVidFooter');
				hideVidFooters('freeTrialVidFooter');
				hideVidFooters('newsVidFooter');
				showVidFooter('freeTrialVidFooter');
			 	showVidFooter('publisherVidFooter');
		  	} else if (window.subPageStatus == '0') {
				hideVidFooters('publisher2VidFooter');
				hideVidFooters('liteVidFooter');
				hideVidFooters('webTvVidFooter');
				hideVidFooters('publisherVidFooter');
				hideVidFooters('newsVidFooter');
			  	showVidFooter('freeTrialVidFooter');
		  	} 
		break;
		case 'showcase':
			showVidFooter('webTvVidFooter');
      		showVidFooter('publisherVidFooter');
			showVidFooter('briefingsVidFooter');
		break;
		case 'production':
			
		break;
		case 'vidBriefings':
			
		break;
		default:
			showVidFooter('freeTrialVidFooter');
	}	
}

function hideVidFooters(which) {
	document.getElementById(which).className = 'hidden';
}
function showVidFooter(which) {
   document.getElementById(which).className = 'shown';
}
function register() {
	hideVidFooters('webTvVidFooter');
	hideVidFooters('newsVidFooter');
	hideVidFooters('freeTrialVidFooter');
	hideVidFooters('publisherVidFooter');
	hideVidFooters('showcaseVidFooter');
   document.getElementById("freeTrialRegister").className = 'shown';
}
function registerDone() {
   showVidFooter('freeTrialVidFooter');
   document.getElementById("freeTrialRegister").className = 'hidden';
   showFooters();
}
function registerCancel() {
   showVidFooter('freeTrialVidFooter');
   document.getElementById("freeTrialRegister").className = 'hidden';
   showFooters();
}

