/*****
* 
* Default Script
* 
* Description:	usual scripts for COPS
* Author:		Matthias von Deetzen
* Copyright:	CeWe Color AG & Co OhG
* 
*****/

var sHref = document.location.href.toLowerCase();
var RedDotPageGuid = null;
var RedDotMode = false;

/** detect browser type **/
var is_moz = false;
var is_ie = false;

/** if no server urls are set, get default **/
if (typeof(server_url_live) == 'undefined') {
	var server_url_live = 'as.photoprintit.de';
	var server_url_test = 'as.photoprintit.de';
}

var server_url = getServerSystem(server_url_live, server_url_test);
var order_link = 'https://' + server_url + '/web/' + (typeof(operator) != 'undefined' ? (operator + '/') : '');

if (sHref.indexOf("action=reddot")!= -1) {
	RedDotMode = true;
	
	var search = /&pageguid\=([0-9A-Za-z]*)/;
	search.exec(sHref);
	RedDotPageGuid = RegExp.$1;
}

if (navigator.appName == 'Microsoft Internet Explorer')
{
	is_ie = true;
}
else if (navigator.appName == 'Netscape')
{
	is_moz = true;
}

/** some simple declarations **/
var last_element = new Object;

/** display info for pricelist **/
function display_price_info(elementId, max_position)
{
	var margin = 0;
	if (typeof($('sub_nav')) != 'undefined' && $('sub_nav').getStyle('float') == 'right') {
		margin = $('page_wrapper').getStyle('paddingLeft').replace('px', '');
	}
	
	var LeftPos = 0;
	if (typeof($('teaser_wrapper')) != 'undefined') {
		LeftPos = $('teaser_wrapper').offsetWidth - $('page_wrapper').offsetLeft;
	}

	max_position = absLeft($('teaser_wrapper')) + LeftPos - $('page_wrapper').style.marginLeft + 3 - margin;

	var windowWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		windowWidth = window.innerWidth + 1;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		windowWidth = document.documentElement.clientWidth;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		windowWidth = document.body.clientWidth;
	}

	var change_value = (windowWidth - document.getElementById('page_wrapper').offsetWidth) / 2;
	max_position = max_position + change_value;

	var element = null;
	if (element = document.getElementById(elementId))
	{
		if (last_element.style)
		{
			last_element.style.display = 'none';
			last_element.parentNode.parentNode.style.zIndex = last_zindex;
		}

		last_element = element;
		last_zindex = element.style.zIndex;

		element.style.opacity = 0;
		element.style.display = 'block';
		fadeIn(element.id);
		element.parentNode.parentNode.style.zIndex = '950';

		if (max_position > 0 && element.style.marginLeft == '')
		{
			if ((absLeft(element) + element.offsetWidth) > max_position)
			{
				element.style.marginLeft = -1 * (absLeft(element) + element.offsetWidth - max_position) - (is_ie ? 2 : 19) + 'px';
			}
		}

	}
}

/** hide an element **/
function hide(elementId)
{
	var element = null;
	if (element = document.getElementById(elementId))
	{
		fadeOut(element.id);
	}
}

/** fade an element in **/
function fadeIn(element_id)
{
	if (document.getElementById(element_id)) {
		document.getElementById(element_id).fadein = new Fx.Style(document.getElementById(element_id), 'opacity', {duration: 300}).start(document.getElementById(element_id).style.opacity,0.9999);
	}
}

/** fade an element out **/
function fadeOut(element_id)
{
	if (document.getElementById(element_id)) {
		document.getElementById(element_id).fadein = new Fx.Style(document.getElementById(element_id), 'opacity', {duration: 300}).start(document.getElementById(element_id).style.opacity,0);
	}
}

/** set an element to active state **/
var elements = new Array();
var act_elements = new Array();
var container_height = 0;
function pricelist_set_active(element, activator)
{
	if (typeof element == 'string')
	{
		if (document.getElementById(element))
		{
			element = document.getElementById(element)
		}
		else
		{
			return false;
		}
	}

	var height = 220;

	if (element && element.className != 'active')
	{
		for (var i = 0; i < elements.length; i++)
		{
			if (elements[i])
			{
				elements[i].className = '';
				elements[i].getElementsByTagName('div')[0].style.display = 'none';
			}
		}


		element.className = 'active';
		element.getElementsByTagName('a')[0].style.outline = '0';
		element.getElementsByTagName('div')[0].style.display = 'block';

		if (is_ie) {
			element.parentNode.style.height = element.getElementsByTagName('div')[0].offsetHeight + height + 'px';
		}
		else {
			element.getParent().getParent().style.height = element.getElementsByTagName('div')[0].offsetHeight + height + 'px';
		}

		if (elements == null || in_array(element, elements) == false)
		{
			elements.unshift(element);
		}
	}

	if (activator)
	{
		for (var i = 0; i < act_elements.length; i++)
		{
			if (act_elements[i])
			{
				act_elements[i].className = '';
			}
		}

		activator.className = 'active';
		activator.blur();

		if (act_elements == null || in_array(activator, act_elements) == false)
		{
			act_elements.unshift(activator);
		}
	}
}

/** get the absolute left position of element **/
function absLeft(el) {
	return (el.offsetParent)? 
	el.offsetLeft+absLeft(el.offsetParent) : el.offsetLeft;
}

/** get the absolute right position of element **/
function absTop(el) {
	return (el.offsetParent)? 
	el.offsetTop+absTop(el.offsetParent) : el.offsetTop;
}

/** own simple in_array function **/
function in_array(item,arr)
{
	for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
	return false;
}

/** open a popup window **/
function popup(element, lightbox, width, height, reddot_mode)
{
	if (reddot_mode)
	{
		myLink = document.createElement("iframe");
		myLink.src = element.href;
		myLink.style.display = "block";
		myLink.style.position = "absolute";
		myLink.style.width = width + 8 + "px";
		myLink.style.height = height + 8 + "px";

		myLink.style.zIndex = 50000;

		left = (screen.width - width) / 2 - 150;
		top = 300;

		myLink.style.left = left + "px";
		myLink.style.top = top + "px";

		body = document.getElementsByTagName("body")[0];
		body.appendChild(myLink);
	}
	else
	{
		if (lightbox)
		{
			element.rev = "width: " + width + "px; height: " + height + "px; border:0; scrolling: no;"
			element.setAttribute('rel', 'lyteframe');
			myLytebox.start(element, false, true);
		}
		else
		{
			var opt = "";
			var top = 0;
			var left = 0;
	
			if (width && height)
			{
				opt += "width=" + width + ",height=" + height + ",";
				left = (screen.width - width) / 2;
				top = (screen.height - height) / 2;
			}
	
			if (top > 0 && left > 0)
			{
				opt += 'top=' + top + ',left=' + left + ',';
			}
			opt += "status=no,scrollbars=yes,resizable=no,toolbar=no";
	
			window.open(element.href, "popup", opt);
		}
	}

	return false;
}

/** display the product sizes of a product **/
function show_product_sizes(element, image, show)
{
	if (element.nodeName != 'IMG')
	{
		element = element.previousSibling;
	}

	if (element && image)
	{
		element.setAttribute('rel', element.src);
		if (image) {
			element.src = image;
		}

		if (show) {
			element.nextSibling.nextSibling.style.display = 'block';
		}
		else {
			element.nextSibling.nextSibling.style.display = 'none';
		}
	}
}

/** display or hide the info box in the lightbox **/
function switch_info(element, show)
{
	if (show)
	{
		if (typeof(element) != 'undefined') {
			if (element.nodeName != 'DIV')
			{
				element = element.nextSibling;
			}
			element.style.opacity = 0;
			element.style.display = 'block';
			element.fadein = new Fx.Style(element, 'opacity', {duration: 550}).start(element.getStyle('opacity'),0.9999);
		}
	}
	else
	{
		if (typeof(element) != 'undefined') {
			element.fadeout = new Fx.Style(element, 'opacity', {duration: 550}).start(element.getStyle('opacity'),0)
			.chain(function() {element.style.display = 'none'});
		}
	}
}

if(!window.Node){
	var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}

function checkNode(node, filter){
	return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}

/** get all children of element **/
function getChildren(node, filter)
{
	var result = new Array();
	var children = node.childNodes;
	for(var i = 0; i < children.length; i++){
		if(checkNode(children[i], filter)) result[result.length] = children[i];
	}
	return result;
}

/** set the link to the IPS order client **/
function set_order_link(product, value)
{
	var order_links = new Object();
	var link = document.getElementById('order_link');
	var design = 'nodesign';

	if (!link)
	{
		return false;
	}
	else if (!operator || !product || product == '')
	{
		link.href = '';
		link.style.display = 'none';
		return false;
	}

	if (!value && document.getElementById('product_select'))
	{
		products = getChildren(document.getElementById('product_select'), 'input');

		for (var i = 0; i < products.length; i++)
		{
			if (products[i].checked)
			{
				value = products[i].value;
			}
		}
	}

	if (document.getElementById('design0') && document.getElementById('design1'))
	{
		design = (document.getElementById('design1').checked ? 'design' : 'nodesign');
	}

	if (product && link)
	{
		var order_links = {

			// Fotofun
			'bib': 'productSettings.do?productid=23',
			'cap': 'productSettings.do?productid=12',
			'moose': 'productSettings.do?productid=69',
			'crystal_pic_80_105': 'productSettings.do?productid=555',
			'sticker': 'productEditor.do?new=true&productId=42&new=true', // changed to new editor
			'globe_glitter': 'productSettings.do?productid=100',
			'barbeque_pinafore': 'productSettings.do?productid=21',
			'easter_bunny': 'productSettings.do?productid=47',
			'child_tshirt': 'productSettings.do?productid=666',
			'crystal_pic': 'productSettings.do?productid=33',
			'heart_of_glass': 'productSettings.do?productid=556',
			'puzzle_20_30': {
				'design': 'productSettings.do?productid=27',
				'nodesign': 'productSettings.do?productid=9'
			},
			//'puzzle_20_30': 'productSettings.do?productid=9',
			'puzzle_30_45': 'productSettings.do?productid=27',
			'key_ring': 'productSettings.do?productid=22',
			'snowglobe': 'productSettings.do?productid=26',
			'playcards': 'productSettings.do?productid=45',
			'pokercards' : 'productSettings.do?productid=10704',
			'pen_bracket': 'productSettings.do?productid=558',
			'memoclip': 'productSettings.do?productid=557',
			'remembory': 'productEditor.do?productId=155&new=true',
			'big_bag': 'productSettings.do?productid=10714',
			'small_bag': 'productSettings.do?productid=10705',
			'alubottle': {
				'design': 'productEditor.do?productId=10703&new=true',
				'nodesign': 'productEditor.do?productId=10703&templateId=empty&new=true'
			},
			'pillow_filled': {
				'design': 'productEditor.do?productId=101&new=true',
				'nodesign': 'productEditor.do?productId=101&templateId=empty&new=true'
			},
			'glass': {
				'design': 'productEditor.do?productId=665&new=true',
				'nodesign': 'productEditor.do?productId=665&templateId=empty&new=true'
			},
			'sweatshirt': {
				'design': 'productEditor.do?productId=38&new=true',
				'nodesign': 'productEditor.do?productId=38&templateId=empty&new=true'
			},
			'teddy': 'productSettings.do?productid=11',
			'cup_panorama': {
				'design': 'productEditor.do?productId=6394&new=true',
				'nodesign': 'productEditor.do?productId=6394&templateId=empty&new=true'
			},
			'cup_set': 'productEditor.do?productId=14&new=true',
			'cup': {
				'design': 'productEditor.do?productId=8&new=true',
				'nodesign': 'productEditor.do?productId=8&templateId=empty&new=true'
			},
			'mousepad': {
				'design': 'productEditor.do?productId=10&new=true',
				'nodesign': 'productEditor.do?productId=10&templateId=empty&new=true'
			},
			'pillow': {
				'design': 'productEditor.do?productId=20&new=true',
				'nodesign': 'productEditor.do?productId=20&templateId=empty&new=true'
			},
			'tshirt': {
				'design': 'productEditor.do?productId=17&new=true',
				'nodesign': 'productEditor.do?productId=17&templateId=empty&new=true'
			},
			'stuffbag': {
				'design': 'productEditor.do?productId=25&new=true',
				'nodesign': 'productEditor.do?productId=25&templateId=empty&new=true'
			},
			'beer_mug_panorama': {
				'design': 'productEditor.do?productId=6400&new=true',
				'nodesign': 'productEditor.do?productId=6400&templateId=empty&new=true'
			},
			'cup_magic': {
				'design': 'productEditor.do?productId=31&new=true',
				'nodesign': 'productEditor.do?productId=31&templateId=empty&new=true'
			},
			'cup_magic_panorama': {
				'design': 'productEditor.do?productId=6401&new=true',
				'nodesign': 'productEditor.do?productId=6401&templateId=empty&new=true'
			},
			'beer_mug': {
				'design': 'productEditor.do?productId=24&new=true',
				'nodesign': 'productEditor.do?productId=24&templateId=empty&new=true'
			},
			'cup_color': 'productSettings.do?productid=6398&new=true',
			'animal_pendant': 'productSettings.do?productid=7106&new=true',
			'stuff_calendar': {
				'': ''
			},
			'saving_box': {
				'design': 'productEditor.do?productId=700&new=true',
				'nodesign': 'productEditor.do?productId=700&templateId=empty&new=true'
			},

			// Collageblock
			'collageblock_a5': 'productEditor.do?productId=10713&new=true',
			'collageblock_a5_notemplate': 'productEditor.do?productId=10713&templateId=empty&new=true',
			'collageblock_a4': 'productEditor.do?productId=10712&new=true',

			// School articles
			'bread_box': 'productEditor.do?productId=10716&new=true',
			'childrens_backpack': 'productEditor.do?productId=10717&new=true',
			'sports_bag': 'productEditor.do?productId=10718&new=true',
			'feather_bag': 'productEditor.do?productId=10719&new=true',
			'school_agenda': {
				'design': 'productEditor.do?productId=10721&new=true',
				'nodesign': 'productEditor.do?productId=10721&templateId=empty&new=true'
			},
			'agenda': {
				'design': 'productEditor.do?productId=10720&new=true',
				'nodesign': 'productEditor.do?productId=10720&templateId=empty&new=true'
			},
			'write_notebook_a4': 'productEditor.do?productId=10722&new=true',
			'write_notebook_a5': 'productEditor.do?productId=10723&new=true',
			'note_issue': 'productEditor.do?productId=10724&new=true',
			'friendsbook': {
				'design': 'productEditor.do?productId=10725&new=true',
				'nodesign': 'productEditor.do?productId=10725&templateId=empty&new=true'
			},
			'letter_paper': 'productEditor.do?productId=8240&new=true',


			// COPS 2.3 articles
			'glass_clock': 'productEditor.do?new=true&productId=917&new=true',
			'magnet': 'productEditor.do?new=true&productId=662&new=true',
			'pillow_heart': 'productEditor.do?new=true&productId=911&new=true',
			'puzzle_xxl': 'productEditor.do?new=true&productId=4005&new=true',
			'advent_calendar': 'productEditor.do?new=true&productId=417&new=true',
			'poster_xxl': 'productEditor.do?new=true&productId=1213&new=true',
			'poster_xxl_30': 'productEditor.do?new=true&productId=1200&new=true',
			'poster_debond': 'productEditor.do?new=true&productId=1004&new=true&templateId=empty',
			'poster_acryl': 'productEditor.do?new=true&productId=1104&new=true&templateId=empty',
			'calendar_photopaper_A2': 'productEditor.do?new=true&productId=6288&new=true',
			'calendar_A3_square': 'productEditor.do?new=true&productId=6292&new=true',

			// Calendar
			'annual_calendar_A3_across': 'productEditor.do?productId=6283&new=true',
			'kitchen_planner': 'productEditor.do?productId=6282&new=true',
			'decorative_calendar_A4_upright': 'productEditor.do?productId=6279&new=true',
			'decorative_calendar_A3_upright': 'productEditor.do?productId=6281&new=true',
			'family_calendar_A4_across': 'productEditor.do?productId=6278&new=true',
			'put_up_table_planner': 'productEditor.do?productId=6280&new=true',
			'table_planner': 'productEditor.do?productId=6277&new=true',

			'calendar_name_a3' : 'productEditor.do?productId=6291&templateId=001-CAL11P-CC&personalized=true&new=true',
			'calendar_name_a4' : 'productEditor.do?productId=6289&templateId=001-CAL9P-CC&personalized=true&new=true',

			'table_calendar': 'productEditor.do?productId=51&new=true',
			'calendar_photopaper_a4_upright': 'productEditor.do?productId=6284&new=true',
			'calendar_photopaper_a3_upright': 'productEditor.do?productId=6285&new=true',
			'calendar_photopaper_a3_across': 'productEditor.do?productId=6286&new=true',
			'calendar_photopaper_square': 'productEditor.do?productId=6287&new=true',

			// Canvas
			'canvas': 'productSettings.do?productid=881',
			'deco_canvas': 'productEditor.do?productId=881&new=true&templateId=empty',
			'canvas_more_formats': 'productEditor.do?productId=881&new=true&templateId=empty',

			// Poster
			'poster': '###order_poster###',
			'deco_poster': 'productEditor.do?productId=904&new=true&templateId=empty',
			'poster_map': 'productEditor.do?new=true&productId=904&geomap=true&templateId=empty',
			'poster_debond_direct_print': 'productEditor.do?new=true&productId=8149&new=true&templateId=empty',
			'poster_acryl_direct_print': 'productEditor.do?new=true&productId=8153&new=true&templateId=empty',

			// Greetingcards
			'greetingcard': {
				'design': 'productEditor.do?productId=6426&new=true',
				'nodesign': 'productEditor.do?productId=6426&templateId=empty&new=true'
			},
			'card_xl_long': {
				'design': 'productEditor.do?productId=6414&new=true',
				'nodesign': 'productEditor.do?productId=6414&templateId=empty&new=true'
			},
			'card_xl_short': {
				'design': 'productEditor.do?productId=6413&new=true',
				'nodesign': 'productEditor.do?productId=6413&templateId=empty&new=true'
			},
			'card_classic': {
				'design': 'productEditor.do?productId=6051&new=true',
				'nodesign': 'productEditor.do?productId=6051&templateId=empty&new=true'
			},
			'postcard_xl': {
				'design': 'productEditor.do?productId=6424&new=true',
				'nodesign': 'productEditor.do?productId=6424&templateId=empty&new=true'
			},
			'postcard_classic': {
				'design': 'productEditor.do?productId=6050&new=true',
				'nodesign': 'productEditor.do?productId=6050&templateId=empty&new=true'
			},
			'place_cards': {
				'design': 'productEditor.do?productId=8110&new=true',
				'nodesign': 'productEditor.do?productId=8110&templateId=empty&new=true'
			},
			

			// Greetingcards VARIO
			'greetingcard_vario': 'designTemplateSelector.do?productIds=6426',
			'card_xl_long_vario': {
				'design' : 'designTemplateSelector.do?productIds=6414,6423',
				'nodesign' : 'designTemplateSelector.do?productIds=6957,6958'
			},
			'card_xl_short_vario': {
				'design' : 'designTemplateSelector.do?productIds=6413,6422',
				'nodesign' : 'designTemplateSelector.do?productIds=6955,6956'
			},
			'card_classic_vario': {
				'design' : 'designTemplateSelector.do?productIds=6051,6425',
				'nodesign' : 'designTemplateSelector.do?productIds=6953,6954'
			},
			'postcard_xl_vario': {
				'design' : 'designTemplateSelector.do?productIds=6424',
				'nodesign' : 'designTemplateSelector.do?productIds=6960'
			},
			'postcard_classic_vario': {
				'design' : 'designTemplateSelector.do?productIds=6050',
				'nodesign' : 'designTemplateSelector.do?productIds=6959'
			},
			//Tablecards
			'table_cards': 'productEditor.do?new=true&productId=8120&new=true',

			'software': (typeof(lnk_software) != 'undefined' ? lnk_software : ''),

			// Photobook
			'photobook': (typeof(lnk_software) != 'undefined' ? lnk_software : ''),
			
			// Photobook
			'photobook_online': (typeof(lnk_software) != 'undefined' ? lnk_software : ''),
			
			//photos
			'photo_acryl': 'productEditor.do?productId=8110&new=true',

			// Textilshop
			'textil_babybody': 'textileEditor.do?productGroupId=2010&color=1',
			'textil_baseball_tshirt': 'textileEditor.do?productGroupId=2002&color=1',
			'textil_baseball_cap': 'textileEditor.do?productGroupId=2011&color=1',
			'textil_bib': 'textileEditor.do?productGroupId=2009&color=1',
			'textil_kids_tshirt': 'textileEditor.do?productGroupId=2008&color=1',
			'textil_men_longsleeve': 'textileEditor.do?productGroupId=2003&color=1',
			'textil_men_premium_tshirt': 'textileEditor.do?productGroupId=2001&color=1',
			'textil_men_tshirt_american': 'textileEditor.do?productGroupId=2005&color=1',
			'textil_pillow_no_filling': 'textileEditor.do?productGroupId=2014&color=1',
			'textil_pinaforte': 'textileEditor.do?productGroupId=2013&color=1',
			'textil_stuff_handlebag': 'textileEditor.do?productGroupId=2012&color=1',
			'textil_women_longsleeve': 'textileEditor.do?productGroupId=2004&color=1',
			'textil_women_tshirt': 'textileEditor.do?productGroupId=2007&color=1',
			'textil_women_tshirt_american': 'textileEditor.do?productGroupId=2006&color=1'
		};
		


		var new_link = '';
		var url_target = order_link;
		if (product == 'photobook' || product == 'software')
		{
			url_target = '';
		}


		if (order_links[product] && order_links[product][design] && order_links[product][design][value])
		{
			new_link = url_target + order_links[product][design][value];
		}
		else if (order_links[product] && order_links[product][design])
		{
			new_link = url_target + order_links[product][design];
		}
		else if (order_links[product])
		{
			new_link = url_target + order_links[product];
		}
		else
		{
			link.href = '';
			link.style.display = 'none';
			return false;
		}
		
		if (typeof(online_photobook) != 'undefined' && online_photobook == 'true' && typeof(lnk_photobook_switch) != 'undefined' && lnk_photobook_switch && product == 'photobook_online')
		{
			new_link = lnk_photobook_switch; 
		}

		link.href = new_link;
		link.style.display = 'block';

		var icarousel_order_link = null;
		if (document.getElementById('icarousel_link'))
		{
			icarousel_order_link = document.getElementById('icarousel_link');
			icarousel_order_link.innerHTML = link.innerHTML;
			icarousel_order_link.style.display = 'block';
			icarousel_order_link.href = new_link;
		}

		return true;
	}
	else
	{
		link.href = '';
		link.style.display = 'none';
		return false;
	}
}

function setOrderLinks(plugin) {
	var AllLinks = document.getElementsByTagName('a');

	var target = 'selectClient.do?type=';
	if (typeof(plugin.activex) != 'undefined' && plugin.activex) {
		target = 'startClient.do?client=actx&type=';
	}
	else if (typeof(plugin.java) != 'undefined' && plugin.java) {
		target = 'startClient.do?client=java&type=';
	}

	/** check photos and poster type for link **/
	if (typeof(icarousel_link) != 'undefined' && icarousel_link.length > 0) {
		for (var i = 0; i < icarousel_link.length; i++) {
			if (typeof(icarousel_link[i]) != 'undefined')
			{
				var iLink = $('icarousel_link');

				if (icarousel_link[i]['link'].indexOf('###') >= 0) {
					if (icarousel_link[i]['link'].indexOf('###order_photos###') >= 0) {

						icarousel_link[i]['link'] = order_link + target + 'print';

						/*if (typeof(order_way_selection) != 'undefined' && order_way_selection == 'true') {
							icarousel_link[i]['link'] = 'onoffline_selection.html?link=' + escape(icarousel_link[i]['link']);
							iLink.rev = "width: 1001px; height: 631px; border:0; scrolling: no; top: 20px;"
							iLink.setAttribute('rel', 'lyteframe');
						}*/
					}
					else if (icarousel_link[i]['link'].indexOf('###order_photos_standard###') >= 0) {
						icarousel_link[i]['link'] = order_link + target + 'print&pmId=standard';
					}
					else if (icarousel_link[i]['link'].indexOf('###order_poster###') >= 0) {
						icarousel_link[i]['link'] = order_link + target + 'poster';
					}

					iLink.href.replace(/###.+###/i, icarousel_link[i]['link']);
				}
			}
		}
	}

	/** change the place holder with links **/
	for (var i = 0; i < AllLinks.length; i++) {
		if (AllLinks[i].href.indexOf('###') > 0 || AllLinks[i].href.indexOf('#%23%23') > 0) {

			var link = AllLinks[i].href = AllLinks[i].href.replace("#%23%23", "###");
			link = AllLinks[i].href = link.replace("%23%23%23", "###");

			if (link.indexOf('###order_photos###') > 0) {
				AllLinks[i].href = link.replace(/.*###order_photos###/, order_link + target + 'print');

				/*if (typeof(order_way_selection) != 'undefined' && order_way_selection == 'true') {
					AllLinks[i].href = 'onoffline_selection.html?link=' + escape(AllLinks[i].href);
					AllLinks[i].rev = "width: 1001px; height: 631px; border:0; scrolling: no; top: 20px;"
					AllLinks[i].setAttribute('rel', 'lyteframe');
				}*/
			}
			else if (link.indexOf('###order_photos_standard###') > 0) {
				AllLinks[i].href = link.replace(/.*###order_photos_standard###/, order_link + target + 'print&pmId=standard');
			}
			else if (link.indexOf('###order_poster###') > 0) {
				AllLinks[i].href = order_link + target + 'poster';
			}
			else if (link.indexOf('###order_businesscards###') > 0)
			{
				AllLinks[i].href = order_link + 'bcSearchTemplates.do';
			}
			else if (link.indexOf('###textil_shop###') > 0)
			{
				AllLinks[i].href = order_link + 'textileshopOverview.do';
			}
			else if (link.indexOf('###textil_shop_design###') > 0)
			{
				AllLinks[i].href = order_link + link.replace(/^.*###textil_shop_design###/, 'textileEditorWithDesign.do?design=');
			}
			else if (link.indexOf('###link_terms###') > 0)
			{
				AllLinks[i].href = order_link + 'sbc.do';
			}
			else if (link.indexOf('###online_album###') > 0)
			{
				AllLinks[i].href = order_link + 'myPhotosIntro.do';
			}
			else if (link.indexOf('###login_page###') > 0)
			{
				AllLinks[i].href = order_link + 'loginRegister.do';
			}
			else if (link.indexOf('###download_windows###') > 0)
			{
				if(getAffiliate() != null && typeof(keyaccount) != 'undefined' && keyaccount != '')
				{
					AllLinks[i].href = 'http://dls.photoprintit.de/api/getClient/' + keyaccount + '/hps/' + getAffiliate() + '/windows'
				}
				else
				{
					AllLinks[i].href = typeof(software_path_windows) != 'undefined' ? software_path_windows : '';
				}
			}
			else if (link.indexOf('###download_mac###') > 0)
			{
				if(getAffiliate() != null && typeof(keyaccount) != 'undefined' && keyaccount != '')
				{
					AllLinks[i].href = 'http://dls.photoprintit.de/api/getClient/' + keyaccount + '/hps/' + getAffiliate() + '/mac'
				}
				else
				{
					AllLinks[i].href = typeof(software_path_mac) != 'undefined' ? software_path_mac : '';
				}
			}
			else if (link.indexOf('###download_linux###') > 0)
			{
				if(getAffiliate() != null && typeof(keyaccount) != 'undefined' && keyaccount != '')
				{
					AllLinks[i].href = 'http://dls.photoprintit.de/api/getClient/' + keyaccount + '/hps/' + getAffiliate() + '/linux'
				}
				else
				{
					AllLinks[i].href = typeof(software_path_linux) != 'undefined' ? software_path_linux : '';
				}
			}
			else if (link.indexOf('###account_page###') > 0)
			{
				AllLinks[i].href = order_link + 'myAccount.do';
			}
			else if (link.indexOf('###register_page###') > 0)
			{
				AllLinks[i].href = order_link + 'myAccountRegister.do';
			}
			else if (link.indexOf('###order_tracking_url###') > 0)
			{
				AllLinks[i].href = typeof(order_tracking_url) != 'undefined' ? order_tracking_url : '';
			}
			else if (link.indexOf('###faq_url###') > 0)
			{
				AllLinks[i].href = typeof(faq_url) != 'undefined' ? faq_url : '';
			}
			else if (link.indexOf('###contact_url###') > 0)
			{
				AllLinks[i].href = typeof(contact_url) != 'undefined' ? contact_url : '';
			}
			else if (link.indexOf('###photobook_reorder_url###') > 0)
			{
				AllLinks[i].href = order_link + 'reorder.do';
			}
			else if (link.indexOf('###gallery_photos###') > 0)
			{
				AllLinks[i].href = order_link + 'showGalleryPhotos.do';
			}
			else if (link.indexOf('###gallery_photobooks###') > 0)
			{
				AllLinks[i].href = order_link + 'showGalleryPhotobooks.do';
			}
			else if (link.indexOf('###gallery_storage###') > 0)
			{
				AllLinks[i].href = order_link + 'showStorage.do';
			}
			else if (link.indexOf('###photobook_wizard###') > 0)
			{
				AllLinks[i].href = order_link + 'photobookWizardIntro.do';
			}
			else if (link.indexOf('###shopping_cart###') > 0)
			{
				AllLinks[i].href = order_link + 'shoppingcart.do';
			}
			else if (link.indexOf('###greetingcard###') > 0)
			{
				AllLinks[i].href = order_link + 'productEditor.do?productId=6426&new=true';
			}
			else if (link.indexOf('###card_classic###') > 0)
			{
				AllLinks[i].href = order_link + 'productEditor.do?productId=6051&new=true';
			}
			else if (link.indexOf('###decorative_calendar_A4_upright###') > 0)
			{
				AllLinks[i].href = order_link + 'productEditor.do?productId=6279&new=true';
			}
			else if (link.indexOf('###decorative_calendar_A3_upright###') > 0)
			{
				AllLinks[i].href = order_link + 'productEditor.do?productId=6281&new=true';
			}
		}

		if (AllLinks[i].target == '_lytebox') {
			AllLinks[i].rev = "width: 800px; height: 600px; border:0; scrolling: no;"
			AllLinks[i].setAttribute('rel', 'lyteframe');
		}

	}
}

function setLoginFrame()
{
	if (document.getElementById('login_iframe'))
	{
		var loginDiv = document.getElementById('login_iframe');

		if (document.URL.indexOf('https://') >= 0) {
			order_link = order_link.replace(/http:\/\//, 'https://');
		}
		if (document.URL.match(/(as[0-9]{0,2}\.photoprintit\.)/) != null && document.URL.match(/(as[0-9]{0,2}\.photoprintit\.)/).length > 0) {
			order_link = '';
		}

		var url = order_link + 'externalLogin.do';
		
		if(getAffiliate() != null)
		{
			url = url + '?aid=' + getAffiliate();
		}

		var iFrame = document.createElement("iframe");
		iFrame.src = url;
		iFrame.style.display = "block";
		iFrame.frameBorder = '0';
		iFrame.scrolling = 'no';
		iFrame.allowTransparency = "true";

		if (iFrame.attachEvent) {
			iFrame.attachEvent('onload',
				function (evt) {
					document.getElementById('login_iframe').style.background = '';
				}
			);
		}
		else if (iFrame.onload) {
			iFrame.onload = function() {
				document.getElementById('login_iframe').style.background = '';
			}
		}
		else if (iFrame.setAttribute) {
			iFrame.setAttribute('onload', "document.getElementById('login_iframe').style.background = '';");
		}

		iFrame.setAttribute('name', 'loginFrame');

		loginDiv.appendChild(iFrame);
	}
}

function animation(elements, options)
{
	this.elements = elements;
	this.options = new Abstract({ // Defaults
		type: 'blink',
		delay: 300,
		times: 3
	});
	if($type(options) == 'object') {this.options.extend(options);}

	this.start = function() {
		if (this.options.type == 'blink')
		{
			for (var i = 0; i < this.elements.length; i++)
			{
				this.elements[i].setStyle('opacity', '1');
				for (j = 0; j < (this.options.times * 2); j+=2)
				{
					this.fadeout.delay(j * this.options.delay, this.elements[i]);
					this.fadein.delay((j + 1) * this.options.delay, this.elements[i]);
				}
			}
		}
	}
	this.fadein = function() {
		this.fadein = new Fx.Style(this, 'opacity', {duration: 300}).start(this.style.opacity, 1);
	}
	this.fadeout = function() {
		this.fadein = new Fx.Style(this, 'opacity', {duration: 300}).start(this.style.opacity, 0.0001);
	}

	this.start();
}
function animateInfo()
{
	if (typeof(Fx) != 'undefined') {
		var options = new Abstract({ // Defaults
			type: 'blink',
			delay: 400,
			times: 2
		});
		var animate = new animation($$('div.info_container'), options);
	}
}

function writeCookie(name, value, days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function check_parameter(name, default_value, possible_values)
{
	if (sHref.indexOf(name + "=")!= -1) {
		var search = /[&?]system\=([0-9A-Za-z]*)/;
		search.exec(sHref);
		if (possible_values.indexOf(RegExp.$1) != -1)
		{
			return RegExp.$1;
		}
	}
	return default_value
}

function getServerSystem(server_url_live, server_url_test) {
	if (sHref.indexOf("system=")!= -1) {
		var search = /[&?]system\=([0-9a-z-_]*)/;
		search.exec(sHref);
		writeCookie('serverSystem', RegExp.$1);
	}
	else if (readCookie('serverSystem') == null) {
		writeCookie('serverSystem', 'live');
	}

	var cookie = readCookie('serverSystem');
	if (cookie != null)
	{
		if (cookie == 'live') {return server_url_live;}
		else if (cookie == 'test') {return server_url_test;}
		else if (cookie == 'localhost') {return 'localhost';}
		else if(cookie.search(/^[0-9a-z-]+\_[a-z-]+\_[a-z-]+$/) == 0) {return cookie.replace(/_/g, '.');}
		else {return server_url_live;}
	}
	else
	{
		return server_url_live;
	}
}

function setServerSystemTitle()
{
	if (readCookie('serverSystem') != 'live')
	{
		// document.title = document.title + ' [TEST]';
	}
}

function setToolTips() {
	if (typeof($$) != 'undefined') {

		var elements = $$('a.info,a.saveOnlineInfo,a.indexInfo');

		elements.each(function(element,index,object) { 

			if (typeof(elements[index].title) != 'undefined' && $(elements[index].title))
			{
				var content = $(elements[index].title).innerHTML;

				if (content.toLowerCase() == '<h1></h1><br>')
				{
					elements[index].style.display = 'none';
				}
				else {
					new Tips(element, {
						initialize:function(){
							this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 300, wait: false}).set(0);
							this.toolTip.className = 'user-tip';
							this.toolTip.innerHTML = content;
						},
						onShow: function(toolTip) {
							this.fx.start(1);
						},
						onHide: function(toolTip) {
							this.fx.start(0);
						},
						className: 'user-tip',
						offsets: {'x': 20, 'y': (element.className == 'saveOnlineInfo' || element.className == 'indexInfo') ? -85 : 20}
					});
				}
			}

		});
	}
}

function displayTeaserContent(content, opener, position, orientation, fadeOutDelay) {
	var child = $(content);
	var element = $(opener);
	var position = position ? position : 'bottom';
	var orientation = orientation ? orientation : 'left';
	var fadeOut = fadeOutDelay ? fadeOutDelay : false;
	var fadeTtimeOut = null;

	if (child && element) {

		var fx = new Fx.Style(child, 'opacity', {duration: 300, wait: false}).set(0);

		if (element.childNodes[(is_ie ? 1 : 3)].className != 'html_content')
		{
			element.onmouseover = function() {
				if (child.childNodes[0].innerHTML != '')
				{
					child.style.display = 'block';
					oldPosition = element.style.position;
					element.style.position = 'relative';
					element.style.zIndex = 950;
					element.style.overflow = 'visible';
					child.style.position = 'absolute';

					var left = 0;
					var top = 0;

					switch (position)
					{
						case 'top':
							top = -1 * child.offsetHeight;
							break;
						case 'right':
							left = element.offsetWidth - 1;
							break;
						case 'bottom':
							top = element.offsetHeight - 1;
							break;
						case 'left':
							left = -1 * child.offsetWidth;
							break;
					}

					switch (orientation)
					{
						case 'top':
							top = -1;
							break;
						case 'right':
							left = element.offsetWidth - child.offsetWidth;
							break;
						case 'bottom':
							top = element.offsetHeight - child.offsetHeight;
							break;
						case 'left':
							left = -1;
							break;
					}

					child.style.left = left + 'px';
					child.style.top = top + 'px';

					fx.start(1);
					if (fadeOutDelay) {
						fadeTtimeOut = window.setTimeout(function() {fx.start(0)}.bind(this), fadeOutDelay);
					}
				}
			}.bind(this);

			element.onmouseout = function() {
				if (child.childNodes[0].innerHTML != '')
				{
					element.style.overflow = 'hidden';
					element.style.zIndex = 900;
					$clear(fadeTtimeOut);
					fx.start(0);
				}
			}.bind(this);
		}
		else {
			element.style.overflow = 'hidden';
		}
	}
}

function GET(parameter)
{
	HTTP_GET_VARS = new Array();
	strGET = document.location.search.substr(1, document.location.search.length);

	if(strGET != '')
	{
		gArr = strGET.split('&');
		for(i=0; i<gArr.length; ++i) {
			v = ''; vArr = gArr[i].split('=');
			if(vArr.length > 1) {
				v = vArr[1];
			}
			HTTP_GET_VARS[unescape(vArr[0])] = unescape(v);
		}
	}

	if(!HTTP_GET_VARS[parameter]){return 'undefined';}
	return HTTP_GET_VARS[parameter];
}

/** send forms over mootools **/
function send_form(link_element, form_element, redirect, loading_element, failure_element)
{
	var fx = {
		'loading': new Fx.Style(loading_element, 'opacity' ),
		'failure': new Fx.Style(failure_element, 'opacity' )
	};

	var showHide = function( el ){
		fx.loading.set(0);
		(fx[ el ]).start(0,1);
		(function(){ (fx[ el ]).start(1,0); }).delay( 4000 );
	}

	$(form_element).send({
		onRequest: function(){
			fx.loading.start( 0,1 );
		},
		onSuccess: function(){
			window.location = redirect;
		},
		onFailure: function(){
			fx.loading.set(0);
			showHide('failure');
		}
	});

	return false;
}

function validateEmail(email)
{
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null )
	{
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null)
	{
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null) 
		{
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null)return false;
		}
		return true;
	}
	return false;
}

function setRoundedCorners()
{
	var elements = $$('.roundedCornerElement');

	elements.each(function(element,index,object) { 
		var options = element.className.match(/\{.+\}/);
		var tmp = new Object();
		tmp = eval('var options = ' + options);
		var roundedCorners = new roundCorners(options);
		roundedCorners.generate(element);
	});

	if (operator == '84010422') {

		var options = {radius:8,antiAliase:true}

		var element = $('login');
		var roundedCorners = new roundCorners(options);
		roundedCorners.generate(element);

		var element = $('cart');
		var roundedCorners = new roundCorners(options);
		roundedCorners.generate(element);
	}
	
	if(typeof(teaser_round_corners) != 'undefined' && $('page_ips') == false) {
		if(teaser_round_corners['set'] == 1) {
			var elements = $$('.teaser');
			elements.each(function(element,index,object) {
				teaser_round_corners['antiAliase'] = true;
				var roundedCorners = new roundCorners(teaser_round_corners);
				roundedCorners.generate(element);
			});
			if($('lightbox') != false) {
				if($('lightbox').getStyle('display') != 'none') {
					var element = $('lightbox');
					var roundedCorners = new roundCorners(teaser_round_corners);
					roundedCorners.generate(element);
				}
			}
			if($('sub_nav') != false) {
				if($('sub_nav').getStyle('display') != 'none') {
					var element = $('sub_nav');
					var roundedCorners = new roundCorners(teaser_round_corners);
					roundedCorners.generate(element);
				}
			}
			if($$('.product_teaser_order') != false) {
				if($$('.product_teaser_order').getStyle('display') != 'none') {
					var element = $$('.product_teaser_order');
					var roundedCorners = new roundCorners(teaser_round_corners);
					roundedCorners.generate(element);
				}
			}
			if($$('.no_border') != false) {
				if($$('.no_border').getStyle('display') != 'none') {
					addNewStyle('.no_border', 'border: 1px solid #F0F0F0 !important;');
				}
			}
			if($$('.full_teaser') != false) {
				if($$('.full_teaser').getStyle('display') != 'none') {
					addNewStyle('.full_teaser', 'border: 1px solid #F0F0F0 !important;');
				}
			}
			if($$('.default_full_teaser') != false) {
				if($$('.default_full_teaser').getStyle('display') != 'none') {
					addNewStyle('.default_full_teaser', 'border: 1px solid #F0F0F0 !important;');
				}
			}
		}
	}
}

function addNewStyle(myElement, newStyle) {
  if(document.styleSheets.item(0).addRule)
	{
	  var style = document.createElement('style');
	  document.getElementsByTagName('head').item(0).appendChild(style);
    document.styleSheets.item(0).addRule(myElement, newStyle);
    document.getElementsByTagName('body').item(0).className = myElement;
  }
	else
	{
	  var styleElement = document.getElementById('styles_js');
	  if (!styleElement) {
	      styleElement = document.createElement('style');
	      styleElement.type = 'text/css';
	      styleElement.id = 'styles_js';
	      document.getElementsByTagName('head')[0].appendChild(styleElement);
	  }
	  styleElement.appendChild(document.createTextNode(myElement+' {'+newStyle+'}'));
	}
}

function setPriceGraphics()
{
	if (typeof(priceElements) != 'undefined' && priceElements.length > 0)
	{
		for (i = 0; i < priceElements.length; i++)
		{
			new Ajax('/cgi-bin/prices_handler.cgi', {
				method: 'get',
				data: priceElements[i][0],
				evalScripts: true,
				onRequest: function(request) {
					this.element = $$('.' + priceElements[i][1]);
				},
				onComplete: function (response) {
					for (i = 0; i < this.element.length; i++) {
						if (response != '') {
							this.element[i].innerHTML = response;
						}
						this.element[i].style.display = "block";
					}
				}
			}).request();
		};
	}
}

function setSftDownloadLink(element, version) {
	element.href = element.href + '?version=' + version;
}

function setSftDownload() {
	setSftDownloadLink($('sft_download_win'), 'windows');
	setSftDownloadLink($('sft_download_linux'), 'linux');
	setSftDownloadLink($('sft_download_mac'), 'mac');
	setSftDownloadLink($('sft_download_win_small'), 'windows');
	setSftDownloadLink($('sft_download_linux_small'), 'linux');
	setSftDownloadLink($('sft_download_mac_small'), 'mac');
}

function setAffiliate()
{
	if(readCookie("affiliate") == null)
	{
		if(GET('cref') != 'undefined')
		{
			writeCookie('affiliate', GET('cref'), '30');
		}
	}
	else
	{
		if(GET('cref') != 'undefined')
		{
			if(GET('cref') != readCookie("affiliate"))
			{
				writeCookie('affiliate', GET('cref'), '30');
			}
		}
	}
}

function getAffiliate()
{
	if(readCookie("affiliate") != null)
	{
		return readCookie("affiliate");
	}
	else
	{
		return null;
	}
}

function startDlsDownload()
{
	var src = '';
    var version = GET('version') != 'undefined' ? GET('version') : 'windows';

    switch (version) {
    	case 'windows':
        	src = software_path_windows;
        break;
        case 'mac':
        	src = software_path_mac;
        break;
        case 'linux':
        	src = software_path_linux;
        break;
    }
	
	if(getAffiliate() != null && typeof(keyaccount) != 'undefined'  && keyaccount != '')
	{
		src = 'http://dls.photoprintit.de/api/getClient/' + keyaccount + '/hps/' + getAffiliate() + '/' + version
	}

	var newFrame = document.createElement("IFRAME");
    newFrame.setAttribute('src', src);
    newFrame.style.display = 'none';
    document.body.appendChild(newFrame);
}
setAffiliate();
/** initialize some basic onload functions **/
window.onload = function()
{
	setServerSystemTitle();

	setAffiliate();

	if (document.getElementById('java_info'))
	{
		document.getElementById('java_info').style.display = 'none';
	}

	if (typeof(iflow_lightbox) != 'undefined')
	{
		iflow_lightbox = new iflow_lightbox;
		iflow_lightbox.onload();
	}

	if (typeof(iflow_products) != 'undefined')
	{
		iflow_products = new iflow_products;
		iflow_products.onload();
	}

	var plugin = false;
	if (typeof(PluginDetection) != 'undefined') {
		plugin = new PluginDetection();
	}

	setTimeout("setPriceGraphics()", 200);
	setOrderLinks(plugin);
	setLoginFrame();

	if (window.MooTools) {
		setRoundedCorners();
	}

	animateInfo();
	setToolTips();
};