/*****************************************************************************************************
 * UTIL.JS
 * Copyright (c) 2001-2008 Eric Raptosh Photography, All Rights Reserved
 * Global helper functions & generic behavior
 *****************************************************************************************************/

//self.onerror = function() { return true; };

function SetCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function GetCookie(strName, strDefault) {
	var nameEQ = strName + "=";
	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 strDefault;
}

function DeleteCookie(name) {
	SetCookie(name,"",-1);
}

function clickIE4()
{
  if (event.button==2)
   {
   rightmousemessage(1);
   return false;
   }
}

function clickNS4(e)
{
  if (document.layers||document.getElementById&&!document.all)
   {
   if (e.which==2||e.which==3)
    {
    rightmousemessage(2);
    return false;
    }
   }
}

function rightmousemessage(n)
{
  //alert("Images on this page are licensed for web viewing only.  Please do not copy them or use them for other purposes.  If you are interested in licensing one of our images, please email 'info@ericraptosh.com'.  Thank you. " + n.toString());
  return false;
}

function registeronrightmouse()
{
  if (document.layers)
   {
   document.captureEvents(Event.MOUSEDOWN);
   document.onmousedown=clickNS4;
   }
  else if (document.all&&!document.getElementById)
   {
   document.onmousedown=clickIE4;
   }
  document.oncontextmenu=new Function("rightmousemessage(3);return false");
}

function getaddy(strname,strdomain,strtld,fhref)
{
  if (fhref)
    {
    return "mailto:" + strname + "@" + strdomain + "." + strtld;
    }
  else
    {
    return strname + "@" + strdomain + "." + strtld;
    }
}

function StrHtmlOrText(fText,str)
{
  if (fText)
     {
     var strOut="<p>";
     for (var i=0;i<str.length;i++)
         if (str.charAt(i)=="<")
            strOut += "&lt;";
         else if (str.charAt(i)==">")
            strOut += "&gt;";
         else
            strOut += str.charAt(i);
      return strOut;
      }
  return str;
}




