/**
* Tyco FIS
*
* Javascript developed by Bloom Media Ltd. | www.bloommedia.co.uk
* Contributors: Dominic Kelly
*/

// Attach events - MooTools syntax (check objects exist first)
document.addEvent( 'domready' , function() {
		// dom ready
		// 'extra' links
		if($('doEmail')){$('doEmail').addEvent( 'click' , doEmail);} //email link
		if($('doPrint')){$('doPrint').addEvent( 'click' , doPrint);} // print link
		if($('doBookmark')){$('doBookmark').addEvent( 'click' , doBookmark);} // bookmark link
		// quick search
		if($('doQuickSearch')){$('doQuickSearch').addEvent( 'click' , doQuickSearch);} //quick search button
		if($('txtQuickSearch')){$('txtQuickSearch').addEvent( 'focus' , focusQuickSearch);} //quick search textbox
		if($('txtQuickSearch')){$('txtQuickSearch').addEvent( 'blur' , blurQuickSearch);} // quick search textbox




if($('SKFCE_15_UserInput')){$('SKFCE_15_UserInput').addEvent( 'focus' , focuscaptcha);} //quick search textbox
if($('SKFCE_12_UserInput')){$('SKFCE_12_UserInput').addEvent( 'focus' , focuscaptcha);} //quick search textbox		



// newsletter sign up
		if($('donewsletter')){$('donewsletter').addEvent( 'click' , donewsletter);} //newsletter button
		if($('txtnewsletter')){$('txtnewsletter').addEvent( 'focus' , focusnewsletter);} //newsletter textbox
		if($('txtnewsletter')){$('txtnewsletter').addEvent( 'blur' , blurnewsletter);} 
// newsletter textbox




// infonet
		if($('doinfonet')){$('doinfonet').addEvent( 'click' , doinfonet);} //infonet button
		if($('txtinfonet')){$('txtinfonet').addEvent( 'focus' , focusinfonet);} //infonet textbox
		if($('txtinfonet')){$('txtinfonet').addEvent( 'blur' , blurinfonet);} 
// infonet textbox

//infonet button
		if($('txtinfonet2')){$('txtinfonet2').addEvent( 'focus' , focusinfonet2);} //infonet textbox
		if($('txtinfonet2')){$('txtinfonet2').addEvent( 'blur' , blurinfonet2);} 
// infonet textbox



		// ask the expert
		if($('doAskTheExpert')){$('doAskTheExpert').addEvent( 'click' , doAskTheExpert);} //quick search button
		if($('txtAskTheExpert')){$('txtAskTheExpert').addEvent( 'focus' , focusAskTheExpert);} //quick search textbox
		if($('txtAskTheExpert')){$('txtAskTheExpert').addEvent( 'blur' , blurAskTheExpert);} // quick search textbox
		if($('ddl-ate-markets')){$('ddl-ate-markets').addEvent( 'change' , changeAskTheExpert);} // navigate to expert pages, drop down


		// add omniture variable to ask the expert form submission page
		//if(getPageName() == "thank-you"){
		//	s.events = 1;
		//}
		
		
	

		
		
		// attach new fValidfator class' to specific fields based on the type validation required
		
		// Information request form
		
    if($('Sitekit_Form_313')){			
			document.getElementById('SKFCE_1_UserInput').className="fValidate['required','blank']";
			document.getElementById('SKFCE_2_UserInput').className="fValidate['required','blank']";
			document.getElementById('SKFCE_3_UserInput').className="fValidate['required','blank']";
			document.getElementById('SKFCE_4_UserInput').className="fValidate['required','blank']";	
			document.getElementById('SKFCE_5_UserInput').className="fValidate['required','email']";
	
		var exValidatorB = new fValidator("Sitekit_Form_313", {required: {msg: "Detta \u00E4r ett obligatoriskt f\u00E4lt."}, email: {msg: "Ange en giltig e-postadress."}} );
		
		
		$('PostEnquiry').addEvent( 'focus' , checkforboxes);
		
		}
		
		function checkforboxes() {
			
			// on enquiry form, check if a checkbox has been ticked //
			
			x=0;
			
			var bitone=""+document.getElementById('SKFCE_12_UserInput').checked;
			var bittwo=""+document.getElementById('SKFCE_13_UserInput').checked;
			var bitthree=""+document.getElementById('SKFCE_14_UserInput').checked;

			
		
			if(bitone=="true") {
			x++;
			}
			if(bittwo=="true") {
			x++;
			}
			if(bitthree=="true") {
			x++;
			}
	
		
			if (x<1) {
	
		alert("Bitte gehen Sie zur\xfcck zum Formular und f\xfcllen Sie alle erforderlichen Felder aus. ");
document.getElementById('SKFCE_15_UserInput').focus();
		return false;
		
		
			}
		
		}
		
		// flv videos - product pages
		if($('videoName')){
		
		    // get video name
			var e = document.getElementById('videoName').innerHTML;
			
			// hide from user. This will appear in SiteKit as javascript is not parsed.
			document.getElementById('videoName').style.display = "none";
			
			// find value between hashes, i.e. #value#
			var firstDelimeter = e.indexOf("#") + 1;
			var lastDelimeter = e.lastIndexOf("#");
			
			// slice string inside delimeters
			e = e.slice(firstDelimeter,lastDelimeter)
			
			// only place the video if the video name is not blank
			if(e!=""){
				displayVideoPlayer(e.toLowerCase());
			}else{
				document.getElementById('video').style.display = "none";
			}			
		}
		
		// contact email addresses for ask the expert contact forms
		if($('notification-email')){
		
		
		// UPDATE FOR GERMAN SITE ONLY - 
		// ADDS TITLE OF PAGE RATHER THAN EMAIL TO SEND WITH RESPONSE
		
		
		    // get email address
			
				e=document.title;
			
			document.getElementById('SKFCE_16_UserInput').value=e;
			

		}	
		
	}
)

// Print 
function doEmail(){
	//email_str = "mailto:?subject=TycoFis website: " + document.title + &body= " + document.title + ": ";

var pagebit=String(location.href);

var qparts = pagebit.split("#");

pagebit=qparts[0];


var subjbit="Tyco Fire and Integrated Solutions Intressant site...";
var bodbit="En anv%E4ndare har skickat en l%E4nk till en del v%E4rdefull information p%E5 Tyco %26 ADT's hemsida.%0A%0A"+pagebit+"%0A%0ATa en titt f%F6r att ta reda p%E5 vad de trodde att du skulle finna var intressant.%0A%0AAvs%E4ndarens detaljer har inte kontrollerats.";
	email_str = "mailto:?subject="+subjbit+"&body=" + bodbit;
	//email_str += "&body= " + document.title + ": ";
	//email_str +=  location.href;
	location.href = email_str; 
}

// Email 
function doPrint(){
	window.print();
}

// Bookmark 
function doBookmark(){

	var title = "Tyco Fire and Integrated Solutions";
	var url = "http://www.tycofis.at";
	
	if (document.all){ // ie
		window.external.AddFavorite(url, title);
	}else if (window.sidebar){ // firefox
		window.sidebar.addPanel(title, url, "");
	}else{ // opera and safari and all other browsers not supported
		alert("Press CTRL + D to bookmark this page");
	}
}

// Quick search
function doQuickSearch(){		
	if(($('txtQuickSearch').value == "s\u00f6k period...")){
	}else{
		$('frmQuickSearch').submit();
	}
}

function focusQuickSearch(){

	this.value = "";	


}


function focuscaptcha(){
if(this.value=="Pflichtfeld"){
	this.value = "";
}	

}


function blurQuickSearch(){
	// user left the text box blank, so reset it
	if(this.value.length < 1){
		this.value = "s\u00f6k period...";
	}
}





// Newsletter 
function donewsletter(){		
	if(($('txtnewsletter').value == "Email Adresse")){
	}else{
		$('frmQuickSearch').submit();
	}
}

function focusnewsletter(){
	this.value = "";	

}
function blurnewsletter(){
	// user left the text box blank, so reset it
	if(this.value.length < 1){
		this.value = "Email Adresse";
	}
}





// Infonet
function doinfonet(){		
		var username = $('txtinfonet').value;
		var password = $('txtinfonet2').value;
		// pass username and password into form action url
		
		var url = "http://" + username + ":" + password +"@www.tycofis.de/totalwalther/tw_infonet_cms.nsf/index/CMSE6AD5F03F215CA43C1256F2300553FFE?openDocument&login&currentURL=CMS1A0CA0911F9B8B6EC1256C5D00542FEB";
		alert(url);
		//window.location = url;
}

function focusinfonet(){
	this.value = "";	

}
function blurinfonet(){
	// user left the text box blank, so reset it
	if(this.value.length < 1){
		this.value = "Benutzername";
	}
}

function focusinfonet2(){
	this.value = "";	

}
function blurinfonet2(){
	// user left the text box blank, so reset it
	if(this.value.length < 1){
		this.value = "Passwort";
	}
}











// ask the expert search
function doAskTheExpert(){		
	if(($('txtAskTheExpert').value == "Ask a question...")){
		alert("Ask a question...");
	}else{
		$('frmFaqSearch').submit();
	}
}

function focusAskTheExpert(){
	this.value = "";	
}

function blurAskTheExpert(){
	// user left the text box blank, so reset it
	if(this.value.length < 1){
		this.value = "Ask a question...";
	}
}

function changeAskTheExpert(){
	if(this.selectedIndex !=0 && this.value != "default"){
		window.location = this.value;
	}else{
		window.location = "http://tycogermany.sitekit.net/branchenlosungen";
	}
}

// returns the html name of the page
function getPageName(){
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}

// display video on product pages
function displayVideoPlayer(e){
			var so = new SWFObject("flash/flv-player.swf", "FLV Player", "480", "307", "8", "#fff");
			so.addVariable("flvLocation", e); // value set in FCK editor. represents video file location, and is passed into flash
			so.useExpressInstall('../flash/expressinstall.swf'); // upgeade user
			so.write("flashcontent");
}





// add flash - nb mootools sometimes doesn't work in ie when flash is on a page


var MM_contentVersion = 4;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
		
	
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}



function placeflash(moviename,widd,hidd) {

document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+widd+'" height="'+hidd+'">');
document.write('<param name="movie" value="'+moviename+'">');
document.write('<param name="quality" value="high">');
document.write('<embed src="'+moviename+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+widd+'" height="'+hidd+'"></embed>');
document.write('</object>');

}


// replace flash on homepage with graphic
function homepagenoflash() {
document.write('<img src="template_images/homepage-flash-no-flash.jpg" alt="Tyco Fire &amp; Integrated Solutions - A vital part of your world" />');	
}
