    $(function() {
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			window.location = "http://www.autentik.rs/br_index.html";
		}
		if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x 
			window.location = "http://www.autentik.rs/br_index.html";
		}
		// Load counter script
		var date;
		var toDate;
		$("div.countdown").each(function(index) {
			date = $(this).children('.countdown_value').html();
//			alert("-" + date + "-");
			if(date != null) {
				var showC = $(this).children(".show_countdown");
				var year = date.substring(0, 4);
				var month = Number(date.substring(4, 6)) - 1;
				var day = Number(date.substring(6, 8));
				toDate = new Date(year, month, day);
				$(this).children(".countdown_value").countdown({until: toDate, format: 'HMS', onTick: function(periods){
//					'dHMS'
//					var dDays = (periods[3] < 10)? "0" + periods[3]: periods[3]; 
//					var hHours = (periods[4] < 10)? "0" + periods[4]: periods[4]; 
					var hHours = (periods[4] < 100)? ((periods[4] < 10)?"00" + periods[4]: "0" + periods[4]): periods[4]; 
					var mMins = (periods[5] < 10)? "0" + periods[5]: periods[5]; 
					var sSecs = (periods[6] < 10)? "0" + periods[6]: periods[6]; 
					showC.html(hHours + '<span style="font-size: .7em">h</span> ' + mMins + '<span style="font-size: .7em">m</span> ' + sSecs + '<span style="font-size: .7em">s</span>');
					}			
				});
			}
		});
		
		$('#header .open-hidden').click( function() {
//			$('.hidden').toggle('slow', 'swing');
			$('.hidden').slideToggle('slow');
		});
		$('.cities .hide').click( function() {
//			$('.hidden').hide('slow');
			$('.hidden').slideToggle('slow');
		});
		
		$("#gallery a").lightBox();
		$('form').jqTransform({imgPath:'jss/jqtransform/img/'});
		
	});
	function show_payment(id) {
		$("ul#payment_option li").removeClass("selected");
		$("ul#payment_option li#option_link_" + id).addClass("selected");
		$("div#payment_form > div").slideUp(500);
		$("div#payment_form div#payment_" + id).slideDown(700);
	}
	function show_formFields() {
		var how_much = $("#qty").val();
		if (how_much >= 1) {
			$("#gifts_for_users > div").hide();
			for (counter=1;counter<=how_much;counter++) {
				$("#box_id_"+counter).show();
			}
		}
	}
	/*
		Function for displaying total price
	*/
	function FormatNumberBy3(num, decpoint, sep) {
	  // check for missing parameters and use defaults if so
	  if (arguments.length == 2) {
		sep = ",";
	  }
	  if (arguments.length == 1) {
		sep = ",";
		decpoint = ".";
	  }
	  // need a string for operations
	  num = num.toString();
	  // separate the whole number and the fraction if possible
	  a = num.split(decpoint);
	  x = a[0]; // decimal
	  y = a[1]; // fraction
	  z = "";
	  if (typeof(x) != "undefined") {
		// reverse the digits. regexp works from left to right.
		for (i=x.length-1;i>=0;i--)
		  z += x.charAt(i);
		// add seperators. but undo the trailing one, if there
		z = z.replace(/(\d{3})/g, "$1" + sep);
		if (z.slice(-sep.length) == sep)
		  z = z.slice(0, -sep.length);
		x = "";
		// reverse again to get back the number
		for (i=z.length-1;i>=0;i--)
		  x += z.charAt(i);
		// add the fraction back in, if it was there
		if (typeof(y) != "undefined" && y.length > 0)
		  x += decpoint + y;
	  }
	  return x;
	}
	function calculate_price(price) {
		qty = $("#qty").val();
		// Convert price to number format that javascript understand
		price = price.replace(',', '.');
		// Calculate total price
		var total_price = qty*price;
		total_price += ''; // cast to string
		// Check if our result contains decimal
		var dpos = total_price.indexOf('.');
		if (dpos != -1) {
			total_price *= 1; // cast to number
			total_price = total_price.toFixed(2);
		}		
		// Convert price to use coma for decimal spot
		total_price = total_price.replace('.', ',');
		// Fill toptal_price div with total price
		$('#total_price').html("<b>" + FormatNumberBy3(total_price, ",", ".") + " din</b>");
	}
	
	$(document).ready(function() {
		var submitForm = false;
		$(':button').click(function(){
			var name1 = $("#name1").val();
//			var lastname1 = $("#lastname1").val();
			var adresa1 = $("#adresa1").val();
			var grad1 = $("#grad1").val();
			var zip1 = $("#zip1").val();
			var name3 = $("#name3").val();
//			var lastname3 = $("#lastname3").val();
			var adresa3 = $("#adresa3").val();
			var grad3 = $("#grad3").val();
			var zip3 = $("#zip3").val();
			var SubType = $(this).attr("name");
			$('#payment_type').val(SubType);
			if ((SubType == "sub2")) {
				if (name1 == '') {
					alert(name1err);
				} else 
//				if (lastname1 == '') {
//					alert(lastname1err);
//				} else
				if (adresa1 == '') {
					alert(adresa1err);
				} else
				if (grad1 == '') {
					alert(grad1err);
				} else
				if (zip1 == '') {
					alert(zip1err);
				} else { submitForm = true; }
			} else
			if ((SubType == "sub4")) {
				if (name3 == '') {
					alert(name3err);
				} else 
//				if (lastname3 == '') {
//					alert(lastname3err);
//				} else
				if (adresa3 == '') {
					alert(adresa3err);
				} else
				if (grad3 == '') {
					alert(grad3err);
				} else
				if (zip3 == '') {
					alert(zip3err);
				} else { submitForm = true; }
			} else
			if ((SubType == "sub1")) {
				submitForm = true;
			} else
			if ((SubType == "sub3")) {
				submitForm = true;
			} else { submitForm = false; }
			
			if(submitForm == true){
				document.buy_form.submit();
			}
		}); 
//		$('#sub').click(function(){
//			alert("=" + $(this).attr("name"));
//		});
		
		$("#sub4").attr("disabled", "disabled");
		$("#terms3").removeAttr("checked");		
		$("#terms3").click(function() {
			var checked_status = this.checked;
			if (checked_status != true) {
				$("#sub4").removeAttr("disabled");
			} else {
				$("#sub4").attr("disabled", "disabled");
			}
		});
		$("#eSubmitttt").attr("disabled", "disabled");
		$("#rSubmittt").attr("disabled", "disabled");
		$("#cbAcceptTerms").removeAttr("checked");		
		$("#cbAcceptTerms").click(function() {
			var checked_status = this.checked;
			if (checked_status != true) {
				$("#rSubmittt").removeAttr("disabled");
			} else {
				$("#rSubmittt").attr("disabled", "disabled");
			}
		});
		
		
		$("#gifts_for_users > div").hide();
		$("#gifts_for_users > div:first").show();
		$("div#payment_form > div").hide();

		
		required = ["u_name", "u_lastname", "r_email", "r_code"];
		email = $("#r_email");
		errornotice = $("#error");
		$("#frmRegister").submit(function(){	
			//Validate required fields
			for (i=0;i<required.length;i++) {
				var input = $('#'+required[i]);
				if ((input.val() == "") || (input.val() == emptyerror)) {
					input.addClass("needsfilled");
					input.val(emptyerror);
//					errornotice.fadeIn(750);
				} else {
					input.removeClass("needsfilled");
				}
			}
			// Validate the e-mail.
			if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
				email.addClass("needsfilled");
				email.val(emailerror);
			}

			var hasError = false;
	        var passwordVal = $("#r_pass").val();
    	    var checkVal = $("#r_pass1").val();
        	if (passwordVal == '') {
            	$("#meter_pass_txt").css('color', '#f00');
            	$("#meter_pass_txt").html(rPassword);
	            hasError = true;
    	    } else if (checkVal == '') {
            	$("#pass2_err").css('color', '#f00');
        	    $("#pass2_err").html(rPassword1);
            	hasError = true;
	        } else if (passwordVal != checkVal ) {
            	$("#pass2_err").css('color', '#f00');
    	        $("#pass2_err").html(rPassword2);
        	    hasError = true;
	        }
    	    if(hasError == true) {return false;}
			else {
            	$("#pass2_err").css('color', '#0c3');
            	$("#pass2_err").html(rPassword3);
			}
			
			if ($(":input").hasClass("needsfilled")) {
				return false;
			} else {
//				errornotice.hide();
				return true;
			}
		});
		$(":input").focus(function(){		
		   if ($(this).hasClass("needsfilled") ) {
				$(this).val("");
				$(this).removeClass("needsfilled");
		   }
		});


		var OSX = {
			container: null,
			init: function () {
				$("#osx-modal-content").modal({
					overlayId: 'osx-overlay',
					containerId: 'osx-container',
					closeHTML: null,
					minHeight: 80,
					opacity: 65, 
					position: ['0',],
					overlayClose: false,
					onOpen: OSX.open,
					onClose: OSX.close
				});
			},
			open: function (d) {
				var self = this;
				self.container = d.container[0];
				d.overlay.fadeIn('fast', function () {
					$("#osx-modal-content", self.container).show();
					var title = $("#osx-modal-title", self.container);
					title.show();
					d.container.slideDown('fast', function () {
						setTimeout(function () {
							var h = $("#osx-modal-data", self.container).height()
								+ title.height()
								+ 20; // padding
							d.container.animate(
								{height: h}, 
								200,
								function () {
									$("div.close", self.container).show();
									$("#osx-modal-data", self.container).show();
								}
							);
						}, 300);
					});
				})
			},
			close: function (d) {
				jQuery.cookie("ATNK-"+"Cookie", "visited", { path: '/'});
				var self = this; // this = SimpleModal object
				d.container.animate(
					{top:"-" + (d.container.height() + 20)},
					100,
					function () {
						self.close(); // or $.modal.close();
					}
				);
			}
		};
		if(jQuery.cookie("ATNK-"+"Cookie")==null && jQuery.cookie("ATNK-"+"Cookie")==null) OSX.init();  //
		$('#autentikpopup').click(function(){
//			AutentikPopupShow();
//			alert("Juuuuuuhuuu!!!");
			OSX.init();
		});
	
	
	});
function addAutentikCookie(){
	jQuery.cookie("ATNK-" + "Cookie", "visited", { path: '/', expires: 7 });
}

function formCheck() {
	if (document.data['u_name'].value == "") {
    	alert(rIme);
	    document.data['u_name'].focus();
    	return false;
	}
	if (document.data['u_lastname'].value == "") {
    	alert(rPrezime);
	    document.data['u_lastname'].focus();
    	return false;
	}
	if (document.data['user'].value.indexOf("@") < 1 || document.data['user'].value.indexOf(".") < 1 || document.data['user'].value.length < 6) {
	    alert(rEmail);
    	document.data['user'].focus();
	    return false;
	}
	if (document.data['password'].value == "") {
    	alert(rPassword);
	    document.data['password'].focus();
    	return false;
	}
	if (document.data['pass1'].value == "") {
    	alert(rPassword1);
	    document.data['pass1'].focus();
    	return false;
	}
	if (document.data['code'].value == "") {
    	alert(rCaptcha);
	    document.data['code'].focus();
    	return false;
	}
}


var valSecure = 0;
function Password_check(obj) {
  valSecure = 0;
  if (obj.value.match(/[a-z]/)) {//jedno malo slovo
    valSecure++;
  }                         
  if (obj.value.match(/[A-Z]/)) {//jedno veliko slovo
    valSecure++;
  }  
  if (obj.value.match(/\d+/)) {//bar jedan broj
    valSecure++;
  }
  if (obj.value.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {//velika i mala slova
    valSecure+=3;
  }
  if (obj.value.match(/(\d.*\D)|(\D.*\d)/)) {//velika, mala slova i bar jos jedan karakter :)
    valSecure+=3;
  }
  if (obj.value.length == 0) {
    valSecure = 0;
  } else if (obj.value.length <= 4) {
    valSecure=1;
  } else if (obj.value.length <= 7) {
    valSecure=2;
  } else {
    valSecure += 4;
  }
  setPasswordMeter(valSecure);
}


var initColor = new Array(208,16);//color -> worst
var endColor = new Array(16,208);//color -> best
var Komponenta3 = 16;

var coefColor = 13; //maksimalna vrednost
function setPasswordMeter(refColor) {
  var rgbColor = new Array();
  rgbColor = getColor(refColor);
  document.getElementById("meter_pass").style.backgroundColor = "rgb("+ rgbColor[0] +"," + rgbColor[1] + "," + Komponenta3 + ")";
  document.getElementById("meter_pass").style.width = getMeterProc(refColor, coefColor) + "%";
  document.getElementById("meter_pass_txt").innerHTML = secureMsg[Math.ceil(refColor/coefColor*(secureMsg.length-1))];
  document.getElementById("meter_pass_txt").style.color = "rgb("+ rgbColor[0] +"," + rgbColor[1] + "," + Komponenta3 + ")";
}
var maxMeter = 2; //maksimalna vrednost
function setStandardMeter(refMeter) {
  var rgbColor = new Array();
  rgbColor = getColor(refMeter);
  document.getElementById("cipee_meter").style.backgroundColor = "rgb("+ rgbColor[0] +"," + rgbColor[1] + "," + Komponenta3 + ")";
  document.getElementById("cipee_meter").style.width = getMeterProc(refMeter, maxMeter) + "%";
}
function getMeterProc(value, maxValue){
	return Math.round(100*value/maxValue);
}
function getColor(coef) {
  var diffr = 0;
  var diffg = 0;
  var tabResult = new Array(0,0);
  var coefV1 = 1;
  var coefV2 = 1;
  if (endColor[0]>=initColor[0]) {
    diffr = endColor[0] - initColor[0];
    coefV1 = 1;
  } else {
    diffr = initColor[0] - endColor[0];
    coefV1 = -1;
  }
  if (endColor[1]>=initColor[1]) {
    diffg = endColor[1] - initColor[1];
    coefV2 = 1;
  } else {
    diffg = initColor[1] - endColor[1];
    coefV2 = -1;
  }
  var diffTotal = diffr + diffg;
  var v1 = diffTotal*coef/coefColor;
  if (initColor[0]>endColor[0]) {
    if (v1<=diffr) {
      tabResult[0] = Math.round(initColor[0]);
      tabResult[1] = Math.round(initColor[1]-(v1*coefV1));
    } else {
      tabResult[0] = Math.round(initColor[0]-(v1*coefV2)+(diffr*coefV2));
      tabResult[1] = Math.round(endColor[1]);
    }
  } else {
    if (v1<=diffr) {
      tabResult[0] = Math.round(initColor[0]+(v1*coefV1));
      tabResult[1] = Math.round(initColor[1]);
    } else {
      tabResult[0] = Math.round(endColor[0]);
      tabResult[1] = Math.round(initColor[1]+(v1*coefV2)-(diffr*coefV2));
    }
  }
  return tabResult;
}
