/**************************** IMAGE ROLLOVERS ****************************/
curId = "";
function onNavOver(id) {
	if(this.timer) {
		clearTimeout(this.timer);
		doHide("sub_"+curId, curId);
	}	
	document.getElementById(id).getElementsByTagName("IMG")[0].src = "images/" + id + "_f2.gif";	
	if(document.getElementById("sub_"+id)) document.getElementById("sub_"+id).style.display = "block";	
	this.curId = id;
}
function onNavOut(id) {
	if(id != "sub_"+curId && document.getElementById("sub_"+id))
		this.timer = setTimeout("doHide('sub_"+id+"', '"+id+"')",300);
	if(!document.getElementById("sub_"+id)) 
		document.getElementById(id).getElementsByTagName("IMG")[0].src = "images/" + id + ".gif";
}
function onSubNavOver(id, parent_id) {
	if(this.timer) clearTimeout(this.timer);
	document.getElementById(parent_id).getElementsByTagName("IMG")[0].src = "images/" + parent_id + "_f2.gif";
	if(document.getElementById(id).style.display) document.getElementById(id).style.display='block';
	this.curId = parent_id;
}
function onSubNavOut(id, parent_id) {
	this.curId = parent_id;
	this.timer = setTimeout("doHide('"+id+"', '"+parent_id+"')",300);
}
function doHide(id, parent_id) {
	document.getElementById(parent_id).getElementsByTagName("IMG")[0].src = "images/" + parent_id + ".gif";
	if(document.getElementById(id)) document.getElementById(id).style.display = "none";
}

function showId(id) {
	document.getElementById(id).style.display = "";
}

function hideId(id) {
	document.getElementById(id).style.display = "none";
}

// custom for icons
var oldIconId = "";
function onIconInfoOver() {
	if(this.timer) clearTimeout(this.timer);
}
function onCloseIconInfo(id) {
	// hide info image
	hideId("info-"+oldIconId);
	// hide icon color and title	
	//if(f3) var id = id + f3;	
	onSubNavOut("sub_"+oldIconId, oldIconId);
	oldIconId = "";
	//  hide title so it doesn't show through on safari	
	document.getElementById('content-title').style.display = "";
}
function onShowIconInfo(id, f3) {
	// hide all id's
	if(oldIconId != "") onCloseIconInfo(oldIconId);
	// show current id
	showId('info-'+id);
	oldIconId = id;
	//  hide title so it doesn't show through on safari	
	document.getElementById('content-title').style.display = "none";
}

/**************************** BLUR ALL SITE ANCHORS ****************************/
function blurAnchors(){
	if(document.getElementsByTagName){
		var a = document.getElementsByTagName("a");
		for(var i = 0; i < a.length; i++){
		  	a[i].onfocus = function(){this.blur()};
		}
	}
}
window.onload = blurAnchors;

function submitForm(formName) {
	document.forms[formName].submit();
}

function onSearchSubmit(txt) {
	document.forms.searchBar.search_str.value = txt;
	document.forms.searchBar.submit();
}

function onNewsletterSubmit(txt) {
	document.forms.newsletterSignup.email.value = txt;
	document.forms.newsletterSignup.submit();
}
function submitPostcard(formName) {
	if(checkRequired('form_postcard', 'to_name,recipient,name,email', 'Recipients Name,Recipients Email,Your Name,Your Email')) 
		submitForm(formName);
}

function checkRequired(formName, required, names) {
	var requiredAry = required.split(",");
	var namesAry = names.split(",");
	var msg = "";
	for(var i = 0; i < requiredAry.length; i++) {
		if (document[formName][requiredAry[i]].value=="") {
			msg += "- " + namesAry[i] + "\n";
		}
	}
	if(msg != "") {
		var msg = "You are required to complete the following fields: \n" + msg;
		alert(msg);
		return false;
	}else
		return true;
}

/**************************** POPUP FOR GIFTCERTIFICATE EXAMPLE ****************************/
function winOpen(theURL, Name, popW, popH, scroller, resize){ // V 1.0
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroller+',resizable='+resize+"'";
	var Win = window.open(theURL, Name, winProp);
	if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
}

function viewGiftCertificate(url) {
	winOpen(url, "giftCertPopup", "625", "446", "no", "no");
}

function viewGiftWrap(url) {
	winOpen(url, "giftWrapPopup", "421", "421", "no", "no");
}

function viewPostcard(url) {
	winOpen(url, "postcardPopup", "594", "431", "no", "no");
}

function viewTerms(url) {
	winOpen(url, "termsPopup", "650", "446", "yes", "no");
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	InsertElement.js - implements IE's insertAdjacentHTML and insertAdjacentText to DOM-based browsers
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	(c) Copyright Thor Larholm (thor@jscript.dk)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
if ( typeof(HTMLElement) != "undefined" ) {
	if ( !(HTMLElement.prototype.insertAdjacentElement) ) {
		HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode) {
			switch (where) {
				case "beforeBegin":
					this.parentNode.insertBefore(parsedNode,this);
					break;
				case "afterBegin":
					this.insertBefore(parsedNode,this.firstChild);
					break;
				case "beforeEnd":
					this.appendChild(parsedNode);
					break;
				case "afterEnd":
					if (this.nextSibling) {
						this.parentNode.insertBefore(parsedNode, this.nextSibling);
					} else {
						this.parentNode.appendChild(parsedNode);
					}
					break;
			}
		};
		HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr) {
			var r = this.ownerDocument.createRange();
			r.setStartBefore(this);
			var parsedHTML = r.createContextualFragment(htmlStr);
			this.insertAdjacentElement(where,parsedHTML);
		};
		HTMLElement.prototype.insertAdjacentText = function(where,txtStr) {
			var parsedText = document.createTextNode(txtStr);
			this.insertAdjacentElement(where,parsedText);
		};
	}
}

