$(document).ready(function(){
	
	/**
	 * set all external links to target="_blank"
	 */
	$("a").each(function () {
		$sTarget = $(this).attr('href');
		if ($sTarget) {
			if ($sTarget.indexOf("http://www.gewerbe-willich.de") == -1 && $sTarget.indexOf("http://www.gewerbewillich.de") == -1 && $sTarget.indexOf("javascript:") == -1) {
				$(this).attr('target', '_blank');
			}
		}
	});
	
	
	$("#idNewInfoFile_Selector").change(
		function() {
			if (this.value == 1)
			{
				$("#idNewInfoFile_File").show();
				$("#idNewInfoFile_Link").hide();
			}
			else if (this.value == 2)
			{
				$("#idNewInfoFile_File").show();
				$("#idNewInfoFile_Link").hide();
			}
			else if (this.value == 3)
			{
				$("#idNewInfoFile_File").hide();
				$("#idNewInfoFile_Link").show();
			}
		}
	);
	
	if ($("#mp01").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp01").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	if ($("#mp02").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp02").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	if ($("#mp03").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp03").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	if ($("#mp04").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp04").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	if ($("#mp05").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp05").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	if ($("#mp06").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp06").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	if ($("#mp07").attr('usecss'))
	{
		$("head").append("<link href=\""+httpURL+"outdata/styles/"+$("#mp07").attr('usecss')+"\" rel=\"stylesheet\" type=\"text/css\" />");
	}
	
	$("#idSearchFormBut").click( function () {
		if ($("#idSearchFormVal").attr("value") != "")
		{
			$("#idSearchForm").submit();
		}
	});
	
	$(".jsNewCompany").each(function (i){
		$(this).click(function (){
			if ($(this).val() == "1") {
				$("#jsCompanyLogin").show();
				$("#jsCompanyInformations").hide();
			}
			else {
				$("#jsCompanyLogin").hide();
				$("#jsCompanyInformations").show();
			}
		});	
	});
	
	
	$("#jsAddImgUpload").click(function (){
		$sVal = $("#jsOtherImgs").html();
		$sVal = $sVal + '<input type="file" class="formTextInput" name="immo_images[]" value="" />' + "\n";
		$("#jsOtherImgs").html($sVal);
	});
	
	$("#jsAddGrundrissUpload").click(function (){
		$sVal = $("#jsOtherGrundrisse").html();
		$sVal = $sVal + '<input type="file" class="formTextInput" name="immo_grundriss[]" value="" />' + "\n";
		$("#jsOtherGrundrisse").html($sVal);
	});	
	
	
	$.fn.checkGewerbeCompanyContact = function() {
		$sUserName = $(".jsAjaxGewerbeCompUser").val();
		$sUserPass = $(".jsAjaxGewerbeCompPass").val();
		$.post(httpURL + "getcompanycontacts.php", {usr: $sUserName, pwd: $sUserPass}, function(data) {
			if (data != "noaccess" && data != "nocomp") {
				var Woerter = data.split("||");
				$("#newimmo_ansprechpartner").val(Woerter[0]);
				$("#newimmo_street").val(Woerter[1]);
				$("#newimmo_hausnr").val(Woerter[2]);
				$("#newimmo_plz").val(Woerter[3]);
				$("#newimmo_ort").val(Woerter[4]);
				$("#newimmo_telefon").val(Woerter[5]);
				$("#newimmo_telefax").val(Woerter[6]);
				$("#newimmo_mobilnummer").val(Woerter[7]);
				$("#newimmo_email").val(Woerter[8]);
				$("#newimmo_weblink").val(Woerter[9]);
			}
		});		
	}
	
	$(".jsAjaxGewerbeCompUser").change(function () { $(this).checkGewerbeCompanyContact(); });
	$(".jsAjaxGewerbeCompUser").keyup(function () { $(this).checkGewerbeCompanyContact(); });
	$(".jsAjaxGewerbeCompPass").change(function () { $(this).checkGewerbeCompanyContact(); });
	$(".jsAjaxGewerbeCompPass").keyup(function () { $(this).checkGewerbeCompanyContact(); });
	 
});
