// JavaScript Document

function errorOutput(errorHtml){
	$('shuttererror').hide();
	if(typeof(errorHtml) != "undefined" && errorHtml != ""){
		$('shuttererrortext').innerHTML = errorHtml;
		$('shuttererror').show();
	}
}

function capturelinks() {

	if (!document.all) {
//		$('pageid27').onclick = function (e) {loadtab(89);return false;};
		$('pageid89').onclick = function (e) {loadtab(89);return false;};
		$('pageid90').onclick = function (e) {loadtab(90);return false;};
		$('pageid91').onclick = function (e) {loadtab(91);return false;};
		$('pageid92').onclick = function (e) {loadtab(92);return false;};
		$('pageid93').onclick = function (e) {loadtab(93);return false;};
	}

}
function capturetablinks(pageid) {

	$('pageid89').removeClassName('subon');
	$('pageid90').removeClassName('subon');
	$('pageid91').removeClassName('subon');
	$('pageid92').removeClassName('subon');
	$('pageid93').removeClassName('subon');

	$(pageid).addClassName('subon');

	if (!document.all) {
		$('tabid89').onclick = function (e) {loadtab(89);return false;};
		$('tabid90').onclick = function (e) {loadtab(90);return false;};
		$('tabid91').onclick = function (e) {loadtab(91);return false;};
		$('tabid92').onclick = function (e) {loadtab(92);return false;};
		$('tabid93').onclick = function (e) {loadtab(93);return false;};

		if($('linkid90')){
			$('linkid90').onclick = function (e) {loadtab(90);return false;};
		}
		if($('linkid91')){
			$('linkid91').onclick = function (e) {loadtab(91);return false;};
		}
		if($('linkid92')){
			$('linkid92').onclick = function (e) {loadtab(92);return false;};
		}
	}
}
function onTick() {
	timerCookie = null;

	if (!document.all) {
		if(document.location.hash == "" && currentpageid != 89){
			loadtab(89);
		}
	}
	if(document.location.hash == "#SizeandDesign" && currentpageid != 89){
		loadtab(89);
	}
	if(document.location.hash == "#PanelSlats" && currentpageid != 90){
		loadtab(90);
	}
	if(document.location.hash == "#ColourWoodType" && currentpageid != 91){
		loadtab(91);
	}
	if(document.location.hash == "#InstallationFinish" && currentpageid != 92){
		loadtab(92);
	}
	if(document.location.hash == "#Help" && currentpageid != 93){
		loadtab(93);
	}
	timerCookie = window.setTimeout(onTick, 200);
}
function loadtab(pageid) {
	currentpageid = pageid;
	new Ajax.Request('/sitestyle/modules/code/shutters/tabloader.php?pageid='+pageid, {onSuccess: loadtabdispay});
	switch (pageid) {
		case 89:
			window.location.hash = "SizeandDesign";
			break;
		case 90:
			window.location.hash = "PanelSlats";
			break;
		case 91:
			window.location.hash = "ColourWoodType";
			break;
		case 92:
			window.location.hash = "InstallationFinish";
			break;
		case 93:
			window.location.hash = "Help";
			break;
	}
	return false;
}
function loadtabdispay(transport) {
	$('tabszone').replace(transport.responseText);
	$$('.columns').each(function(item) { item.style.height = "";});
}

function unitswitch(unit) {
	Delete_Cookie('defaultunits');
	Delete_Cookie('defaultunits', '/', 'theshutterstore.com' );
	Set_Cookie( 'defaultunits', unit, 60, '/', '.www.theshutterstore.com' );
	if($('unitesmm')) {
		if(unit == 'mm'){
			$('unitesmm').style.display = '';
			$('unitesinch').style.display = 'none';
		}
		else {
			$('unitesmm').style.display = 'none';
			$('unitesinch').style.display = '';
		}
	}
	drawlayout();
	detaillayout();
}

function railstyle(heightmm) {
	if (heightmm >= 500) {
		$('typeFullHeightwithRail').show();
		$('typeFullHeightwithRailOff').hide();
		$('typeCafeStylewithRail').show();
		$('typeCafeStylewithRailOff').hide();
	} else {
		$('typeFullHeightwithRail').hide();
		$('typeFullHeightwithRailOff').show();
		$('typeCafeStylewithRail').hide();
		$('typeCafeStylewithRailOff').show();
	}
	if (heightmm >= 1800) {
		$('typeFullHeight').hide();
		$('typeFullHeightOff').show();
		$('typeCafeStyle').hide();
		$('typeCafeStyleOff').show();
	} else {
		$('typeFullHeight').show();
		$('typeFullHeightOff').hide();
		$('typeCafeStyle').show();
		$('typeCafeStyleOff').hide();
	}
}

function shapesSwitch(widthmm) {
	if (widthmm <= 900) {
		$('typeFrenchDoorCutOut').show();
		$('typeFrenchDoorCutOutOff').hide();
	} else {
		$('typeFrenchDoorCutOut').hide();
		$('typeFrenchDoorCutOutOff').show();
	}

	if (widthmm <= 2538) {
		$('typeHalfArch').show();
		$('typeHalfArchOff').hide();
	} else {
		$('typeHalfArch').hide();
		$('typeHalfArchOff').show();
	}

	if (widthmm <= 1524) {
		$('typePerfectArch').show();
		$('typePerfectArchOff').hide();
		$('typeElongatedArch').show();
		$('typeElongatedArchOff').hide();
	} else {
		$('typePerfectArch').hide();
		$('typePerfectArchOff').show();
		$('typeElongatedArch').hide();
		$('typeElongatedArchOff').show();
	}
}

function sizevalue(transport) {
	$('shuttererror').style.display = "NONE";
	if(transport){
		var sizes = transport.responseText.evalJSON(true);
		switch(sizes.field) {
			case 'widthmm':
			  $('widthmm').innerHTML = sizes.value;
			  $('widthin').innerHTML = sizes.value2;
			  shapesSwitch(sizes.value);
			  break;
			case 'widthin':
			  $('widthin').innerHTML = sizes.value;
			  $('widthmm').innerHTML = sizes.value2;
			  shapesSwitch(sizes.value2);
			  break;
			case 'heightmm':
			  $('heightmm').innerHTML = sizes.value;
			  $('heightin').innerHTML = sizes.value2;
			  railstyle(sizes.value);
			  break;
			case 'heightin':
			  $('heightin').innerHTML = sizes.value;
			  $('heightmm').innerHTML = sizes.value2;
			  railstyle(sizes.value2);
			  break;
			case 'dividerpositionmm':
			  $('dividerpositionmm').innerHTML = sizes.value;
			  $('dividerpositionin').innerHTML = sizes.value2;
			  break;
			case 'dividerpositionin':
			  $('dividerpositionin').innerHTML = sizes.value;
			  $('dividerpositionmm').innerHTML = sizes.value2;
			  break;
		}
	}
	if (sizes.type != "") {
		$("type"+sizes.type).siblings().each(function(s) {s.removeClassName('imagechoice-on');});
		$("type"+sizes.type).addClassName('imagechoice-on');
	}
	drawlayout();
	detaillayout();
	errorOutput(sizes.error);
};

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

function sectionaction(action) {
	new Ajax.Request('/sitestyle/modules/code/shutters/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();
	errorOutput(sectioncode.error);
}



function drawlayout() {
	new Ajax.Request('/sitestyle/modules/code/shutters/drawlayout.php', {onSuccess: drawlayoutdisplay});
}
function drawlayoutdisplay(transport) {

	var shutter = transport.responseText.evalJSON(true);

	switch(shutter.colour) {
		case 'Paint Bright White':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-white.gif" width="167" height="287" />';
		  break;
		case 'Paint Cloudy White':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-all-white.gif" width="167" height="287" />';
		  break;
		case 'Paint Biscuit':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-white-tie.gif" width="167" height="287" />';
		  break;
		case 'Paint Shell':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-shell.gif" width="167" height="287" />';
		  break;
		case 'Paint Ivory':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-ivory.gif" width="167" height="287" />';
		  break;
		case 'Paint Clotted Cream':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-cream.gif" width="167" height="287" />';
		  break;
		case 'Paint Pearl':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-pearl.gif" width="167" height="287" />';
		  break;
		case 'Paint Alabaster':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/paint-alabaster.gif" width="167" height="287" />';
		  break;

		case 'Elm Natural':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-natural.jpg" width="167" height="287" />';
		  break;
		case 'Elm Honey Oak':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-honey-oak.jpg" width="167" height="287" />';
		  break;
		case 'Elm Light Oak':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-light-oak.jpg" width="167" height="287" />';
		  break;
		case 'Elm Sugar Maple':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-sugar-maple.jpg" width="167" height="287" />';
		  break;
		case 'Elm Golden Oak':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-golden-oak.jpg" width="167" height="287" />';
		  break;
		case 'Elm Walnut':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-walnut.jpg" width="167" height="287" />';
		  break;
		case 'Elm Cherry':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-cherry.jpg" width="167" height="287" />';
		  break;
		case 'Elm Black Walnut':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-black-walnut.jpg" width="167" height="287" />';
		  break;
		case 'Elm Wenge':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-wenge.jpg" width="167" height="287" />';
		  break;
		case 'Elm Black':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-black.jpg" width="167" height="287" />';
		  break;
		case 'Elm Unfinished':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/elm-unfinished.jpg" width="167" height="287" />';
		  break;

		case 'Poplar Natural':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-natural.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Honey Oak':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-honey-oak.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Light Oak':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-light-oak.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Sugar Maple':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-sugar-maple.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Golden Oak':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-golden-oak.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Walnut':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-walnut.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Cherry':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-cherry.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Black Walnut':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-black-walnut.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Wenge':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-wenge.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Black':
			$('closeupfinish').style.backgroundColor = '#ffffff';
		  $('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-black.jpg" width="167" height="287" />';
		  break;
		case 'Poplar Unfinished':
			$('closeupfinish').style.backgroundColor = '#ffffff';
			$('closeupfinish').innerHTML = '<img src="/sitestyle/modules/code/shutters/colours/poplar-unfinished.jpg" width="167" height="287" />';
		  break;
		default:
			$('closeupfinish').innerHTML = '<span>'+shutter.colour+'</span>';
			$('closeupfinish').style.backgroundColor = '#'+shutter.colorhex;
			shutter.colour = shutter.colorhex;
	}

	flash = $('shutterlayout');

	if(flash.drawShutterLayout) {
		flash.drawShutterLayout(shutter.width,shutter.height,shutter.dividerposition,shutter.type,shutter.left,shutter.right,shutter.colour,shutter.hingecolour,shutter.slatsize,shutter.pushrod,shutter.installation);
	}
	else {
		$('shutterlayoutembed').drawShutterLayout(shutter.width,shutter.height,shutter.dividerposition,shutter.type,shutter.left,shutter.right,shutter.colour,shutter.hingecolour,shutter.slatsize,shutter.pushrod,shutter.installation);
	}
}
function detaillayout() {
	new Ajax.Request('/sitestyle/modules/code/shutters/detailview.php', {onSuccess: function(transport) { $('detailview').replace(transport.responseText);}});
}
function listlayout() {
	new Ajax.Request('/sitestyle/modules/code/shutters/listview.php', {onSuccess: function(transport) { $('listview').replace(transport.responseText);}});
}


function buttonchange(field,action) {
	new Ajax.Request('/sitestyle/modules/code/shutters/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();
}

var colorComapany = '';
var colorName = '';

function choicechange(field,action) {

	if(field == "colour"){
		if(action == 'Benjamin Moore' || action == 'Sherwin Williams'){
			$('moreColorChoice').show();
			colorComapany = action;
		}
		else {
			$('moreColorChoice').hide();
			colorComapany = '';
		}
	}
	idString = field + action.replace(/ /g, "");
	if(!$(idString).hasClassName('imagechoice-on')){
		new Ajax.Request('/sitestyle/modules/code/shutters/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');

		if(btcode.name != ""){
			$('Color_Search').value = btcode.name;
			$('currentColor').style.backgroundColor = '#'+btcode.hex;
		}
		else {
			$('doc').scrollTo();
		}
	}
	if (btcode.choice == "slatsize") {
		sectionaction('');
		detaillayout();
	} else {
		drawlayout();
		detaillayout();
	}
	errorOutput(btcode.error);
}
function setchoice(choice) {
	if($(choice)) $(choice).addClassName('imagechoice-on');
	if(choice == 'sidesNoFrames'){
		$('frame_installation').hide();
	}
}
function setcolorchoice(choice,company,name,hex) {
	if($(choice)) $(choice).addClassName('imagechoice-on');

	if(name != ""){
		colorComapany = company;
		$('Color_Search').value = name;
		$('currentColor').style.backgroundColor = '#'+hex;
		$('moreColorChoice').style.display = "";
	}
}

function moreColorChoiceSelect(element, entry) {
	// alert(entry + "&searchComapany=" + colorComapany);
	return entry + "&searchComapany=" + colorComapany;
}
function moreColorChoiceSelected(text, id) {
	$('currentColor').style.backgroundColor = id.style.borderLeftColor;
	new Ajax.Request('/sitestyle/modules/code/shutters/choicechange.php?choice=colour&value='+id.title, {onSuccess: moreColorChoiceDisplay});
}
function moreColorChoiceDisplay(transport) {
	var btcode = transport.responseText.evalJSON(true);
	$('doc').scrollTo();
	drawlayout();
	detaillayout();
	errorOutput(btcode.error);
}
