$(document).ready(function(){

		$("#apraksts").colorize({bgColor:'#202020', altColor:'#101010', hiliteColor:'none', hoverColor:'#606060', banRows:[1]});

});
//<!---------------------------------+
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
	$("#pietepasts").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Pārbauda...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("validmail.php",{ adrese:$(this).val() } ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Nepareizi ievadīts e-pasts!<br />Ja tomēr uzskatat ka ievadījāt pareizi<br />šo paziņojumu varat ignorēt.').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Derīga e-pasta adrese!').addClass('messageboxok').fadeTo(900,1);	
			});
		  }
				
        });
 
	});
});

$(function() {
		//$("#datepicker").datepicker({dateFormat: 'yy-mm-dd'});
		var dates = $( "#from, #to" ).datepicker({
			dateFormat: 'yy-mm-dd',
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 3,
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});

	});

$(document).ready(function() {
	$("#izstade").validationEngine({scroll:false})
})

$.fn.clearForm = function() {
  return this.each(function() {
  var type = this.type, tag = this.tagName.toLowerCase();
  if (tag == 'form')
    return $(':input',this).clearForm();
  if (type == 'text' || type == 'password' || tag == 'textarea')
    this.value = '';
  else if (type == 'checkbox' || type == 'radio')
    this.checked = false;
	else if (tag == 'select')
  	this.selectedIndex = -1;
   });
};

$(function() {
$(".addcom").click(function() {
var kid = $("#kid").val();
var name = $("#name").val();
var email = $("#email").val();
var komentars = $("#komentars").val();
var dataString = 'kid='+ kid + '&name=' + name + '&email=' + email + '&komentars=' + komentars;
if(kid=='' || name=='' || email=='' || komentars=='')
{
$('.successcom').fadeOut(200).hide();
$('.errorcom').fadeOut(200).show();
}
else
{
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "commentajax.php",
data: dataString,
success: function(){
$('.successcom').fadeIn(200).show();
$('.errorcom').fadeOut(200).hide();
$('#commentform').clearForm();
}
});
}
return false;
});
});

function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("pvards", "epasts", "ktel");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Vārds, Uzvārds", "E-pasts", "Kontakttālrunis");
	// dialog message
	var alertMsg = "Lūdzu aizpildiet sekojošus laukus:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

$(function () {
			
			$("#submitBtn1").formValidator({
				scope		: '#form-1',
				errorDiv	: '#errorDiv1'
			});

		});
