$(document).ready(function() {
	$('a#tablink1').attr('href', '#tabs-1');
	$('a#tablink2').attr('href', '#tabs-2');
	$('a#tablink3').attr('href', '#tabs-3');
	
	$('table.simple td.included.da-DK').attr('title', 'Mulighed for webshop');
	$('div.tabarea td.included.da-DK').attr('title', 'Inkluderet i prisen');
	
	$('table.simple td.included.sv-SE').attr('title', 'Möjlighet för webbshop');
	$('div.tabarea td.included.sv-SE').attr('title', 'Inkluderad i grundlösningen');
	
	$('table.simple td.included.en-GB').attr('title', 'Web shop available');
	$('div.tabarea td.included.en-GB').attr('title', 'Included');
	
	$('div#tabs').tabs();
	
	$('td.header a').cluetip({
		splitTitle: '|',
		cluetipClass: 'default',
		arrows: true,
		dropShadow: false,
		hoverIntent: false,
		sticky: true,
		mouseOutClose: true
	});
	
	$('a.moduleactivator').bind({
		click: function() {
			$('div#pricingplan').show();
			$('div#modules').hide();
		}
	});
	
	$('.goto_express').bind({
		click: function() {
			$('div#pricingplan').hide();
			$('div#modules').show();
			$('#tabs').tabs('select',0);
		}
	});
	
	$('.goto_business').bind({
		click: function() {
			$('div#pricingplan').hide();
			$('div#modules').show();
			$('#tabs').tabs('select',1);
		}
	});
	
	$('.goto_portal').bind({
		click: function() {
			$('div#pricingplan').hide();
			$('div#modules').show();
			$('#tabs').tabs('select',2);
		}
	});
	
	if ($('form[name="submitUserData"]').length != '0' && getParameterByName('step') == '6') {
		$('form[name="submitUserData"]').remove();		
	}
});

function getParameterByName(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function toggleHeight(lang) {
	var extenderheight = $('div#extended').css('height');
	if (extenderheight=='0px') {
		$('div#extended').animate({
			height: 163 + 'px'
		});
		if (lang == 'en-GB') {
			$('a.activator').html('&#187; Close');
		} else if (lang == 'sv-SE') {
			$('a.activator').html('&#187; Luk');
		} else {
			$('a.activator').html('&#187; Luk');
		};
	} else {
		$('div#extended').animate({
			height: 0 + 'px'
		});
		if (lang == 'en-GB') {
			$('a.activator').html('&#187; More information');
		} else if (lang == 'sv-SE') {
			$('a.activator').html('&#187; Mer information');
		} else {
			$('a.activator').html('&#187; Se flere forskelle');
		};
	};
}

function getRefs(reftype, reftypeid) {
	var date = new Date();
	var execUrl = 'http://www.dynamicweb.dk/Admin/Public/DataManagement/PublishingOutput.aspx?ID=2&industrytype=' + reftype + '&cacheprev=' + date.getTime();
	
	/* Deactivating the previous tab and activating the right tab */
	$('ul#reftabs li.active').removeAttr('class');
	$('ul#reftabs li#id' + reftypeid).addClass('active');
	
	/* Creating the list or emptying it for the next tab */
	if ($('ul.referencelist').length == 0) {
		$('div#ref_details').remove();
		$('<ul class="referencelist"></ul>').appendTo('div#ref_column1');
	}else{
		$('ul.referencelist').empty();
	};

	/* In case of loading times we add a progressbar to the list */	
	$('ul.referencelist').addClass('startprogressani');
	
	/* Here we start an Ajax call with an XML Publication from the variable execUrl in line 2 in getRefs() */
	$.ajax({
		async: false,
		url: execUrl,
		cache: false,
		success: function(xml) {
            $(xml).find('Row').each(function(intIndex){
            	var projectname = $(this).find('Value[Column="cust_references_form_Projectname"]').text();
            	var formid = $(this).find('Value[Column="cust_references_formID"]').text();
            	var logo = $(this).find('Value[Column="cust_references_form_Logo"]').text();
            	var industrytype = $(this).find('Value[Column="cust_references_form_Branche"]').text();
        		var detailUrl = 'http://www.dynamicweb.dk/Ref-2010-32923.aspx?industrytype='+ industrytype +'&mode=detail&RowId='+ intIndex +'&ViewPID=168536&projectid='+ formid;
        		var listitem = 'listitem' + intIndex % 2;
        		
        		$('<li class="'+ listitem +'"></li>')
            		.html('<a href="'+ detailUrl +'" title="'+ projectname +'"><img src="http://engage.dynamicweb-cms.com/admin/public/getimage.aspx?width=199&amp;height=80&amp;image='+ logo +'" alt="'+ projectname +'" border="0" /></a>')
            		.appendTo('ul.referencelist');
            }); //close each(
            
            /* After building the new list we remove the progressbar added in line 21 */
            $('ul.referencelist').removeClass('startprogressani');
        },
        complete: function(requestObject, statusText) {
        	/* alert(execUrl +' - '+ requestObject.getResponseHeader("Content-Type") +' - '+ statusText); */
        }
	});
}
