function ucfirst (str) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}

function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 911.718
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    
	// *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}

function closeError(){var ob=parent.document.getElementById('msgI').style; ob.opacity = 0;ob.MozOpacity=0;ob.KhtmlOpacity = 0;ob.filter = "alpha(opacity=0)"; ob.display='none';enable();}
function opacity() {var timer = 0;	for(i = 100; i >= 0; i--) {	setTimeout("changeOpac(" + i + ")",(timer * 10));	timer++;		}}
function changeOpac(opa) {var ob=document.getElementById('msgI').style;ob.opacity=(opa/100);ob.MozOpacity=(opa/100);ob.KhtmlOpacity=(opa/100);ob.filter="alpha(opacity="+opa+")";}
function shiftOpa(fade) {
	var ob= document.getElementById('msgI').style; ob.opacity = 1;ob.MozOpacity=1;ob.KhtmlOpacity = 1;ob.filter = "alpha(opacity=100)";
	if(fade==1){setTimeout("opacity()", 2000);setTimeout("closeError()",3000); } 
}
//function hideflash() { /* hide all flash in the page */ flash = document.getElementsByTagName('object'); for (var i = 0; i < flash.length; i++) { flash[i].style.visibility = 'hidden'; } }
//function showflash() { /* show all flash */ flash = document.getElementsByTagName('object'); for (var i = 0; i < flash.length; i++) { flash[i].style.visibility = 'visible'; } }

function msg(msg,end){
	disable();
	shiftOpa(0);
	document.getElementById('msgI').height=10+'px';
	document.getElementById('msgI').style.display='block';
	window["msgI"].document.getElementById('m').innerHTML=msg;
	if(end!=''){
		window["msgI"].document.getElementById('end').innerHTML=end;
	}else{
		window["msgI"].document.getElementById('end').innerHTML="<input type='button'  class='btn'value='ok' onClick='parent.closeError(); return false;'>";
	}
	//alert(document.getElementById('msgI').contentWindow.document.body.scrollHeight)
	document.getElementById('msgI').height=document.getElementById('msgI').contentWindow.document.body.scrollHeight;
}


function rNum(num) {
	var result = Math.round(num * 100) / 100;

	return result;
}
function enable(){ 	document.getElementById("blanket").style.display='none';}
function disable(){ 	document.getElementById("blanket").style.display='block'; 
}


function pop(id){
	var l='';
	switch (id){
		case 'intW':
//		alert('vdgvf');
	  		l+="<b class='black'>INTERNAL WARDROBE WIDTH</b><br><BR>This is the internal width of your wardrobe from the outer edge of the far left structural pole,";
			l+="to the outer edge of the far right structural pole. When entering this measurement, it is important ";
			l+="to consider that in order to adjust positioning of shelves/rails mounted to these poles, ";
			l+="that the pole will need to be set a few cms away from any walls. Otherwise there will be no room to insert the allen key.<br><BR>";
			l+="Layout and design you create on this website can be adjusted or repositioned during build, so don't worry too much at this stage.";
	  		break
		case 'intH':
  			l+="<b class='black'>INTERNAL WARDROBE HEIGHT</b><br><BR>The internal height of your wardrobe is not really limited, but our floor ";
 	 		l+="to ceiling poles are supplied at a maximum height of 2500mm. If your ceiling is taller than this, you will need to use floor to wall ";
	 		l+="poles (supplied at a height of 2200mm). A long shelf can run along the top of the floor to wall pole returns enabling use of a high ";
			l+="storage shelf if required, fittings are not supplied for this as it is a modification of the standard setup procedure.";
	 		break
		case 'intDoors':
			l+="<b class='black'>NUMBER OF DOORS</b><br><BR>";
  			l+="It is important that we know how many doors you have while designing your wardrobe interior, as door overlap positions will affect drawer openings and pole placement.";
	 		break
		case 'intPoles':
			l+="<b class='black'>INTERIOR STRUCTURAL POLES</b><br><BR>";
  			l+="The internal strucural poles form the backbone of a Door Stop pole interior. There are 2 types available - floor to ceiling and floor to wall. ";
			l+="The most commonly used pole type is floor to wall, as floor to ceiling poles are only suitable for use when your ceiling height is lower than 2500mm. ";
			l+="Floor to wall poles are supplied at a height of 2200mm. Either pole type can be cut down to size on site if required.<BR>";
			l+="<img src='images/howto/intPoles.gif' >";
	 		break
		case 'intWoodWork':
			l+="<b class='black'>WOOD WORK FINISH</b><br><BR>";
  			l+="This is the exterior finish of all shelves, and drawer boxes used in your interior. Although we have tried our best to replicate trues colours in this designer, ";
	 		l+="different computer screens will displat these colours slightly differently. If you looking to colour match any finishes you see here, order some samples through our ";
			l+="<a href='samples.php'>samples page</a> but be aware that if you don't save this deign first you will lose it when you leave this page.";
			break
		case 'intComType':
			l+="<b class='black'>COMPARTMENT TYPE</b><br><BR>";
  			l+="This select menu will give you different options depending on the width and door positionings of the selected compartment ";
			l+="(highlighted with the red 'edit' button). For instance, if the width of the selected compartment is 392, 592 or 792mm, drawer boxes will be offered, but only if there is no door overlap which might get in the way of the drawer openings.";
	 		break
		case 'intFixed':
			l+="<b class='black'>FIXED WIDTH COMPARTMENTS</b><br><BR>";
  			l+="Compartments at specific widths of 392, 592 and 792mm are known as fixed width compartments. They differ from variable width compartments as they facilitate the use of our drawer ";
			l+="boxes (if the fixed width compartment is positioned accross a door overlap, the drawer box option will not be available). <br><BR>Any shelves included into fixed width compartments with ";
			l+="the Pole Interior Designer will be supplied cut to size, edged, and pre-drilled with holes for attaching to our shelf supports. <br><BR>Shelves used in compartments which are not fixed width ";	 
	 		l+="will be supplied in lengths of 2130mm (edged long sides only) and will require cutting, edging and drilling for supports on site.";
	 		break
		case 'slidFrameCol':
			l+="<b class='black'>SLIDING DOOR FRAME FINISH</b><br><BR>";
  			l+="All doors are offered framed in anodised silver aluminium as standard. Our Deluxe range has the option of black frame and tracks.";
	 		break
		case 'slidSoftClose':
			l+="<b class='black'>SLIDING DOOR SOFT CLOSE</b><br><BR>";
  			l+="Soft close is a mechanism which fits to the back doors to enable them to glide smoothly into a closed position. It is not available on our Standard S600 door range.";
	 		l+="A diagram of the soft close mechanism can be seen in <a href='howtosliding.php#TYPES700' target='new'>these</a> technical drawings.";
			break
		case 'slidPanels':
			l+="<b class='black'>MULTIPLE PANEL DOOR OPTIONS</b><br><BR>";
  			l+="All of our doors can be manufactured to contain several panels of different finishes allowing a truly versatile combination of styles. The effect of ";
			l+="multiple panels in a door can be obtained by adding decorative bars, although you will be limited to 1 front finish for the entire door.";
			break
		case 'slidBars':
			l+="<b class='black'>DECORATIVE BARS</b><br><BR>";
  			l+="Decorative bars can be used on all of our single panelled doors, they match the door frame in finish, and are attached to the front face of the door with very strong adhesive tape.";
			break
		case 'slidBack':
			l+="<b class='black'>DOUBLE SIDED DOORS</b><br><BR>";
  			l+="Our Double Sided S725 range can accomodate a second 4mm glass panel to the rear making these doors ideal for walk in wardrobes, or to conceal an on-suite. The";
  			l+=" frame of this door series is identical front and back and the bottom wheel and top guide mechanisms are concealed within the frame profiles of the door.";
			break
		case 'drawerSize':
			l+="<b class='black'>Drawer Unit Size</b><br><BR>";
  			l+="The height dimension shown here is accurate for your currently selected number of drawers, but will amend itself if you select a different number of drawers. If height is a consideration, please recheck the unit height in this field whenever you change the selection for 'Number of Drawers'";
  			break
		case 'drawerFrame':
			l+="<b class='black'>Drawer Chest Frame Finish</b><br><BR>";
  			l+="There are a variety of finishes available to suit your drawer chest to its intended environment. Have a look at our <a href='samples.php' target='new'>samples page</a> to see what would work best for you.";
  			break
		case 'drawerSame':
			l+="<b class='black'>Make All Drawer Fronts the Same</b><br><BR>";
  			l+="This option saves you selecting a finish for each of your drawer fronts if you intend to make them all the same. Unchecking this box will create a finish select menu for each individual drawer front.";
  			break
		case 'drawerFin':
			l+="<b class='black'>Drawer Fronts Finish</b><br><BR>";
  			l+="There are a variety of finishes available to suit your drawer fronts to their intended environment. Have a look at our <a href='samples.php' target='new'>samples page</a> to see what would work best for you.<br /><br />";
  			l+="Please note that wood effect drawer fronts use different handle types than framed glass drawer fronts. For this reason, wood and glass drawer fronts can not be mixed on the same chest with this software, nor can wood drawer fronts be framed to utilise the same handles as a glass front. However, in practise this is possible, and should you be interested in doing so please contact us on 01923 433 214 or use the form on our <a href='contact.php' target='new'>contact us page</a>";
			break
		case 'drawerTop':
			l+="<b class='black'>Drawer Chest Tops</b><br><BR>";
  			l+="Drawer chest tops are intended for use when the drawer chest will standalone. If you would like to use a drawerchest under, or as part of a desk, you could use your own top, or purchase an end panel from our <a href='http://localhost/doorstop/poleinteriors.php#frame' target='new'>frame work page</a> to use as a desk top. Alternatively, our framed glass unit tops can be manufactured to any size and are suitable for use as desk tops, please contact us on 01923 433 214 or use the form on our <a href='contact.php' target='new'>contact us page</a> for information. <br /><br />";
 			l+="There are a variety of finishes available to suit your drawer top to its intended environment. Have a look at our <a href='samples.php' target='new'>samples page</a> to see what would work best for you.";
			break
		case 'drawerHandle':
			l+="<b class='black'>Drawer Front Handles</b><br><BR>";
  			l+="Because of the very thin lip or frame showing at the front of our framed glass drawer fronts, it is required that handles be integrated into the frame. For this reason, if you change your selection from glass to wooden drawer fronts, your handle choice will reset. See below for images of various handle types.";
			l+="<br /><br /><div style='width:480px; height:200px; overflow:auto' >";
			l+="<b>Handles Suitable for Wooden Drawer Fronts</b><br />";
			l+="<div style='width:110px; float:left;'>Short T-Bar<img src='images/handles/C2H30.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Long T-Bar<img src='images/handles/C2H31.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Rounded Bar<img src='images/handles/C2H40.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Enclosed Handle<img src='images/handles/C2H50.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Arch Handle<img src='images/handles/C2H60.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Small Button<img src='images/handles/C1H70.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Large Button<img src='images/handles/C1H71.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Small Square<img src='images/handles/C1H80.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Large Square<img src='images/handles/C1H81.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Cone Handle<img src='images/handles/H93316.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Roll Top<img src='images/handles/H93306.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Wing Handle<img src='images/handles/H93276.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Right Angle<img src='images/handles/H93286.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Bar Handle<img src='images/handles/BARH.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Arc Handle<img src='images/handles/arc.jpg'/></div>";
			l+="<div style='clear:both'></div><br /><b>Integrated Handles Suitable for Framed Drawer Fronts</b><br />";
			l+="<div style='width:110px; float:left;'>Straight Handle<img src='images/handles/straight.jpg'/></div>";
			l+="<div style='width:110px; float:left;'>Angled Handle<img src='images/handles/angled.jpg'/></div>";
			l+="</div><div style='clear:both'></div>";
			break
}
	msg(l,'')
}
function saveBasket(){
	disable();
	$.post("showcart_savebasket.php",
  	function(data){
	var res = data.split("||");
	if(eval(res[0])){
		if(typeof(loadAll)=='function'){loadAll();}
		msg("Save success. Please make a note of your retieval code, it is "+res[1],'');
		if(document.getElementById('loadCode')){document.getElementById('loadCode').value=res[1];}
	}	else{   alert(res[1]);}
						
});}

function basketLoad(){
	$.post("basketLoad.php",
  	function(data){
	var res = data.split("||");
	if(res[1]>0){
		document.getElementById("basketContent").innerHTML="<div style='height:40px;'><b>Last Item: </b>"+res[0]+"</div><div style='float:right;' ><b>Total: </b> £"+res[2]+"</div><div style='float:left;'><b>Items: </b>"+res[1]+"<b></div>";	
	}else{
		document.getElementById("basketContent").innerHTML="<div style='height:40px;'><b>There are no items in your basket</b></div>";	
	}						
});}