function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function detect_flash(){
	var flashinstalled = 0;
	var flashversion = 0;
	MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length){
		x = navigator.plugins["Shockwave Flash"];
		if (x){
			flashinstalled = 2;
			if (x.description){
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
		else
			flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"]){
			flashinstalled = 2;
			flashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length){
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin){
			flashinstalled = 2;
		}else{
			flashinstalled = 1;
		}
	}else{
		MSDetect = "true";
	}

	return MSDetect;
}


function changeDemo(sPath){
  sFileName = document.demo.demoname.options[document.demo.demoname.selectedIndex].value; 
  sFile    =  sPath + sFileName;
  document.getElementById("demolayer").innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0' width='383' height='242' id='demo1' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='" + sFile + "' /><param name='menu' value='false' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='" + sFile + "' menu='false' quality='high' bgcolor='#ffffff' width='383' height='242' name='demo1' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";

}

<!--
function MM_findObj(n, d) { //v3.0
  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); 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 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 loadSearch(){
  //document.search.keyword.value="Search PEIsland.com";
}
function clearSearch(){
 //if(document.search.keyword.value=="Search PEIsland.com"){
 // document.search.keyword.value="";
// }
}
//-->

function validateContactForm(){
  if(!valid_email(document.mail.sEmail.value)){
	window.alert("The e-mail you entered seems to be invalid.\nPlease correct the e-mail address field and resubmit the form.");
    return false;
  }
  if(document.mail.sName.value==""){
	window.alert("You have left the name field blank!\nPlease correct the name field and resubmit the form.");
    return false;
  }  if(document.mail.sPhone.value==""){
	window.alert("You have left the phone number field blank!\nPlease correct the phone number field and resubmit the form.");
    return false;
  }
  if(document.mail.sSubject.value==""){
	window.alert("You have left the subject field blank!\nPlease correct the subject field and resubmit the form.");
    return false;
  }  
  if (document.mail.sMessage.value == ""){
	window.alert("You have left the message field blank!\nPlease enter a message and resubmit the form.");
    return false;
  }else{
    return true;
  }
}

function valid_email(strTest) {
  var mask = new RegExp("^[^\*|,\\\":<>\\[\\]{}`';()&%@ ]+@[^\*|,\\\":<>\\[\\]{}`';()&%@ ]+[^\*|,.\\\":<>\\[\\]{}`';()&%@ ]+$", "g");
  strTest = Trim(strTest);
  return mask.test(strTest);
}

function LTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
      j++;
    }
    s = s.substring(j, i);
  }
  return s;
}

function RTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1; 
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
      i--;
    }
    s = s.substring(0, i+1);
  }
  return s;
}

function Trim(str) {
  return RTrim(LTrim(str));
}

function openAWindow( pageToLoad, winName, width, height, center, sb) {
/* Opens a new window on the users desktop.   Arguments:
    pageToLoad - The URL of a page to load in the browser window.
                 This can be a relative URL or fully qualified.
    winName -    Name of the new window.
    width -    The horizontal size of the new window.
    height -    The vertical size of the new window.
    center -     toggle centering on 4.0 browsers.
                  1=centered window 0=no centering
    Values in the "args" section below can all be toggled in the
    same fashion as the center toggle.  Just modify the appropriate
    value in the args section to be either 0 or 1.
    A call to this function might look like this:
    <a href="javascript:openAWindow('ice.html','ice',375,250,1)">Ice</a>
   If you use this routine please leave all comments in place so that
   others may benefit as well.*/

    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;    
	}
    var args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=0," + "scrollbars=0, " + "status=0," + "titlebar=1," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
	+ "status=no" + ","     //IE Only
    + "top=" + yposition;           //IE Only
    window.open( pageToLoad,winName,args );
}
function openBrowser(theURL, winName, width, height) { 
  var features, top, left;
  top = (screen.availHeight - height) / 3;
  left = (screen.availWidth - width) / 2;
  if ((navigator.appName.indexOf('Netscape') != -1) && (navigator.appVersion.substr(0, 3) < '5.0')) {
    height = parseInt(height) + 15;
  }
  features = 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',screenY=' + top + ',screenX=' + left + ',location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no';
  var newWindow = window.open(theURL, winName, features);
  newWindow.focus();
}