function getParameter ( queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return "null";
	}
}
function getSelectedRadio(obj){
	var ret = '';
	for(var prop=0;prop<obj.length; prop++){
		if(obj[prop].checked){
			ret= obj[prop].value;
		}
	}
	return ret;
}

function setVideoFileCookie(name){
	document.cookie = 'videocookie='+name+'; expires=always; path=/'
}
function getVideoFileCookieValue(){
	var file = readCookie('videocookie');
	eraseCookie('videocookie');
	return file;
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function getExpireTime(){
	var theDate = new Date();
	var tenSecondsLater = new Date( theDate.getTime() + 10000 );
	var expiryDate = tenSecondsLater.toGMTString();
	return expiryDate;
}
function loadIframe(theURL) {
	document.getElementById("contentframe").src = theURL;
}
function loadParentIframe(theURL) {
	parent.document.getElementById("contentframe").src = theURL;
}
function autofitIframe(id){
	var failed=false;
	try{parent.document.getElementById(id).style.height="500px";}catch(err){failed=true;}
	if (!window.opera && !document.mimeType && document.all && document.getElementById){
		try{parent.document.getElementById(id).style.height=this.document.body.offsetHeight+50+"px";}catch(err){failed=true;}
	}
	else if(document.getElementById) {
		try{parent.document.getElementById(id).style.height=this.document.body.scrollHeight+50+"px";}catch(err){failed=true;}
	}
	if(failed){
		window.location = "http://www.tidrapport.nu/";
	}
}


function updateContent(url){
	try{		
		new Ajax.Updater('content', url, {
			method: 'post' ,
			asynchronous: false
		});
	}catch(err){}
}

function attachToMainPage(currPage){
	queryString=window.location.href;
	//alert(queryString);
	// Check if page parameter is included
	var page = null; 
	// Linked from index.php
	if(queryString.indexOf("?page", 0)>0){
		// All good
		return;
	}
	// A google link
	else if(queryString.indexOf(".php", 0)>0){
		try{window.top.location="http://tidrapport.nu/index.php?page="+currPage;}catch(err){window.location="http://tidrapport.nu/index.php?page="+currPage;}
	}
	//main page
	else{
		// All good do nothing
	}
	
}
function validateSupportForm(){
	if(!$("name").value){
		alert('Ange ditt namn!');
		return false;
	}if(!$("mail").value){
		alert('Ange mail adress!');
		return false;
	}if(!$("company").value){
		alert('Ange företagsnamn!');
		return false;
	}if(!$("question").value){
		alert('Mailet är tomt!');
		return false;
	}
	return true;
}

String.prototype.isValidEmail = function(){
	return !!this.match(/^([a-zA-Z0-9]{1}([a-zA-Z0-9\.\-\_]*)[a-zA-Z0-9]{1})@([a-zA-Z0-9]{1}([a-zA-Z0-9\.\-\_]*)[a-zA-Z0-9]{1})\.([a-zA-Z]{2,4})$/)
}

function validateOrderForm() {
	try{
	if (!$("contactname").value) {
		alert("Du måste fylla i en kontakt person.");
		return false;
	} else if (!$("mail").value.isValidEmail()) {
		alert("Du måste fylla i korrekt en E-mail adress.");
		return false;
	} 
	else if (!$("tel").value) {
		alert("Du måste fylla i ett telefon nummer.");
		return false;
	}
	else if (!$("company").value) {
		alert("Du måste fylla i ett företagsnamn.");
		return false;
	}
	else if (!$("orgno").value) {
		alert("Du måste fylla i ett organisationsnummer.");
		return false;
	}
	else if (!$("address").value) {
		alert("Du måste fylla i en adress.");
		return false;
	}
	else if (!$("postalcode").value) {
		alert("Du måste fylla i ett postnummer.");
		return false;
	}
	else if (!$("city").value) {
		alert("Du måste fylla i en ort.");
		return false;
	}
	else if(!$("agreed").checked){
		alert("Avtalet måste godkännas!");
		return false;
	}
		return true;

	}catch(err){alert(err);}
}

//Show hide Layers
//http://bontragerconnection.com/ and http://www.willmaster.com/
//Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}
	else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all) {
		cX += rX; 
		cY += rY;
	}
	d.style.left = (cX+10) + "px";
	d.style.top = (cY+10) + "px";
}
function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}

function showHideDiv(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}

//HELP

function updateHelpdiv(divid){
	try{
		url='./help.php';
		new Ajax.Updater(divid, url, {
			method: 'post' ,
			asynchronous: false
		});
	}catch(err){}
}
