// JavaScript Document
// copy right current year

function current_year()
{
	var current_year = new Date();
	var year = current_year.getFullYear();
	
	document.write(year);
	
	return;
}

// Are you eligible to be a member added March 2010

function loan_note(the_location, the_name, third_party, the_width, the_height)
{
	if (third_party == true)
	{
		//outside_url  = the_location;										// URL where user wants to go
		outside_url = getURL (the_location);
		the_location = 'site/loan_note.php';									//Can you be a member?
	}
	
	if ((the_width == 0 && the_height == 0) || navigator.userAgent.match('Firefox/2'))
	{
		window.open(the_location, the_name);				// Firefox 2 does some weird stuff, so this is necessary.  See note above.
	}
	else
	{
		var from_top  = ((parseInt(screen.height) - the_height) / 2);						// Position window from the top
		var from_left = ((parseInt(screen.width) - the_width) / 2);						// Position window from the left
		
		window.open(the_location, the_name, 'width=' + the_width + ', height=' + the_height + ', top=' + from_top + ', left=' + from_left + ', location=yes, scrollbars=yes');
	}
	
	return;
}

// Outside Site code
function external_site(the_location, the_name, third_party, the_width, the_height)
{
	if (third_party == true)
	{
		outside_url  = the_location;										// URL where user wants to go
		the_location = 'outside_site.html';									// Third party site disclaimer
	}
	
	if ((the_width == 0 && the_height == 0) || navigator.userAgent.match('Firefox/2'))
	{
		window.open(the_location, the_name);									// Firefox 2 does some weird stuff, so this is necessary.  See note above.
	}
	else
	{
		var from_top  = ((parseInt(screen.height) - the_height) / 2);						// Position window from the top
		var from_left = ((parseInt(screen.width) - the_width) / 2);						// Position window from the left
		
		window.open(the_location, the_name, 'width=' + the_width + ', height=' + the_height + ', top=' + from_top + ', left=' + from_left + ', location=yes, scrollbars=yes');
	}
	
	return;
}
// disclaimer pop-up added Feb 2010

function new_window(url, v_height, v_width ) 
{
 var count=Math.floor(Math.random()*101)
 var width  = v_width;
 var height = v_height;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=yes';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'win'+count, params);
 if (window.focus) {newwin.focus()}
 
 return false;
}
// Query string
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

//Add tags to url
// The second field for the campaign variable will need to be changed every time we change campaign
function getURL (toPage) {
	var source= getQuerystring('utm_source','iwantacarloan');
	var medium=getQuerystring('utm_medium','web');
	var campaign=getQuerystring('utm_campaign', 'iwcl');
	var page =toPage +"?utm_source=" + source + "&utm_medium="+ medium +"&utm_campaign="+campaign;
	
	return page;
}
