function emailOK(e)
{
    var at = e.value.indexOf('@');
    var dot = e.value.lastIndexOf('.');
    var space = e.value.indexOf(' ');
    var len = e.value.length - 1;

    return ((at > 1) && (dot >= at + 1) && (dot < len) && (space  == -1)) ? true : false;
}
		
function checkDomainName(dname)
{
	for(var j=0; j<dname.length; j++)
	{
		var dh = dname.charAt(j);
		var hh = dh.charCodeAt(0);
		if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		{
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 //alert("Ime domena ne može početi niti se završavati sa znakom "-" ");
			      return 1;
		 	 }
		}
		else	
		{
		  	 //alert("Ime domena koje ste unijeli sadrži nedozvoljene karaktere");
			 return 2;
		}
		
}

return 0;
}

function showEmailForm()
{
	var dom='';
	$(":checkbox").each(function(t){
		if(this.checked==true)
		{
			dom+=this.value+'%20';
		}
 	});
 	if(dom!='')
 	{
		$('#emaildiv_err').text('')
 		$('#emaildiv').load('emailform.php?dom='+dom);
 	}
	else
	{
		$('#emaildiv_err').css('color', '#FF0000');
		$('#emaildiv_err').text('  Morate čekirati bar jedan domen.')
	}
}

function checkEmail()
{
	
			//alert($('#domname').val());
	
			name	 		 = new String;
			phone	 		 = new String;
			email			 = new String;
			postal			 = new String;
			grad			 = new String;
			jmbg			 = new String;
			adresa			 = new String;

			name 		 	 = document.emailform.name.value;
			phone 		 	 = document.emailform.phone.value;
			email			 = document.emailform.email.value;
			postal			 = document.emailform.postal.value;
			grad			 = document.emailform.grad.value;
			jmbg			 = document.emailform.jmbg.value;
			adresa			 = document.emailform.adresa.value;
			domname			 = $('#domname').val();
			pravno_fizicko_h = $('#pravno_fizicko_h').val();
			
			document.emailform.name.style.border = '1px solid black';
			document.emailform.email.style.border = '1px solid black';
			document.emailform.phone.style.border = '1px solid black';
			document.emailform.postal.style.border = '1px solid black';
			document.emailform.grad.style.border = '1px solid black';
			document.emailform.jmbg.style.border = '1px solid black';
			document.emailform.adresa.style.border = '1px solid black';
			
			$('#emf-name').text('');
			$('#emf-email').text('');
			$('#emf-phone').text('');
			$('#emf-postal').text('');
			$('#emf-grad').text('');
			$('#emf-jmbg').text('');
			$('#emf-adresa').text('');
			$('#emailnotice').text('')
			
			var dom='';
			$(":checkbox").each(function(t){
				if(this.checked==true)
				{
					dom+=this.value+' ';
				}
		 	});
		 	if(dom!='')
		 	{
		 		$('#domname').attr('value', dom);
		 	}
			else
			{
				$('#emailnotice').css('color', '#FF0000');
				$('#emailnotice').text('Morate čekirati bar jedan domen.')
				return false;
			}
		
			
		if(name == '')
			{
				$('#emf-name').text('Unesite ime i prezime');
				document.emailform.name.style.border = '1px solid red';
				return false;
			}
			
		if(!emailOK(document.emailform.email))
			{
				$('#emf-email').text('Unesite ispravnu email adresu');
				document.emailform.email.style.border = '1px solid red';
				return false;
			}
			
		
			
		if(phone == '')
			{
				$('#emf-phone').text('Unesite broj telefona');
				document.emailform.phone.style.border = '1px solid red';
				return false;
			}
		if(adresa == '')
		{
			$('#emf-adresa').text('Unesite adresu');
			document.emailform.adresa.style.border = '1px solid red';
			return false;
		}
			
		if(postal == '')
			{
				$('#emf-postal').text('Unesite postanski kod');
				document.emailform.postal.style.border = '1px solid red';
				return false;
			}
			
		if(grad == '')
			{
				$('#emf-grad').text('Unesite grad');
				document.emailform.grad.style.border = '1px solid red';
				return false;
			}
			
		if(jmbg == '')
			{
				$('#emf-jmbg').text('Unesite JMBG');
				document.emailform.jmbg.style.border = '1px solid red';
				return false;
			}
		
	
	$('#emailform').ajaxSubmit(
	 {
		 success: function(t)
		 {
		 	if(pravno_fizicko_h == 'FIZICKO')
			{
				var getData = 'name='+name+'&adresa='+adresa+'&grad='+grad+'&postal='+postal+'&phone='+phone+'&domname='+domname+'&jmbg='+jmbg;
			}
			else
			{
				var getData = 'name='+name+'&adresa='+adresa+'&grad='+grad+'&postal='+postal+'&phone='+phone+'&domname='+domname;
			}
		 	window.open( "uplatnica.php?"+getData, "myWindow", "status=1,height=400,width=765,resizable=0");
		 	$('#emailnotice').css('color', '#00BB00');
		 	$('#emailnotice').html(t);
		 	$('#submit-button').attr('disabled', 'disabled');
		 }
	 });
	return true;	
}
/////////////////////////
function enterSubmit(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
     {
          checkDomain();
          return false;
     }
     else 
          return true;
}

function checkDomain()
{
	$('#emaildiv').text('');
	$('#domainnotice_err').text('');	
	$('#domainnotice').css('color', '#000000');
	$('#domainnotice_limg').html('<img src="images/loading.gif"/>');
	if(typeof($('#whois').attr('value'))==='undefined' || $('#whois').attr('value')=='')
	{
		$('#domainnotice_err').css('color', '#FF0000');
		$('#domainnotice_err').text('Upišite naziv domena');
		$('#domainnotice_limg').html('');
		$('#domainnotice').html('');
		return;
	}
	if($('#whois').attr('value').length<3 || $('#whois').attr('value').length>63)
	{
		$('#domainnotice_err').css('color', '#FF0000');
		$('#domainnotice_err').text('Naziv domena ne može biti kraći od 3 ili duži od 63 znaka');
		$('#domainnotice_limg').html('');
		$('#domainnotice').html('');
		return;
	}
	if(checkDomainName($('#whois').attr('value'))=='1')
	{
		$('#domainnotice_err').css('color', '#FF0000');
		$('#domainnotice_err').text('Prvi i posljednji znak u nazivu domena ne smije biti "-".');
		$('#domainnotice_limg').html('');
		$('#domainnotice').html('');
		return;
	}
	if(checkDomainName($('#whois').attr('value'))=='2')
	{
		$('#domainnotice_err').css('color', '#FF0000');
		$('#domainnotice_err').text('Domen može sadržati samo slova od A-Z, brojeve 0-9 i znak "-".');
		$('#domainnotice_limg').html('');
		$('#domainnotice').html('');
		return;
	}
	$('#domainform').ajaxSubmit(
	 {
		 success: function(t)
		 {
			$('#domainnotice_limg').html('');
		 	$('#domainnotice').html(t);
		 }
	 });
	return true;	
}

function Pravno_Fizicko()
{
	$('#pravno_fizicko').ajaxSubmit(
	 {
		 success: function(t)
		 {
		 	$('#emaildiv').html(t);
		 	$('#html_referer').val($('#referer').val());
		 }
	 });
	return false;
}


function popupUplatnica()
{
	name 		 	 = document.emailform.name.value;
	phone 		 	 = document.emailform.phone.value;
	email			 = document.emailform.email.value;
	postal			 = document.emailform.postal.value;
	grad			 = document.emailform.grad.value;
	jmbg			 = document.emailform.jmbg.value;
	adresa			 = document.emailform.adresa.value;
	domname			 = $('#domname').val();
	pravno_fizicko_h = $('#pravno_fizicko_h').val();
	
	document.emailform.name.style.border = '1px solid black';
		document.emailform.email.style.border = '1px solid black';
		document.emailform.phone.style.border = '1px solid black';
		document.emailform.postal.style.border = '1px solid black';
		document.emailform.grad.style.border = '1px solid black';
		document.emailform.jmbg.style.border = '1px solid black';
		document.emailform.adresa.style.border = '1px solid black';
		
		$('#emf-name').text('');
		$('#emf-email').text('');
		$('#emf-phone').text('');
		$('#emf-postal').text('');
		$('#emf-grad').text('');
		$('#emf-jmbg').text('');
		$('#emf-adresa').text('');
		$('#emailnotice').text('')
		
		var dom='';
		$(":checkbox").each(function(t){
			if(this.checked==true)
			{
				dom+=this.value+' ';
			}
	 	});
	 	if(dom!='')
	 	{
	 		$('#domname').attr('value', dom);
	 	}
		else
		{
			$('#emailnotice').css('color', '#FF0000');
			$('#emailnotice').text('Morate čekirati bar jedan domen.')
			return false;
		}
	
		
	if(name == '')
		{
			$('#emf-name').text('Unesite ime i prezime');
			document.emailform.name.style.border = '1px solid red';
			return false;
		}
		
	if(!emailOK(document.emailform.email))
		{
			$('#emf-email').text('Unesite ispravnu email adresu');
			document.emailform.email.style.border = '1px solid red';
			return false;
		}
		
	
		
	if(phone == '')
		{
			$('#emf-phone').text('Unesite broj telefona');
			document.emailform.phone.style.border = '1px solid red';
			return false;
		}
	if(adresa == '')
	{
		$('#emf-adresa').text('Unesite adresu');
		document.emailform.adresa.style.border = '1px solid red';
		return false;
	}
		
	if(postal == '')
		{
			$('#emf-postal').text('Unesite postanski kod');
			document.emailform.postal.style.border = '1px solid red';
			return false;
		}
		
	if(grad == '')
		{
			$('#emf-grad').text('Unesite grad');
			document.emailform.grad.style.border = '1px solid red';
			return false;
		}
		
	if(jmbg == '')
		{
			$('#emf-jmbg').text('Unesite JMBG');
			document.emailform.jmbg.style.border = '1px solid red';
			return false;
		}

	
	if(pravno_fizicko_h == 'FIZICKO')
	{
		var getData = 'name='+name+'&adresa='+adresa+'&grad='+grad+'&postal='+postal+'&phone='+phone+'&domname='+domname+'&jmbg='+jmbg;
	}
	else
	{
		var getData = 'name='+name+'&adresa='+adresa+'&grad='+grad+'&postal='+postal+'&phone='+phone+'&domname='+domname;
	}
	window.open( "uplatnica.php?"+getData, "myWindow", "status=1,height=400,width=765,resizable=0");
}
function preloader() 

{


     // counter
     var i = 0;


     // create object
     imageObj = new Image();


     // set image list
     images = new Array();
     images[0]="images/on.gif"
     images[0]="images/on_s.gif"
     images[0]="images/off.gif"
     images[0]="images/off_s.gif"


     // start preloading
     for(i=0; i<=3; i++) 
     {
          imageObj.src=images[i];
     }



} 

