//common.js for deluxe.com

// Omniture unique links 
//onclick="javascript:return navUniqueLink(this.href,'ftr_prvcy-terms','MSTRT')"
function navUniqueLink(urlTarget, locid, channel, popupAttribs){
 if (channel == undefined) {
	channel="DLX:";
 } else {
	channel = channel + ":";
 }
 if (urlTarget.indexOf("?") > 0) {
	urlTarget = urlTarget + "&locid=" + channel + locid;
 } else {
	urlTarget = urlTarget + "?locid=" + channel + locid;
 }
 if( popupAttribs == undefined ){
  parent.location = urlTarget;
 } else if( popupAttribs.length == 0) {
  parent.location = urlTarget;
 } else {
  window.open(urlTarget, "_blank", popupAttribs);
 }
 return false
}    

// Omniture custom links
//onclick="var s=s_gi(s_account);s.tl(this, 'o', 'Logo A Download');"
//onclick="javascript:navCustomLink(this,'ftr_2_partnerup','MSTRT')"
function navCustomLink(referrer, linkName, channel, linkType) {
	var ltype = "o";
	if (channel == undefined) {
		channel = "DLX:";
	} else {
		channel = channel + ":";
	}
	linkName = channel + linkName;
	if (linkType != undefined && linkType.length > 0) {
		ltype = linkType;
	}
	var s=s_gi(s_account);s.tl(referrer, ltype, linkName);
//	alert(linkName);
}

// Omniture tracking code for form fields
// onfocus="javascript:trackFieldFocusEvent(this, 'form name')"
function trackFieldFocusEvent(referrer, formName) {
	var s=s_gi(s_account);
	s.events=s.events||'';
	if(s.events.indexOf('event41')==-1){
		s.linkTrackVars='events'
		s.linkTrackEvents='event41';
		s.events='event41';
		formName += ": Initiate";
		s.tl(referrer,'o',formName);
	}
}

// class manipulation

function setClassname(id, classname){ document.getElementById(id).className = classname; }
function getClassname(id){ return document.getElementById(id).className; }
function replaceClassname(id, find, replace){ setClassname(id, getClassname(id).replace(new RegExp(find), replace)); }

// show hide drop down menus

var old_menu = null, hide = null;
function hide_menu(id){
	if(id == null) return;
	obj = document.getElementById('dropnav-' + id);
	navobj = 'nav-' + id;
	if(obj) obj.style.visibility = 'hidden';
    if(navobj) replaceClassname(navobj, 'nav_mouseon', 'nav_mouseoff');
	clear_timeout();
}

function show_menu(id){
	if(old_menu) hide_menu(old_menu);
	obj = document.getElementById('dropnav-' + id);
	navobj = 'nav-' + id;
	if(obj){
		obj.style.visibility = 'visible';
	    obj.className = 'menu_navigation';
	}
	if(navobj){
	    replaceClassname(navobj, 'nav_mouseoff', 'nav_mouseon');
	}
	old_menu = id;
	clear_timeout();
}

function set_timeout(){
	hide = setTimeout("hide_menu('" + old_menu + "')",700);
}

function clear_timeout(){
	clearTimeout(hide);
}

// popup window

var forcedRefresh = true;
var alreadyopen = new Array();
var newwin = new Array();

function openCenteredWindow(theURL, winName, features, w, h){
  var winl = parseInt((screen.width - w - 10) / 2);
  var wint = parseInt((screen.height - h - 29) / 2);
  var retval = openWindow(theURL, winName, features + ',height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl);
  if(!theURL) return retval;
}

function openWindow(theURL, winName, features){
  if(forcedRefresh == false && alreadyopen[winName] && !newwin[winName].closed){
    newwin[winName].focus();
  }
  else{
    alreadyopen[winName] = 1;	
    newwin[winName] = window.open(theURL, winName, features);
    newwin[winName].focus();
  }
  if(!theURL) return newwin[winName];
}


