$(document).ready(function() {
	

$.localScroll();
$('.quicklinkshelp').parent().localScroll();
$(".morefields").hide();  //hides extrafields onload on the feedback form

$(".pm_box").corner("11px"); //adds rounded corner to private message box
$(".profileBoxBlue").corner("11px"); //adds rounded corner to private message box
$(".profileBoxGray").corner({
				tl: false,
				tr:false,
			bl: { radius: 7 },
			  br: { radius: 7 }
							   }); //adds rounded corner to quicklinks box
$(".helpBoxGray").corner({
				tl: false,
				tr:false,
			bl: { radius: 7 },
			  br: { radius: 7 }
							   }); //adds rounded corner to quicklinks box

$(".helpQuickLinks tr:not(:last-child)").find("td").removeClass("qlbtm").addClass("qltop");

$(".toggleTomo").corner({
			  tl: false,
			  tr: false,
			  bl: { radius: 5 },
			  br: { radius: 5 },
			  antiAlias: true,
			  autoPad: true,
			  validTags: ["span"] });
$(".toggleTE").corner({
			  tl: false,
			  tr: false,
			  bl: { radius: 5 },
			  br: { radius: 5 },
			  antiAlias: true,
			  autoPad: true,
			  validTags: ["span"] });

$(".tablink").parent().find(".sub").hide(); //hides submenus on pageload

$(".tabonlink").parent().find(".sub").show(); //show active submenus on pageload

//on page load hide all 'inactive' subnav
$(".tabonlink").parent().siblings().find(".sub").hide();


// tab hover function
$(".tablink").hover(function(){
		$(this).parent().addClass("tabhover");				//show the tab bkg on hover	
		$(this).parent().siblings().find(".sub").hide();	//hide all other tabs subnav
		$(this).parent().find(".sub").show();				//show this tab's subnav
	},function(){
		$(this).parent().removeClass("tabhover");				//remove the tab bkg 
		$(this).parent().find(".sub").hide();					//hide this tab's subnav
		$(".tabonlink").parent().find(".sub").show();			//show this page's subnav by default
	});	


$(".tab .sub").hover(function(){							
		$(this).show();										//shows the subnav when hovered
		$(this).parent().addClass("tabhover");				//preserves tab bkg on subnav hover
		$(".tabonlink").parent().find(".sub").hide();		//hides this pages default subnav
	},function(){
		$(this).hide();									//hides the subnav
		$(this).parent().removeClass("tabhover");		//removes the tab bkg
		$(".tabonlink").parent().find(".sub").show();	//shows this pages default subnav

	});

// toggle help Q/A



//controls view via the question link
$(".togglethis").click(function(){
		
			
		$(this).parent().next(".answer").animate({ height: 'toggle', opacity: 'toggle' }, 'fast');
	    $(this).parent("div").toggleClass("toggleminus");
	
		return false;
  });
  
//service request

var serviceRequestWarning = 'Are you sure you want to report a system down (not able to treat patients) ?';
var freeformReturnURL     = $('#service-request-form input[name="return"]').val();

$('#service-question').keyup(function() {

                var len = this.value.length;
				if (len >= 40) {
					this.value = this.value.substring(0, 40);
				}
				if (len >= 40) {
					$('#charLeft').text('0');
					}
					else {
						$('#charLeft').text(40 - len);
					}

            });
            
            
$("a.language").click(function(){
		var thisLanguage= $(this).attr('id');
		$(this).addClass('active');
		$(this).siblings('a.language').removeClass('active');
		
		if ( thisLanguage=='english'){
		   var thisIntro='Please fill in the information below to request a call back from Medical Physics or Technical Support.';
		   var thisGantry='Gantry Serial Number (Format 110xxx)';
		   var thisSiteName='Site Name';
		   var thisContact='Contact Name';
		   var thisContactNumber='Contact Phone Number, including country code (format +XXX-XX...)';
		   var thisFseEmail='Contact Email Address';

		   var thisPriority='Priority of Issue';
		   var thisPriority1='System Down – unable to treat';
		   var thisPriority2='System not Down – System Operational, still able to treat';
		   
		   var thisSupport='Requesting Contact from TomoTherapy';
		   var thisSupport1='Medical Physics';
		   var thisSupport2='Technical Support';
		   var thisQuestion='Description of problem';
		   var thisSubmit='Submit';
		   
		   var thisWarning='Are you sure you want to report a system down (not able to treat patients) ?';
		   var thisSubject='TomoTherapy: Thank you for your Service Request';

		   var thisCharTitle='Maximum characters: 40';		
		   var thisCharLabel='Characters left';
		}



		if ( thisLanguage=='german'){
		   var thisIntro='Bitte füllen Sie die untenstehenden Informationen vollst&auml;ndig aus, um einen Rückruf von Medizinische Physik oder Technische Unterstützung zu bekommen.';
		  
		   var thisGantry='Seriennummer (Format 110xxx)';
		   var thisSiteName='Standort';
		   var thisContact='Ansprechpartner';
		   var thisContactNumber='Telefonnummer des Ansprechpartners, inklusive der<br />Landes- und Städtevorwahl (Format: +49 – XX…)';
		   var thisFseEmail='Email Adresse';
		   
		   var thisPriority='Dringlichkeit des Problems';
		   var thisPriority1='Maschine gestoppt – keine Behandlung möglich';
		   var thisPriority2='Kein Stillstand – Maschine ist in Verwendung und es werden Patienten bestrahlt';
		   
		   var thisSupport='Rückruf erforderlich von';
		   var thisSupport1='Medizinische Physik';
		   var thisSupport2='Technische Kundenbetreuung';
		   
		   var thisQuestion='Problembeschreibung:<br /><span>(Bitte schreiben Sie die Fehlermeldung auf Englisch)</span>';
		   var thisSubmit='Meldung senden';
		
		   var thisWarning='Wollen Sie wirklich ein System Down melden (Sie sind nicht in der Lage Patienten zu behandeln) ?';
		   var thisSubject='TomoTherapy: Thank you for your Service Request';
		
		   var thisCharTitle='maximal 40 Zeichen';		
		   var thisCharLabel='Zeichen übrig';
		}
		
		if ( thisLanguage=='spanish'){
		   var thisIntro='Por favor introduzca la informaci&oacute;n requerida para ser contactado por Física Médica o Soporte Técnico';
		   var thisGantry='Número de Serie del Gantry (Formato 110xxx)';
		   var thisSiteName='Nombre del centro';
		   var thisContact='Persona de Contacto';
		   var thisContactNumber='Teléfono de Contacto, incluyendo el código de pais (+34-XX...)';
		   var thisFseEmail='Correo electrónico de contacto';
		   
		   var thisPriority='Prioridad de la petición de asistencia';
		   var thisPriority1='Máquina Parada – los tratamientos han cesado por problemas técnicos';
		   var thisPriority2='Máquina no Parada – Sistema Operative, los tratamientos continúan';
		   
		   var thisSupport='Solicitud de Contacto con';
		   var thisSupport1='Física Médica';
		   var thisSupport2='Soporte Técnico';
		   var thisQuestion='Descripcion del Problema<br /><span>(Por favor, describa la avería en inglés)</span>';
		   var thisSubmit='Enviar';
		
		   var thisWarning='¿Quiere informar de maquina parada (no se puede tratar pacientes) ?';
		   var thisSubject='TomoTherapy: Thank you for your Service Request';
		
		   var thisCharTitle='Máximo 40 Caracteres';		
		   var thisCharLabel='Caracteres Libres';
		}
		
		if ( thisLanguage=='french'){
		   var thisIntro='Veuillez remplir le questionnaire ci-dessous afin que notre Physique Médicale ou notre Support Technique puisse vous contacter.';
		   var thisGantry='Numéro de Série de la Machine (Format 110xxx)';
		   var thisSiteName='Nom du Site';
		   var thisContact='Nom du Contact';
		   var thisContactNumber='Numéro de Téléphone du Contact, incluant le code <br />international (+ 33- XX…)';
		   var thisFseEmail='Adresse Email du Contact';
		   
		   var thisPriority='Niveau de Priorité du Problème';
		   var thisPriority1='Système en Panne – Traitement patient impossible';
		   var thisPriority2='Système non arrêté – Système opérationnel, traitement patient toujours possible';
		   
		   var thisSupport='Demande de Contact auprès de: ';
		   var thisSupport1='Physique Médicale';
		   var thisSupport2='Support Technique';
		   var thisQuestion='Description du problème:<br /><span>(Veuillez décrire le problème en anglais s&acute;il vous plait)</span>';
		   var thisSubmit='Envoyer';
		
		   var thisWarning='Souhaitez-vous déclarer la machine comme étant "en panne" (impossibilité de traiter les patients) ?';
		   var thisSubject='TomoTherapy: Thank you for your Service Request';

		   var thisCharTitle='Nombre de caractères maximum: 40';		
		   var thisCharLabel='caractères restant';
		}
		
		if ( thisLanguage=='italian'){
		   var thisIntro='Si prega gentilmente di inserire tutti i dati nei campi sottostanti al fine di poter essere correttamente contattati dal supporto Clinco/Fisico o dall&acute;Assistenza Tecnica.';
		   var thisGantry='Numero di Serie del Gantry (Formato 110xxx)';
		   var thisSiteName='Nome del Sito';
		   var thisContact='Nome della Persona da Contattare';
		   var thisContactNumber='Numero Telefonico della Persona da Contattare, includendo il codice <br />telefonico del paese (formato +39-XX..)';
		   var thisFseEmail='Indirizzo Email della Persona da Contattare';
		   
		   var thisPriority='Priorià della Richiesta';
		   var thisPriority1='Sistema Inutilizzabile –  Non in grado di effettuare trattamenti';
		   var thisPriority2='Sistema Funzionante – Operativo e in grado di effettuare trattamenti';
		   
		   var thisSupport='Tipologia della richiesta';
		   var thisSupport1='Supporto Clinico/Fisico';
		   var thisSupport2='Assistenza  Tecnica';
		   var thisQuestion='Descrizione del Problema:<br /><span>(Si prega gentilmente di descrivere il problema in lingua inglese)</span>';
		   var thisSubmit='Invia';
		
		   var thisWarning='Ci conferma che il sistema è inutilizzabile ( non possono essere trattati pazienti )?';
		   var thisSubject='TomoTherapy: Thank you for your Service Request';

		   var thisCharTitle='Massimo caratteri: 40';		
		   var thisCharLabel='Caratteri rimanenti';
		}
		
		if ( thisLanguage=='dutch'){
		   var thisIntro='Gelieve de hierna volgende informatie in te vullen om telefonisch contact aan te vragen met Medische Fysica of Technische Ondersteuning.';
		   
		   var thisGantry='Machine Serie Nummer (Formaat 110xxx)';
		   var thisSiteName='Kliniek Naam';
		   var thisContact='Contact Naam';
		   var thisContactNumber='Contact Telefoonnummer, inclusief de landcode (+31 –XX...)';
		   var thisFseEmail='Contact Email adres';
		   
		   var thisPriority='Prioriteit van het Probleem';
		   var thisPriority1='Systeem onbruikbaar – Systeem niet in staat om te behandelen';
		   var thisPriority2='Systeem operationeel – Systeem bruikbaar en in staat om te behandelen';
		   
		   var thisSupport='Aanvraag voor Telefonisch Contact met';
		   var thisSupport1='Medische Fysica';
		   var thisSupport2='Technische Ondersteuning';
		   var thisQuestion='Omschrijving van het Probleem:<br /><span>(U wordt vriendelijk verzocht het probleem in het Engels te omschrijven)</span>';
		   var thisSubmit='Versturen';
		
		   var thisWarning='Bent u er zeker van om het systeem als "onbruikbaar" te melden';
		   var thisSubject='TomoTherapy: Thank you for your Service Request';

		   var thisCharTitle='Maximum aantal karakters: 40';		
		   var thisCharLabel='Aantal karakters over';
		}
		
		
		
			
		$('label.gantry').html(thisGantry);
		$('label.site_name').html(thisSiteName);
		$('label.contact').html(thisContact);
		$('label.contact_number').html(thisContactNumber);
		$('label.fse_email').html(thisFseEmail);
		$('label.priority').html(thisPriority);
		$('label.priority_1').html(thisPriority1);
		$('label.priority_2').html(thisPriority2);
		
		$('label.support_type').html(thisSupport);
		$('label.support_1').html(thisSupport1);
		$('label.support_2').html(thisSupport2);
		$('label.question').html(thisQuestion);
		
		$('span.charTitle').html(thisCharTitle);
		$('span.charLabel').html(thisCharLabel);
		
		$('input.submit').attr('value',thisSubmit);
		
		// Set warning message
		serviceRequestWarning = thisWarning;
		
		// Update hidden fields for response email template language parsing
		$('input[name="language"]').attr('value',thisLanguage);
		$('input[name="subject"]').attr('value',thisSubject);
		
		// Append language to stored default Freeform return URL for success message translation
		$('#service-request-form input[name="return"]').val(freeformReturnURL+'&#47;'+thisLanguage);
	
		return false;
  });

	// Confirm P1 System Down priority
	$('#service-request-form form').submit(function(){

		if($('input#urgent_1').is(':checked')) {
			
			if(confirm(serviceRequestWarning)) {
				$('input.submit').attr('disabled', 'disabled');
				$('<img src="http://www.tomotherapy.com/images/site/ajaxLoader.gif" id="loading" width="20" height="20" />').insertAfter($('input.submit'));
				return true;
			} else {
				// Uncheck and re-check medium
				$('input#urgent_1').removeAttr('checked');
				$('input#urgent_3').attr('checked', 'checked');
				return false;
			}
			
		} else {
			// Clear out default text from phone field if they haven't
			// added anything so Freeform can validate it as empty
			if($('input#phone1').val() == '+') {
				$('input#phone1').val('');
			}
			$('input.submit').attr('disabled', 'disabled');
			$('<img src="http://www.tomotherapy.com/images/site/ajaxLoader.gif" id="loading" width="20" height="20" />').insertAfter($('input.submit'));
			return true;
		}
	
		
		
	});
  
	// Tabs
	
	/*
				$('#tabs').tabs();
				
				$('.video_details').corner();
			
				$('.ui-tabs-panel').corner({
							  tr: { radius: 6 },
							  tl:false,
							  bl: { radius: 6 },
							  br: { radius: 6 }}
							  );
				
					$('.tile,.playlist').corner();
				
			
					*/

	



//external links to open in new window
$('a[@rel*="external"]').click( function() {
window.open( $(this).attr("href") );
return false;
});

/*$('.popup').popupWindow({ 
centerBrowser:1 
}); 
*/


});
