/* ----------------------------------------------
/ This file is home to JS functions shared
/ by all pages on the site.
 ---------------------------------------------- */

// -------------------------- //
// Temporary insert
// -------------------------- //

function popUpJay(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500');");
}

//  End Temporary
// -------------------------- //

function PopUpWindow(URL, params, pWidth, pHeight, windowName) {
	day = new Date();
	id = windowName == null ? day.getTime() : windowName;
	
	pWidth = pWidth == null ? 600 : pWidth;
	pHeight = pHeight == null ? 500 : pHeight;

	switch (params)
	{
		case 1:
			// not resizable
			wOptions = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+pWidth+",height="+pHeight;
			break;
		case 2:
			// resizable
			wOptions = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+pWidth+",height="+pHeight;
			break;
		default:
			wOptions = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+pWidth+",height="+pHeight;
			break;
	}
	
	eval("page" + id + " = window.open(URL, '" + id + "', '" + wOptions + "');");
}

// -------------------------- //
// originally from header.ascx
// -------------------------- //

function ValidateSearch(TextID)
{
	var txtSearch = eval("document.forms['searchform']." + TextID)
	var searchString = trimAll(txtSearch.value)				
	if (searchString.length  == 0) {
		alert("Please enter search text.");
		return false;
	}				
	
	txtSearch.value = searchString.replace('--','-');
	
	return true;
}

function Validate(TextID)
{
	var txtSearch = eval("document.forms['searchform']." + TextID)
	var searchString = trimAll(txtSearch.value)				
	if (searchString.length  == 0) {
		alert("Please enter search text.");
		return false;
	}				
	return true;
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function validateEmail(email)
{
	var re = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/;
	return re.test(email);
}


function ClearText(el)
{
	if (el.defaultValue==el.value) el.value = ""
}

// end header.ascx
// -------------------------- //

function validateSQFTUpdate(obj) {
	if (document.getElementById("ucProductInfoT2_txtSquareFeet")) {
		convertTo(obj,obj.id.replace('txtQty','txtSquareFeet'),1)
	}
}

function loadDimension(divID, dimURL) {
	$.ajax({url: dimURL, success: function(data){if(data.replace(/[\s\n\r]/g,"").length>0){$("#"+divID).parent().html(data);}}});
	return false;
}

// -------------------------- //
// To be used for Omniture
// -------------------------- //

function OmnitureOnClickPassVar(param, value, tag){
	var s_hd = s_gi(s_account_hd);
	s_hd.linkTrackVars=param;		
	eval('s_hd.'+param+'=\''+value+'\';');
	s_hd.tl(tag,'o',value);
	return true;
}

function OmnitureOnClickPDTab(productID, productTitle, tabID){
	if (typeof(s_gi) != "undefined"){
		var s_hd = s_gi(s_account_hd);
		s_hd.linkTrackVars = 'prop5,prop7,products';
		s_hd.prop5 = tabName(tabID);
		s_hd.prop7 = 'PD: ' + productTitle;
		s_hd.products = ';' + productID;
		s_hd.tl(true,'o',tabID + ' - ' + tabName(tabID));
	}
	return true;
}


// end Omniture
// -------------------------- //


// -------------------------- //
// Global Document.ready
// -------------------------- //

$(document).ready(function() {

	// ----------------------------------------------------
	// Omniture section tagging
	// ----------------------------------------------------
	$("a[OMN-FindMethod]").bind("click", function() {
		var param = "eVar13";
		var value = $(this).attr("OMN-FindMethod");

		OmnitureOnClickPassVar(param, value, this);
	});

	$("div[OMN-FindMethod] a").bind("click", function() {
		var param = "eVar13";
		var value = $(this).parents('div[OMN-FindMethod]').attr("OMN-FindMethod");

		OmnitureOnClickPassVar(param, value, this);
	});
	// ----------------------------------------------------
	// end Omniture
	// -------------------------- //


	// ----------------------------------------------------
	// Cluetip Defaults
	// ----------------------------------------------------
	$.fn.cluetip.defaults.cluetipClass = 'jtip';
	$.fn.cluetip.defaults.arrows = true;
	
	$('a.cluetip_simple').cluetip({
		splitTitle: '|'
	});

	$('a.cluetip_local').cluetip({
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		local: true,
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});

	$('area.cluetip_local').cluetip({
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		local: true,
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});

	$('div.cluetip_local').cluetip({
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		local: true,
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});

	$('a.cluetip_remote').cluetip({
		width: 600,
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});

	$('a.cluetip_remote_2').cluetip({
		width: 400,
		height: 500,
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});

	$('a.cluetip_remote_3').cluetip({
		width: 400,
		height: 200,
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		arrows: true,
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});

	$('a.cluetip_remote_noheightlimit').cluetip({
		width: 400,
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		arrows: true,
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});
	
	$('a.cluetip_newsletter').cluetip({
		width: 300,
		sticky: true,
		activation: 'click',
		closePosition: 'title',
		positionBy: 'bottomTop',
		local: true,
		closeText: '<img src="/web/js/cluetip/images/cross.png" />'
	});
	
	// ----------------------------------------------------

});



