// JS functions common to all screens

// give keyboard focus to first text element in first form on page
function giveFocusToFirstText() {
   if (!document.forms[0]) {
      return;
   }
   for (var i = 0; i < document.forms[0].length; i++) {
      if (document.forms[0].elements[i].type == "text") {
            document.forms[0].elements[i].focus();
         break;
      }
   }
}

function popWindow(handler) {
   var info_window = window.open(handler, "popWindow", "width=500,height=400,toolbar=no,resizable=yes,scrollbars=yes");
   info_window.focus();
}

function myPopWindow(handler, width, height, name) {
   var info_window = window.open(handler, name, "width=" + width + ",height=" + height +
		 ",toolbar=yes,resizable=yes,scrollbars=yes");
			info_window.focus();
}

function myPopWindow2(handler, width, height, name) {
   var info_window = window.open(handler, name, "width=" + width + ",height=" + height +
      ",toolbar=no,resizable=yes,scrollbars=yes,left=20,screenX=20,top=20,screenY=20");
   info_window.focus();
}

function validEmail(elem)
{
   if (/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z0-9-]+)$/.test(elem.value))
   {
      return true;
   }
   return false;
}

function validEmail0(elem) 
{
   if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(elem.value))
   {
      return true;
   }
   return false;
}

function stripSpaces(x) 
{
   x = ""+x;
   while (x.substring(0,1) == ' ') 
   {   
      x = x.substring(1);
   }
   return x;
}

function empty(x) 
{
   if (x.length > 0) 
   {   return false;   }
   else 
   {   return true;    }

}

function myVoid()
{}
ns4 = (document.layers) ? true : false
ie4 = (document.all)? true:false

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 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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}


function isNN4() {
	if (navigator.appname == "Netscape" && parseFloat(navigator.appVersion) < 5) {
		return true;
	} else {
		return false;
	}
}

function goToTop() {
	window.scrollTo(1,1);
}

// Original:  Mike Canonigo (mike@canonigo.com) 
// Web Site:  http://www.munkeehead.com 
// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 

// Original slideshow code from above. Enhanced by Damian to allow 
// multiple slideshows.
function chgImg(num, direction) {
	if (document.images) {
		self["ImgNum" + num] = eval("ImgNum" + num) + direction;
		
		if (eval("ImgNum" + num) > eval("ImgLength" + num)) {
			self['ImgNum' + num] = 0;
		}
		if (eval("ImgNum" + num) < 0) {
			self['ImgNum' + num] = eval("ImgLength" + num);
		}
		var tmp = eval("ImgNum" + num);
		document.images["slideshow" + num].src = eval("NewImg" + num + "[tmp]");
   }
}
function showRaisedSamples() {
	myPopWindow2('/common/images/raised.gif', 454, 454, 'Samples');
}

function showMatteSamples() {
	myPopWindow2('/common/images/matte.gif', 364, 444, 'Samples');
}

function showPaper4Samples() {
	myPopWindow2('/common/images/paperColor4.jpg', 334, 344, 'Samples');
}

function showPaper2Samples() {
	myPopWindow2('/common/images/paperColor2.jpg', 344, 204, 'Samples');
}

function showNapkinSamples() {
	myPopWindow2('/common/images/napkinColors.jpg', 364, 344, 'Samples');
}

function showMonogramSamples() {
	myPopWindow2('/common/images/monogram_letters.gif', 344, 574, 'Samples');
}

function showSealSamples() {
	myPopWindow2('/common/images/singleSeal.gif', 414, 394, 'Samples');
}

function showInitialSamples() {
	myPopWindow2('/common/images/singleInitial.gif', 354, 464, 'Samples');
}
