	/**
	 * Class
	 * 
	 * Calculator / Travel Health Insurance
	 * 
	 * This class contain method and parameters 
	 * for calculation of Travel Health Insurance
	 * 
	 * @author Marko Lecic / Eximius Solutions
	 */
	function calculatorTravelHealthIns()
	{
		// define class params
		
		// global
		this.durationDays 			= 0; 	// total duration of insurance / days
		this.sectorIns				= ''; 	// sector of insurance
		this.insType				= ''; 	// type of insurance
		this.insValue				= ''; 	// amount of insurance / set A, B or C option
		this.insRate				= 0; 	// insurance rate from DB
		this.insPersons				= 0; 	// number of persons
		
		this.totalPrice				= 0; 	// total amount of insurance
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Calculate total duration of insurance in days
		 * 
		 * @return none
		 */
		this.calcDaysDuration = function calcDaysDuration(){
		
			var dateFrom 	= document.getElementById('insDurationFrom').value;
			var dateTo 		= document.getElementById('insDurationTo').value;
						
			if( dateFrom != '' && dateTo != '' )
			{			
				var date1Arr = dateFrom.split('-');
				var date2Arr = dateTo.split('-');
				
				// date one
				var dateFromNew 	= new Date(date1Arr[2], date1Arr[1], date1Arr[0]);
				
				// date two
				var dateToNew 		= new Date(date2Arr[2], date2Arr[1], date2Arr[0]);
								
				// check if date value TO is bigger
				if( dateFromNew > dateToNew )
				{
					// disable elements
					document.getElementById('insSector').disabled 	= true;
					document.getElementById('insType').disabled 	= true;
					document.getElementById('insValue').disabled 	= true;
					
					$('#insDuration div.error').slideDown('normal');
					
					return false;
				}
				else
				{				
					// calculate
					var diff = new Date(dateToNew - dateFromNew);
	
					// get days
					var days = diff / 1000 / 60 / 60 / 24;
					
					// set duration days
					this.durationDays = days;
					
					// set input field value
					document.getElementById('insDurationDays').value = parseInt(days);
					
					// enable next element
					document.getElementById('insSector').disabled 	= false;
				}
			}
			
		}		
			
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set total duration of insurance in days / User input
		 * 
		 * @param days			= DAYS / user input
		 * @return none
		 */
		this.setUserDays = function setUserDays(days){
		
			this.durationDays = parseInt(days);
			
			if(this.durationDays != '' && !isNaN(this.durationDays) )
			{
				// enable next element
				document.getElementById('insSector').disabled 	= false;
			}
			else
			{
				// disable elements
				document.getElementById('insSector').disabled 	= true;
				document.getElementById('insType').disabled 	= true;
				document.getElementById('insValue').disabled 	= true;
			}
		}
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set sector of insurance / Fizicko lice
		 * 
		 * @return none
		 */
		this.setSectorFizicko = function setSectorFizicko(){
		
			var html = '<input type="radio" name="vrstaOsiguranja" onclick="calculatorTravelHealthIns.setInsType(this.value);" value="pojedinacno" /> Pojedinačno';
			html += '<br /><br />';
			
			html += '<input type="radio" name="vrstaOsiguranja" onclick="calculatorTravelHealthIns.setInsType(this.value);" value="porodicno" /> Porodično';
			html += '<br /><br />';
			
			html += '<input type="radio" name="vrstaOsiguranja" onclick="calculatorTravelHealthIns.setInsType(this.value);" value="grupno" /> Grupno';
			html += '<br /><br />';		
			
			this.sectorIns = 'fizicko';
			
			// enable next elements and set values
			document.getElementById('insType').disabled 		= false;
			document.getElementById('sectorHtml').innerHTML 	= html;
			
			// disable elements
			document.getElementById('insValue').disabled 	= true;
			
		}	
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set sector of insurance / Pravno lice
		 * 
		 * @return none
		 */
		this.setSectorPravno = function setSectorPravno(){
		
			var html = '<input type="radio" name="vrstaOsiguranja" onclick="calculatorTravelHealthIns.setInsType(this.value);" value="pojedinacno" /> Pojedinačno';
			html += '<br /><br />';
			
			html += '<input type="radio" name="vrstaOsiguranja" onclick="calculatorTravelHealthIns.setInsType(this.value);" value="grupno" /> Grupno';
			html += '<br /><br />';
			
			html += '<input type="radio" name="vrstaOsiguranja" onclick="calculatorTravelHealthIns.setInsType(this.value);" value="kolektivno" /> Kolektivno';
			html += '<br /><br />';		
			
			this.sectorIns = 'pravno';
			
			// enable next elements and set values
			document.getElementById('insType').disabled 		= false;
			document.getElementById('sectorHtml').innerHTML 	= html;
			
			// disable elements
			document.getElementById('insValue').disabled 	= true;
			
		}	
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set insurance type and enable next element
		 * 
		 * @param type = type of insurance
		 * @return none
		 */
		this.setInsType = function setInsType(type){
			
			// set type
			this.insType = type;
			
			// enable element
			document.getElementById('insValue').disabled 		= false;
			
		}
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set insurance value and enable additional elements
		 * *** amount of insurance
		 * 
		 * @param value = value of insurance
		 * @return none
		 */
		this.setInsValue = function setInsValue(value){
			
			// set value
			this.insValue = value; // amount of insurance
						
			// show additional fields
			switch( this.sectorIns )
			{
				case 'fizicko': 
					
					$('#pravnoVrstaSluzbenogPoravka').css('display', 'none');
					$('#insPersons').css('display', 'block');
					
					// call helper method to set ins rate
					this.insRate = this.callUrl(site_url + 'bs/calculatorPZO/calcPZORateFizicko/days/' + this.durationDays + '/sector/' + this.sectorIns + '/type/' + this.insType + '/value/' + this.insValue);
										
				break;
				
				case 'pravno': 
					
					$('#pravnoVrstaSluzbenogPoravka').css('display', 'block');
					$('#insPersons').css('display', 'block');
					
				break;
				
			}
						
		}
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set insurance rate for PRAVNA LICA
		 * 
		 * @param value = id of option
		 * @return none
		 */
		this.setInsRatePravna = function setInsRatePravna(value){
		
			if( value == 'izaberite' )
			{
				$('#pravnoVrstaSluzbenogPoravka div.error').slideDown('normal');
				return false;
			}
			else
			{
				$('#pravnoVrstaSluzbenogPoravka div.error').hide();
				
				// call helper method to set ins rate
				this.insRate = this.callUrl(site_url + 'bs/calculatorPZO/calcPZORatePravno/pravnotype/' + value + '/days/' + this.durationDays + '/sector/' + this.sectorIns + '/type/' + this.insType + '/value/' + this.insValue);
								
			}
		}
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Set number of insurance persons
		 * 
		 * @param num = number of persons
		 * @return none
		 */
		this.setInsPersons = function setInsPersons(num){
		
			this.insPersons = parseInt(num);
			
		}
					
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Helper method for asynhron calls
		 * 
		 * @param url		= string to call (url); URL EXAMPLE: lang flag > class > method > params (optional)
		 * @return none
		 */
		this.callUrl = function callUrl(url){
			
			var urlData = null;
			
			$.ajax({
				url: url,
				type: 'get',
				async: false,
				success: function(data) {
					urlData = data;
				}
			});	
			
			return urlData;
			
		}
				
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Validate email
		 * 
		 * @return boolean
		 */	
		this.checkEmail = function checkEmail(eMailInput)
		{			
			if(eMailInput != '')
			{
				var eMailReg = new RegExp("^[0-9a-zA-Z\.]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$");
	
				var eMailReturn = eMailReg.test(eMailInput);
				if(eMailReturn == false)
				{
					return false;
				}
				return true;
			}
		}
		
		/**
		 * Calculator / Travel Health Insurance
		 * 
		 * Calculate final insurance price 
		 * 
		 * @return price
		 */
		this.calcResult = function calcResult(){
						
			// calculation
			switch( this.sectorIns )
			{
				case 'fizicko':
				
					if( this.insType == 'pojedinacno' )
					{
						this.totalPrice = parseFloat(this.insPersons * this.insRate * this.durationDays);
					}
					if( this.insType == 'porodicno' )
					{
						this.totalPrice = parseFloat(1 * this.insRate * this.durationDays);
					}
					if( this.insType == 'grupno' )
					{
						this.totalPrice = parseFloat(this.insPersons * this.insRate * this.durationDays);
					}
				
				break;
				
				case 'pravno':
					
					if( this.insType == 'pojedinacno' )
					{
						this.totalPrice = parseFloat(this.insPersons * this.insRate);
					}
					if( this.insType == 'grupno' )
					{
						this.totalPrice = parseFloat(this.insPersons * this.insRate);
					}
					if( this.insType == 'kolektivno' )
					{
						this.totalPrice = parseFloat(this.insPersons * this.insRate);
					}
					
				break;
				
			}			
			
			
			// check if result exist and return
			if( this.totalPrice != 'undefind' && this.totalPrice != 0 && !isNaN(this.totalPrice) )
			{
				var email = document.getElementById('userInfoEmail').value;
				
				// check if email has been entered
				if( this.checkEmail(email) == false)
				{
					alert('Unesite validnu e-mail adresu.');
					return false;
				}
				
				
				document.getElementById('totalInsPrice').value = this.totalPrice.toFixed(2);
				
				return true;
			}
			else
			{
				alert('Unesite sve neophodne parametre.');
				
				return false;
			}
			
			
			
		}
		
		
	}
	
	// create an istance of calculator
	var calculatorTravelHealthIns = new calculatorTravelHealthIns();
