﻿$(document).ready(function(){ 
	$("#click").click(function(){ SwitchTopBar(); });
	$("h1").click(function(){location.href='index.asp';});
});

function SwitchTopBar() {
	if($("#tmenubar").css("top") == "0px") {
		$("#tmenubar").animate({ top: '-45px' }, 500, 'swing');
	} else {
		$("#tmenubar").animate({ top: '0px' }, 500, 'swing');
	}
}

// --------
// Växlar bilder
//---------

		function swapImage(strContainer, strFolder, strBild) {
			document.getElementById(strContainer).innerHTML = "<img src='img/upload/" + strFolder + "/" + strBild + "' alt='' class='border' />";
		}

// --------
// Växlar mellan IDn vilken div som skall vara öppen
//---------

		function showInfo(strVisa) {
			document.getElementById(strVisa).style.display = 'block';
		}

		function swapDiv(strDolja, strVisa) {
			var divCollection = document.getElementsByTagName('div');
			var thisDiv = document.getElementById(strVisa);
										
			if(thisDiv.style.display == "block") {
				var intDo = 1;
			} else {
				var intDo = 2;
			}										
			for (var i=0; i<divCollection.length; i++) {
				if(divCollection[i].id.substring(0,3) == strDolja) {
					divCollection[i].style.display = "none";
				} 	
			}													
			if(intDo == 2) {
				thisDiv.style.display = "block";									
			} else {
				thisDiv.style.display = "none";
			}
		}
		
		
		
		
		function swapMenu(strDolja, strVisa) {
			var divCollection = document.getElementsByTagName('div');
			var thisDiv = document.getElementById(strVisa);

			for (var i=0; i<divCollection.length; i++) {
				if(divCollection[i].id.substring(0,3) == strDolja) {
					divCollection[i].style.display = "none";
				} 	
			}													
				thisDiv.style.display = "block";									
		}
		
		
		
		function closeInfo() {
			var divCollection = document.getElementsByTagName('div');
			for (var i=0; i<divCollection.length; i++) {
				if(divCollection[i].id.substring(0,4) == 'info') {
					divCollection[i].style.display = "none";
				} 	
			}													
		}
		
		
		
		function swapMBG(strVisa) {
			var divCollection = document.getElementsByTagName('div');
			var thisDiv = document.getElementById(strVisa);


			for (var i=0; i<divCollection.length; i++) {
				if(divCollection[i].id.substring(0,6) == 'toppen') {
					divCollection[i].style.background = "";
				} 	
			}
			thisDiv.style.background = "#ebf1f7";			
		}
		
		
// --------
// Öppnar div utan att stänga annan
//---------
		
		function swapDivNoClose(strDolja, strVisa) {
			var divCollection = document.getElementsByTagName('div');
			var thisDiv = document.getElementById(strVisa);
										
			for (var i=0; i<divCollection.length; i++) {
				if(divCollection[i].id.substring(0,3) == strDolja) {
					divCollection[i].style.display = "none";
				} 	
			}													

				thisDiv.style.display = "block";									
		}

// --------
// Stänger alla divar vars 3 första tecken i IDt motsvarar medskickade tecken
//---------

		function closeAll(strDolja) {
			var divCollection = document.getElementsByTagName('div');
			for (var i=0; i<divCollection.length; i++) {
				if(divCollection[i].id.substring(0,3) == strDolja) {
					divCollection[i].style.display = "none";
				} 	
			}													
		}
		

// --------
// Lägg till flagga i input
//---------

		function addFlag(strFlag) {
			strInput = document.getElementById('flaggorna');
			if(strInput.value.length==0) {
				strInput.value = strFlag;
			} else {
				strInput.value = strInput.value + ", " + strFlag;
			}
		}


// --------
// Genererar kod för länkning till HorseLink via banner
//---------

		function genCode() {
				var e = document.forms['kodfix'].elements['format'];
				
				if (e[0].checked) {
					var strFormat = "120x60"
				} else {
					var strFormat = "460x68"
				}
				
				document.kodfix.visa.value = "<a href=\"http://www.horselink.se?ref=" + document.kodfix.url.value + "\" target=\"_blank\"><img src=\"http://www.horselink.se/img/ourbanners/banner_" + strFormat + ".gif\" /></a>";
				document.getElementById('showlinkcode').style.display = "block";
		}
		
//----------
// Javascript som validerar formulär genom att kolla så samtliga fält vars id börjar på 2 valda bokstäver är ifyllda.
// Exempel på anrop: if(validForm('rq','Du måste fylla i samtliga obligatoriska fält.')){document.formen.submit()};
// Scriptet letar då upp samtliga element vars ID börjar på "rq" och kollar så dessa är ifyllda (rq kan bytas mot önskade 2 bokstäver)
// Av: Eric Johansson, eyeconmedia.se/eric 
//----------
		function validForm(strReq,strMessage) {
			intError = 0;
			var formCollection = document.getElementsByTagName("*");
			for (var i=0; i<formCollection.length; i++) {
				if(formCollection[i].id.substring(0,2) == strReq) {
					if(formCollection[i].value.length == 0 || formCollection[i].value == null || formCollection[i].value == '') {
						intError = 1;
						formCollection[i].style.backgroundColor = '';
					} else {
						formCollection[i].style.backgroundColor = '';
					}
				}					
			}
			if(intError == 1) {
				alert(strMessage);
				return false;
			} else {
				return true;
			}													
		}

//----------
// Öppnar popup fönster
//----------

		function popitup(strUrl,strName, intHeight, intWidth) {
			newwindow=window.open(strUrl,strName,'height='+intHeight+',width='+intWidth+',scrollbars=auto');
			if (window.focus) {newwindow.focus()}
		}