// 06/28/2006, jstrimpe
// pulse (newsletter) JS

// calls browser's print diolog box on a PC 
// and sends an alert on a Mac
function printPage(){
	 if(window.print) 
	 {
				window.print();
	 }
	 else
	 {
			 if(agt.indexOf("mac") != -1)
			 {
				 alert("To print this page press Command-P.")
			 }
			 else 
			 {
				 alert("To print this page press Control-P.")
			 }
	 }
}  
// creates link to call mail.sfe as a pop-up.
// it grabs the title of the article by getting the text 
// in between the h3 tags where the id="title". it also grabs the
// page url. both these values are passed to mail.sfe via URL vars.
function EmailLink()
{
	var pageurl = new String(document.location);
	var pageurl = pageurl.replace(/#[a-z]/,"");
	var pageurl = encodeURIComponent(pageurl);
	var articletile = encodeURIComponent(document.getElementById('title').innerHTML);
	//pageurl = pageurl.replace(/#[a-z]/,"");
	//alert(pageurl);
	document.write('<a href="');
	document.write("javascript:newWin('");
	document.write('/pulse/mail.sfe?link=');
	document.write(pageurl);
	document.write('&article=');
	document.write(articletile);
	document.write("','','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resize=0,width=475,height=200')");
	document.write('" alt="Email Atricle">');
}
// This is used to write the file path and link for the pulse logo. The file path needs to be generated
// based upon the current URL because the search and the archive pages require that 
// the image path be absolute and the image path for all other pages needs to be relative.
function LogoURL(){
var pageurl = (new String(document.location));
var LogoPath = "";
if (pageurl.match("search.shtml")||pageurl.match("archive.shtml")||pageurl.match("subscribe.sfe")||pageurl.match("/origami/")){
		LogoPath = '<a href="/pulse/"><img src="/pulse/assets/images/pulse_quarter.gif" width="700" height="66" alt="Pulse" /></a>';
	}else{
		LogoPath = '<a href="."><img src="images/pulse_quarter.gif" width="700" height="66" alt="Pulse" /></a>';
	}								 
	document.write(LogoPath);
}

function newWin(URL,winName,features){
  window.open(URL,winName,features);
}

function validateSearch(myForm) {

  message = '';
  cnt = 0;
  var f_query=myForm.query.value;

   
  if (!f_query) {
    message += '\n  - You must enter a word or phrase.';
    cnt++;
  }


  if (cnt > 0) {
    message ="The following field(s) is/are either empty or incorrectly entered:\n" +
    message + "\n______________________________________________" +
    "\n            PLEASE RE-ENTER AND SUBMIT AGAIN!";
    alert(message);
    return false;
  } else {
    return true;
  }

}

function ValidateSubscription (myForm) {
	
  message = '';
  cnt = 0;
	
  // function defined /assets/scripts/CrossSite.js 
	// file called by /assets/scripts/loader.js
	CrossSite();	
	
	var f_subscribe="";	
	var f_fname=myForm.fname.value;
	var f_lname=myForm.lname.value;
	var f_address=myForm.address.value;
	var f_city=myForm.city.value;
	var f_zip=myForm.zip.value;
		
	mySubscribe = -1;
	for (i=0; i<myForm.subscribe.length; i++) {
		if (myForm.subscribe[i].checked) {
		mySubscribe = i;
		f_subscribe=myForm.subscribe[i].value;
		}
	 }	
	 
	if (mySubscribe == -1) {
		 message += '\n  - Subscribe/Unsubscribe';
		cnt++;
	}	 

  if (!f_fname) {
    message += '\n  - First Name';
    cnt++;
  }
	
  if (!f_lname) {
    message += '\n  - Last Name';
    cnt++;
  }
	
	if(f_subscribe=="Y"){
		
		if (!f_address) {
			message += '\n  - Address';
			cnt++;
		}		
		
		if (!f_city) {
			message += '\n  - City';
			cnt++;
		}	
		
		if (!f_zip) {
			message += '\n  - Zip Code';
			cnt++;
		} else if (!isZip.test(f_zip)) {
			message += '\n  -Zip Code';
			cnt++;
		}
									
		
	}


  if (cnt > 0) {
    message ="The following field(s) is/are either empty or incorrectly entered:\n" +
    message + "\n______________________________________________" +
    "\n            PLEASE RE-ENTER AND SUBMIT AGAIN!";
    alert(message);
    return false;
  } else {
    return true;
  }

	
	
}