//window.alert(document.cookie);

var mail_filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var cur_width = screen.availWidth;
var cur_height = screen.availHeight;
site_url  = "http://www.sonataarctica.it";   
img_url = site_url+"/images";

//window.alert(document.cookie);
//window.alert(cur_width);
//window.alert(getCookie("screen_res"))

if(cur_width>=1024) {
	 cur_width=1024;
}
else {
	cur_width=800;
}

if(cur_width != getCookie("screen_res"))
{
	setCookie('screen_res',cur_width,7);
	window.location.reload();
}

function getCookie(name) { 
	var cookiestr = document.cookie;
	var index = cookiestr.indexOf(name + "=");
	
	if (index == -1) return null;
	index = cookiestr.indexOf("=", index) + 1;
	var endstr = cookiestr.indexOf(";", index);
	if (endstr == -1) endstr = cookiestr.length;
	return unescape(cookiestr.substring(index, endstr));
}

function setCookie(name, value, day) 
{
	var today = new Date();
	var expiry = new Date(today.getTime() + day * 24 * 3600*1000); 

	if (value != null && value != "")
	  document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}

function mailto(address,domain) 
{ 
	document.location.href = "mailto:" + address + "@" + domain; 
}

function chk_poll_answer(f,total,msg) {
	for(var i=0;i<total;i++) {
		if(f.panswer[i].checked)
			return true;
	}
	window.alert(msg);
	return false;
}
  
function open_win(url, prop, name) {
	  	newWind = window.open(url, name, prop)
}

function rollOff(name, toload)
{
	if(document.images) {
		var src = (toload) ? off[toload].src : off[name].src; 
		document.images[name].src = src;
		}
}
	
function rollOn(name, toload)
{	
	if(document.images) {
		var src = (toload) ? on[toload].src : on[name].src;
		document.images[name].src = src
		}
}

function mailto(address,domain) 
{ 
	document.location.href = "mailto:" + address + "@" + domain; 
}
	
function onload_init()
{
	/****
	Set the height of the content div so that the footer appear at the end 
	of the page
	****/
	var agt=navigator.userAgent.toLowerCase();
	var nav = document.getElementById('navigation')
	var extra = document.getElementById('extra')
	var content = document.getElementById('content')
	var container = document.getElementById('container');
	var corH = (nav.scrollHeight>=extra.scrollHeight) ? nav.scrollHeight : extra.scrollHeight;
	
	//window.alert(container.scrollWidth);

	//if(agt.indexOf('gecko') != -1) {
	//	var newwidth = container.scrollWidth+6;
	//	container.style.width = newwidth+"px";
	//}
	//window.alert(container.scrollWidth);
	
	/*
	window.alert("n"+nav.scrollHeight+"c"+
				 content.scrollHeight+"e"+
				 extra.scrollHeight);
	
	
	window.alert(corH);
	*/
	
	if(content.scrollHeight<corH)
		content.style.height=corH+"px";

	/****
	Find all the link with rel attribute set to external and set the target
	attribute to make them open in a new windows.
	****/
	if (!document.getElementsByTagName) return;
 	var anchors = document.getElementsByTagName("a");
 	for (var i=0; i<anchors.length; i++) 
	{
   		var anchor = anchors[i];
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
     		anchor.target = "_blank";
	}
	//window.alert(document.getElementById('container').scrollWidth);
}

window.onload = onload_init;