//====================================================================================================//
//======== DataSite's Global JavaScript: Contains Custom Functions and Plug-in Configurations ========//
//====================================================================================================//




$(document).ready(function ()
{

	//====  Run Main Nav drop-down menu script  ====//
	$('ul#nav').superfish();

	if ($("#mainCenter").length > 0)
	{
		pickLogos(8);
	}
	/*===================  END  ===================*/



	//====  Run Geolocation Script for Contact Phone Number  ====//
	if (typeof geoplugin_countryName != 'undefined')
	{
		Country(geoplugin_countryName());
	}
	/*===================  END  ===================*/



	/*========== Site-wide Assign Link Type Icons  ==========*/
	$('#mainContent a').each(function ()
	{
		// Get all the link's href values, put them into an array by splitting on the '.' within said href value 
		var linkAttr = $(this).attr('href').toUpperCase().split('.');
		// Setting Variable to check if file is actually a Word document varient or a web page (e.g., default.do)
		var notWordDoc = linkAttr[linkAttr.length - 1].substring(0, 3);

		// Get the first two characters of the last value in each of the link arrays
		linkAttr = linkAttr[linkAttr.length - 1].substring(0, 2);

		// Exclude interal links from getting affected next action
		if (linkAttr != 'HT' && linkAttr != 'CO')
		{
			// All other link types insert a <span> tag with the corresponding class name to the link type just AFTER the closing </a> tag
			$(this).after("<span class='linkType-" + linkAttr + "'>&nbsp;</span>");//.attr('target', '_newTab');
		}

		// Find all External Links
		if (!$('#socialLikingContainer')){
		if (this.hostname && this.hostname !== window.location.hostname )
		{
			// Insert a <span> tag with the external-link classname to said <span> just AFTER the closing </a> tag
			$(this).after("<span class='linkType-EX'>&nbsp;</span>");//.attr('target', '_newTab');
		};
		}

		// Remove any Word icons that were assigned to an actual web page
		if (notWordDoc == 'DO?' || notWordDoc == 'DO%')
		{
			$('span.linkType-DO').remove();
		}
        
	});
	/*===================  END  ===================*/


	/*========== Initialize Facebook 'Like' feature ==========*/
	(function (d, s, id)
	{
		var js, fjs = d.getElementsByTagName(s)[0];
		if (d.getElementById(id)) { return; }
		js = d.createElement(s); js.id = id;
		js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
		fjs.parentNode.insertBefore(js, fjs);
	} (document, 'script', 'facebook-jssdk'));
	/*========================  END  ========================*/





	//--END of $(document).ready()--//
});








$(window).load(function ()
{
	
	
	//====  Home page Focus Image Sliding rotation feature  ====//
	if ($('#slider')) 
	{
		$('#slider').nivoSlider({
			effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
			animSpeed: 500, // Slide transition speed
			pauseTime: 6000, // How long each slide will show
			startSlide: 0, // Set starting Slide (0 index)
			directionNav: true, // Next & Prev navigation
			directionNavHide: false, // Only show on hover
			controlNav: true, // 1,2,3... navigation
			controlNavThumbs: false, // Use thumbnails for Control Nav
			controlNavThumbsFromRel: false, // Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', // Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
			keyboardNav: true, // Use left & right arrows
			pauseOnHover: true, // Stop animation while hovering
			manualAdvance: false, // Force manual transitions
			captionOpacity: 0.8, // Universal caption opacity
			prevText: 'Prev', // Prev directionNav text
			nextText: 'Next', // Next directionNav text
			beforeChange: function () { }, // Triggers before a slide transition
			afterChange: function () { }, // Triggers after a slide transition
			slideshowEnd: function () { }, // Triggers after all slides have been shown
			lastSlide: function () { }, // Triggers when last slide is shown
			afterLoad: function () { } // Triggers when slider has loaded
		});
	}
	//====  END  ====//



//--END of $(window).load()--//
});








//===  Client Logo slider arrows  ===//
$(function ()
{
	if ($('.wrapper')) 
	{
		$('.wrapper').jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev"
		});
	}
});
//=== END ===//











//==== Geolocation for Contact Phone Number Configurations  ====//
function Country(countryName) {

		if (countryName == "United States")
		{
			$('#headerAux p:first-child').html('Call Us: 1.888.867.0309');
		}
		else if (countryName == "United Kingdom")
		{
			$('#headerAux p:first-child').html('Call Us: +44 (0)20 7562 3200');
		}
		else if (countryName == "France")
		{
			$('#headerAux p:first-child').html('Appelez dès maintenant: 0033 1 40 06 1312');
		}
		else if (countryName == "Germany")
		{
			$('#headerAux p:first-child').html('Jetzt anrufen: 0800 664 72 73');
		}
		else if (countryName == "Italy")
		{
			$('#headerAux p:first-child').html('Chiama: 800 915 963');
		}
		else if (countryName == "Spain")
		{
			$('#headerAux p:first-child').html('Llame ahora: 900 812 144');
		}
		else if (countryName == "Brazil" || countryName == "Portugal")
		{
			$('#headerAux p:first-child').html('Ligue para a gente: 55 (11) 3895-8545');
		}
		else
		{
			$('#headerAux p:first-child').html('Call Us: 1.888.867.0309');
		}

}
//=== END ===//





//==========  DISCONTINUED   ============//
//====  Client Logo Rotation Script  ====//
//==========  DISCONTINUED   ============//
/*
function pickLogos(num)
{
	var aLogos = new Array("logo_hmpg_3M.gif","logo_hmpg_BP.gif","logo_hmpg_Chevron.gif","logo_hmpg_Chrysler.gif","logo_hmpg_Dell.gif","logo_hmpg_Honeywell.gif","logo_hmpg_CIBC.gif","logo_hmpg_KKR.gif","logo_hmpg_Kraft.gif","logo_hmpg_Motorola.gif","logo_hmpg_Oaktree.gif");	
*/
//  Logos Not In Use  //
/*	
	logo_hmpg_Intel.gif
	logo_hmpg_GE.gif
*/

/*
	var aRandom = new Array();
	var count=0;

	while (count < num) {
		bFlag = false;
		var currNum = Math.round((aLogos.length-1)*Math.random());
	
		if(count!=0)  {
			for(var i=0; i<aRandom.length; i++) {
				if(aLogos[currNum]==aRandom[i]) {
					bFlag=true;
					break;
				}
			}
		}
		
		if(!bFlag) {
			aRandom[count]=aLogos[currNum];
			count+=1;
		}
	}
	$("#mainCenter .left  img:eq(0)").attr("src", "img/"+aRandom[0]);
	$("#mainCenter .left  img:eq(1)").attr("src", "img/"+aRandom[1]);
	$("#mainCenter .left  img:eq(2)").attr("src", "img/"+aRandom[2]);
	$("#mainCenter .left  img:eq(3)").attr("src", "img/"+aRandom[3]);
	$("#mainCenter .right img:eq(0)").attr("src", "img/"+aRandom[4]);
	$("#mainCenter .right img:eq(1)").attr("src", "img/"+aRandom[5]);
	$("#mainCenter .right img:eq(2)").attr("src", "img/"+aRandom[6]);
	$("#mainCenter .right img:eq(3)").attr("src", "img/"+aRandom[7]);
}
*/
//==========  DISCONTINUED   ============//
//==============  END   =================//
//==========  DISCONTINUED   ============//





//====  FUNCTION USED TO VALIDATE EMAIL ADDRESS  ====//
function validateEmailAddr(theText) 
{ 
// VALIDATE THE EMAIL ADDRESS 
// Here are the logical checks: 
// 
// One or more characters before the "@" 
// An optional "[", because user@[255.255.255.0] is a valid e-mail 
// A sequence of letters, numbers, and periods, which are all valid domain or IP address characters 
// A period followed by a 2-3 letter suffix 
// An optional "]" 
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
var reg2 = /^[a-zA-Z0-9]([a-zA-Z0-9_\-\.]*)\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
if (!reg1.test(theText) && reg2.test(theText)) // if syntax is valid 
{ 
return true; 
} else { 
alert("\"" + theText + "\" is an invalid e-mail address.\n\nPlease enter a valid address."); 
return false; 
} 
} 
function CheckValidation() { 

if(document.MerrillDS_DEMO_REQUEST.txtFirstName.value == "First Name") 
{ 
alert("Please enter your First Name"); 
document.MerrillDS_DEMO_REQUEST.txtFirstName.focus(); 
return false; 
} 

if(document.MerrillDS_DEMO_REQUEST.txtLastName.value == "Last Name") 
{ 
alert("Please enter your Last Name"); 
document.MerrillDS_DEMO_REQUEST.txtLastName.focus(); 
return false; 
} 
if(document.MerrillDS_DEMO_REQUEST.txtCompany.value == "Company") 
{ 
alert("Please enter your Company"); 
document.MerrillDS_DEMO_REQUEST.txtCompany.focus(); 
return false; 
}
if(document.MerrillDS_DEMO_REQUEST.txtPhone.value == "Phone Number") 
{ 
alert("Please enter your Phone Number"); 
document.MerrillDS_DEMO_REQUEST.txtPhone.focus(); 
return false; 
}
if(document.MerrillDS_DEMO_REQUEST.ddlCountry.value == "") 
{ 
alert("Please enter your Country"); 
document.MerrillDS_DEMO_REQUEST.ddlCountry.focus(); 
return false; 
}
if(document.MerrillDS_DEMO_REQUEST.ddlState.value == "") 
{ 
alert("Please enter your State"); 
document.MerrillDS_DEMO_REQUEST.ddlState.focus(); 
return false; 
}
if(document.MerrillDS_DEMO_REQUEST.txtEmail.value == "E-mail Address") 
{ 
alert("Please enter your Email"); 
document.MerrillDS_DEMO_REQUEST.txtEmail.focus(); 
return false; 

} 
if (document.MerrillDS_DEMO_REQUEST.txtEmail.value!=="") { 
if (!validateEmailAddr(document.MerrillDS_DEMO_REQUEST.txtEmail.value)) { 
document.MerrillDS_DEMO_REQUEST.txtEmail.focus(); 
return false; 
} 
} 
document.MerrillDS_DEMO_REQUEST.action="http://now.eloqua.com/e/f2.aspx"; 
document.MerrillDS_DEMO_REQUEST.submit();
}
//=== END ===//




