function showHideElement(element) {
	for (i = 1; i <= 10; i++) {
		if (document.getElementById("secondLevelNavi" + i) != undefined) {
			if (document.getElementById("secondLevelNavi" + i).style.display = 'block') {
				document.getElementById("secondLevelNavi" + i).style.display = 'none';
			}
		}
	}
	if (element != '') {
		document.getElementById(element).style.display = 'block';
	}
}

function switchElement(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function getRef(id){
  return document.getElementById(id);
}

var currentlyShowing = "";

function showLayer(id){
  getRef(id).style.visibility = "visible";
}
function showLayerForum(id){
  getRef(id).style.visibility = "visible";
}

function hideLayer(id){
  getRef(id).style.visibility = "hidden";
  if(currentlyShowing == id)
    currentlyShowing = "";
}
function hideLayerForum(id){
  getRef(id).style.visibility = "hidden";
  if(currentlyShowing == id)
    currentlyShowing = "";
}
function addQuote(toForm, fromField, toField){
	document.forms[toForm].elements[toField].value += document.forms[toForm].elements[fromField].value;
	document.forms[toForm].elements[toField].focus();
}

function showLayerWithCheck(id){
  if(currentlyShowing != ""){
    hideLayer(currentlyShowing);
  }
  showLayer(id);
  currentlyShowing = id;
}

function hideLayerDelay(id){
  setTimeout("hideLayer('" + id + "')", 1500);
}
function avaaIkkuna2(url,size1,size2){
    window.open(url,"UusiIkkuna","WIDTH="+ size1 +",HEIGHT="+ size2 +",scrollbars=yes,toolbars=no");
}

function avaaIkkuna(url){
    window.open(url,"Esitetilaus","WIDTH=415,HEIGHT=410,scrollbars=yes,toolbars=no");
}

function login(){

  showLayer("login-bar");
  for(var i=0; i<document.forms[0].elements.length; i++){
    if(document.forms[0].elements[i].type == "text")
    document.forms[0].elements[i].focus();
  }

}

function checkEnter(e, formi, sendForm) {
	var characterCode;
	if (e && e.which) { //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
		if (sendForm == 1) {
			formi.submit() //submit the form
		}
		return false;
	} else {
		return true;
	}
}

function toggleLivescoring(obj) {
	var el = document.getElementById(obj);
	if (el.style.display != "none") {
		el.style.display = 'none';
		el.style.visibility = "hidden";
		document.getElementById('livescoring_open').innerHTML = '» Avaa Live Scoring';
	} else {
		el.style.display = '';
		el.style.visibility = 'visible';
		document.getElementById('livescoring_open').innerHTML = '» Sulje Live Scoring';
	}
}

var xmlHttp = null;

function GetXmlHttpObject() {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function getCaptchaImage(CaptchaId, CaptchaMode) {

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Varmistunumero päivitys ei onnistu.");
		return;
	}

	var sid = Math.random()*100000000000000000;
	var url = "/captcha/index.asp";
	url = url + "?cmode=" + CaptchaMode;
	url = url + "&sid=" + sid;
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			document.getElementById("captcha").src = url;
		}
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}



// Replaces the currently selected text with the passed text.
function replaceText(text, textarea)
{
	// Attempt to create a text range (IE).
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		caretPos.select();
	}
	// Mozilla text range replace.
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);

		textarea.value = begin + text + end;

		if (textarea.setSelectionRange)
		{
			textarea.focus();
			textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
		}
	}
	// Just put it on the end.
	else
	{
		textarea.value += text;
		textarea.focus(textarea.value.length - 1);
	}
}



function addText(myField, startChar, endChar) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange().text;
		document.selection.createRange().text = startChar + sel + endChar;

	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionEnd && (myField.selectionEnd - myField.selectionStart > 0)) {
		startPos = myField.selectionStart;
		endPos = myField.selectionEnd;
		lenSel = endPos - startPos;
		myField.value = myField.value.substring(0, startPos)
			+ startChar
			+ myField.value.substring(startPos, startPos+lenSel)
			+ endChar
			+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.focus();
		myField.value += startChar + endChar;
	}
}
function avaaPalaute(url){
    window.open(url,"PalauteIkkuna","WIDTH=496,HEIGHT=470,SCROLLBARS=no,toolbars=no");
}

function stripHTML(string) {
    return string.replace(/<(.|\n)*?>/g, '');
}

// Invert all checkboxes at once by clicking a single checkbox.
function invertAll(headerfield, checkform, mask)
{
	for (var i = 0; i < checkform.length; i++)
	{
		if (typeof(mask) != "undefined" && checkform[i].name.substr(0, mask.length) != mask)
			continue;

		if (!checkform[i].disabled)
			checkform[i].checked = headerfield.checked;
	}
}

function toggle_checkbox(checkbox)
{
	checkbox . checked = ! checkbox . checked;
}


$(document).ready(function(){

	$('.golfCourseNewsboxPic').cycle({
		fx: 'fade',
		speed: 2500,
		timeout: 5000,
		pause: 1
	});
	$('#golfCourseNewsboxPicBuf').cycle({
		fx: 'fade',
		speed: 2500,
		timeout: 5000,
		pause: 1
	});

	$(".iframe").colorbox({
		width:"800px",
		height:"370px",
		iframe:true,
		innerWidth:"100%",
		innerHeight:"100%",
		scrolling:true

	});


	$(".palauteLink").colorbox({
		width:"600px",
		height:"525px",
		iframe:true,
		innerWidth:"100%",
		innerHeight:"100%",
		scrolling:false
	});

});

