function lengthValidator(theField,minLength,maxLength,eXact) {
				if (eXact == 1) {
	        if (theField.length == maxLength) {
	        		return true;
	            
	            } else {
	            	return false;
	        }
        } else {
        	if ((theField.length >= minLength) && (theField.length <= maxLength)) {
        			return true;
            
            } else {
            		return false;
        	}
        }
    }

var popup=null;

function viewer(image_front, image_back, name) {
		 window.open( "viewer.php?"+image_front, "",  
     "resizable=1,scrollbars=yes,HEIGHT=200,WIDTH=200");
   } 

function outviewer(image_front, image_back, name)
{

	var width = 600;
	var height = 400;
	var poswx = 10;
	var poswy = 10;
	
	if (!popup || popup.closed)
	{	
		popup=window.open("","popup","width=" + width + ",height=" + height + ",status=no,hotkeys=no,menubar=no,toolbar=no,resizable=no,scrollbars=yes,top=" + poswy + ",left=" + poswx + ",dependent=yes,alwaysRaised=yes");
		
		setTimeout('writeToWindow(\'' + image_front + '\',\'' + image_back + '\',\'' + name + '\')', 50);
		popup.focus();
	}
	else if(popup.focus)
	{
		popup.focus();
	}
}

function writeToWindow(image_front, image_back, name)
{	
	popup.document.write("<html><head><title>" + name + "</title><meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'>\n");
	popup.document.write("<script\>\nif (document.images)\n{\nvar imageOn = 'front';\nvar imagesNormal = new Object();\nimagesNormal['front'] = new Image();\nimagesNormal['front'].src = '" + escape(image_front) + "';\nimagesNormal['back'] = new Image();\nimagesNormal['back'].src  = '" + escape(image_back) + "';\n}\n function setImage(imgName)\n{\n if (document.images)\n{ \nif (imageOn == 'back')\n { \n document.images[imgName].src = imagesNormal['front'].src;\ndocument.getElementById('viewBtn').value = 'View Backside';\nimageOn = 'front';return true;\n}\nelse if (imageOn == 'front')\n{\ndocument.images[imgName].src =imagesNormal['back'].src;\ndocument.getElementById('viewBtn').value = 'View Frontside';\nimageOn = 'back';return true;\n}\n}\nreturn false;}\nfunction checkImage()\n{\nif(imagesNormal['front'].complete)\n{\n document.getElementById('loadingImg').style.visibility = 'hidden';\n document.getElementById('mainImg').style.visibility = 'visible';\n }\nif(imagesNormal['back'].src.indexOf('jpg') == -1)\ndocument.getElementById('viewBtn').style.display = 'none';\n}\n");
	popup.document.write('function resizeWinTo() {\n'+
    'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
    'var oH = document.images[0].height + 65, oW = document.images[0].width + 20;\n'+
    'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
    'window.doneAlready = true;\n'+ //for Safari and Opera
    'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
    'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
    'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
    'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
    'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
    'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
    'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
    'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
    'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
    'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
    '}\n</script\>\n');
	popup.document.write("\n</head>\n<body marginwidth='0' marginheight='0' topmargin='0' leftmargin='0' onLoad='resizeWinTo(); checkImage();' onblur='window.focus();'>\n");
	popup.document.write("\n<div id='loadingImg' align='center' style='visibility:visible;'>Please wait while loading images...</div><div id='mainImg' align='center' style='visibility:hidden;'><img onLoad='resizeWinTo();' name='product' src='" + escape(image_front) + "' border='0' /></div>\n");
	popup.document.write('\n<p align="center"><input id="viewBtn" name="viewBtn" onclick="return setImage(\'product\');" value="View Backside" type="button" />&nbsp;&nbsp;&nbsp;<input type="button" onclick="self.close();" value="Close Window"></p>\n</body>\n</html>');
	popup.document.close();
}

function ctFormValidator(theForm)
{

	if (theForm.login.value == "")
  {
    alert("Please enter a username.");
    theForm.login.focus();
    return (false);
  }

  if (lengthValidator(theForm.login.value,4,8,0) == false) {
		alert("Please enter a username between 4 and 8 characters long.");
    theForm.login.focus();
    return (false);
  }

	if (theForm.pin1.value == "")
  {
    alert("Please enter a password.");
    theForm.pin1.focus();
    return (false);
  }

  if (lengthValidator(theForm.pin1.value,4,8,0) == false) {
		alert("Please enter a password between 4 and 8 characters long.");
    theForm.pin1.focus();
    return (false);
  }

  if (theForm.pin1.value != theForm.pin2.value)
  {
    alert("Please ensure that you've entered the same password twice.");
    theForm.pin1.focus();
    return (false);
  }

	if (theForm.email.value == "")
  {
    alert("Please enter your email address.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.fname.value == "")
  {
    alert("Please enter your first name.");
    theForm.fname.focus();
    return (false);
  }

  if (theForm.lname.value == "")
  {
    alert("Please enter your last name.");
    theForm.lname.focus();
    return (false);
  }

  if (theForm.address.value == "")
  {
    alert("Please enter your address.");
    theForm.address.focus();
    return (false);
  }

  if (theForm.city.value == "")
  {
    alert("Please enter your city.");
    theForm.city.focus();
    return (false);
  }

  if (theForm.state.value == "")
  {
    alert("Please select your state.");
    theForm.state.focus();
    return (false);
  }

  if (theForm.zip.value == "")
  {
    alert("Please enter your zip code.");
    theForm.zip.focus();
    return (false);
  }

  if (theForm.parea.value == "")
  {
    alert("Please enter your phone number area code.");
    theForm.parea.focus();
    return (false);
  }

	if (theForm.pprefix.value == "")
  {
    alert("Please enter your phone number prefix.");
    theForm.pprefix.focus();
    return (false);
  }

  if (theForm.psuffix.value == "")
  {
    alert("Please enter your phone number suffix.");
    theForm.psuffix.focus();
    return (false);
  }

  if (theForm.agreement.checked == false) {
  	alert("You must first agree to our Terms of Service and Acceptable Use policies before you can register with AdvecorLeads.");
    theForm.agreement.focus();
    return (false);
  }

  theForm.submit();
}

function autoTab(theField,theForm) {
		if(theField.value.length == theField.getAttribute("maxlength")) {
						var elementArray = document.getElementsByTagName('input');
            for(i = 0; i < elementArray.length; i++) {
            	var element = elementArray[i];
            	if (element.getAttribute("tabindex") == (theField.tabIndex + 1)) {
            		var selElement = element;
            	}
            }
           selElement.focus();
        }
}

function satellite(srcFile,winWidth,winHeight,scrollInt) {
	window.open(srcFile,null,'height='+winHeight+',width='+winWidth+',status=no,toolbar=no,menubar=no,location=no,top=0,left=0,scrollbars='+scrollInt+'');
}
