var Kthis = null;
var Kname = '';

function Klibrary (name)
{

	Kname = name;
	Kthis = this;

	this.itemOptions=new Array();
	this.listTypeId=10;
    this.miniTestimonialArray=new Array();
    this.miniTestimonialMax=0;
    this.miniTestimonialId=0;
    this.miniTestimonialDisplayed=false;
    this.mainTestimonialDisplayed=false;
    this.glowButtonDisplayed=true;
	this.check = function() { alert("you have accessed Klibrary.check()"); }


	// Add a class name to an objects class list
	this.addClassName=function(obj,classname) {
		var classes = document.getElementById(obj).className;
		if(classes.indexOf(classname)>=0) return;
		classes += " " + classname;
		document.getElementById(obj).className = classes;
	}


	//Add a new product
	this.addProduct=function() {
		var msg="";
		if (document.getElementById('title').value=='') {
			msg='Please enter a name for the new product';
		}
		if (msg!='') alert(msg);
		else document.getElementById('addProductForm').submit();
	}

	//
	//Swap image using a given sel image class
	this.changeImgNew=function(selImageId,file,selImageClass) {
		document.getElementById('mainImage').src=file;
		var imageList=document.getElementById('imgIdArray').value;
		var imageArray=imageList.split(',');
		var imageId='';
		for(var i=0;i<imageArray.length;i++) {
			imageId=imageArray[i];
			if (document.getElementById(imageId)) {
				if (imageId==selImageId) {
				 	this.addClassName(imageId,selImageClass);
				 	this.removeClassName(imageId,'nonSelImage');
				} else {
					this.addClassName(imageId,'nonSelImage');
					this.removeClassName(imageId,selImageClass);
				}
			}
		}
	}

	//Swap image
	this.changeImg=function(selImageId,file) {
		document.getElementById('mainImage').src=file;
		var imageList=document.getElementById('imgIdArray').value;
		var imageArray=imageList.split(',');
		var imageId='';
		for(var i=0;i<imageArray.length;i++) {
			imageId=imageArray[i];
			if (document.getElementById(imageId)) {
				if (imageId==selImageId) {
				 	this.addClassName(imageId,'selImage');
				 	this.removeClassName(imageId,'nonSelImage');
				} else {
					this.addClassName(imageId,'nonSelImage');
					this.removeClassName(imageId,'selImage');
				}
			}
		}
        
        //show the holder
        if (document.getElementById('photoViewer')) this.removeClassName('photoViewer','hidden');
	}


	//Swap image and text
	this.changeImgPanelStyle=function(selImageId,file,name,timber,glass,finish,thickness,comments,panelSizes) {
		document.getElementById('mainImage').src=file;
		var imageList=document.getElementById('imgIdArray').value;
		var imageArray=imageList.split(',');
		var imageId='';
		for(var i=0;i<imageArray.length;i++) {
			imageId=imageArray[i];
			if (document.getElementById(imageId)) {
				if (imageId==selImageId) {
				 	this.addClassName(imageId,'selImageTall');
				 	this.removeClassName(imageId,'nonSelImageTall');
				} else {
					this.addClassName(imageId,'nonSelImageTall');
					this.removeClassName(imageId,'selImageTall');
				}
			}
		}
		document.getElementById('nameFld').innerHTML=name;
		document.getElementById('timberFld').innerHTML=timber;
		document.getElementById('glassFld').innerHTML=glass;
		document.getElementById('finishFld').innerHTML=finish;
		document.getElementById('thicknessFld').innerHTML=thickness;
		document.getElementById('commentsFld').innerHTML=comments;
		document.getElementById('sizesFld').innerHTML=panelSizes;
		
		//display the panel div
		this.removeClassName('panelHolderDiv','hidden');
	}
	
	this.hidePanelDiv=function() {
		this.addClassName('panelHolderDiv','hidden');
	}


	//Swap Explanation
	this.setExp=function(exp) {
		document.getElementById('mainImageText').innerHTML=exp;
	}


	// Delete a banner
	this.deleteBanner=function(bannerId,title) {
		if(confirm('Are you sure you wish to delete this banner ('+title+')')) {
			//delete the image
			window.location='deleteBanner.process.php?bannerId='+bannerId;
		}
	}


	// Delete a blind
	this.deleteBlind=function(productId,blindId,title) {
		if(confirm('Are you sure you wish to delete this blind ('+title+')')) {
			//delete the bline
			window.location='deleteBlind.process.php?productId='+productId+'&blindId='+blindId;
		}
	}


	// Delete a case study
	this.deleteCaseStudy=function(productId,csId,title) {
		if(confirm('Are you sure you wish to delete this case study ('+title+')')) {
			//delete the image
			window.location='deleteCaseStudy.process.php?productId='+productId+'&csId='+csId;
		}
	}


	// Delete a colour finish
	this.deleteColourFinish=function(productId,colourId,title) {
		if(confirm('Are you sure you wish to delete this colour finish ('+title+' '+colourId+')')) {
			//delete the colour finish
			window.location='deleteColour.process.php?productId='+productId+'&colourId='+colourId;
		}
	}


	// Delete a colour list item
	this.deleteColourList=function(colourListId,title) {
		if(confirm('Are you sure you wish to delete this item ('+title+')')) {
			//delete the item
			window.location='deleteColourList.process.php?colourListId='+colourListId;
		}
	}


	// Delete an enquiry list item
	this.deleteEnquiryList=function(enquiryListId,title) {
		if(confirm('Are you sure you wish to delete this item ('+title+')')) {
			//delete the image
			window.location='deleteEnquiryList.process.php?enquiryListId='+enquiryListId;
		}
	}


	// Delete an event
	this.deleteEvent=function(eventId,title) {
		if(confirm('Are you sure you wish to delete this event ('+title+')')) {
			//delete the image
			window.location='deleteEvent.process.php?eventId='+eventId;
		}
	}


	// Delete a frame
	this.deleteFrame=function(productId,frameId,title) {
		if(confirm('Are you sure you wish to delete this frame ('+title+')')) {
			//delete the image
			window.location='deleteFrame.process.php?productId='+productId+'&frameId='+frameId;
		}
	}


	// Delete a faq
	this.deleteFaq=function(productId,faqId,title) {
		if(confirm('Are you sure you wish to delete this FAQ ('+title+')')) {
			//delete the image
			window.location='deleteFaq.process.php?productId='+productId+'&faqId='+faqId;
		}
	}


	// Delete an image
	this.deleteGalleryImage=function(productId,imageId,title) {
		if(confirm('Are you sure you wish to delete this image ('+title+')')) {
			//delete the image
			window.location='deleteGallery.process.php?productId='+productId+'&imageId='+imageId;
		}
	}


	// Delete a glazing
	this.deleteGlazing=function(productId,glazingId,title) {
		if(confirm('Are you sure you wish to delete this glazing ('+title+')')) {
			//delete the glazing
			window.location='deleteGlazing.process.php?productId='+productId+'&glazingId='+glazingId;
		}
	}


	// Delete a handle
	this.deleteHandle=function(productId,handleId,title) {
		if(confirm('Are you sure you wish to delete this handle/hinge ('+title+')')) {
			//delete the handle
			window.location='deleteHandle.process.php?productId='+productId+'&handleId='+handleId;
		}
	}


	// Delete a hardware item
	this.deleteHardware=function(productId,hardwareId,title) {
		if(confirm('Are you sure you wish to delete this hardware('+title+')')) {
			//delete the hardware item
			window.location='deleteHardware.process.php?productId='+productId+'&hardwareId='+hardwareId;
		}
	}
	

	// Delete a internal door
	this.deleteInternalDoor=function(productId,internalDoorId,title) {
		if(confirm('Are you sure you wish to delete this internal door ('+title+')')) {
			//delete the image
			window.location='deleteInternalDoor.process.php?productId='+productId+'&internalDoorId='+internalDoorId;
		}
	}


	// Delete an open config
	this.deleteOpenConfig=function(productId,openConfigId,title) {
		if(confirm('Are you sure you wish to delete this opening config ('+title+')')) {
			//delete the open config
			window.location='deleteOpenConfig.process.php?productId='+productId+'&openConfigId='+openConfigId;
		}
	}


	// Delete a panel style
	this.deletePanelStyle=function(productId,panelStyleId,title) {
		if(confirm('Are you sure you wish to delete this panel style('+title+')')) {
			//delete the panel style
			window.location='deletePanelStyle.process.php?productId='+productId+'&panelStyleId='+panelStyleId;
		}
	}


	// Delete a price
	this.deletePrice=function(productId,priceId,title) {
		if(confirm('Are you sure you wish to delete this price ('+title+')')) {
			//delete the price
			window.location='deletePrice.process.php?productId='+productId+'&priceId='+priceId;
		}
	}


	// Delete a press release
	this.deletePressRelease=function(prId,headline) {
		if(confirm('Are you sure you wish to delete this press release ('+headline+')')) {
			//delete the press release
			window.location='deletePressRelease.process.php?prId='+prId;
		}
	}


	// Delete a show room
	this.deleteShowRoom=function(sId,title) {
		if(confirm('Are you sure you wish to delete this show room ('+title+')')) {
			//delete the show room
			window.location='deleteShowRoom.process.php?sId='+sId;
		}
	}


	// Delete a testimonial
	this.deleteTestimonial=function(tId,blurb) {
		if(confirm('Are you sure you wish to delete this testimonial ('+blurb+')')) {
			//delete the testimonial
			window.location='deleteTestimonial.process.php?tId='+tId;
		}
	}


	// Delete a product
	this.deleteProduct=function(productId,title) {
		if(confirm('Are you sure you wish to delete this product ('+title+')')) {
			//delete the product
			window.location='deleteProduct.process.php?productId='+productId;
		}
	}


	// Delete a product group
	this.deleteProductGroup=function(productGroupId,title) {
		if(confirm('Are you sure you wish to delete this product group ('+title+')')) {
			//delete the product group
			window.location='deleteProductGroup.process.php?productGroupId='+productGroupId;
		}
	}


	// Delete a sill
	this.deleteSill=function(productId,sillId,title) {
		if(confirm('Are you sure you wish to delete this sill ('+title+')')) {
			//delete the image
			window.location='deleteSill.process.php?productId='+productId+'&sillId='+sillId;
		}
	}


    // Delete a table row
    this.deleteTableRow=function(tblName,link) {
        var tbl= document.getElementById(tblName);
        var tableRow = link.parentNode.parentNode;
        if (tableRow!=null) {
            tbl.deleteRow(tableRow.rowIndex);
        }
    }


	// Delete a technical data
	this.deleteTechData=function(productId,techDataId,title) {
		if(confirm('Are you sure you wish to delete this item('+title+')')) {
			//delete the technical data
			window.location='deleteTechData.process.php?productId='+productId+'&techDataId='+techDataId;
		}
	}


	// Delete a technical drawing
	this.deleteTechDrawings=function(productId,techDrawingId,title) {
		if(confirm('Are you sure you wish to delete this item ('+title+')')) {
			//delete the technical drawing
			window.location='deleteTechDrawing.process.php?productId='+productId+'&techDrawingId='+techDrawingId;
		}
	}


	// Delete a trickle vent
	this.deleteTricklevent=function(productId,trickleventId,title) {
		if(confirm('Are you sure you wish to delete this trickle vent ('+title+')')) {
			//delete the image
			window.location='deleteTricklevent.process.php?productId='+productId+'&trickleventId='+trickleventId;
		}
	}

    //return the y position of an element
    this.getY=function( obj_id )
    {
        var oElement = document.getElementById(obj_id);
        var iReturnValue = 0;
        while( oElement != null ) {
            iReturnValue += oElement.offsetTop;
            oElement = oElement.offsetParent;
        }
        return iReturnValue;
    }

	// Find a value in an array returns element position if found otherwise it returns false
	this.in_Array=function(needle,haystack,offset) {
		if (offset==null || offset==undefined) offset=0;
		for(var i=offset;i<haystack.length;i++) {
			if (haystack[i]==needle) return i;
		}
		return false;
	}


    //Move an object
    this.moveObject=function(obj_id,val_top) {
        var obj=document.getElementById(obj_id);
        if (val_top) obj.style.top=val_top+'px';
    }


	// Remove a class name from an objects class list
	this.removeClassName=function(obj,classname) {
		if (!document.getElementById(obj)) alert(obj+' does not exist');
		var classes = document.getElementById(obj).className;
		if(classes.indexOf(classname)<0) return;
		var cl = classes.split(" ");
		classes = '';
		for (i=0; i<cl.length; i++)
		{
			if(cl[i]!=classname) classes += cl[i] + " ";
		}
		document.getElementById(obj).className = classes;
	}


    // Resize a case study div
    this.resizeCSDiv=function(id,action) {
        if (action=='open') {
            this.removeClassName('csExp_'+id,'caseStudyDescription_min');
            this.addClassName('csExp_'+id,'caseStudyDescription_max');
            document.getElementById('resizeButtonsBottom_'+id).innerHTML="<a href='#cs_"+id+"' onclick='kloeberlib.resizeCSDiv(\""+id+"\",\"close\");'><img src='images/closeCS1.jpg' title='Click here to close this case study' alt='Close'/></a>";
            document.getElementById('resizeButtonsTop_'+id).innerHTML="<a href='#cs_"+id+"' onclick='kloeberlib.resizeCSDiv(\""+id+"\",\"close\");'><img src='images/closeCS1.jpg' title='Click here to close this case study' alt='Close'/></a>";
        } else {
            this.removeClassName('csExp_'+id,'caseStudyDescription_max');
            this.addClassName('csExp_'+id,'caseStudyDescription_min');
            document.getElementById('resizeButtonsBottom_'+id).innerHTML="<a href='#cs_"+id+"' onclick='kloeberlib.resizeCSDiv(\""+id+"\",\"open\");'><img src='images/readmoreCS1.jpg' title='Click here to read this case study in full' alt='Read More'/></a>";
            document.getElementById('resizeButtonsTop_'+id).innerHTML="<a href='#cs_"+id+"' onclick='kloeberlib.resizeCSDiv(\""+id+"\",\"open\");'><img src='images/readmoreCS1.jpg' title='Click here to read this case study in full' alt='Read More'/></a>";
        }
    }



	// Save the banner form
	this.saveBanner=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['file','File']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendBannerForm').submit();
		}
	}


	// Save the blind form
	this.saveBlind=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['blindImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendBlindForm').submit();
		}
	}



	// Save the case study form
	this.saveCaseStudy=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['caseStudyImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendCaseStudyForm').submit();
		}
	}


	// Save the colour finish
	this.saveColourFinish=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['colourImage','Image'],['hexVal','Hex Value']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendColourForm').submit();
		}
	}


	// Save the frame form
	this.saveFrame=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['frameImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendFrameForm').submit();
		}
	}


	// Save the event form
	this.saveEvent=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['name','Name'],['location','Location'],['date','Date']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendEventForm').submit();
		}
	}


	// Save the faq form
	this.saveFaq=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['question','Question'],['answer','Answer']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendFaqForm').submit();
		}
	}
	
	//a generic save form function
	this.saveForm=function(formName, reqFields) {
		//reqFields should be exploded then checked
		document.getElementById(formName).submit();
	}


	// Save the gallery form
	this.saveGalleryImage=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendGalleryForm').submit();
		}
	}


	// Save the glazing form
	this.saveGlazing=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['glazingImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendGlazingForm').submit();
		}
	}


	// Save the handle form
	this.saveHandle=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['handleImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendHandleForm').submit();
		}
	}
	
	
	// Save the hardware item
	this.saveHardware=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['name','Name'],['file','File']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendHardwareForm').submit();
		}
	}
	
	
	// Save the internalDoor form
	this.saveInternalDoor=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['internalDoorImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendInternalDoorForm').submit();
		}
	}


	// Save the open config form
	this.saveOpenConfig=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendOpenConfigForm').submit();
		}
	}


	//Save the page content
	this.savePageContent=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['pageContent','Content']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendPageContentForm').submit();
		}
	}
	
	
	// Save the panel style
	this.savePanelStyle=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['name','Name'],['file','File']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendPanelStyleForm').submit();
		}
	}

    
    //Save the press release
	this.savePressRelease=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['prContent','Content'],['headline','Headline']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendPressReleaseForm').submit();
		}
	}

	
	//Save the show room
	this.saveShowRoom=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Title']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendShowRoomForm').submit();
		}
	}

	
	//Save the testimonial
	this.saveTestimonial=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['tContent','Content'],['blurb','Blurb']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendTestimonialForm').submit();
		}
	}
	

	// Save the price form
	this.savePrice=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['price','Price']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendPriceForm').submit();
		}
	}


	// Save the product form
	this.saveProduct=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['description','Description']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendProductForm').submit();
		}
	}


	// Save the product group form
	this.saveProductGroup=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['description','Description']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendProductGroupForm').submit();
		}
	}


	// Save the sill form
	this.saveSill=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['sillImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendSillForm').submit();
		}
	}


	// Save the stop press form
	this.saveStopPress=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('stopPressForm').submit();
		}
	}


	// Save the tech data form
	this.saveTechData=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['file','File']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendTechDataForm').submit();
		}
	}


	// Save the tech draw form
	this.saveTechDrawing=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['techDrawImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendTechDrawingForm').submit();
		}
	}


	// Save the trickle vent form
	this.saveTricklevent=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['title','Name'],['trickleventImage','Image']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			document.getElementById('amendTrickleventForm').submit();
		}
	}

    //displays the glow buttons
    this.showGlowButton=function() {
        if (this.glowButtonDisplayed) {
            //hide glow button
            new Effect.Opacity('glowButtonDiv', { from: 1.0, to: 0.1, duration: 0.1 });
            this.glowButtonDisplayed=false;
            setTimeout("kloeberlib.showGlowButton()",200);
        } else {
            //show glow button
            new Effect.Opacity('glowButtonDiv', { from: 0.1, to: 1.0, duration: 0.1 });
            this.glowButtonDisplayed=true;
            setTimeout("kloeberlib.showGlowButton()",2000);
        }
    }

    //displays the mini testimonials
    this.showMiniTestimonial=function() {
      if (this.miniTestimonialMax>0) {
        if (this.miniTestimonialDisplayed) {
            //hide testimonial
            new Effect.BlindUp('miniTestimonialDiv', {duration: 1, scaleX: true, scaleContent: true});
            this.miniTestimonialId++;
            if (this.miniTestimonialId==this.miniTestimonialMax) this.miniTestimonialId=0;
            this.miniTestimonialDisplayed=false;
            setTimeout("kloeberlib.showMiniTestimonial()",2000);
        } else {
            //show testimonial
            var tVal=this.miniTestimonialArray[this.miniTestimonialId];
            var tArray=tVal.split('>::<');
            var tId=tArray[0];
            var tText=tArray[1];
            document.getElementById('miniTestimonialDiv').innerHTML='<span onclick="kloeberlib.showMainTestimonial('+tId+')" class="pointer miniTestimonial">'+tText+'</span>';
            new Effect.BlindDown('miniTestimonialDiv', {duration: 1, scaleX: true, scaleContent: true});
            this.miniTestimonialDisplayed=true;
            setTimeout("kloeberlib.showMiniTestimonial()",5000);
        }
      }
    }


    //displays the main testimonials
    this.showMainTestimonial=function(tId) {
        if (this.mainTestimonialDisplayed) {
            //hide testimonial
            new Effect.Fade('mainTestimonialDiv',{duration: 2, from: 1, to: 0});
            this.mainTestimonialDisplayed=false;
        } else {
            //get testimonial
            var targetPage='getTestimonial.php?tId='+tId;
            var kloeberAjax = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
            kloeberAjax.open('GET', targetPage, false);
            kloeberAjax.send(null);

            //put the result in the calendar div
            var result = kloeberAjax.responseText;
            if (result) {
                //show testimonial
                document.getElementById('mainTestimonialText').innerHTML=result;
                new Effect.BlindDown('mainTestimonialDiv', {duration: 1, scaleX: true, scaleContent: true});
                this.mainTestimonialDisplayed=true;
            }
        }
    }


	//display an image in the main image viewer
	this.showMainImage=function(imgSrc,title) {
		this.removeClassName("photoViewer","hidden");
		if (document.getElementById("mainImage")!=null && imgSrc!='') document.getElementById("mainImage").src='images/loaderbar.gif';
		if (document.getElementById("mainImage")!=null && imgSrc!='') document.getElementById("mainImage").src=imgSrc;
    if (document.getElementById("mainImageFooterContent")!=null && title!='') document.getElementById("mainImageFooterContent").innerHTML='';
		if (document.getElementById("mainImageFooterContent")!=null && title!='') document.getElementById("mainImageFooterContent").innerHTML=title;
	}


  //highlight showroom
  this.showroomHighlight=function(sr,pos) {
      this.addClassName(sr,"showroomHighlight");
      document.getElementById('sr_div').scrollTop=pos;
  }


  //unhighlight showroom
  this.showroomUnhighlight=function(sr) {
      this.removeClassName(sr,"showroomHighlight");
  }


	//display text in an object
	this.showText=function(obj,text){
		if(obj!='' && document.getElementById(obj)){
			document.getElementById(obj).innerHTML=text;
		}
	}


	//check the fields for the enquiry form
	this.submitEnqForm=function() {
		//check fields and save
		var params="";
		var msg="";
		var currentFieldName="";
		var currentFieldTitle="";
		var currentFieldValue="";

		//check the required fields are valid
		var reqFields = [['name','Name'],['email','E-mail'],['telephone','Telephone'],['postcode','Postcode']];
		for(var i=0;i<reqFields.length;i++) {
			currentFieldName=reqFields[i][0];
			currentFieldTitle=reqFields[i][1];
			if(document.getElementById(currentFieldName)) {
				currentFieldValue=document.getElementById(currentFieldName).value;
				if (currentFieldValue=='') {
					msg+="The "+currentFieldTitle+" is blank \n";
				}
			}
		}

		//check the address is valid
		var address=document.getElementById('address').value
		if (address.indexOf('http://')>=0 || address.indexOf('www.')>=0 || address.indexOf('@')>=0) {
			msg += "Address is invalid\n";
		}

		//check the email address is valid
		if (!document.getElementById('email').value.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/))  {
	  		msg += "Email address is invalid\n";
		}

		//if the form is valid then post else display an error
		if (msg!='') alert(msg);
		else {
			this.addClassName("submitFormDiv","hidden");
			this.removeClassName("confirmFormDiv","hidden");
			document.getElementById("confirmFormTD").innerHTML="<input type='button' class='button' onclick='kloeberlib.submitEnqFormCancel()' value='Click To Cancel'/>&nbsp;<input type='button' class='button' onclick='kloeberlib.submitEnqFormConfirm()' value='Click To Confirm'/>";
		}
	}

	//hide the enquiry form confirmation window
	this.submitEnqFormCancel = function() {
		this.removeClassName("submitFormDiv","hidden");
		this.addClassName("confirmFormDiv","hidden");
		document.getElementById("confirmFormTD").innerHTML='';
	}

	//submit the enquiry form
	this.submitEnqFormConfirm = function() {
		document.getElementById('enqForm').submit();
	}


	// validates input - numeric values only
	this.validateInputNumeric = function(obj) {
		var numbers;
		var err=false;
		numbers=new Array(0,1,2,3,4,5,6,7,8,9,'-','.');
		if (document.getElementById(obj)!=null) {
			var number=document.getElementById(obj).value.toString();
			var newnumber='';
			var decUsed=false;

			for(var i=0;i<number.length;i++) {
				var numbChar=number.substring(i,(i+1));
				if (this.in_Array(numbChar,numbers)!==false) {
					if (numbChar=='-' && i>0) continue;
					if (numbChar=='.') {
						if (decUsed) continue;
						else decUsed=true;
					}
					newnumber+=numbChar;
				} else {
					err=true;
				}
			}
			document.getElementById(obj).value=newnumber;
			if (err)document.getElementById(obj).style.border = '1px solid #FF0000';
			else document.getElementById(obj).style.border = '1px solid #AAAACC';
		}
	}
}
