$(function() {
	
			function isURL(s){
				var regexp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
				return regexp.test(s);
		} 
		
		function isEmail(email){
		    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
		    if(RegExp.test(email)){
		        return true;
		    }else{
		        return false;
		    }
		} 


	
	
// Lupen

var MultiPlicator = 1.1;

$("img[id='ZoomIn']").click(function() {

		$("*").each(function() {
		
			tfs = $(this).css("font-size");
			tfs = parseFloat(tfs);
			nfs = tfs * MultiPlicator;

			if($.browser.msie) {
				nfs = 20;
			}

			$(this).css({
				'font-size': nfs + 'px'
			});
			
		});

	});

$("img[id='ZoomOut']").click(function() {

		$("*").each(function() {
			
		
			tfs = $(this).css("font-size");
			tfs = parseFloat(tfs);
			nfs = tfs / MultiPlicator;

			if($.browser.msie) {
				nfs = 12;
			}
			
			$(this).css({
				'font-size': nfs + 'px'
			});
			
		});


	});


$("a[id^='MainMenuLink_']").click(function() {

//	return false;
	
});


// News Navigation

	// Define Page-Break
	var NN_pagebreak = ".NewsPageBreak";

	// Get Pages
	var NN_pages = 0;
	$(NN_pagebreak).each(function(){
		NN_pages++;
	});

	// Define Navigation Buttons
	var NN_next = "#NewsMoverRight";
	var NN_prev = "#NewsMoverLeft";
	
	// Define Current Page
	var NN_currentpage = 1;

	// Define Steps per Move
	var NN_steps = 1;
	
	// Define ShownPages per Page
	var NN_ppp = 1;
	
	// Define Key Navigation activation - Remove on an Input Focus!
	var NN_keyActive = 1;
	
// Script-Nothing to Change Anymore!

	// To Aply to the Zero-Index
	NN_currentpage--;
	NN_pages--;

	function NN_CheckRange() {
		if(NN_currentpage <= 0) {
			NN_currentpage = 0;
			$(NN_prev).hide();
			$(NN_next).show();
			return false;
		}
		
		if(NN_currentpage == NN_pages){
			NN_currentpage = NN_pages;
			$(NN_next).hide();
			$(NN_prev).show();
			return false;
		}
		
		if(NN_currentpage > 0 && NN_currentpage < NN_pages) {
			$(NN_prev).show();
			$(NN_next).show();
			return true;
		} 
	}

	function NN_isPossible(action) {
		
		if(action == "back") {
			if(NN_currentpage > 0) {
			// Back Possible
			return true;
			} else {
				return false;
			}
		} else if(action == "next") {
			
			if (NN_currentpage < NN_pages) {
				// Next Possible
				return true;
			} else {
				return false;
			}

		} else {
			return false;
		}
		
	}

	function NN_JumpToIndex(id) {
		$(NN_pagebreak+":visible").slideUp();		
		$(NN_pagebreak+":eq("+id+")").slideDown();
	}

	function NN_ShowNext() {
//		alert("Next Page");	

		NN_currentpage++;
		NN_JumpToIndex(NN_currentpage);
		NN_CheckRange();
	}
	
	function NN_ShowPrev() {
//		alert("Prev Page");
		NN_currentpage--;
		NN_JumpToIndex(NN_currentpage);
		NN_CheckRange();
	}
	
	function NN_GetStartView() {
		$(NN_pagebreak).hide();
		$(NN_pagebreak+":eq("+NN_currentpage+")").show();
		NN_CheckRange();
	}

	// Event Handling
	
	$(NN_next).click(function() {
		NN_ShowNext();
	});
	
	$(NN_prev).click(function() {
		NN_ShowPrev();
	});



	
	// First Autorun
	NN_GetStartView();




// News-Entry hover 

	NF_StartPart = "#NewsPart_Start_";
	NF_BreakPart = "#NewsPart_Break_";
	NF_EndPart = "#NewsPart_Rest_";	
	NF_EntryClass = ".RightShortnewsEntry";
	
	$(NF_EntryClass).hover(function() {
		
		// Doing on MouseOver
		
		id = getIdByName($(this).attr('id'));
		
		$(NF_BreakPart+id).hide();
		$(NF_EndPart+id).show().effect("highlight");
		
	},
	function() {

		// Doing on MouseOut
		
		id = getIdByName($(this).attr('id'));
		
		$(NF_EndPart+id).hide();
		$(NF_BreakPart+id).show().effect("highlight");
		
	})


	
// Little Helpers

	function getIdByName(name) {
		name = name.split("_");
		anzahl = name.length;
		anzahl--;
		return name[anzahl];
	}


// Team-Handling

function countElements(selector) {
	i = 0;
	$(selector).each(function() {
		i++;
	});
	return i;
}

if(countElements("div[id^='portrait_']:first") > 0) {
	var currOpenMa = getIdByName($("div[id^='portrait_']:first").attr('id'));
}
	
 function switchMa(to) {

	if(to != currOpenMa) {

		$("div[id='portrait_"+currOpenMa+"']").hide();
		$("div[id='portrait_"+to+"']").show();

		currOpenMa = to;

	} 	
	
 }
	
 $("div[id^='team_portrait_select_']").hover(function() {
	
	maId = getIdByName($(this).attr('id')); 	
	switchMa(maId);	

	 },function() {
// 	alert("off");
 })
 
 // Click-Selector
 
 $("div[id^='QB_']").click(function(){
		id = getIdByName($(this).attr('id'));
		link = $("div[id='QBLink_"+id+"']").text();
		lowerlink = link.toLowerCase();
		
		intern = lowerlink.search(/http:\/\/www.top-telcom-service.ch.+/);
		
		if(link != "" && intern >= 0) {
			window.location.href = link;
		} else if(link != "") {
			window.open(link);
		}
 });

	// Externer Link
 
 $("a.LinkExt").click(function(){
		window.open($(this).attr('href'));
		return false;
 });

	
	// Spam Key Detection
	
	var TrueVar = "genau";
	var SpamKeyInput = "input[id='KSpamCode']";
	var SpamKeyValue = $("#SpamCode").text();
	var SpamTrueTarget = "input[id='KSpamOk']";
	var SpamTrueMessageBox = $("#SpamCodeOk");
	var SpamCodeSection = $("#SpamCodeSection");
	var KWrongClass = "KWrongClass";
	
	$(SpamKeyInput).keyup(function() {
		if($(SpamKeyInput).val() == SpamKeyValue) {
			$(SpamTrueTarget).val(TrueVar); 
			SpamCodeSection.hide();
			SpamTrueMessageBox.show();
		} else {
			$(SpamTrueTarget).val('Falsch'); 
			SpamTrueMessageBox.hide();
			SpamCodeSection.show();
		}
	});

	function checkContactForm() {

		

//		return false;

		// Remove Class
		
		$("."+KWrongClass).removeClass(KWrongClass)

		// Name

		nameFeld = $("#KName");
		name = jQuery.trim(nameFeld.val());

		// E-Mail

		emailFeld = $("#KEmail");
		email = jQuery.trim(emailFeld.val());

		// Kommentar

		textFeld = $("#KText");
		text = jQuery.trim(textFeld.val());

		if(name == "") {
			alert("Bitte füllen Sie das Feld für den Namen aus.");
			nameFeld.addClass(KWrongClass);
			nameFeld.select();
		} else if(email == "") {
			alert("Bitte füllen Sie das Feld für Ihre E-Mail Adresse aus.");
			emailFeld.addClass(KWrongClass);
			emailFeld.select();
		} else if(isEmail(email) != true) {
			alert("Ihre Eingabe unter E-Mail-Adresse ist ungültig.");
			emailFeld.addClass(KWrongClass);
			emailFeld.select();
		} else if(text == "") {
			alert("Bitte geben Sie uns einpaar Stichworte, damit wir Ihr Anliegen raschmöglichst bearbeiten können.");
			textFeld.addClass(KWrongClass);
			textFeld.select();
		} else if($(SpamKeyInput).val() != SpamKeyValue) {
			alert("Bitte übertragen Sie den Spam-Code im schwarzen Feld in das nebenstehende Textfeld.");
			$(SpamKeyInput).addClass(KWrongClass);
			$(SpamKeyInput).select();
		} else {
			$("#KontaktFormDiv").slideUp();
			$("#KMessSend").slideDown();
			return true;
		}


	}
	
	$("#KontaktForm").ajaxForm({
		beforeSubmit : function() {
			return checkContactForm();
		}
	});

	
	// Produkte Navigation

	var MaxProdPerPage = 3;
	var ProdElement = "div[id^='Produkt_']";
	var StartProdPage = 0;
	var CountProducts = countElements(ProdElement);
	var ProdElementString = "";
	
	$(".ProdSelByMarken a").click(function() {

		text = $(this).text();
		text = text.toLowerCase();

		$(ProdElement).hide();
		$(ProdElement+":contains('"+text+"')").show();
		updateProduktSeite(StartProdPage);
		
		return false;

	});
	
	if(CountProducts >= 1) {
//		alert("Es sind "+CountProducts+" Produkte gelistet.");
		updateProduktSeite(StartProdPage);
	}
	
	function getProduktElementString() {
		ProdElementString = "";
		$(ProdElement+":visible").each(function() {
			if(ProdElementString == "") {
				ProdElementString = getIdByName($(this).attr('id'));
			} else {
				ProdElementString += ","+getIdByName($(this).attr('id'));
			}
		});
	}
	
	function updateProduktSeite(start) {
		getProduktElementString();
		createProduktIndex(start);
		updateProductPaging();
	}

	function createProduktIndex(start) {
		iCount = 0;
		endPoint = start + MaxProdPerPage;
		iCount2 = 0;
		ElArray = ProdElementString.split(",");
		$(ProdElement).hide();
		jQuery.each(ElArray, function() {
			if(iCount2 <= endPoint && iCount2 >= start) {
				if(iCount < MaxProdPerPage) {
					$("#Produkt_"+this).show();
					iCount++;
				}
			}
			iCount2++;
		});
	}

	function updateProductPaging() {
		cont = $("#ProduktPaging").text();
		
		if(cont == "") {
			createProductPaging();
		} else {

			ElArray = ProdElementString.split(",");
			anz = ElArray.length;
			seiten = anz / MaxProdPerPage;
			seiten = Math.ceil(seiten);	

			$("a[id^='ProduktPaging_']:lt("+seiten+")").show();
			seiten = seiten - 1;
			$("a[id^='ProduktPaging_']:gt("+seiten+")").hide();
		}
		
	}

	function createProductPaging() {
		ElArray = ProdElementString.split(",");
		anz = ElArray.length;
		seiten = anz / MaxProdPerPage;
		seiten = Math.ceil(seiten);	
		htapp = "";
		for(i = 1;i <= seiten; i++) {
			htapp += "<a href='#' id=\"ProduktPaging_"+i+"\">"+i+"</a> ";
		}
		$("#ProduktPaging").html(htapp);
	}


	$("a[id^='ProduktPaging_']").click(function(){
		page = getIdByName($(this).attr('id'));
		start = (page -1) * MaxProdPerPage;
		createProduktIndex(start);
		return false;
	});	

// Formular


	$("#CMSLoginForm").ajaxForm({
		beforeSubmit : function() {
			user = jQuery.trim($("#User").val());
			pw = jQuery.trim($("#Passwort").val());
			
			if(user != "" && pw != "") {
				return true;				
			} else {
				alert("Bitte füllen Sie die Felder für den Benutzername und das Passwort aus.");
				return false;
			}
		},
		success : function(xy) {
		if(xy == "falsch") {
			alert("Login fehlgeschlagen.");
		} else if(xy == "ok") {
			window.location.href = "http://www.top-telcom-service.ch/tts/";			
		}
		}
	});


	$(".CMSLoginForm").each(function() {
		
		
		lw = $(this).width();
		lh = $(this).height();
		
		sw = $(document).width();
		sh = $(document).height();

		nl = (sw / 2) - (lw / 2);
		nt = (sh / 2) - (lh / 2);

		
		$(this).css({
			top: nt+"px",
			left: nl+"px"
		});
		
		
		
	});


	$(".eyecatcher_text_swisscom").click(function() {
		
		url = "http://swisscomonlineshop.sso.bluewin.ch/onlineshop/pages/ProductDetail/ProductDetail.aspx?id=IP_Connect_basic30%28MasterProducts%29&PartnerId=45159&lang=DE";
		window.open(url);
		
	});
	
	$("div[id^='team_portrait_select_']").click(function(){
		EMail = jQuery.trim($(this).attr('rel'));
		if (EMail != "") {
			splittedMail = EMail.split(' # ');
			NeueMail = splittedMail[0] + "@" + splittedMail[1];
			window.location.href = 'mailto: ' + NeueMail;
		}
	});


	$(".SubmenuStarRight a img").hover(function() {
		$(".SubmenuStarRight a span").show();
	},function() {
		$(".SubmenuStarRight a span").hide();
	});

});

