function commons_ck(commonsurl, docurl) 
{
	//check whether the commons cookie exists
	var cookieval=getCookie('commons');
	if (cookieval!=null && cookieval!="") {
		//open the document url
		window.open(docurl,'imagewindow');
	} else {
		//open the commons page
		commons(commonsurl+'?submitTo='+docurl);
	}
	return false;
}

function commons_ck_email(commonsurl, imageurl, prefix, width, height) 
{
	//check whether the commons cookie exists
	var cookieval=getCookie('commons');
	if (cookieval!=null && cookieval!="") {
		//open the image url 
		sendEmail(imageurl, prefix, width, height);
	} else {
		//open the commons page
		commons(commonsurl+'?submitTo='+imageurl+'&prefix='+prefix+'&width='+width+'&height='+height);
	}
	return false;
}

function commons_addThis_open(theObject, url, title) 
{
	//check whether the commons cookie exists
	var cookieval=getCookie('commons');
	if (cookieval!=null && cookieval!="") {		
		//call the addthis function
		return addthis_open(theObject, '', url, title);
	} 	
	return false;
}

function commons_addThis_sendto(commonsurl, docurl) 
{
	//check whether the commons cookie exists
	var cookieval=getCookie('commons');
	if (cookieval!=null && cookieval!="") {
		//call the addthis function
		return addthis_sendto();
	} else {
		//open the commons page
		commons(commonsurl+'?submitTo='+docurl);		
	}
	return false;	
}

function commonsAgree(form, prefix, width, height)
{
	var agreementRadio = form.agreementBtn;
	var agreement;
	var returnval;
	for(var i = 0; i < agreementRadio.length; i++) {
		if (agreementRadio[i].checked == true){
			agreement = agreementRadio[i].value;
		}
	}	

	if ( agreement == 'Yes') { 
		setCookie('commons', agreement);
		if (form.action!=null && form.action!="") {
			if (prefix!=null && prefix!="") {
				window.opener.sendEmail(form.action, prefix, width, height);
			} else {
				window.opener.open(form.action, 'assetwindow');
			}
		}
		self.close();
		returnval = false;
	} else {
		self.close();
		returnval = false;
	}

	return returnval;
}//


function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "; path=/" : ";expires="+exdate.toGMTString()+"; 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 "";
}//

//Submit the email link form to the email form processing script in a new window
function sendEmail(imagePath, prefix, width, height)
{
	var form = document.getElementById(prefix + "emailLinkForm");
	form.imagePath.value = imagePath;
	var winRef = window.open("", "emailFormWindow", "location=1,status=1,scrollbars=1,width=" + width + ",height=" + height);
	winRef.moveTo(0,0);
	if (parseInt(navigator.appVersion) >= 4) { winRef.window.focus(); }	
	form.submit();	
}

function commons(url) 
{
 var width  = 475;
 var height = 560;
 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=no';
 params += ', menubar=no';
 params += ', resizable=yes';
 params += ', scrollbars=no';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'Send', params);
 if (window.focus) {newwin.focus()}
 return false;
}