var scrollLocation = 0;

function randString()
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	
	return randomstring;
}

function ReloadCAPTCHA()
{
	document.getElementById("captcha").value = "";
    document.capaIMG.src = "http://www.topcoasters.com/sources/captcha_image.php?NEW=" + randString();
}

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());
}

function verifyCancel(url)
{
	var conf = confirm("Are you sure you would wish to cancel what you are doing right now, all changes will be lost");
	
	if(conf == true)
	{
		window.location = url;
	}
	else
	{
		return false;
	}
}

function deleteMsg(id)
{
	var conf = confirm("Are you sure that you would like to delete this personal message\n\nThis action cannot be undone!");
	
	if(conf == true)
	{
		window.location = 'http://www.topcoasters.com/index.php?core=account&DO=messenger&act=delete&id=' + id;
	}
	else
	{
		// nada
	}
}

function time()
{
	var time;
	var d = new Date();
	time = d.getTime() / 1000;
	
	return time;
}

function empty(str)
{
	if(str == "")
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function showHide_popup(id)
{
	var div = document.getElementById(id);
	
	if(div.style.display == "block")
	{
		div.style.display = "none";
	}
	else
	{
		div.style.display = "block"
	}
}

function login()
{
	showHide_popup("login_popup");
	document.getElementById("login_email").value = "";
	document.getElementById("login_pword").value = "";
	document.getElementById("login_msg").innerHTML = "";
}

function fixWrapper_Size()
{
    var myWidth = 0, myHeight = 0;
    if(typeof(window.innerWidth) == 'number')
	{
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{
      //IE 4 compatible
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
	
	var wrapperHeight = document.getElementById("content").style.height;
}

function showPOV_box(rideName, rideID, yt_id)
{
	var lightbox = document.getElementById("pov_popout");
	
	var inner = "<h1>" + rideName + " POV</h1>" + '<div align="center" style="margin:25px;"><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/' + yt_id + '&hl=en_US&fs=1&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + yt_id + '&hl=en_US&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></div>' + "<a href='" + home_url + "index.php?core=viewride&id=" + rideID + "'>Learn More About this Roller Coaster &raquo;</a><div style='float:right;' align='center'>(<a href='javascript: closePOV_box();'>Close</a>)</div>";
	
	lightbox.innerHTML = inner;
	
	document.getElementById("blackout").style.display = "block";
	lightbox.style.display = "block";
	
	scrollLocation = document.documentElement.scrollTop;
	
	window.scroll(0,0)
}

function closePOV_box()
{
	var lightbox = document.getElementById("pov_popout");
	
	lightbox.innerHTML = "";
	
	document.getElementById("blackout").style.display = "none";
	lightbox.style.display = "none";
	
	window.scroll(0,scrollLocation)
	
	scrollLocation = 0;
}