$(document).ready(function() {

	
	
	function gal_scroll_left ()
	{
		
		var max=	$('#gallery_max').val();
		var current=	$('#gallery_current').val();
		var gsrc = $('#'+current).attr('src');
		current=current.replace ('galpic_', "");
		
		var next = current-1;
		if (next<0)
			next=max-1;
			
		var nextid ='galpic_'+next; 
		$('#gallery_current').val(nextid);
		var nsrc = $('#'+nextid).attr('src');
		$('#expose_mainpic').attr('src',nsrc);
		
		
	}
	
	function gal_scroll_right ()
	{
		
		var max=	$('#gallery_max').val();
		var current=	$('#gallery_current').val();
		var gsrc = $('#'+current).attr('src');
		
		current=current.replace ('galpic_', "");
		
		var next = current-0+1;
		if (next==max)
			next=0;
		
		var nextid ='galpic_'+next; 
		$('#gallery_current').val(nextid);
		var nsrc = $('#'+nextid).attr('src');
		$('#expose_mainpic').attr('src',nsrc);
		
		
	}
	
	// expose - gallery
	
	$('#galctrl_left').mouseover(function (){
		
		$('#galctrl_left').css ('cursor', 'pointer');
		
	});
	
	
	$('#galctrl_left').mouseout(function (){
		
		$(this).css ('cursor', 'default');
		
	});
	
	$('#galctrl_right').mouseover(function (){
		
		$('#galctrl_right').css ('cursor', 'pointer');
		
	});
	
	
	$('#galctrl_right').mouseout(function (){
		
		$(this).css ('cursor', 'default');
		
	});
	
	
	
	$('#galctrl_left').click(function (){
		
		gal_scroll_left();
	});
	
	
	$('#galctrl_right').click(function (){
		gal_scroll_right();
	});
	
	
	//
	
	
	// usability input fields
	$('#search_city').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Stadt");		
	
	});
	
	$('#search_zip').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Postleitzahl");		
	
	});
	
	$('#search_objectid').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Objektnummer");		
	
	});
	
	$('#contact_name').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Ihr Name:");		
	
	});
	
	$('#contact_email').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Email Adresse:");		
	
	});
	
	$('#contact_tel').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Telefon:");		
	
	});
	
	$('#contact_message').blur(function (){
	
	  var val = $(this).val();
		if (val=="")
			$(this).val("Ihre Nachricht:");		
	
	});
	
	
	
	$('.emptyonclick').focus(function (){
	
	  	var val = $(this).val();
	  	if (val=="Stadt" || val=="Postleitzahl" || val=="Ihr Name:" || val=="Email Adresse:" ||  val=="Telefon:" || val=="Ihre Nachricht:" || val=="Objektnummer")
				$(this).val("");
					
	
	});
	
	// end input field usability section


	// clear button
	$('#btn_reset').click(function (){
		
		$('#contact_name').val("Ihr Name:");
		$('#contact_email').val("Email Adresse:");
			$('#contact_tel').val("Telefon:");
		$('#contact_message').val("Ihre Nachricht:");
	});
	
	 // jquery template
	//$('#id').EVENT(function (){
	//});
	

	$(".expose_gallery").click(function() {
	
		var gsrc = $(this).attr('src');
		var id = $(this).attr('id');
		$('#gallery_current').val(id); 
		$('#expose_mainpic').attr('src',gsrc);
	
	
	});
	

  $('#immotype1').click(function (){
		
		$('#immotype').val(1);
		$('#smenu li a').css('font-weight','normal');
		$(this).css('font-weight','bold');
		$('#smenu li a').css('text-decoration','none');
		$(this).css('text-decoration','underline');
		
	});
	
	$('#immotype2').click(function (){
		
		$('#immotype').val(2);
		$('#smenu li a').css('font-weight','normal');
		$(this).css('font-weight','bold');
		$('#smenu li a').css('text-decoration','none');
		$(this).css('text-decoration','underline');
		
	});
	
	
	$('#immotype3').click(function (){
		
		$('#immotype').val(3);
		$('#smenu li a').css('font-weight','normal');
		$(this).css('font-weight','bold');
		$('#smenu li a').css('text-decoration','none');
		$(this).css('text-decoration','underline');
		
	});
	
	$('#immotype4').click(function (){
		
		$('#immotype').val(4);
		$('#smenu li a').css('font-weight','normal');
		$(this).css('font-weight','bold');
		$('#smenu li a').css('text-decoration','none');
		$(this).css('text-decoration','underline');
		
	});
	
	$('#immotype5').click(function (){
		
		$('#immotype').val(5);
		$('#smenu li a').css('font-weight','normal');
		$(this).css('font-weight','bold');
		$('#smenu li a').css('text-decoration','none');
		$(this).css('text-decoration','underline');
		
	});
	
	$('#immotype6').click(function (){
		
		$('#immotype').val(6);
		$('#smenu li a').css('font-weight','normal');
		$(this).css('font-weight','bold');
		$('#smenu li a').css('text-decoration','none');
		$(this).css('text-decoration','underline');
		
	});


// end document.ready section

	

});


// before submit
function check_contact_form ()
{
	var email = $('#contact_email').val();
	var validmail = checkEmail(email);
	if (!validmail)
	{
		$('#contact_error').html ("Die Email-Adresse ist nicht korrekt!");
		$('#contact_email').focus();
		return false;
	}
	else
		return true;
}





// commons

function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

function is_ie8 ()
{
	  var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver >= 8.0)
        	return true;
        else
        	return false;
     }
		return false;
}

function is_ie7 ()
{
	  var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver >= 7.0 && ver<8.0)
        	return true;
        else
        	return false;
     }
		return false;
}

function is_ie6 ()
{
	  var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver < 7.0)
        	return true;
        else
        	return false;
     }
		return false;
}


 function checkBrowserName(name){  
	    var agent = navigator.userAgent.toLowerCase();  
	    if (agent.indexOf(name.toLowerCase())>-1) {  
	      return true;  
	    }  
	    return false;  
	    
  
  }

function checkEmail(email) {

var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email)) {

	return false;
}
return true;

}


function formcheck ()
{

 $('#errors').css('display','none');
 $('#error_text').html('');
 var errors="";
 
 if (isempty ('vorname'))
 	errors = errors + "Bitte geben Sie Ihren Vornamen ein!" +'<br/>';
 	
 if (isempty ('nachname'))
 	errors = errors + "Bitte geben Sie Ihren Nachnamen ein!" +'<br/>';
 	
 if (isempty ('street'))
 	errors = errors + "Bitte geben Sie Ihre Strasse und Hausnr. ein!" +'<br/>';
 	
 if (isempty ('plz'))
 	 errors = errors + "Bitte geben Sie Ihre PLZ ein!" +'<br/>';
 	
 if (isempty ('ort'))
  errors = errors + "Bitte geben Sie Ihren Ort ein!" +'<br/>';
 	
	 var email =         $('#email').val();
 	//alert (email); 
 if (isempty ('email'))
 	errors = errors + "Bitte geben Sie Ihre Email ein!" +'<br/>';
 	 else if (!checkEmail (email))
 	errors = errors + "Bitte geben Sie eine korrekte Email-Adresse ein!" +'<br/>';
 	
 if (isempty ('telefon'))
 	errors = errors + "Bitte geben Sie Ihre Telefonnummer ein!" +'<br/>';
 
 if( $('input[name=datenschutz]').attr('checked') == false){
		
	errors = errors + "Bitte stimmen Sie der Datenschutzbestimmung zu!" +'<br/>';
}
 
 if (errors =='')
 	return true;
 else
 {
  $('#error_text').html(errors);
  $('#errors').css('display','block');
  
 	return false;
 }

}



function formcheck1 ()
{

 $('#errors').css('display','none');
 $('#error_text').html('');
 var errors="";
 

 if (isempty ('nachname'))
 	errors = errors + "Bitte geben Sie Ihren Nachnamen ein!" +'<br/>';
 	

 	
	 var email =         $('#email').val();
 	//alert (email); 
 if (isempty ('email'))
 	errors = errors + "Bitte geben Sie Ihre Email ein!" +'<br/>';
 	 else if (!checkEmail (email))
 	errors = errors + "Bitte geben Sie eine korrekte Email-Adresse ein!" +'<br/>';
 	
 if (isempty ('telefon'))
 	errors = errors + "Bitte geben Sie Ihre Telefonnummer ein!" +'<br/>';
 
 if( $('input[name=datenschutz]').attr('checked') == false){
		
	errors = errors + "Bitte stimmen Sie der Datenschutzbestimmung zu!" +'<br/>';
}
 
 if (errors =='')
 	return true;
 else
 {
  $('#error_text').html(errors);
  $('#errors').css('display','block');
  
 	return false;
 }

}

function isempty (name)
{
	return ($('input[name=' + name +  ']').val()=='')
}

function print_expose (id)
{

 popup = window.open('print_expose.php?id='+id, "Exposé", "width=800,height=400,status=no,scrollbars=yes,resizable=yes,top=240,left=300");
 popup.focus();


}





