carouselArray = new Array();
var browserSuffix = "";
var langSuffix = "";
if (($.browser.msie == true) && (Math.floor($.browser.version) < 7)) {
	browserSuffix = "_ie";
}

$.post("getLang.php", function(data) {
		if (data.length > 0) {
			langSuffix = "_"+data;
		}
		if (data == "eng") {
			langSuffix = "";
		}
		if (browserSuffix == "_ie") {
			carouselArray[0] = "url('pictures/main1"+browserSuffix+langSuffix+".jpg')";
			carouselArray[1] = "url('pictures/main2"+browserSuffix+langSuffix+".jpg')";
			carouselArray[2] = "url('pictures/main3"+browserSuffix+langSuffix+".jpg')";
			carouselArray[3] = "url('pictures/main4"+browserSuffix+langSuffix+".jpg')";
			carouselArray[4] = "url('pictures/main5"+browserSuffix+langSuffix+".jpg')";
		}
	}
);
//alert("langSuffix: "+langSuffix);
carouselArray[0] = "url('pictures/main1"+browserSuffix+langSuffix+".jpg')";
carouselArray[1] = "url('pictures/main2"+browserSuffix+langSuffix+".jpg')";
carouselArray[2] = "url('pictures/main3"+browserSuffix+langSuffix+".jpg')";
carouselArray[3] = "url('pictures/main4"+browserSuffix+langSuffix+".jpg')";
carouselArray[4] = "url('pictures/main5"+browserSuffix+langSuffix+".jpg')";
carouselCounter = 1;
carouselCounterLimit = 4;
carouselInterval = 8000;

function News(){
	$.get("news.php", function(data) {
		var loc = window.location.href;
		var pos = loc.lastIndexOf("/");
		loc = loc.substring(0, pos+1);
		$("#news").html(data);
		$("#news").css("behavior", "url('"+loc+"scripts/iepngfix/iepngfix.htc')");
	});
}

function ShowNewsDetail(id, type) {
	$("#newsDetail").show();
	var postData = { 'newsId': id }
	$.post("readNews.php",
		postData,
		function(data) {
			if (data == "ERROR") {
			} else {
				$('#newsDetail').html(data);
				if (type == 1) {
					$('#newsDetail').css('background-image', 'url(pictures/news_detail.png)');
					$('#newsDetail').css('border', '1px solid darkgreen');
					$('#newsDetailSeparator').css('border', '1px solid darkgreen');
				} else {
					$('#newsDetail').css('background-image', 'url(pictures/news_detail_gray.png)');
					$('#newsDetail').css('border', '1px solid gray');
					$('#newsDetailSeparator').css('border', '1px solid gray');
				}
				$('#newsDetail').css('left', ($('#mainContentPictureOuter').position().left + 20 + 'px'));
				$('#newsDetail').css('top', ($('#mainContentPictureOuter').position().top + 20 + 'px'));
				$('#newsDetail').css('width', ($('#mainContentPictureOuter').width() + 70 + 'px'));
				$('#newsDetail').css('height', ($('#mainContentPictureOuter').height() - 100 + 'px'));
			}
		}
	);
}

function HideNewsDetail() {
	$("#newsDetail").hide();
}

function showFeedback() {
	$("#fbFormLabelWF").css("display", "block");
	$("#fbContentLabelWF").css("display", "block");
	$("#fbFormLabelPI").css("display", "none");	
	$("#fbContentLabelPI").css("display", "none");
	$("#fbProductLabel").css("display", "none");
	$("#fbProductName").css("display", "none");
	$("#fbContentLabel").html("I want more information about ... *");
	$("#fbFormLabel").html("Your questions & comments");
	$("#feedback").css("display", "block");
	$("#feedback").css("left", ($("#moreInfo").offset().left-325)+"px");
	$("#feedback").css("top", ($("#moreInfo").offset().top+5)+"px");
}

function hideFeedback() {
	$("#feedback").css("display", "none");
}

function resetFeedback() {
	$("#fbFormLabelWF").css("display", "block");
	$("#fbContentLabelWF").css("display", "block");
	$("#fbFormLabelPI").css("display", "none");	
	$("#fbContentLabelPI").css("display", "none");
	$("#fbProductLabel").css("display", "none");
	$("#fbProductName").css("display", "none");
	$("#fbContentLabel").html("I want more information about ... *");
	$("#fbFormLabel").html("Your questions & comments");
	$("#feedback").css("display", "none");
	$("#feedbackContent").css("background-color", "white");
	$("#feedbackOrg").css("background-color", "white");
	$("#feedbackEmail").css("background-color", "white");
	$("#feedbackName").css("background-color", "white");
	$("#feedbackContent").val("");
	$("#feedbackOrg").val("");
	$("#feedbackEmail").val("");
	$("#feedbackName").val("");
}

function validateFeedback() {
	$("#feedbackContent").css("background-color", "white");
	$("#feedbackOrg").css("background-color", "white");
	$("#feedbackEmail").css("background-color", "white");
	$("#feedbackName").css("background-color", "white");
	if ((jQuery.trim($("#feedbackName").val()) == "") || (jQuery.trim($("#feedbackEmail").val()) == "") || (jQuery.trim($("#feedbackOrg").val()) == "") || (jQuery.trim($("#feedbackContent").val())) == ""){
		if (jQuery.trim($("#feedbackName").val()) == "")
				$("#feedbackName").css("background-color", "red");
		if (jQuery.trim($("#feedbackEmail").val()) == "")
				$("#feedbackEmail").css("background-color", "red");
		if (jQuery.trim($("#feedbackOrg").val()) == "")
				$("#feedbackOrg").css("background-color", "red");
		if (jQuery.trim($("#feedbackContent").val()) == "")
				$("#feedbackContent").css("background-color", "red");
		return false;
	}
	return true;
}

function sendFeedback() {
	if (validateFeedback() == true) {
		var postData = { 'fbUserName': 'Web page guest', 'fbType': 'WF', 'fbName': $("#feedbackName").val(), 'fbOrganization': $("#feedbackOrg").val(), 'fbEmail': $("#feedbackEmail").val(), 'fbMessage': $("#feedbackContent").val() }
		$.post("http://www.qprojects.fi/vip/sendFeedback.php",
				postData,
				function(data) {
			if (data == "OK") {
				resetFeedback();
			} else {
				alert("Error occured, please try later or send standard email to qp@qp.fi");
			}
		}
		);
	} else {
//		alert("All fields marked with * are compulsory.");
	}
}
