// JavaScript Document
var xmlHttp

function getContent(url)
{
	url = url + "&month=" + document.getElementById("date").value;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("commentArea").innerHTML=xmlHttp.responseText;
		document.getElementById("loader").innerHTML="";
	}
	else
	{
		document.getElementById("loader").innerHTML="<img src='lib/img/icons/loading.gif'>";
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	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 submitInfo()
{
	botkiller = document.getElementById("botkiller").value;
	noofrows = document.getElementById("noofrows").value;
	topicId = document.getElementById("topicId").value;
	name = document.getElementById("name").value;
	heading = document.getElementById("heading").value;
	comment = document.getElementById("comment").value;
	prelink = document.getElementById("prelink").value;
	
	comment = comment.replace(/\n/g, "<br>");
	
	document.getElementById("name").value = "";
	document.getElementById("heading").value = "";
	document.getElementById("comment").value = "";
	document.getElementById("checkbox").checked = false
	
	url = prelink + "insertCom.php?page=0&nr=" + noofrows + "&topicId=" + topicId + "&name=" + name + "&heading=" + heading + "&comment=" + comment + "&prelink=" + prelink;
	
	if (botkiller.length == 0) {
		getContent(url);
	}
}


function submitInvite()
{
	noofFields = document.getElementById("noofFields").value;
	
	url = "sendInvite.php";
	
	myName = document.getElementById("myName").value;
	myEmail = document.getElementById("myEmail").value;
	message = document.getElementById("message").value;
	prelink = document.getElementById("prelink").value;

	url = prelink + url + "?myName=" + myName + "&myEmail=" + myEmail + "&message=" + message + "&prelink=" + prelink;
	
	for (i=0; i<noofFields; i++)
	{
		/*if (i == 0)
		{
			nameForm = "name_" + i;
			nameValue = document.getElementById(nameForm).value;
			emailForm = "email_" + i;
			emailValue = document.getElementById(emailForm).value;
			url = url + "?name_" + i + "=" + nameValue + "&email_" + i + "=" + emailValue;
		}*/
		//else
		//{
			nameForm = "name_" + i;
			nameValue = document.getElementById(nameForm).value;
			emailForm = "email_" + i;
			emailValue = document.getElementById(emailForm).value;
			url = url + "&name_" + i + "=" + nameValue + "&email_" + i + "=" + emailValue;
		//}
	}
	
	url = url + "&noofFields=" + noofFields;
	
	getContent1(url);
}

function getContent1(url)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged1
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("inviteArea").innerHTML=xmlHttp.responseText 
		document.getElementById("inviteloader").innerHTML="";
	} 
	else
	{
		//document.getElementById("inviteloader").innerHTML="<img id='orangeloader' src='lib/img/icons/orangeloader.gif'>";
		document.getElementById("inviteloader").innerHTML="<object id='orangeloader' width='50' height='50'><param name='movie' value='lib/img/icons/loaderTip.swf'><embed src='lib/img/icons/loaderTip.swf' width='50' height='50'></embed></object>";
	}
	/*if (xmlHttp.readyState=="complete")
	{
		alert('goats');
	}*/
}


function validateEmail(email)
{
	var patt = /(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/;
	if (patt.test(email))
	{
		return true;
	}
	else
	{
		return false;	
	}
}



function submitInfo2()
{
	language = document.getElementById("language").value;
	if (language == "en")
	{
		language = document.getElementById("country").value;
	}
	fname = document.getElementById("fname").value;

//	surname = document.getElementById("surname").value;
//	city = document.getElementById("city").value;

//	email = document.getElementById("email").value;
//	newsletter = document.getElementById("newsletter").checked;
	anonymous = document.getElementById("anonymous").checked;
	prelink = document.getElementById("prelink").value;
	
	user_hash = document.getElementById("user_hash").value;
	refererID = document.getElementById("refererID").value;
	polski = document.getElementById("polski").checked;
	
	if (polski == true) {polishcheck = 1;} else {polishcheck = 0}
	
//	if (newsletter == true) {newsletter = 1;} else {newsletter = 0}
	if (anonymous == true) {anonymous = 1;} else {anonymous = 0}
	
//	url = "insertMan.php?language=" + language + "&fname=" + fname + "&email=" + email + "&newsletter=" + newsletter + "&anonymous=" + anonymous;	
	url = prelink + "insertMan.php?language=" + language + "&fname=" + fname + "&anonymous=" + anonymous + "&user_hash=" + user_hash + "&refererID=" + refererID + "&polishcheck=" + polishcheck + "&prelink=" + prelink;
	getContent2(url);
	dcsMultiTrack('DCS.dcsuri', 'manifesto_signed.htm', 'WT.ti', 'Manifesto signed');

}

function getContent2(url)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged2
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("manifesto").innerHTML=xmlHttp.responseText;
		
		//function tb_show('', '#TB_inline?height=476&width=735&inlineId=popup1', '');
		//tb_show("success,bravo","#TB_inline?height=476&width=735&inlineId=popup1"); 
	} 
}


function submitQ()
{
	question = document.getElementById("question").value;
	prelink = document.getElementById("prelink").value;
	
	question = question.replace(/\n/g, "<br>");
	
	firstName = document.getElementById("firstName").value;
	email = document.getElementById("email").value;
	
	url = prelink + "sendQ.php?question=" + question + "&firstName=" + firstName + "&email=" + email;

	getContent3(url);
}

function getContent3(url)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged3
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("qHolder").innerHTML=xmlHttp.responseText
	} 
}

function selectNoCo(noofrows, prelink)
{
	topicId = document.getElementById("topicId").value;
	month = document.getElementById("month").value;
	document.getElementById("noofrows").value = noofrows;
	url = prelink + "comment.php?page=0&nr=" + noofrows + "&topicId=" + topicId + "&month=" + month + "&prelink=" + prelink;
	//alert(url);
	getContent(url);
}

function selectMonth(month, prelink)
{
	topicId = document.getElementById("topicId").value;
	noofrows = document.getElementById("noofrows").value;
	document.getElementById("month").value = month
	url = prelink + "comment.php?page=0&nr=" + noofrows + "&topicId=" + topicId + "&month=" + month + "&prelink=" + prelink;
	//alert(url);
	getContent(url);
}

function report(page, noofrows, topicId, month, reportCommentId, prelink)
{
	url = prelink + "comment.php?page=" + page + "&nr=" + noofrows + "&topicId=" + topicId + "&month=" + month + "&reportCommentId=" + reportCommentId + "&prelink=" + prelink;
	getContent(url);
}

function reportBlog(page, noofrows, topicId, month, reportCommentId, prelink)
{
	url = prelink + "blogcomment.php?page=" + page + "&nr=" + noofrows + "&topicId=" + topicId + "&month=" + month + "&reportCommentId=" + reportCommentId + "&prelink=" + prelink;
	getContent5(url);
}

function trim(str)
{
	if (str.charAt(0) == " ")
	{
		str = trim(str.substring(1));	
	}
	if (str.charAt(str.lenght-1) == " ")
	{
		str = trim(str.substring(0, str.lenght-1));	
	}
	return str;
}

var t;

function scrollUp() 
{
    var y = document[getDocElName()].scrollTop;
    if (y > 500)
	{
        window.scrollBy(0,-20);
        t=setTimeout('scrollUp()',1);
    }
    else 
	{
		clearTimeout(t);
		fadetoview(0);
	}

    return false;
}

function getDocElName()
{
    if(document.compatMode && document.compatMode == "CSS1Compat")
	{
        return "documentElement";
    }
    else
	{
        return "body";
    }
}


function fadetoview(j)
{
	if (j<=100)
	{
		var obj=document.getElementById('first').style;
		obj.filter = "alpha(opacity=" + j + ")";
		obj.opacity = j / 100;
		obj.MozOpacity = j / 100;
		obj.KhtmlOpacity = j / 100;
			
		setTimeout(function() { fadetoview(j+5) }, 70);
	}
}


function getContent4(url)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged4;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged4() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		strJS = "$('.q div:not(:first)').hide();" +
				"$('.q p.published:not(:first)').hide();" +
				"$('.q:first').addClass('active');" +

				"$('.q a.headline').click(function(){" +
				"$('.q div:visible').hide();" +
				"$('.q p.published:visible').hide();" +
				"$('.q:visible').removeClass('active');" +	
				"$(this).next('div').fadeIn();" +
				"$(this).prev('p').show();"	+
				"$(this).parent('.q').addClass('active');" +
				"return false;" +
				"})";
		
		document.getElementById("qaa").innerHTML=xmlHttp.responseText + eval(strJS);
	}
}

function makeSearch(value, e)
{
	if(e.keyCode == 13)
	{
		url = "showQ.php?search=" + value;
		getContent4(url);
	}
}

function submitBlogComment()
{
	botkiller = document.getElementById("botkiller").value;
	noofrows = document.getElementById("noofrows").value;
	topicId = document.getElementById("topicId").value;
	name = document.getElementById("name").value;
	heading = document.getElementById("heading").value;
	comment = document.getElementById("comment").value;
	prelink = document.getElementById("prelink").value;
	
	comment = comment.replace(/\n/g, "<br>");
	
	document.getElementById("name").value = "";
	document.getElementById("heading").value = "";
	document.getElementById("comment").value = "";
	document.getElementById("checkbox").checked = false
	
	url = prelink + "insertBlogCom.php?page=0&nr=" + noofrows + "&topicId=" + topicId + "&name=" + name + "&heading=" + heading + "&comment=" + comment + "&prelink=" + prelink;
	
	if (botkiller.length == 0) {
		getContent5(url);
	}
}

function getContent5(url)
{
	url = url + "&month=" + document.getElementById("date").value;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged5;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged5() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("blogcommentArea").innerHTML=xmlHttp.responseText 
	} 
}

function selectBlogMonth(month, prelink)
{
	topicId = document.getElementById("topicId").value;
	noofrows = document.getElementById("noofrows").value;
	document.getElementById("month").value = month
	url = prelink + "blogcomment.php?page=0&nr=" + noofrows + "&topicId=" + topicId + "&month=" + month + "&prelink=" + prelink;
	//alert(url);
	getContent5(url);
}

function selectBlogNoCo(noofrows, prelink)
{
	topicId = document.getElementById("topicId").value;
	month = document.getElementById("month").value;
	document.getElementById("noofrows").value = noofrows;
	url = prelink + "blogcomment.php?page=0&nr=" + noofrows + "&topicId=" + topicId + "&month=" + month + "&prelink=" + prelink
	//alert(url);
	getContent5(url);
}

function unwantedError(strText)
{
		strText = strText.toLowerCase();
		var error = false;
		
		var unwanted = new Array('vattenfall', 'kol', 'kolkraft', 'kolkraftverk');
		for (i in unwanted)
		{
			if (strText.indexOf(unwanted[i]) != -1)
			{
				if ((strText.charAt(strText.indexOf(unwanted[i])-1) == "" && strText.charAt(strText.indexOf(unwanted[i])+unwanted[i].length) == "") || (strText.charAt(strText.indexOf(unwanted[i])-1) == " " && strText.charAt(strText.indexOf(unwanted[i])+unwanted[i].length) == " ") || (strText.charAt(strText.indexOf(unwanted[i])-1) == "" && strText.charAt(strText.indexOf(unwanted[i])+unwanted[i].length) == " ") || (strText.charAt(strText.indexOf(unwanted[i])-1) == " " && strText.charAt(strText.indexOf(unwanted[i])+unwanted[i].length) == ""))
				{
					error = true;
				}
			}
		}
		
		return error;
}





