var ua = navigator.userAgent.toLowerCase();	
var an = navigator.appName.toLowerCase();	
var MAC = ua.indexOf("mac") != -1; 
var MSIE = ua.indexOf("msie")>-1;		
var NTSC = an.indexOf("netscape")>-1;	
var N6 = ua.indexOf('netscape6')>-1;	
var N4 = navigator.userAgent.substring(7+navigator.userAgent.indexOf("ozilla"),8+navigator.userAgent.indexOf("ozilla"))<="4" && NTSC;	
var MACN6 = N6 && MAC;		
var MACN4 = N4 && MAC;		
var loc1 = document.URL;

if (loc1.indexOf("Print_1")!=-1 || loc1.indexOf("Print=1")!=-1) {
  document.writeln("<link rel=stylesheet href='/styleieprt.css'>");
} else {
  document.writeln("<link rel=stylesheet href='/styleie.css'>");
}

/* for print command */
var whichBrowser = navigator.appName;
whichBrowser = whichBrowser.toLowerCase();
var whichPlatform = navigator.userAgent;
whichPlatform = whichPlatform.toLowerCase();

function alertPrint() {
  if (whichPlatform.indexOf("mac") != -1){
	alert("Your browser does not support automatic printing. Please press command + P on your keyboard to print.");
	return true;
  } else {
	alert("Your browser does not support automatic printing. Please press control + P on your keyboard to print.");
	return true;
  }
}

var isNSMac;
if ((whichPlatform.indexOf("mac") != -1) && (whichBrowser == "netscape") && (parseInt(navigator.appVersion) < 6)) isNSMac = true;

function printPage(){
  if (isNSMac){
	alertPrint();
  } else {
	window.print();
	//setTimeout("goToURL();", 3000);
  }
}

function Publish(s)
{
 return s;
}

function connector() {
  var s = document.URL;
  if (s.indexOf(".exe") == -1) {
    return ".htm?";
  } else {
    return "";
  }
}

function _v_test_sub(condition,fld,msg) {
  if (condition) return (true);
  if (fld != null) fld.focus();
  alert(msg);
  return (false);
}

function _v_retest_sub(re,fld,msg,required) {
  if (!required && /^\s*$/.test(fld.value)) return (true);
  if (required && /^\s*$/.test(fld.value)) return (_v_test_sub(false,fld,msg));
  return (_v_test_sub(re.test(fld.value),fld,msg));
}

function v_isnotempty(fld,msg) { return (_v_test_sub(/\S/.test(fld.value),fld,msg)); }
function v_isselected(fld,msg) { return (_v_test_sub(fld.selectedIndex != 0,fld,msg)); }

function v_isemailaddress(fld,msg,required) {
  var valid = "[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]";
  return (_v_retest_sub(new RegExp("^" + valid + "+(\\." + valid + "+)*@" + valid + "+(\\." + valid + "+)+$"),fld,msg,required));
}

function v_radiochecked(fld,msg) {
  var i;
  for (i = 0; i < fld.length; i++)
    if (fld[i].checked)
      return (true);
  return (_v_test_sub(false,fld[0],msg));
}

function openSubscrWin(mail,type) {
 with (document.sform) {
  if (!v_isemailaddress(email, "Please enter valid e-mail address.",true )) return false;
 }

  var dyn_url = "/ma/maStore/cgi-bin/ma_onlinestorecatalog.exe?VM_CGI_RULE=Display&VM_CGI_OBJECT=StaticLinksPageSt&mac=AtRiskAlert.mac&email=" + mail + "&type=" + type + "&";
  //var w = window.open(dyn_url, 'SubscribeWindow', 'resizable=no,status=no,location=no,toolbar=no,scrollbars=no,directories=no,menubar=no,height=500,width=500,height=500');
  //w.focus();
  popWindowNoScroll(dyn_url,'SubscribeWindow','500','500');
  return(false);
}
function clearVal() {
  if (document.sform.email.value=="enter e-mail"){
    document.sform.email.value = "";
  }
}


function checkCookie(exec)
{
  var gc = getCookie("VM_MS_ADMIN_USERID");
//  alert("getcookie = "+gc);
  if(!gc) {
   //redirect to 403
	window.location = exec + "?VM_CGI_RULE=Display&VM_CGI_OBJECT=StaticLinksPageSt&mac=NotLoggedIn.mac"
  }
}

// this function to retrieves a cookie.
	function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
  	  if (dc.length > 0) {              
  	  begin = dc.indexOf(cname);       
  	      if (begin != -1) {           
  	      begin += cname.length;       
   		     end = dc.indexOf(";", begin);
   	         if (end == -1) end = dc.length;
  	          return unescape(dc.substring(begin, end));
  	      } 
  	  }
	return null;
	}

        // this function saves a cookie
	function setCookie(name, value) {
		cookieString = name + "=" + escape(value); 
		cookieString = cookieString + "; path=/";
		document.cookie = cookieString;
		}

function TextScroller() {
  var mainMessage=theMessage;
  var tempLoc=(scrollingRegion*3/mainMessage.length)+1;
  if (tempLoc<1) {tempLoc=1}
  var counter;
  for(counter=0;counter<=tempLoc;counter++)
  mainMessage+=mainMessage;
  document.mainForm.TextScroller.value=mainMessage.substring(startPosition,startPosition+scrollingRegion);
  startPosition++;
  if(startPosition>scrollingRegion) startPosition=0;
  setTimeout("TextScroller()",speed); 
}

oHTMLWin = null;

function centerWindow(url, name, w, h, scroll, menu, resizable)
{
	if (window.screen)
	{
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		
		winprops = 'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + ',scrollbars=' + scroll + ',menubar=' + menu + ',resizable=' + resizable;
		
		oHTMLWin = window.open(url, name, winprops);
		oHTMLWin.window.focus();
	}
}

function popWindow(url,title,width,height){
		centerWindow(url, title, width, height, "yes", "no", "no");
}

function popWindowNoScroll(url,title,width,height){
		centerWindow(url, title, width, height, "no", "no", "no");
}

function popupCartoonWin2(pid) { 
  popWindow('/ma/mastore/cgi-bin/ma_onlinestorecatalog.exe?VM_CGI_RULE=Display&VM_CGI_OBJECT=StaticLinksPageSt&mac=CartoonPID.mac&Product_ID=' + pid,'CartoonWindow','519','500');
}

function popupContactWin() {
popWindowNoScroll('/st/Contact.htm','ContactUsWindow','500','580'); 
}