
//Title: 	Global Javascript Functions for QuebecScene.ca 
//Author:	jay.west
//Contact:	creative@jaywest.com
//Updated:	February 15, 2009 




// use jQuery to open external links in a new window


$(document).ready(function() {
						   
	// open external links in a new browser window
	$("a[href^='http']").attr('target','_blank');

	// open pdf links in a new browser window, add pdf icon
	$("a[href$='.pdf']").attr('target','_blank').attr('class','pdf');


});




// Sets the class of an input field to "fieldFocus" on focus or removes the className on blur.
// Will also clear the default field contents

function findField() {
  if (!document.getElementsByTagName) return false;
  var fieldList = document.getElementsByName("q");
  for ( var i=0; i < fieldList.length; i++) {
    fieldList[i].onfocus = function() {
      this.className ="fieldFocus";
	  this.value = "";
    }
	fieldList[i].onblur = function() {
      this.className ="";
    }
  }
}


// adds history.go function to cancel buttons

function cancelButton() {
  if (!document.getElementsByName) return false;
  var cancel = document.getElementsByName("cancel");
  for (var i=0; i < cancel.length; i++) {
    if (cancel[i].name.match("cancel")) {
      cancel[i].onclick = function() {
		window.history.go(-1)
        //window.open(this.href);
        return false;
      }
    }
  }
}






// Run the functions once the page has loaded: 

window.onload=function(){
	findField();
	cancelButton();
}
