// JavaScript Document

function capturelinks() {

	if (!document.all) {
		$('pageid22').onclick = function (e) {loadtab(23);return false;};
		$('pageid23').onclick = function (e) {loadtab(23);return false;};
		$('pageid24').onclick = function (e) {loadtab(24);return false;};
		$('pageid25').onclick = function (e) {loadtab(25);return false;};
		$('pageid26').onclick = function (e) {loadtab(26);return false;};
		$('pageid72').onclick = function (e) {loadtab(72);return false;};
	}
}
function capturetablinks(pageid) {
	
	$('pageid23').removeClassName('subsubmenuon');
	$('pageid24').removeClassName('subsubmenuon');
	$('pageid25').removeClassName('subsubmenuon');
	$('pageid26').removeClassName('subsubmenuon');
	$('pageid72').removeClassName('subsubmenuon');
	
	$(pageid).addClassName('subsubmenuon');

	if (!document.all) {
		$('tabid23').onclick = function (e) {loadtab(23);return false;};
		$('tabid24').onclick = function (e) {loadtab(24);return false;};
		$('tabid25').onclick = function (e) {loadtab(25);return false;};
		$('tabid26').onclick = function (e) {loadtab(26);return false;};
		$('tabid72').onclick = function (e) {loadtab(72);return false;};
	
		if($('linkid24')){
			$('linkid24').onclick = function (e) {loadtab(24);return false;};
		}
		if($('linkid25')){
			$('linkid25').onclick = function (e) {loadtab(25);return false;};
		}
		if($('linkid26')){
			$('linkid26').onclick = function (e) {loadtab(26);return false;};
		}
	}
}
function onTick() {
	timerCookie = null;
	
	if (!document.all) {
		if(document.location.hash == "" && currentpageid != 23){
			loadtab(23);
		}
	}
	if(document.location.hash == "#Maat" && currentpageid != 23){
		loadtab(23);
	}
	if(document.location.hash == "#Assortiment" && currentpageid != 24){
		loadtab(24);
	}
	if(document.location.hash == "#KleurenHoutsoorten" && currentpageid != 25){
		loadtab(25);
	}
	if(document.location.hash == "#Afwerkingen" && currentpageid != 26){
		loadtab(26);
	}
	if(document.location.hash == "#Hulp" && currentpageid != 72){
		loadtab(72);
	}
	timerCookie = window.setTimeout(onTick, 200);
}
function loadtab(pageid) {
	currentpageid = pageid;
	new Ajax.Request('/sitestyle/modules/code/blinds/tabloader.php?pageid='+pageid, {onSuccess: loadtabdispay});
	switch (pageid) {
		case 23:
			window.location.hash = "Maat";
			break;
		case 24:
			window.location.hash = "Assortiment";
			break;
		case 25:
			window.location.hash = "KleurenHoutsoorten";
			break;
		case 26:
			window.location.hash = "Afwerkingen";
			break;
		case 72:
			window.location.hash = "Hulp";
			break;
	}
	return false;
}
function loadtabdispay(transport) {
	$('tabszone').replace(transport.responseText);
	$$('.columns').each(function(item) { item.style.height = "";});
	setEqualHeightColumns('columns');
}
function unitswitch(unit) {
//	Delete_Cookie('defaultunits');
	Set_Cookie( 'defaultunits', unit, 60, '/', document.domain );
	if($('unitesmm')) {
		if(unit == 'mm'){
			$('unitesmm').style.display = '';
			$('unitesinch').style.display = 'none';
		}
		else {
			$('unitesmm').style.display = 'none';
			$('unitesinch').style.display = '';
		}
	}
	detaillayout();
}

function sizevalue(transport) {	
	$('blinderror').style.display = "NONE";
	if(transport){
		var sizes = transport.responseText.evalJSON(true);
		switch(sizes.field) {
			case 'widthmm':
			  $('widthmm').innerHTML = sizes.value;
			  $('widthin').innerHTML = sizes.value2;
			  break;    
			case 'widthin':
			  $('widthin').innerHTML = sizes.value;
			  $('widthmm').innerHTML = sizes.value2;
			  break;
			case 'heightmm':
			  $('heightmm').innerHTML = sizes.value;
			  $('heightin').innerHTML = sizes.value2;
			  break;    
			case 'heightin':
			  $('heightin').innerHTML = sizes.value;
			  $('heightmm').innerHTML = sizes.value2;
			  break;
		}
	}
	drawlayout();
	detaillayout();
	if(sizes.error != ""){
		$('blinderrortext').innerHTML = sizes.error;
		$('blinderror').style.display = "";
	}
};

Object.extend(Ajax.InPlaceEditor.prototype, {
	getText: function() {
		return this.element.innerHTML.stripTags();
	}
});

function sectionaction(action) {
	new Ajax.Request('/sitestyle/modules/code/blinds/sectionchange.php?action='+action, {onSuccess: sectiondisplay});
}
function sectiondisplay(transport) {
	var sectioncode = transport.responseText.evalJSON(true);
	$('sectionlayout').replace(sectioncode.layout);
	if(sectioncode.remove == 1) {
		$('sectionremove').style.display = "none";
	}
	else {
		$('sectionremove').style.display = "";
	}
	if(sectioncode.add == 1) {
		$('sectionadd').style.display = "none";
	}
	else {
		$('sectionadd').style.display = "";
	}
	$('sectioncount').innerHTML = sectioncode.count;
	drawlayout();
	detaillayout();
}




function drawlayout() {
	new Ajax.Request('/sitestyle/modules/code/blinds/drawlayout.php', {onSuccess: drawlayoutdisplay});
}
function drawlayoutdisplay(transport) {
	
	var blind = transport.responseText.evalJSON(true);
		
	blindcolourhtml = "";
	tapecolourhtml = "";

	switch(blind.range) {
		case 'Malibu':
		case 'Santa Ana':
			switch(blind.tapecolour) {
				case 'White':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-white-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Ecru':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-ecru-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Light Grey':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-light-grey-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Taupe':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-taupe-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Beige':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-beige-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Chocolate':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-chocolate-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Cypress':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-cypress-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Maroon':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-maroon-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Royal Blue':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-royal-blue-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
				case 'Black':
					tapecolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/45-black-tape.jpg" width="45" height="225" id="closeupfinishtape" />';
					break;    
			}
			
		case 'Monterey':
			switch(blind.blindcolour) {
				case 'White':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-white.jpg" width="167" height="287" />';
					break;    
				case 'Snow White':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-snowwhite.jpg" width="167" height="287" />';
					break;    
				case 'Ivory':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-ivory.jpg" width="167" height="287" />';
					break;    
				case 'Bleached White':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-bleached.jpg" width="167" height="287" />';
					break;    
				case 'Oyster':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-oyster.jpg" width="167" height="287" />';
					break;    
				case 'Natural':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-natural.jpg" width="167" height="287" />';
					break;    
				case 'Pine':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-pine.jpg" width="167" height="287" />';
					break;    
				case 'Maple':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-maple.jpg" width="167" height="287" />';
					break;    
				case 'Oak':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-oak.jpg" width="167" height="287" />';
					break;    
				case 'Pecan':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-pecan.jpg" width="167" height="287" />';
					break;    
				case 'Cherry':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-cherry.jpg" width="167" height="287" />';
					break;
				case 'Mahogany':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-mahogony.jpg" width="167" height="287" />';
					break;
					
				case 'Wood Effect White':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-wood-white.jpg" width="167" height="287" />';
					break;    
				case 'Wood Effect Ivory':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-wood-ivory.jpg" width="167" height="287" />';
					break;    
				case 'Wood Effect Oyster':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/M-wood-oyster.jpg" width="167" height="287" />';
					break;    
			}
		break;
		
		case 'Beverly Hills':
			switch(blind.blindcolour) {
				case 'White':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/BH-white.jpg" width="167" height="287" />';
					break;    
				case 'Ivory':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/BH-ivory.jpg" width="167" height="287" />';
					break;    
				case 'Pine':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/BH-pine.jpg" width="167" height="287" />';
					break;    
				case 'Maple':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/BH-maple.jpg" width="167" height="287" />';
					break;    
				case 'Pecan':
					blindcolourhtml = '<img src="/sitestyle/modules/code/blinds/colours/BH-pecan.jpg" width="167" height="287" />';
					break;    
			}
		break;
		
	}
	$('closeupfinish').innerHTML = blindcolourhtml+tapecolourhtml;

	if($('flashzone')){
		flash = $('blindlayout');

		if(flash.drawFlashLayout) {
			flash.drawFlashLayout(blind.width, blind.height, blind.range, blind.blindcolour, blind.tapecolour, blind.pelmetreturn, blind.pullcord, blind.tilt);
		}
		else {
			flash = $('blindlayoutembed');
			if(flash.drawFlashLayout) {
				flash.drawFlashLayout(blind.width, blind.height, blind.range, blind.blindcolour, blind.tapecolour, blind.pelmetreturn, blind.pullcord, blind.tilt);
			}
		}
	}
}
function detaillayout() {
	new Ajax.Request('/sitestyle/modules/code/blinds/detailview.php', {onSuccess: function(transport) { $('detailview').replace(transport.responseText);}});
}
function listlayout() {
	new Ajax.Request('/sitestyle/modules/code/blinds/listview.php', {onSuccess: function(transport) { $('listview').replace(transport.responseText);}});
}


function buttonchange(field,action) {
	new Ajax.Request('/sitestyle/modules/code/blinds/buttonchange.php?button='+field+'&value='+action, {onSuccess: buttondisplay});
}
function buttondisplay(transport) {
	var btcode = transport.responseText.evalJSON(true);
	if(btcode.button != ""){
		$(btcode.button+btcode.value).siblings().each(function(s) {s.style.display = "none";});
		$(btcode.button+btcode.value).style.display = "";	
	}
	drawlayout();
	detaillayout();
	
}
function choicechange(field,action) {
	new Ajax.Request('/sitestyle/modules/code/blinds/choicechange.php?choice='+field+'&value='+action, {onSuccess: choicedisplay});
}
function choicedisplay(transport) {
	var btcode = transport.responseText.evalJSON(true);
	if(btcode.choice != ""){
		
		$(btcode.choice+btcode.value).siblings().each(function(s) {s.removeClassName('imagechoice-on');});
		$(btcode.choice+btcode.value).addClassName('imagechoice-on');
	}
	drawlayout();
	detaillayout();
	
}
function setchoice(choice) {
	if($(choice)) $(choice).addClassName('imagechoice-on');
}