var expdate = new Date();

function DelCookie(name)
{
		var expDateTmp = expdate;
		expDateTmp.setTime(expdate.getTime() - (24*60*60*1000));
		SetCookie(name, "this is a test", expDateTmp);
}

function SetCookie(name, value, expires, path, domain, secure)
{
	path='/';
	domain='www.imagecapsule.com';
	
	document.cookie = name + "=" + escape(value) +
				((expires) ? "; expires=" + expires.toGMTString() : "") +
				((path) ? "; path=" + path : "") +
				((domain) ? "; domain=" + domain : "") +
				((secure) ? "; secure" : "");
}

function FixCookieDate(date)
{	//-- fix mac problem with date
	var base = new Date(0);
	var skew = base.getTime();
	if(skew >0)
		date.setTime(date.gettime() - skew);
}



function isCookieExist(label)
{
	var labelLen = label.length;
	var cLen = document.cookie.length;
	var i=0;
	
	while(i<cLen)
	{
		var j=i+labelLen;
		if(document.cookie.substring(i,j) == label)
			return(true);
		i++;
	} 
	return (false);
}


function ICap_login(URL, winName, option)
{
	window.open(URL, winName, ('scrollbars=yes,resizable=1,toolbar=no,status=yes,menubar=no'));
}

function ICap_clean_up()
{
	var label="ICAPSC2Catalog";
	DelCookie(label);
}

function turnOnImage(strImageNumber)
{
	document.images.imgmain.src = strImageNumber;
}

function turnOffImage()
{
	document.images.imgmain.src = "http://66.93.135.133/accounts/imgblack.jpg";
}


function Icap_isJava()
{
	if (navigator.javaEnabled() < 1)
	{
		alert("Please enable Java in the options menu.\nYou'll need it for these pages!");
		return(false);
	}	
	else
	{
		turnOffEvent();
		return(true);
	}
}

//----------------------
function open_Popup( URL, winName, winWidth, winHeight, iScroll, iResize, iTool, iStatus, iMenu) 
{
		if(navigator.appVersion.indexOf("AOL") != -1)
		{
			theWidth = winWidth+10; theHeight = winHeight*0.8;
		}
		else
		{
			theWidth = winWidth+10; theHeight = winHeight-50;
		}
		
		var newWin = window.open(URL, (winName), ('width=' + theWidth + ',height=' + 	theHeight + 
		',scrollbars='+ iScroll + ',resizable=' + iResize + 
		',toolbar=' + iTool + ',status=' + iStatus + 
		',menubar=' + iMenu) );
	}

function centerPopup(winWidth, winHeight)
{		
	if(navigator.appVersion.indexOf("AOL") != -1)
		return;
	
	var centerY=0; var centerX=0;
	
	if(winWidth!=0)
		centerX = (screen.availWidth-winWidth)/2;
		
	if(winHeight!=0)		
		centerY = (screen.availHeight-winHeight)/2;
	
	window.moveTo(centerX,centerY);	
}

function handleMouseEvent(e)
{  
	if (navigator.appName.indexOf("Microsoft") != -1)  
	{    
		if (event.button == 2 || event.button == 3)    
		{      
			alert('This option is disabled.');      
			return false;    
		}  
	}  
	else if (navigator.appName.indexOf("Netscape") != -1)  
	{    
		if (e.which == 2 || e.which == 3)    
		{     
			alert('This option is disabled.');      
			return false;    
		}  
	}  	
	return true;
}

function handleKeyPress(e)
{
	if (navigator.appName.indexOf("Netscape") != -1)  
	{    
		if( (e.which == 0)||(e.which == 17) )    
		{     
			alert('This key option is disabled.');         
			return false;    
		}  
	} 
	else if (navigator.appName.indexOf("Microsoft") != -1)  
	{
		if(event.keyCode==17)
		{
			alert('This key option is disabled.');         
			return false;
		}
	}
}

function turnOffEvent()
{
	if (document.layers)
	{  
		document.captureEvents(Event.MOUSEDOWN | Event.KEYDOWN);  
		for (var i=0; i<document.images.length; i++)    
		{
			document.images[i].onmousedown = handleMouseEvent;
			document.images[i].onkeydown = handleKeyPress;
		}
	}
	document.onmousedown = handleMouseEvent;
	document.onkeydown = handleKeyPress;
}

FixCookieDate(expdate);		//Correct for Mac.. call only once
expdate.setTime(expdate.getTime() + (24*60*60*1000));	// live for 24 hrs

 
