var scj = {
	clickElement: function(elementId) {
		var id = elementId;
		//alert(typeof id);
		//$(id).fireEvent('click');
		/*if (navigator.userAgent.indexOf('Firefox') != -1 && navigator.appVersion.indexOf('Mac') != -1)
			$(id).fireEvent('clickOV', $(id), 0);  //without the two parameters it triggers a C is undefined error in 
		else */
			$(id).fireEvent('click');
	},
	parseHashInURL: function()
	{
		var hashvalue = location.hash;
		return hashvalue;
	},
	closeEffectDiv: function() {
		$('media_close').fireEvent('click');
	},
	getQueryString: function(parameter)	{
		var queryString = window.location.search.substring(1);
		var sections = queryString.split("&");
		var store = new Array();
		for (var i = 0; i < sections.length; i++)
		{
			var pieces = sections[i].split("=");
			if (pieces.length > 1)
			{
				store[pieces[0]] = pieces[1];
			} else {
				store[pieces[0]] = null;
			}
		}
		if (parameter == null)
		{
			return store;
		}
		if (typeof store[parameter] != undefined)
		{
			return store[parameter];
		}
		return null;
	}
};

scj.omniture = {
	cleartracking: function() {
		s = s_gi(s_account);
	    s.events='';
    	s.products='';
    	s.pageName='';
	    s.linkTrackVars = '';
	    s.linkTrackEvents = '';
	    for (i=1; i<51; i++) {
		    s['prop' + i.toString()] = '';
		    s['eVar' + i.toString()] = '';
	    }    	    
	    return true;
	},
	track: function(obj) {
		scj.omniture.cleartracking();
		var obj = obj ? obj : {};
		for (key in obj) {
			s[key] = obj[key];
			
		}
		var s_code=s.t();if(s_code)document.write(s_code);
		return true;
	},
	trackLink: function(obj) {
		//obj.linkType = o|d|e;
		scj.omniture.cleartracking();
		for (key in obj) {
			s[key] = obj[key];
	        s.linkTrackVars += key + ',';
	    }
		if (obj.events) s.linkTrackEvents = obj.events;
		s.tl(this, obj.linkType, obj.linkName);
 	}
};

//popup functionality
window.onerror=null;
var win = null;
function PopWindow(mypage,myname) {
	//closePopWin();
	winprops = 'height=500,width=820,top=30,left=0,scrollbars=1,resizable=1,status=1';
	win = window.open(mypage, myname, winprops);
	}
function SizedPopWindow(mypage,myname,w,h) {
	//closePopWin();
	winprops = 'height='+h+',width='+w+',top=30,left=0,scrollbars=1,resizable=1,status=1';
	win = window.open(mypage, myname, winprops);
	}
function closePopWin() {
	if(win != null) { 
		if(!win.closed) { 
			win.close();
			win = null; 
			} else {
			win = null;
			}
		}	
	}
function writeObj(obj) {
trimString(obj);
document.write(obj);
}
function trimString (str) {
  var pattern = /\s+/g;
  return str.replace(pattern,'');
}


function trackPrint(t){
	var trackString = "28~ziploc~5~"+t+"_print~53~"+t+"_print";
	var domain = location.host;
	domain = domain.toLowerCase();
	var currentRSID = null;
	if (domain.indexOf("qa.") == -1 && domain.indexOf("staging.") == -1 && domain.indexOf("localhost") == -1 && domain.indexOf("-dev") == -1)
		currentRSID = "prod";
	else 
		currentRSID = "dev";
	var s_account="scjziploc" + currentRSID;
	var s=s_gi(s_account);
	var obj = {};
	obj.pageName="Ziploc_Recipes_" + t + "_Print";
	obj.prop8= t + " Print";
	obj.events="event10";
	obj.eVar5="print recipe - ziploc";
	obj.channel="Recipes";
	scj.omniture.track(obj);
	
	if(window.hs_chgState){window.hs_chgState(trackString,1)};
}

function openNewWindow(URLtoOpen, windowName, windowFeatures)
{
	newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}
function openNewWindowObj(params)
{
	var link = params;

    //by F.Rosario; fixed resize / scrolling issue in JS call from Flash
    //debugger;
    
    var h = 520;
    var w = 600;
    
    link.windowFeatures = link.windowFeatures.replace('\'_blank\',','');
    link.windowFeatures = link.windowFeatures.replace('resizable=yes','resizable=1');
    link.windowFeatures = link.windowFeatures.replace('scrollbars=yes','scrollbars=1');
    link.windowFeatures += ',width=' + w + ',height=' + h;

	window.open(link.URLtoOpen, link.windowName, link.windowFeatures);
}