// JavaScript Document


	var samoBrojke = /[1234567890]/g;
	var samoBrojkeTocka = /[0-9\.]/g;
	var samoSlova = /[a-z A-Z ŠĐČĆŽ šđčćž]/g;
	
		var samoBrojkeTockaZarez = /[0-9\.\,]/g;
	
	

	function restrictCharacters(myfield, e, restrictionType) {
		if (!e) var e = window.event
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		var character = String.fromCharCode(code);
	
		
		// if they pressed esc... remove focus from field...
		if (code==27) { this.blur(); return false; }
	
		
	
		// ignore if they are press other keys
		// strange because code: 39 is the down key AND ' key...
		// and DEL also equals .
		if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
			
			if (character.match(restrictionType)) {
					
					
						
						
				
					//zabrana unosa dvije točke
					if(myfield.value.indexOf(".") != -1 && code == 46){
						return false;
					}
					
					
				
					
									
				return true;
			
			} else {
				
				
				
				
				if(restrictionType == '/[a-z A-Z ŠĐČĆŽ šđčćž]/g'){
					//moguć unos šđčćž ako je 'samoSlova"; 
					if(code == 219 || code == 220 || code == 221 || code == 222 || code == 186){
						return true;
					}
					
				}
				
				
				
				
				return false;
			}
			
			
			
			
	
		}
	}
	
	
	
	
	var zabranjeniZnakovi_1 = '&#\\%';
	///////////////////////////////////// nedozvoljeni znakovi ... upisuje se sve osim navedenih znakova////////////////////////////////////
	function nedozvoljeniCharacters(myfield, e, zabranjeniZnakovi) {
		
		if (!e) var e = window.event
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		var character = String.fromCharCode(code);

			
			if (zabranjeniZnakovi.indexOf(character)!=-1) {
				return false;
			
			} 
			else{
								
				return true;
			}
			

	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function VrijednostIfEmpty(polje,vrijednost){
		
		if(polje.value==''){
			polje.value=vrijednost;
		}
		
	}

   
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
	function isNumeric2(x) {
	// I use this function like this: if (isNumeric(myVar)) { }
	// regular expression that validates a value is numeric
	var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452.
	
	// compare the argument to the RegEx
	// the 'match' function returns 0 if the value didn't match
	var result = x.match(RegExp);
	return result;
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
   
   function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

   
   
   
   
   
   
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
   
   function formatCurrency(num) {
			num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
			if(cents<10)
			cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '' + num + '.' + cents);
		}
/////////////////////////////////////////////////////////////// ajax stuff /////////////////////////////////////////////////////////////////////////////////////

		function GetXmlHttpObject(){
			//za provjeru ajax
			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 writeHTML(req, kojiDiv) {
			document.getElementById(kojiDiv).innerHTML = req.responseText;
		}
		
//////////////////////////////////////////////////////////////////////////////
		
		
function validate_EMAIL(form_id,poruka) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById(form_id).value;
   if(reg.test(address) == false) {
      alert(poruka);
      return false;
   }
   else{
   return true;
   }
}
/////////////////////////////////////////////////////////////////////////////////////////


function validacijaKartice(type,ccnum) {
		  
		  
		   if (type == "VISA") {
			  var re = /^(4[0-9]{12}([0-9]{3})?)/;
		   } else if (type == "MASTERCARD") {
			 var re = /^(5[1-5][0-9]{14})/;
		   } else if (type == "AMEX") {
			  var re = /^(3[47][0-9]{13})/;
		   } else if (type == "DINERS") {
			  var re = /^(3(0[0-5]|[68][0-9])[0-9]{11})/;
		   }
		   
		   if (!re.test(ccnum)){
				return false;
				
		   }
		   
		   // Remove all dashes for the checksum checks to eliminate negative numbers
		   ccnum = ccnum.split("-").join("");
		   // Checksum ("Mod 10")
		   // Add even digits in even length strings or odd digits in odd length strings.
		   var checksum = 0;
		   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
			  checksum += parseInt(ccnum.charAt(i-1));
		   }
		   // Analyze odd digits in even length strings or even digits in odd length strings.
		   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
			  var digit = parseInt(ccnum.charAt(i-1)) * 2;
			  if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
		   }
		   if ((checksum % 10) == 0){
		   		
				return true;
		   }else{
		   		
				return false;
				
		   }
		}
		
		
////////////////////////////////////////////////////////////////////////////////////////////////////////




			function trim(str, chars) {
				return ltrim(rtrim(str, chars), chars);
			}
			
			function ltrim(str, chars) {
				chars = chars || "\\s";
				return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
			}
			
			function rtrim(str, chars) {
				chars = chars || "\\s";
				return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
			}
			
			/////////////////////////////////////////////////////////////////////////////////////



function zamjenaKaraktera(karakter){

var vrijednost = karakter;
								vrijednost = vrijednost.replace(/s777Finder/g,'š');
								vrijednost = vrijednost.replace(/z777Finder/g,'ž');
								vrijednost = vrijednost.replace(/d777Finder/g,'đ');
								vrijednost = vrijednost.replace(/c777Finder/g,'ć');
								vrijednost = vrijednost.replace(/c666Finder/g,'č');
								vrijednost = vrijednost.replace(/S777Finder/g,'Š');
								vrijednost = vrijednost.replace(/Z777Finder/g,'Ž');
								vrijednost = vrijednost.replace(/D777Finder/g,'Đ');
								vrijednost = vrijednost.replace(/C777Finder/g,'Ć');
								vrijednost = vrijednost.replace(/C666Finder/g,'Č');
								
								return vrijednost;


}
	
		
		
		
			///////////////////////***************
function zamjenaKarakteraKontra(karakter){

			var vrijednost = karakter;
								vrijednost = vrijednost.replace(/š/g,'s777Finder');
								vrijednost = vrijednost.replace(/ž/g,'z777Finder');
								vrijednost = vrijednost.replace(/đ/g,'d777Finder');
								vrijednost = vrijednost.replace(/ć/g,'c777Finder');
								vrijednost = vrijednost.replace(/č/g,'c666Finder');
								vrijednost = vrijednost.replace(/Š/g,'S777Finder');
								vrijednost = vrijednost.replace(/Ž/g,'Z777Finder');
								vrijednost = vrijednost.replace(/Đ/g,'D777Finder');
								vrijednost = vrijednost.replace(/Ć/g,'C777Finder');
								vrijednost = vrijednost.replace(/Č/g,'C666Finder');
												
												return vrijednost;
				
				
}