// JavaScript Document


// Basic cookie & QS manipulation functions

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";domain=alaskastockprints.com;path=/");
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
} 

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];
}


// Get QS with analytics data (if present) and put into a cookie lasting 90 days

if (getQuerystring('utm_campaign')!='') 
{

setCookie('prPartnerName',getQuerystring('utm_campaign'),90);

}

// If there is a cookie with analytics data, then send to printroom partner area, else go to default area. This function is triggered by an onClick event in anchor.
// Works with function call using onClick event in cgi/imagefolio.../if_lib/thumbnail.pl & image.pl

function buildLink(strImageName) 
{

	var strPartnerName = getCookie('prPartnerName'); // Get cookie of printroom partner name
	
	// strPartnerName = ''; // temp disable
	
	// Update: Check if cookie is from an approved partner (listed in approvedpartners.js) before it uses for printroom.
	if (strApprovedPartners.indexOf(strPartnerName) < 0) {
		
		strPartnerName = ''; 
	}
	
	if (strPartnerName!='') { 
	
		strURL = 'http://www.printroom.com/partner.asp?name='+strPartnerName+'&go='+escape('ViewFoundPhoto.asp?userid=alaskastockprints&stype=0&sword='+strImageName);	
		
	}else{
		
		strURL = 'http://www.printroom.com/ViewFoundPhoto.asp?userid=alaskastockprints&stype=0&sword='+strImageName;	
		
	}
	
 window.open(strURL,'welcome','menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes');
 
 return false;
	
} 

