/*
All JavaScripts copyright 2007 by Mad Goose Web Design unless otherwise noted.
*/

/********** Add Page to Bookmarks or Favorites **********
Cross-Browser Bookmark creater by Eddie Traversa (http://www.devpapers.com/article/156)
*/
function addBookmark(){
	var title = "Stock Bully";
	var url = "http://www.stockbully.com";
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}
	else if (document.all){ window.external.AddFavorite(url, title); }
	else if (window.opera && window.print){ return true; }
}


/********* popup function *********
Opens window if it is not already open. Brings it into focus if it is already open.
*/
objMyWindow = null;
function popup(strURL, strWinName, intWidth, intHeight){
	if (objMyWindow && !objMyWindow.closed){
		objMyWindow.focus();
	} else {
		objMyWindow = window.open(strURL, strWinName, 'location=0,status=0,scrollbars=1,left=25,top=25,width=' + intWidth + ',height=' + intHeight);
	}
}


/********* emailFieldText *********
Makes default text disappear when you click the field and reappear when you leave the field blank.
*/
function subscriberFieldText(){
	var elemEmail = document.forms['subscribe'].elements['subscriber'];
	if (elemEmail.value == 'email address'){
		elemEmail.value = '';
	} else if (elemEmail.value == ''){
		elemEmail.value = 'email address';
	}
}
			

/********* eventsToRegister *********
Events that need to wait for the DOM to load before being registered.
*/
function eventsToRegister(){
	var elemEmail = document.forms['subscribe'].elements['subscriber'];
	Event.observe(elemEmail, 'focus', subscriberFieldText);
	Event.observe(elemEmail, 'blur', subscriberFieldText);
}


/********* addValidationToForms *********
Adds validation routine to all forms on page.
*/
function addValidationToForms(){
	var valid = null;
	for (i = 0; i < document.forms.length; i++){
		if (document.forms[i].id == 'contact'){
			valid = new Validation('contact', {onFormValidate : preSubmit});
		} else {
			valid = new Validation(document.forms[i]);
		}
	}
}


/********* Functions to run once the DOM has loaded *********
These functions will run once the DOM has loaded instead of waiting for images to download first.
*/
FastInit.addOnLoad(eventsToRegister, addValidationToForms);
