var objURL = new Object();
// Use the String::replace method to iterate over each
// name-value pair in the query string. Location.search
// gives us the query string (if it exists).
window.location.search.replace(
new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
  
// For each matched query string pair, add that
// pair to the URL struct using the pre-equals
// value as the key.
function( $0, $1, $2, $3 ){
 objURL[ $1 ] = $3;
}
);

function getECICookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function SetECICookie(name,value,expires,path,domain,secure) { 
	var cookieString = name + "=" +escape(value) + 
	( (expires) ? ";expires=" + expires.toGMTString() : "") + 
	( (path) ? ";path=" + path : "") + 
	( (domain) ? ";domain=" + domain : "") + 
	( (secure) ? ";secure" : "");
	document.cookie = cookieString;
}

function showPopupSignUpDailyConcepts() {
	if(typeof(objURL.utm_source) == 'undefined') {
		jQuery('a#signUpDailyConceptsLink').trigger('click');
	} else {
		if (objURL.utm_source && objURL.utm_source!= 'dailyconcept') {
			jQuery('a#signUpDailyConceptsLink').trigger('click');
		}
	}
}

function setMessageDisplayedCookie() {
	var dt = new Date();
	dt.setDate(dt.getDate() + 365);
	var cookie_expiry_date = dt;
	SetECICookie('eciBlog-messageClosed','1',dt);
}

jQuery(document).ready(function(){
  var isfirsttime = getECICookie('eciBlog-FirstTime');
	var messageDisplayed = getECICookie('eciBlog-messageClosed');
	if(isfirsttime == "") {

		var dt = new Date();
		dt.setDate(dt.getDate() + 365);
		var cookie_expiry_date = dt;
		SetECICookie('eciBlog-FirstTime','1',dt);
		
		setTimeout('showPopupSignUpDailyConcepts()',30*1000); 	// Display after 30 seconds
		
	} else {
		if(messageDisplayed == "") {
			setTimeout('showPopupSignUpDailyConcepts()',2*1000); // Display after 2 seconds
		}
	}
});	

jQuery(document).ready(function() {	

	//select all the a tag with name equal to modal
	jQuery('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = jQuery(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		jQuery('#mask').fadeIn(1000);	
		jQuery('#mask').fadeTo("slow",0.7);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/10);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	jQuery('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		jQuery('#mask').hide();
		jQuery('.window').hide();
		setMessageDisplayedCookie(); 

	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
		//setMessageDisplayedCookie(); 
	});			
	
});
