/*
 * Ersetzt ein DIV durch ein Flash, das den gleichen Text (ohne HTML-Tags)
 * anzeigt.
 */
function replaceHeadline(id,width,height,color,size,padding) {
	var div = document.getElementById(id);
	if (div) {
		// Text der Headline suchen
		var text = div.innerHTML;// ? div.innerText : div.textContent;
		if (text) {
			text = text.replace(/^\s+/, "");
			text = text.replace(/&/, "%26");
		}

		// Link der Headline suchen
		var link;
		var atags = getElementsByTagName(div, "a");
		if (atags && atags.length > 0) {
			link = atags[0].href;
		}

		// Flash einsetzen
		var so = new SWFObject("/swf/headline-at.swf", id, width, height, "8", "#FFFFFF");
		so.addVariable("text", text);
		so.addVariable("colorhex", color);
		so.addVariable("fontsize", size);
		so.addVariable("padding_left", padding);
		if (link && link != '') {
			so.addVariable("link", link);
		}
		so.addParam("wmode", "transparent");
		so.write(id);

		// Gefundened DIV zurückliefern
		return div;
	}
}

/*
 * Liefert alle Tags eines bestimmten Namens unterhalb des
 * übergebenen Root-Knotens
 */
function getElementsByTagName(root, tagname) {
	// Neue Liste für zu bearbeitende Knoten
	var todo = new Array(root);
	// Neue Liste für gefundene Tags
	var found = new Array();
	// Tagnamen auf Großbuchstaben bringen
	tagname = tagname.toUpperCase();

	// Liste abarbeiten
	while(todo.length > 0) {
		var tag = todo.pop();
		if (tag.nodeName.toUpperCase() == tagname) {
			found.push(tag);
		}
		if (tag.childNodes) {
			for(var i=tag.childNodes.length-1 ; i>=0 ; --i) {
				todo.push(tag.childNodes[i]);
			}
		}
	}

	return found;
}


function productIconMouseOver(which)
{
	$('#producticontitle'+which).show();
	$('#producticontitle'+which).stop().animate({height:"22px",paddingTop:"4px"}, {duration:150})
}


function productIconMouseOut(which)
{
	$('#producticontitle'+which).stop().animate({paddingTop:"0px",height:"0px"}, {duration:290},function(){$('#producticontitle'+which).hide();})
}


function showPopupWithLink(phoneId, w, h, pageId) 
{
	var popupLink = pageId + "?productId=" + phoneId;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var properties = "width=" + w + ",height=" + h + ",top="+wint+",left="+winl+",scrollbars=1,addressbar=0,toolbar=0,resizable=yes";
	window.open(popupLink, 'popup',properties);
	return false;
}

function showPopup(popupLink, w, h) 
{
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var properties = "width=" + w + ",height=" + h + ",top="+wint+",left="+winl+",scrollbars=1,addressbar=0,toolbar=0,resizable=yes,target=_blank";
	window.open(popupLink, 'popup', properties);
}


function showFlashLayer(siteIndex){
	
	$('#flashContentLayer').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="644" height="634" id="Main" align="middle"><param name="movie" value="../swf/layer/videolayer.swf?siteIndex='+siteIndex+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="play" value="true" /><param name="loop" value="true" /><param name="wmode" value="transparent" /><param name="scale" value="showall" /><param name="menu" value="true" /><param name="devicefont" value="false" /><param name="salign" value="" /><param name="allowScriptAccess" value="sameDomain" /><object type="application/x-shockwave-flash" data="../swf/layer/videolayer.swf?siteIndex='+siteIndex+'" width="644" height="634"><param name="movie" value="../swf/layer/videolayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#666666" /><param name="play" value="true" /><param name="loop" value="true" /><param name="wmode" value="transparent" /><param name="scale" value="showall" /><param name="menu" value="true" /><param name="devicefont" value="false" /><param name="salign" value="" /><param name="allowScriptAccess" value="sameDomain" /><a href="http://www.adobe.com/go/getflash"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" /></a></object>');
	$('#layer_flashteaser').modal({opacity:40});
	
	trackingVideoLayer();
	
}

function hideFlashLayer(){
	$.modal.close();
}


function showEmailLayer(){
	$('#layer_email_div').modal({opacity:40});
	
}



function sendPdfFormular(namefail, ownemailfail, friendemailfail, subjectfail, textfail){
	
	var name = $('#name').val();
	var ownemail = $('#ownemail').val(); 
	var friendemail = $('#friendemail').val();
	var subject = $('#subject').val();
	var text = $('#text').val();
	var file = $('#file').val();
	
	
	if(validateEmail(ownemail) && validateEmail(friendemail) && name != "" && name != "" ) 
	{
			
		$.getJSON("/ajax/pdfemailsend.opl",
		{
		    	action: 0,
		    	name: name,
		    	ownemail: ownemail,
		    	friendemail: friendemail,
		    	subject: subject,
		    	text: text,
		    	file: file
		},
		function(json)
		{
			$.modal.close();
		});
	}else{
		if(!validateEmail(ownemail)){
			alert("Please correct your email, it's not valid.");
		}
		if(!validateEmail(friendemail)){
			alert("Please correct your recipientemail, it's not valid.");
		}
		if(name == "" || name == null){
			alert("Please insert a Name.");
		}
		if(subject == "" || subject == null){
			alert("Please insert a Subject.");
		}
		if(text == "" || text == null){
			alert("Please insert a Text.");
		}
	}
}

function validateEmail(email) 
{ 
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
	return email.match(re) 
}







