function changeprice(x) {
  var day = document.getElementById('day').value;
  var servicetype = document.getElementById('servicetype').value;
  var total = document.getElementById('total').value;
  var maney = document.getElementById('maney').value;
  var bannertype = document.getElementById('bannertype').value;
  if (document.getElementById('addsize').value != '') {
    servicetype = 4.80;
  }

$("#price").animate( { opacity: 0.2 } , 100, function() {

var price = ((Number(day) + Number(servicetype) + Number(bannertype) + Number(maney)) * Number(total)).toFixed(2);
var discounts = Number(price)+((30/100)*Number(price));

	document.getElementById('price').innerHTML = "<del>"+discounts.toFixed(2)+"<span style='color:#9BB70D;'>Ls</span></del> "+price;
//	document.getElementById('price').innerHTML = price;
	$("#price").animate( { opacity: 1.0 } , 400 );
});

}


//-------------------------------

$(document).ready(function() {

  $("#teaser").editable("/cgi-bin/edit.pl", {
    indicator: "<img src='/images/loading2.gif' alt='Loading' title='Loading'> <h2>"+langLoading+"...</h2>",
    type: 'textarea',
    submit: langSeve,
    cancel: langCansel,
    event: "dblclick",
    submitdata: function() {
      _method: "PUT";
      return {
        file: $("#teaser").attr("class"),
        pass: document.getElementById("pass").value
      };
    }
  });


  $("#feature").editable("/cgi-bin/edit.pl", {
    indicator: "<img src='/images/loading3.gif' alt='Loading' title='Loading'> <h3>"+langLoading+"...</h3>",
    type: 'textarea',
    submit: langSeve,
    cancel: langCansel,
    event: "dblclick",
    placeholder: "",
    submitdata: function() {
      _method: "PUT";
      return {
        file: $("#feature").attr("class"),
        pass: document.getElementById("pass").value
      };
    }
  });


  $("#bread").editable("/cgi-bin/edit.pl", {
    indicator: "<img src='/images/loading3.gif' alt='Loading' title='Loading'> <h3>"+langLoading+"...</h3>",
    type: 'textarea',
    submit: langSeve,
    cancel: langCansel,
    event: "dblclick",
    placeholder: "",
    submitdata: function() {
      _method: "PUT";
      return {
        file: $("#bread").attr("class"),
        pass: document.getElementById("pass").value
      };
    }
  });


  $("#content").editable("/cgi-bin/edit.pl", {
    indicator: "<img src='/images/loading.gif' alt='Loading' title='Loading'> <h3>"+langLoading+"...</h3>",
    type: 'textarea',
    submit: langSeve,
    cancel: langCansel,
    event: "dblclick",
    placeholder: "",
    submitdata: function() {
      _method: "PUT";
      return {
        file: $("#content").attr("class"),
        pass: document.getElementById("pass").value
      };
    }
  });

  var max = 0;
  $("label").each(function() {
    if ($(this).width() > max) max = $(this).width();
  });
  $("label").width(max);

  //-------------------------------
  $("#frmorder").validate({
    submitHandler: function(form) {
      form.submit();
      $(".button_calc_orange").attr("innerHTML", "<span>"+langLoading+"<\/span>");
      $("#order").animate( { opacity: 0.3 } , 400 );
    },
    rules: {
      username: {
        minlength: 3
      },
      website: {
        minlength: 4
      },
      addsize: {
        minlength: 3,
        maxlength: 7
      }
    },
    errorPlacement: function(error, element) {}
  });

});

//-------------------------------
function simple_tooltip(target_items, name) {
  $(target_items).each(function(i) {
    $("body").append("<div class='" + name + "' id='" + name + i + "'><p>" + $(this).attr('title') + "<\/p><\/div>");
    var my_tooltip = $("#" + name + i);

    $(this).removeAttr("title").mouseover(function() {
      my_tooltip.css({
        opacity: 0.8,
        display: "none"
      }).fadeIn(400);
    }).mousemove(function(kmouse) {
      my_tooltip.css({
        left: kmouse.pageX - 30,
        top: kmouse.pageY + 20
      });
    }).mouseout(function() {
      my_tooltip.fadeOut(400);
    });
  });
}
$(document).ready(function() {
  simple_tooltip(".help", "tooltip");
});

function loadpage(page, who) {
window.location.href = "#teaser";

var teaser = '';
if (who == 'teaser') { teaser = '2'; }

  document.getElementById(who).innerHTML = '<img title="Loading" alt="Loading" src="/images/loading'+teaser+'.gif" width="32" height="32"> <h3>'+langLoading+'...</h3>';

$.ajax({
  url: "data/" + page,
  cache: false,
  success: function(html){
document.getElementById(who).innerHTML = '';
   //var html = html.replace(/\[/g, "<").replace(/\]/g, ">");

    $("#"+who).append(html);
 //$('#chat_box').append(data.show("slide", {direction: "down"},"1000"));
document.getElementById(who).className = page;
window.location.href = "#"+page;
  }
});


}

//-------------------------------
function get(obj) {
  $.ajax({
    type: "POST",
    url: "/cgi-bin/post.pl",
//  data: "username=" + encodeURI(document.getElementById('username').value) + "&email=" + encodeURI(document.getElementById('email').value) + "&website=" + encodeURI(document.getElementById('website').value) + "&servicetype=" + encodeURI(document.getElementById('servicetype').options[document.getElementById('servicetype').selectedIndex].text) + "&addsize=" + encodeURI(document.getElementById('addsize').value) + "&bannertype=" + encodeURI(document.getElementById('bannertype').options[document.getElementById('bannertype').selectedIndex].text) + "&total=" + encodeURI(document.getElementById('total').options[document.getElementById('total').selectedIndex].text) + "&messages=" + encodeURI(document.getElementById('messages').value) + "&day=" + encodeURI(document.getElementById('day').options[document.getElementById('day').selectedIndex].text) + "&maney=" + encodeURI(document.getElementById('maney').options[document.getElementById('maney').selectedIndex].text) + "&lang=" + encodeURI(document.getElementById('lang').value),
    data: "username=" + document.getElementById('username').value + "&email=" + document.getElementById('email').value + "&website=" + document.getElementById('website').value + "&servicetype=" + document.getElementById('servicetype').options[document.getElementById('servicetype').selectedIndex].text + "&addsize=" + document.getElementById('addsize').value + "&bannertype=" + document.getElementById('bannertype').options[document.getElementById('bannertype').selectedIndex].text + "&total=" + document.getElementById('total').options[document.getElementById('total').selectedIndex].text + "&messages=" + document.getElementById('messages').value + "&day=" + document.getElementById('day').options[document.getElementById('day').selectedIndex].text + "&maney=" + document.getElementById('maney').options[document.getElementById('maney').selectedIndex].text + "&lang=" + document.getElementById('lang').value,
    success: function(msg) {
      document.getElementById("frmorder").innerHTML = msg;
    }
  });
}

window.onload = function() {
var url=window.location.href.split("#");
//var slength=window.location.search.length;
//alert(slength);
if (url[1] != null) {
loadpage(url[1],'content');
}

if ($.browser.msie && $.browser.version <= 6) {
$("body").append("<div class=\"error\"><h2>Error<\/h2>For a complete site work. Install a new version Internet Explorer browser.<\/div>");
}
}


//-------------------------------
jQuery.extend({
    csv: function(delim, quote, linedelim) {
        delim = typeof delim == "string" ? new RegExp( "[" + (delim || ","   ) + "]" ) : typeof delim == "undefined" ? ","    : delim;
        quote = typeof quote == "string" ? new RegExp("^[" + (quote || '"'   ) + "]" ) : typeof quote == "undefined" ? '"'    : quote;
        lined = typeof lined == "string" ? new RegExp( "[" + (lined || "\r\n") + "]+") : typeof lined == "undefined" ? "\r\n" : lined;

        function splitline (v) {
            // Split the line using the delimitor
            var arr  = v.split(delim),
                out = [], q;
            for (var i=0, l=arr.length; i<l; i++) {
                if (q = arr[i].match(quote)) {
                    for (j=i; j<l; j++) {
                        if (arr[j].charAt(arr[j].length-1) == q[0]) { break; }
                    }
                    var s = arr.slice(i,j+1).join(delim);
                    out.push(s.substr(1,s.length-2));
                    i = j;
                }
                else { out.push(arr[i]); }
            }

            return out;
        }

        return function(text) {
            var lines = text.split(lined);
            for (var i=0, l=lines.length; i<l; i++) {
                lines[i] = splitline(lines[i]);
            }
            return lines;
        };
    }
});

function loadCSVFile(files)
{
$('.tableContent').find("tr:gt(-1)").remove();
//$('button').append("<tr><td style='width:100px;text-align:left'><img title='Loading' alt='Loading' src='/images/loading.gif' width='32' height='32'></td></tr>");

$.post(files+'.csv', function(data) { 
	array = $.csv() (data); 

var startitem='0';

	$.each(array, function() {
			var row = String(this).split(";");
			if (row[0] != "") {
			   if (startitem == '0') {
			     $('.tableContent').append("<tr><td colspan=11><b><a style=color:#444141 href="+files+".csv>&#1057;&#1082;&#1072;&#1095;&#x430;&#x442;&#x44c;</a> &#x432;&#x435;&#x441;&#x44c; &#1072;&#x440;&#1093;&#x438;&#x432; (.csv)</b></tr></td>");
			     $('.tableContent').append("<tr><td style='width:100px;text-align:left'><b>" + row[0] + "</b></td><td><b>" + row[1] + "</b></td><td><b>" + row[2] + "</b></td><td><b>" + row[3] + "</b></td><td><b>" + row[4] + "</b></td><td><b>" + row[5] + "</b></td><td><b>" + row[6] + "</b></td><td><b>" + row[7] + "</b></td><td><b>" + row[8] + "</b></td><td><b>" + row[9] + "</b></td><td><b>" + row[10] + "</b></td></tr>");
			   } else {
			     $('.tableContent').append("<tr><td style='width:100px;text-align:left'>" + row[0] + "</td><td>" + row[1] + "</td><td><a href=http://"+row[2]+">" + row[2] + "</a></td><td><a href=\"#\" onclick=\"sendmail('"+row[3]+"', '"+row[1]+"','"+row[4]+row[5]+"')\">" + row[3] + "</a></td><td>" + row[4] + "</td><td>" + row[5] + "</td><td>" + row[6] + "</td><td class=\"komment\">" + row[7] + "</td><td>" + row[8] + "</td><td>" + row[9] + "</td><td><a href=http://show-ip.net/whois/?query=" + row[10] + ">" + row[10] + "</a></td></tr>");
			   } startitem++;
			}
		});
	$('.tableContent tr:odd').css('background-color', '#EAEADE');
	$('.tableContent').find("tr:eq(1)").css('background', '#EAEADE url(/images/sub_back.gif) repeat-x scroll center bottom');

$().ready(function() {  
 $('.tableContent tr td.komment').jTruncate();  
});  


	});

 $('#loading').fadeOut();

}


function sendmail(mail, author, type) {
  window.location.href = "mailto:" + mail + "?subject=%D0%94%D0%B8%D0%B7%D0%B0%D0%B9%D0%BD %D1%81%D1%82%D1%83%D0%B4%D0%B8%D1%8F Flaer.lv / Dizaina studija Flaer.lv / Design studio Flaer.lv&body=%D0%97%D0%B4%D1%80%D0%B0%D0%B2%D1%81%D1%82%D0%B2%D1%83%D0%B9%D1%82%D0%B5, "+author+".%0d%0d%0d%0d%0d%0dBanners: "+type+".";
}

//-------------------------------

//---------------------------------------
(function($){
	$.fn.jTruncate = function(options) {
	   
		var defaults = {
			length: 50,
			minTrail: 20,
			moreText: "more",
			lessText: "less",
			ellipsisText: "...",
			moreAni: "fast", 
			lessAni: "fast"

		};
		
		var options = $.extend(defaults, options);
	   
		return this.each(function() {
			obj = $(this);
			var body = obj.html();
			
			if(body.length > options.length + options.minTrail) {
				var splitLocation = body.indexOf(' ', options.length);
				if(splitLocation != -1) {
					// truncate tip
					var splitLocation = body.indexOf(' ', options.length);
					var str1 = body.substring(0, splitLocation);
					var str2 = body.substring(splitLocation, body.length - 1);
					obj.html(str1 + '<span class="truncate_ellipsis">' + options.ellipsisText + 
						'</span>' + '<span class="truncate_more">' + str2 + '</span>');
					obj.find('.truncate_more').css("display", "none");
					
					// insert more link
					obj.append(
						//'<div class="clearboth">' +
							' <a href="#" class="truncate_more_link">' + options.moreText + '</a>'
						// + '</div>'
					);

					// set onclick event for more/less link
					var moreLink = $('.truncate_more_link', obj);
					var moreContent = $('.truncate_more', obj);
					var ellipsis = $('.truncate_ellipsis', obj);
					moreLink.click(function() {
						if(moreLink.text() == options.moreText) {
							moreContent.show(options.moreAni);
							moreLink.text(options.lessText);
							ellipsis.css("display", "none");
						} else {
							moreContent.hide(options.lessAni);
							moreLink.text(options.moreText);
							ellipsis.css("display", "inline");
						}
						return false;
				  	});
				}
			} // end if
			
		});
	};
})(jQuery);