// Debugging aktivieren wenn stacktrace.js eingebunden ist
//if("printStackTrace" in window && typeof printStackTrace == "function") {
//	window.onerror = function error(msg, file, line) {
//		var errorMSG = msg + " @ " + file + ":" + line + "\nStacktrace:\n" + printStackTrace();
//
//		if("console" in window && "log" in window.console && typeof window.console.log === "function") {
//			console.log(errorMSG);
//		} else {
//			alert(errorMSG);
//		}
//	};
//}

// Standard-Optionen
var colorboxDefaults = {
	'transition'   : 'none',
	'speed'        : 250,
	'opacity'      : 0.25,
	'initialWidth' : 100,
	'initialHeight': 100
};

$(document).ready(function() {
	// Zustand des Sliders und die Galerie-Komponente ermitteln
	var pageWidth    = $('#mask-gallery').width();
	var $gallery     = $('#gallery');

	// reale Breite der Galerie berechnen
	var galleryWidth = 0;

	$gallery.children('li').each(function() {
		galleryWidth += $(this).outerWidth();
	});

	// minimale x-Position berechnen
	var minLeft = 0 - (galleryWidth - pageWidth);
	// maximale x-Position
	var maxLeft = 0;

	// Galerie auf feste Breite setzen
	$gallery.css('width', galleryWidth);

	// Buttons je nach Position der Galerie anzeigen
	if(getCSSLeft($gallery) > minLeft) $('#btn-next').show();
	if(getCSSLeft($gallery) < maxLeft) $('#btn-prev').show();
    
	// Event-Handler fuer die Buttons
	// Links:
	$('#btn-prev').click(function() {
		// aktuelle x-Position
		var currentLeft = getCSSLeft($gallery);

		// nur Sliden wenn noch nicht das Maximum erreicht wurde
		if(currentLeft < maxLeft) {
			var targetLeft = currentLeft + pageWidth;

			// falls der Slide das Maximum erreicht oder ueberschreitet,
			// das Ziel auf "Maximum" setzen und den Button ausblenden
			if(targetLeft >= maxLeft) {
				targetLeft = maxLeft;
				$(this).hide();
			}

			$gallery.animate({left : targetLeft}, 1000, 'swing');

			// Wenn die Galerie noch nicht ganz Links ist den Button zum
			// Weiterscrollen einblenden
			if(targetLeft > minLeft) $('#btn-next').show();
		}

		return false;
	});
	// Rechts:
	$('#btn-next').click(function() {
		// aktuelle x-Position
		var currentLeft = getCSSLeft($gallery);

		// nur Sliden wenn noch nicht das Minimum erreicht wurde
		if(currentLeft > minLeft) {
			var targetLeft = currentLeft - pageWidth;

			// falls der Slide das Minimum erreicht oder unterschreitet,
			// das Ziel auf "Minimum" setzen und den Button ausblenden
			if(targetLeft <= minLeft) {
				targetLeft = minLeft;
				$(this).hide();
			}

			$gallery.animate({left : targetLeft}, 1000, 'swing');

			// Wenn die Galerie noch nicht ganz Rechts ist den Button zum
			// Zurueckscrollen einblenden
			if(targetLeft < maxLeft) $('#btn-prev').show();
		}

		return false;
	});
	// Loginbox / Settingsbox
	$('li.login').bind("mouseenter", function() {
		$('div.loginbox').show();
		$('div.loginbox_top_left').show();
		$('div.loginbox_top_right').show();
		$('li.login').css({'background-color' : '#656565'});
        $('li.login a').css({'color':'white'});
	}).bind("mouseleave", function(evt) {
		// chrome fix: Beim Mouseover ueber bestimmte form elemente wird beim
		// mouseenter ein mouseleave erzeugt
		if("nodeName" in evt.target && evt.target.nodeName === "FIELDSET") {
			// weitere event-behandlung verhindern
			return false;
		}
		$('div.loginbox').hide();
		$('div.loginbox_top_left').hide();
		$('div.loginbox_top_right').hide();
		$('li.login').css({'background-color' : ''});
        $('li.login a').css({'color':''});
	});
	$('li.newsletter').bind("mouseenter", function() {
		$('div.newsletterbox').show();
		$('div.newsletterbox_top_left').show();
		$('div.newsletterbox_top_right').show();
		// $('li.newsletter').css({'background-color' : '#656565'});
        $('li.newsletter a').css({'color':'white'});
	}).bind("mouseleave", function() {
		$('div.newsletterbox').hide();
		$('div.newsletterbox_top_left').hide();
		$('div.newsletterbox_top_right').hide();
		$('li.newsletter').css({'background-color' : ''});
        $('li.newsletter a').css({'color':''});
	});

	$('li.change').bind("mouseenter", function() {
		$('div.settingbox').show();
		$('div.settingbox_top_left').show();
		$('div.settingbox_top_right').show();
	}).bind("mouseleave", function() {
		$('div.settingbox').hide();
		$('div.settingbox_top_left').hide();
		$('div.settingbox_top_right').hide();
	});
    
	// Bildtausch Slider
	$('#gallery li a').bind("mouseenter", function() {
		var $img = $(this).children("img");
		var source = $img.attr("src");
		if(!$.data(this, "original_source")) {
			$.data(this, "original_source", source);
		}
		var new_source = source.substr(0,source.lastIndexOf(".")) + "_hover." + source.substr(source.lastIndexOf(".") + 1);
		$img.attr("src",new_source);
	}).bind("mouseleave", function() {
		var $img = $(this).children("img");
		$img.attr("src",$.data(this, "original_source"));
	});
	// Steuerung Tabnavi
	if($('.tab_navi_holder ul li.akt').length == 0){

	    $('.tab_navi_holder ul li').each(function() {
		$(this).removeClass("akt");
	    });
	    $('.tab_navi_holder ul li:first').addClass("akt");

	    $('.tab_content_holder .tabnavi_content').each(function() {
		    $(this).hide();
	    });
	    $('.tab_content_holder .tabnavi_content:first').show();

	}
	else{
	    $('.tab_content_holder .tabnavi_content').each(function() {
		    $(this).hide();
	    });
	    var target = $('.tab_navi_holder ul li.akt a').attr('id') + "_content";
	    $('#' + target).show();
	}


	$('.tab_navi_holder ul li a').bind("click", function() {
		$('.tab_navi_holder ul li').each(function() {
			$(this).removeClass("akt");
		});
		$(this).closest('li').addClass("akt");
		$('.tab_content_holder .tabnavi_content').each(function() {
			$(this).hide();
		});
		$('.tab_content_holder #' + $(this).attr('id') + '_content').show();
	});


	 // Steuerung Tabnavi Standards
     if ($('.view_switch ul li:first').hasClass('list'))
	     {
	         $('.view_switch ul li:first').addClass("listakt");
	     }
	     else if ($('.view_switch ul li:first').hasClass('grid'))
	     {
	         $('.view_switch ul li:first').addClass("gridakt");
	     }

     $('.tab_content_holder .standards_content_list').each(function() {
         $(this).hide();
     });
     $('.tab_content_holder .standards_content_list:first').show();

     $('.view_switch ul li').bind("click", function() {
         $('.view_switch ul li').each(function() {
             $(this).removeClass("listakt");
             $(this).removeClass("gridakt");
         });
         if ($(this).closest('li').hasClass('list'))
         {
             $(this).closest('li').addClass("listakt");
         }
         else if ($(this).closest('li').hasClass('grid'))
         {
             $(this).closest('li').addClass("gridakt");
         }
         $('.tab_content_holder .standards_content_list').each(function() {
             $(this).hide();
         });
         $('.tab_content_holder #tabnavi_' + $(this).attr('id') + '_content').show();
     });



	// Steuerung Tabnavi Contact
	$('.goolemaps_tabnavi a:first').addClass("akt");
	$('.googlemaps_functional_link ul li').each(function() {
		$(this).hide();
	});
	$('.googlemaps_functional_link ul li:first').show();
	$('.goolemaps_tabnavi a').bind("click", function() {
		$('.goolemaps_tabnavi a').each(function() {
			$(this).removeClass("akt");
		});
		$(this).closest('a').addClass("akt");
		$('.googlemaps_functional_link ul li').each(function() {
			$(this).hide();
		});
		$('.googlemaps_functional_link #tabnavi_' + $(this).attr('id')).show();
	});

	$('#cap_reload_holder img').bind("click", function() {
	   $.ajax({
	      type: "GET",
	      url: "typo3conf/ext/rb_asamregister/pi1/cap_pic.php",
	      data: '',
	      success: function(msg){
	         var img_src = $('.captcha_display img').attr('src');
	           var timestamp = new Date().getTime();
	           $('.captcha_display img').attr('src',img_src+'?'+timestamp);
	        }
	   });
	});


	function reloadPic(thumb,video,aspect,id){
   var string = 'thumb='+thumb+'&video='+video+'&aspect='+aspect;
   var imageID = '#' + id;
   $.ajax({
      type: "GET",
      url: "test.php",
      data: string,
      success: function(msg){
         var img_src = $(imageID).attr('src');
           var timestamp = new Date().getTime();
           $(imageID).attr('src',img_src+'?'+timestamp);
        }
   });
}


	if ($('#accordion').length > 0)
	{
		var accordionOpts = {'fillSpace': false, 'clearStyle': true, 'autoHeight': false };


		$('#accordion').accordion(accordionOpts);
		/*$('#accordion h3').click(function() {
			$( "#accordion" ).accordion(accordionOpts);
		});*/
	}

	$('#accordion_spec h3').each(function() {
		var $h3 = $(this);
		var $body = $h3.next('div');
		$h3.click(function() {
			if($body.is(':visible')) {
				$body.slideUp();
				$h3.removeClass('ui-state-active');
			} else {
				$body.slideDown();
				$h3.addClass('ui-state-active');
			}
		});
		$body.slideUp();
	});

	$('ul.list_faq,ul.accordion').accordion({autoHeight:false, active:false, collapsible: true});

	if ($('ul.accordion_forum').length > 0)
	{
		$('ul.accordion_forum h3').bind("click", function() {
			if($(this).next('table').is(':hidden'))
			{
			$(this).next('table').show();
			$(this).removeClass('close');
			}
			else
			{
			$(this).next('table').hide();
			$(this).addClass('close');
			}
		});
	}
	if ($('ul.accordion_marginal').length > 0)
	{
		$('ul.accordion_marginal h3').bind("click", function() {
			if($(this).next('ul').is(':hidden'))
			{
			$(this).next('ul').show();
			$(this).removeClass('close');
			}
			else
			{
			$(this).next('ul').hide();
			$(this).addClass('close');
			}
		});
	}

	/* Suchswitch */
	$('#searchswitch').bind("click", function() {
		if($(this).attr('rel')=='sim')
		{
			$(this).attr('rel','adv');
			$(this).html('Simple search');
			$('.searchform_avanced').show();
			$('.searchform_simple').hide();
		}
		else
		{
			$(this).attr('rel','sim');
			$(this).html('Advanced search');
			$('.searchform_avanced').hide();
			$('.searchform_simple').show();
		}

	});

    /* Verstecken von Company-Feldern bei Auswahl "Private member" */
    if($('#tx-srfeuserregister-pi1-tx_rbasamregister_membertype-0').length > 0){
    	if(document.getElementById('tx-srfeuserregister-pi1-tx_rbasamregister_membertype-0').checked) {
		$('.company_info').hide();
	}
    }

    $('#tx-srfeuserregister-pi1-tx_rbasamregister_membertype-0').bind("click", function() {
        $('.company_info').hide();
    });
    $('#tx-srfeuserregister-pi1-tx_rbasamregister_membertype-1').bind("click", function() {
        $('.company_info').show();
    });

    
    $('#errorclose').bind("click", function() {
		$('.error_login').hide();
	});


    /* Wiki-Neu-Layer */
    $('#openwikicreate').bind("click", function() {
        $('.wiki_create_title').kkmodal("show", {createDialogView : false, canvasOpacity: 0.25 });
    });


    /* Steuerung Registerform */
    var cCodes = new Array();
    cCodes['ABW'] = '+297';
    cCodes['AFG'] = '+93';
    cCodes['AGO'] = '+244';
    cCodes['AIA'] = '+1-264';
    cCodes['ALB'] = '+355';
    cCodes['AND'] = '+376';
    cCodes['ANT'] = '+599';
    cCodes['ARE'] = '+971';
    cCodes['ARG'] = '+54';
    cCodes['ARM'] = '+7';
    cCodes['ASM'] = '+1-684';
    cCodes['ATG'] = '+1-268';
    cCodes['AUS'] = '+61';
    cCodes['AUT'] = '+43';
    cCodes['AZE'] = '+994';
    cCodes['BDI'] = '+257';
    cCodes['BEL'] = '+32';
    cCodes['BEN'] = '+229';
    cCodes['BFA'] = '+226';
    cCodes['BGD'] = '+880';
    cCodes['BGR'] = '+359';
    cCodes['BHR'] = '+973';
    cCodes['BHS'] = '+1-242';
    cCodes['BIH'] = '+387';
    cCodes['BLR'] = '+375';
    cCodes['BLZ'] = '+501';
    cCodes['BMU'] = '+1-441';
    cCodes['BOL'] = '+591';
    cCodes['BRA'] = '+55';
    cCodes['BRB'] = '+1-246';
    cCodes['BRN'] = '+673';
    cCodes['BTN'] = '+975';
    cCodes['BWA'] = '+267';
    cCodes['CAF'] = '+236';
    cCodes['CAN'] = '+1';
    cCodes['CHE'] = '+41';
    cCodes['CHL'] = '+56';
    cCodes['CHN'] = '+86';
    cCodes['CIV'] = '+225';
    cCodes['CMR'] = '+237';
    cCodes['COD'] = '+243';
    cCodes['COG'] = '+242';
    cCodes['COK'] = '+682';
    cCodes['COL'] = '+57';
    cCodes['COM'] = '+269';
    cCodes['CPV'] = '+238';
    cCodes['CRI'] = '+506';
    cCodes['CUB'] = '+53';
    cCodes['CYM'] = '+1-345';
    cCodes['CYP'] = '+357';
    cCodes['CZE'] = '+420';
    cCodes['DEU'] = '+49';
    cCodes['DJI'] = '+253';
    cCodes['DMA'] = '+1-767';
    cCodes['DNK'] = '+45';
    cCodes['DOM'] = '+1-809';
    cCodes['DZA'] = '+213';
    cCodes['ECU'] = '+593';
    cCodes['EGY'] = '+20';
    cCodes['ERI'] = '+291';
    cCodes['ESP'] = '+34';
    cCodes['EST'] = '+372';
    cCodes['ETH'] = '+251';
    cCodes['FIN'] = '+358';
    cCodes['FJI'] = '+679';
    cCodes['FLK'] = '+500';
    cCodes['FRA'] = '+33';
    cCodes['FRO'] = '+298';
    cCodes['FSM'] = '+691';
    cCodes['GAB'] = '+241';
    cCodes['GBR'] = '+44';
    cCodes['GHA'] = '+233';
    cCodes['GIB'] = '+350';
    cCodes['GIN'] = '+224';
    cCodes['GLP'] = '+590';
    cCodes['GMB'] = '+220';
    cCodes['GNB'] = '+245';
    cCodes['GNQ'] = '+240';
    cCodes['GRC'] = '+30';
    cCodes['GRD'] = '+1-473';
    cCodes['GRL'] = '+299';
    cCodes['GTM'] = '+502';
    cCodes['GUF'] = '+594';
    cCodes['GUM'] = '+1-671';
    cCodes['GUY'] = '+592';
    cCodes['HKG'] = '+852';
    cCodes['HND'] = '+504';
    cCodes['HRV'] = '+385';
    cCodes['HTI'] = '+509';
    cCodes['HUN'] = '+36';
    cCodes['IDN'] = '+62';
    cCodes['IND'] = '+91';
    cCodes['IRL'] = '+353';
    cCodes['IRN'] = '+98';
    cCodes['IRQ'] = '+964';
    cCodes['ISL'] = '+354';
    cCodes['ISR'] = '+972';
    cCodes['ITA'] = '+39';
    cCodes['JAM'] = '+1-876';
    cCodes['JOR'] = '+962';
    cCodes['JPN'] = '+81';
    cCodes['KAZ'] = '+7';
    cCodes['KEN'] = '+254';
    cCodes['KGZ'] = '+996';
    cCodes['KHM'] = '+855';
    cCodes['KIR'] = '+686';
    cCodes['KNA'] = '+1-869';
    cCodes['KOR'] = '+82';
    cCodes['KWT'] = '+965';
    cCodes['LAO'] = '+856';
    cCodes['LBN'] = '+961';
    cCodes['LBR'] = '+231';
    cCodes['LBY'] = '+218';
    cCodes['LCA'] = '+1-758';
    cCodes['LIE'] = '+423';
    cCodes['LKA'] = '+94';
    cCodes['LSO'] = '+266';
    cCodes['LTU'] = '+370';
    cCodes['LUX'] = '+352';
    cCodes['LVA'] = '+371';
    cCodes['MAC'] = '+853';
    cCodes['MAR'] = '+212';
    cCodes['MCO'] = '+377';
    cCodes['MDA'] = '+373';
    cCodes['MDG'] = '+261';
    cCodes['MDV'] = '+960';
    cCodes['MEX'] = '+52';
    cCodes['MHL'] = '+692';
    cCodes['MKD'] = '+389';
    cCodes['MLI'] = '+223';
    cCodes['MLT'] = '+356';
    cCodes['MMR'] = '+95';
    cCodes['MNE'] = '+382';
    cCodes['MNG'] = '+976';
    cCodes['MNP'] = '+1-670';
    cCodes['MOZ'] = '+258';
    cCodes['MRT'] = '+222';
    cCodes['MSR'] = '+1-664';
    cCodes['MTQ'] = '+596';
    cCodes['MUS'] = '+230';
    cCodes['MWI'] = '+265';
    cCodes['MYS'] = '+60';
    cCodes['MYT'] = '+269';
    cCodes['NAM'] = '+264';
    cCodes['NCL'] = '+687';
    cCodes['NER'] = '+227';
    cCodes['NGA'] = '+234';
    cCodes['NIC'] = '+505';
    cCodes['NIU'] = '+683';
    cCodes['NLD'] = '+31';
    cCodes['NOR'] = '+47';
    cCodes['NPL'] = '+977';
    cCodes['NRU'] = '+674';
    cCodes['NZL'] = '+64';
    cCodes['OMN'] = '+968';
    cCodes['PAK'] = '+92';
    cCodes['PAN'] = '+507';
    cCodes['PER'] = '+51';
    cCodes['PHL'] = '+63';
    cCodes['PLW'] = '+680';
    cCodes['PNG'] = '+675';
    cCodes['POL'] = '+48';
    cCodes['PRI'] = '+1';
    cCodes['PRK'] = '+850';
    cCodes['PRT'] = '+351';
    cCodes['PRY'] = '+595';
    cCodes['PSE'] = '+970';
    cCodes['PYF'] = '+689';
    cCodes['QAT'] = '+974';
    cCodes['REU'] = '+262';
    cCodes['ROU'] = '+40';
    cCodes['RUS'] = '+7';
    cCodes['RWA'] = '+250';
    cCodes['SAU'] = '+966';
    cCodes['SDN'] = '+249';
    cCodes['SEN'] = '+221';
    cCodes['SGP'] = '+65';
    cCodes['SHN'] = '+290';
    cCodes['SLB'] = '+677';
    cCodes['SLE'] = '+232';
    cCodes['SLV'] = '+503';
    cCodes['SMR'] = '+378';
    cCodes['SOM'] = '+252';
    cCodes['SPM'] = '+508';
    cCodes['SRB'] = '+381';
    cCodes['STP'] = '+239';
    cCodes['SUR'] = '+597';
    cCodes['SVK'] = '+421';
    cCodes['SVN'] = '+386';
    cCodes['SWE'] = '+46';
    cCodes['SWZ'] = '+268';
    cCodes['SYC'] = '+248';
    cCodes['SYR'] = '+963';
    cCodes['TCA'] = '+1-649';
    cCodes['TCD'] = '+235';
    cCodes['TGO'] = '+228';
    cCodes['THA'] = '+66';
    cCodes['TJK'] = '+992';
    cCodes['TKL'] = '+690';
    cCodes['TKM'] = '+993';
    cCodes['TLS'] = '+670';
    cCodes['TON'] = '+676';
    cCodes['TTO'] = '+1-868';
    cCodes['TUN'] = '+216';
    cCodes['TUR'] = '+90';
    cCodes['TUV'] = '+688';
    cCodes['TWN'] = '+886';
    cCodes['TZA'] = '+255';
    cCodes['UGA'] = '+256';
    cCodes['UKR'] = '+380';
    cCodes['URY'] = '+598';
    cCodes['USA'] = '+1';
    cCodes['UZB'] = '+998';
    cCodes['VAT'] = '+379';
    cCodes['VCT'] = '+1-784';
    cCodes['VEN'] = '+58';
    cCodes['VGB'] = '+1-284';
    cCodes['VIR'] = '+1-340';
    cCodes['VNM'] = '+84';
    cCodes['VUT'] = '+678';
    cCodes['WLF'] = '+681';
    cCodes['WSM'] = '+685';
    cCodes['YEM'] = '+967';
    cCodes['ZAF'] = '+27';
    cCodes['ZMB'] = '+260';
    cCodes['ZWE'] = '+263';
    var singleValue = cCodes[$('#tx-srfeuserregister-pi1-static_info_country').val()];
    $('#countrycode').val(singleValue);


    $('#tx-srfeuserregister-pi1-static_info_country').bind('change', function() {
        var singleValue = cCodes[$('#tx-srfeuserregister-pi1-static_info_country').val()];
        $('#countrycode').val(singleValue);
    });


    // Steuerung Company Edit
    $('#firstname').bind('change', function() {
        var firstname = $('#firstname').val();
        var lastname = $('#lastname').val();
        $('#name').val(firstname + ' ' + lastname);
    });
    $('#lastname').bind('change', function() {
        var firstname = $('#firstname').val();
        var lastname = $('#lastname').val();
        $('#name').val(firstname + ' ' + lastname);
    });



	/* Colorbox */
	var pageTypeNum = 5;
	// Alle Links mit der Klasse box_trigger zur Colorbox umwandeln und nach dem
	// Laden bei allen sich im Ergebnis befindenden HTML-Formulare das Submit-Event
	// ueberschreiben. In diesem wird dann das Formular per AJAX versand und bei
	// Erfolg die Rueckgabe als neues Dialog-HTML gesetzt.
	$('a.box_trigger').each(function() {
		var rel = $(this).attr('rel');
		var width, height = false;

		// Groesse aus dem rel-Attribut entnehmen wenn vorhanden
		if(rel && rel.indexOf('x') > 0) {
			var split = rel.split('x');
			width = split[0];
			height = split[1];
		}

		$(window).load(function() {
		     $(' #gallery > li > a > img').each(function() {
			 var $topposi = (65-$(this).height())/2;
			 $(this).css("margin-top", $topposi);
		     });

		});


		// Colorbox erzeugen
		$(this).colorbox(colorboxOptions({
			'onComplete': function() {
				// Formulare durchgehen
				$('#cboxLoadedContent form').each(function() {
					var $form = $(this);

					// pageType nummer (config s.o.) an action anhaengen
					var formAction = $form.attr('action');

					formAction += formAction.indexOf('?') > 0 ? '&type=' + pageTypeNum : '?type=' + pageTypeNum

					// action anpassen und submit-event ueberschreiben mit dem ajax-submit
					$form.attr('action',formAction).submit(function() {
						$(this).ajaxSubmit({
							'success' : function(responseText, statusText) {
								// colorbox mit der rueckgabe des aufrufs aktualisieren
								responseText = '<div style="display: block; width: 400px; height: 180px; padding: 0pt;" class="login_layer"><h2 style="margin-bottom: 15px;">Reset Password</h2>Instructions for resetting the password will be immediately emailed to you.</div>';
								$.colorbox(colorboxOptions({html: responseText, width:400, height:180}));
							}
						})
						return false;
					});

					// vorhandene links ueberschreiben
					$('#cboxLoadedContent a').click(function() {
						// pageType nummer (config s.o.) an href anhaengen
						var href = $(this).attr('href');
						href += href.indexOf('?') > 0 ? '&type=' + pageTypeNum : '?type=' + pageTypeNum;
						// colorbox mit der neuen url aktualisieren
						$.colorbox(colorboxOptions({href: href}));
						return false;
					});
				});
			},
			width: width,
			height: height
		}));
	});

	createToggleFields($('body'));
	// default für NL-Subscription First- und Lastname
    if($('#nl_subscriber').length > 0){
	var nl_scr_fname = document.getElementById('tx-sremailsubscribe-pi1-first_name').value;
	var nl_scr_lname = document.getElementById('tx-sremailsubscribe-pi1-last_name').value;
	var nl_scr_comp = document.getElementById('tx-sremailsubscribe-pi1-company').value;
	var nl_scr_email = document.getElementById('tx-sremailsubscribe-pi1-email').value;
	$('#nl_subscriber').bind("click", function() {
	    if(document.getElementById('tx-sremailsubscribe-pi1-last_name').value == nl_scr_lname) {
	      document.getElementById('tx-sremailsubscribe-pi1-last_name').value="";
	    }
	    if(document.getElementById('tx-sremailsubscribe-pi1-first_name').value == nl_scr_fname) {
		document.getElementById('tx-sremailsubscribe-pi1-first_name').value="";
	    }
	    if(document.getElementById('tx-sremailsubscribe-pi1-company').value == nl_scr_comp) {
		document.getElementById('tx-sremailsubscribe-pi1-company').value="";
	    }
	    if(document.getElementById('tx-sremailsubscribe-pi1-email').value == nl_scr_email) {
		document.getElementById('tx-sremailsubscribe-pi1-email').value="";
	    }
	    this.form.submit();
	});
    }
    
    
    
});

function getCSSLeft($obj) {
	if($('#gallery').size() > 0) {
	return parseInt($obj.css('left').match(/[-0-9]+/)[0], 10);
	}
}

function messageDialog(title, content, buttons, width, height) {
	var dialogHTML = '<h3>' + title + '</h3>' +
		content +
		'<br/><span class="dialog-buttons">';
	var buttonCount = 0;

	for(var buttonName in buttons) {
		dialogHTML += '<button name="' + buttonName + '" class="yellow-button" id="confirm-button-' + buttonCount + '">' + buttonName + '</button>';
		buttonCount++;
	}

	dialogHTML += '</span>';

	$.colorbox(colorboxOptions({
			html: dialogHTML,
			width: width,
			height: height,
			onComplete: function() {
				for(var i = 0; i < buttonCount; i++) {
					$('#confirm-button-' + i).click(function() {
						var buttonFunc = buttons[$(this).attr('name')];
						if($.isFunction(buttonFunc)) {
							var closeDialog = buttonFunc.apply(null);
							if(closeDialog !== false) $.colorbox.close();
						} else {
							$.colorbox.close();
						}
					});
				}

				createToggleFields($('#cboxContent'));
			}
		}
	));
}

function createToggleFields(container) {
	$(container).find('.toggleField').each(function() {
		var $field = $(this);
		var isPassword = $field.attr('type') == 'password';
		var defaultValue = $field.attr('title');
		var hiddenFieldID = $field.attr('name').replace(/[^a-z0-9]/ig, '-') + '-display';

		if(!defaultValue) defaultValue = $field.val();

		$field.addClass('inactive').focus(function() {
			if($field.val() == defaultValue) {
				$field.val('').removeClass('inactive');
			}
		}).blur(function() {
			if($field.val() == '') {
				if(isPassword) {
					$field.hide();
					$('#' + hiddenFieldID).show().val(defaultValue);
				} else {
					$field.val(defaultValue).addClass('inactive');
				}
			}
		});

		if($field.val() == '' || $field.val() == defaultValue) {
			if(isPassword) {
				var $text = $('<input type="text" id="' + hiddenFieldID + '" class="' + $field.attr('class') + ' inactive" value="' + defaultValue + '">');
				$field.before($text).hide();
				$text.focus(function() {
					$(this).hide();
					$field.show().val('').focus();
				});
			} else {
				$field.val(defaultValue).addClass('inactive');
			}
		}
	});
}

function sortcompanylist(id) {
    var selectBox = document.getElementById(id);
    selectArray = new Array();
    for (i = 1; i < selectBox.length; i++) {
        selectArray[i] = new Array();
        selectArray[i][0] = selectBox.options[i].text;
        selectArray[i][1] = selectBox.options[i].value;
    }
    selectArray.sort();
    for (j = 0; j < selectBox.length - 1; j++) {
        selectBox.options[j+1].text = selectArray[j][0];
        selectBox.options[j+1].value = selectArray[j][1];
    }
}

function colorboxOptions(options) {
	return $.extend($.extend({}, colorboxDefaults), options);
}

