
// Topnav image rollover pre-loads
if (document.images) {
	var tnRoll = new Array();
		tnRoll[0] = new Image();
    	tnRoll[0].src = "/assets/tn_la_tell_roll.gif";
		tnRoll[1] = new Image();
    	tnRoll[1].src = "/assets/tn_la_getcheck_roll.gif";
		tnRoll[2] = new Image();
    	tnRoll[2].src = "/assets/tn_la_stdinfo_roll.gif";
		tnRoll[3] = new Image();
    	tnRoll[3].src = "/assets/tn_la_resources_roll.gif";
		tnRoll[4] = new Image();
    	tnRoll[4].src = "/assets/tn_la_treatment_roll.gif";
		tnRoll[5] = new Image();
    	tnRoll[5].src = "/assets/tn_la_about_on.gif";
		tnRoll[6] = new Image();
    	tnRoll[6].src = "/assets/tn_la_contact_on.gif";
}





// NN4 resize
function reDo() { 
	if (window.innerWidth != winW || window.innerHeight != winH) window.location.reload();
}
if (document.layers) {
	var winW = window.innerWidth;
	var winH = window.innerHeight;
	window.onresize = reDo;
}



// Card preview
var newWindow;
function cardPreview(file,name,thelink) {
	if (!newWindow || newWindow.closed) {
		newWindow = window.open('','','width=500,height=475');
		if (!newWindow.opener) {
			newWindow.opener = window;
		}
		var winContent = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
		winContent += '<html><head><title>inSPOT FR &middot;&gt; CHOISISSEZ CETTE CARTE</title>';
		winContent += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
		winContent += '<link rel="stylesheet" href="/assets/primary.css" type="text/css"></head><body>';
		winContent += '<table width="500" cellpadding="0" cellspacing="0"><tr bgcolor="#000000">';
		winContent += '<td align="left" valign="middle" width="230">';
		winContent += '<div class="popupCloserLeft"><a href="#" onclick="window.close()" ';
		winContent += 'class="popupCloserLeftLink">Fermer la fen&eacute;tre</a></div></td>';
		winContent += '<td align="right" valign="middle" width="230">';
		winContent += '<div class="popupCloserRight" style="padding:10px 0px 10px 10px;">';
		winContent += '<a href="'+thelink+'" onClick="window.opener.location=\''+thelink+'\'; ';
		winContent += 'window.close();" class="popupCloserRightLink">CHOISISSEZ CETTE CARTE</a></div></td>';
		winContent += '<td align="right" valign="middle" width="40"><div class="popupCloserRight">';
		winContent += '<a href="'+thelink+'" onClick="window.opener.location=\''+thelink+'\'; ';
		winContent += 'window.close();" class="popupCloserRightLink">';
		winContent += '<img src="/assets/tell_la_card_arrow.gif" width="40" height="40" alt="CHOISISSEZ CETTE CARTE" border="0"></a></div></td>';
		winContent += '</tr>';
		winContent += '<tr><td align="center" valign="top" width="100%" colspan="3">';
		winContent += '<img src="'+file+'" width="500" height="400" alt="" border="0"></td></tr>';
		winContent += '</table></body></html>';
		newWindow.document.write(winContent);
		newWindow.document.close();
	} else {
		newWindow.focus();
	}
	newWindow.moveTo(0,0);
	return true;
}

// Map view
var newWindow;
function mapView(file,name,thelink) {
	if (!newWindow || newWindow.closed) {
		newWindow = window.open('','','scrollbars=1,resizable=1,width=1100,height=925');
		if (!newWindow.opener) {
			newWindow.opener = window;
		}
		var winContent = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
		winContent += '<html><head><title>inSPOT FR &middot;&gt; View Map</title>';
		winContent += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
		winContent += '<link rel="stylesheet" href="/assets/primary.css" type="text/css"></head><body>';
		winContent += '<table width="1056" cellpadding="0" cellspacing="0"><tr bgcolor="#000000">';
		
//		winContent += '<td align="left" valign="middle" width="230">';
//		winContent += '<div class="popupCloserLeft"> </div></td>';
		
//		winContent += '<td align="right" valign="middle" width="600">';
//		winContent += '<div class="popupCloserLeft"> </div></td>';
		
		winContent += '<td align="left" valign="middle" width="230">';
		winContent += '<div class="popupCloserRight" style="padding:10px 10px 10px 10px;"><a href="#" onclick="window.close()" ';
		winContent += 'class="popupCloserRightLink">Fermer la fen&eacute;tre</a></div></td>';
	//	winContent += '<td align="right" valign="middle" width="40"><div class="popupCloserRight">';
	//	winContent += '<a href="#" onclick="window.close()" ';
	//	winContent += 'class="popupCloserRightLink">';
	//	winContent += '<img src="/assets/tell_la_card_arrow.gif" width="40" height="40" alt="close this window" border="0"></a></div></td>';
	
	    winContent += '</tr>';
		winContent += '<tr><td align="center" valign="top" width="100%" colspan="3">';
		winContent += '<img src="'+file+'" width="1100" height="850" alt="" border="0"></td></tr>';
		winContent += '</table></body></html>';
		newWindow.document.write(winContent);
		newWindow.document.close();
	} else {
		newWindow.focus();
	}
	newWindow.moveTo(0,0);
	return true;
}





// Valid e-mail check
function isEmailAddr(email) {
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0) {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function isValidZip(zip) {
   var Char;
   var ValidNums = "0123456789";
   var ValidSecondNum = "0123";
   var theStr = new String(zip);

   if ( theStr.length != 5 ) {
     return false;
   }


   for (i = 0; i < 5; i++) 

   { 
       Char = theStr.charAt(i); 
       if (ValidNums.indexOf(Char) == -1) {
	     return false;
       }
   }
   
   return true;
}


// Form Validation
function FormValidator(theForm) {

if (theForm.theirEmail0.value == "" && theForm.theirEmail1.value == "" && theForm.theirEmail2.value == "" && theForm.theirEmail3.value == "" && theForm.theirEmail4.value == "" && theForm.theirEmail5.value == "") {
    alert("Veuillez inscrire d'au moins un recipiendaire.");
    return false;
}

if ((theForm.theirEmail0.value != "" && !isEmailAddr(theForm.theirEmail0.value)) || (theForm.theirEmail1.value != "" && !isEmailAddr(theForm.theirEmail1.value)) || (theForm.theirEmail2.value != "" && !isEmailAddr(theForm.theirEmail2.value)) || (theForm.theirEmail3.value != "" && !isEmailAddr(theForm.theirEmail3.value)) || (theForm.theirEmail4.value != "" && !isEmailAddr(theForm.theirEmail4.value)) || (theForm.theirEmail5.value != "" && !isEmailAddr(theForm.theirEmail5.value))) {
    alert("Veuillez inscrire votre adresse courrielle ou cochez \"envoyez de facon anonyme\" si vous preferez ne pas utiliser votre adresse courrielle");
    return false;
}
   
if (theForm.yourEmail.value != "" && !isEmailAddr(theForm.yourEmail.value)  && theForm.yourAnonymous.checked != true) {
    alert("Veuillez inscrire votre adresse courrielle ou cochez \"envoyez de facon anonyme\" si vous preferez ne pas utiliser votre adresse courrielle");
    return false;
}

if (!isValidZip(theForm.yourZipCode.value)) {
    alert("Please enter a valid, 5-digit zip code.");
    return false;
}
  
  return true;
}