// JavaScript Document

/* === Standard Macromedia Dreamweaver functions */
/* ============================================= */

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
	}
    obj.visibility=v; }
}


function displayNoneBlock() { //   Customised version of MM_showHideLayers 
  var i,p,v,obj,args=displayNoneBlock.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'block':(v=='hide')?'none':v; 
	}
    obj.display=v; }
}


/* customised version of the Macromedia OpenWindow Behaviour
This makes sure that the newly opened window is always 
at the front i.e focussed */

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var wintwo = window.open(theURL,winName,features);
  wintwo.focus();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {
	  if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
	
MM_reloadPage(true);



function openDMXzoneLightbox(arg, options, context) {//v1.2
		context = context || window, options = options || {};
		if (context.DMX && context.DMX.Lightbox) {
			context.DMX.Lightbox.open(options.plugin || "", arg, options);
      document.MM_returnValue = false;
		}
	}


function GUnload() {
// stub function that is used in body onunload. It is redefined on google_maps.js 	
}

function load() {
// stub function that is used in  load. It is redefined on google_maps.js 	
}


/* =========================================================================================================== */
/* Start of Popup calendar functions */

var monthArray = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
var monthNumArray = ["01", "02", "03", "04", "05", "06", "07", "08", "09","10", "11", "12"];

var hilite = ''
var dateFieldObj , calDivObj

function ShowCalendarPopUp(dateFieldName,calendarDiv) {
		var args = ShowCalendarPopUp.arguments 
		
//		dateFieldObj 	= document.getElementById(dateFieldName);
//		calDivObj 		= document.getElementById(calendarDiv);
		
		dateFieldObj	= MM_findObj(args[0]) ;
		calDivObj		= MM_findObj(args[1]) ;
		
		ShowCalendar(dateFieldObj.value)		
}


function HideCalendar(){
	
	var args = HideCalendar.arguments 
	
	if (args.length > 0 ) {
		if ((calHideDivObj=MM_findObj(args[0]))!=null) {
			if (calHideDivObj.style) {
				calHideDivObj = calHideDivObj.style
			}
			calHideDivObj.display = "none";	
		}
	}
/*	
	if (calDivObj.style) {
		calDivObj = calDivObj.style
	}
	calDivObj.display = "none";		
*/
}


function ShowCalendar(dateValue){

// if there is no date yet, make a new one. 
//Otherwise, use the date in the input box or the date passed by the next/previous buttons.

var currentDate = (dateValue == null || dateValue == "") ? new Date() : FormatDate(dateValue) ;

var prevYear = new Date(currentDate);
prevYear.setYear(currentDate.getFullYear()-1);

var prevMonth = new Date(currentDate);
prevMonth.setMonth(currentDate.getMonth()-1);

var nextMonth = new Date(currentDate);
nextMonth.setMonth(currentDate.getMonth()+1);

var nextYear = new Date(currentDate);
nextYear.setYear(currentDate.getFullYear()+1);

var currentYear 		= currentDate.getFullYear();
var currentMonth 		= currentDate.getMonth();
var currentDisplayDate 	= currentDate.getDate();

// shift the current day to day 1 to make calendar to build it from day 1.
var firstDay = new Date(currentDate);
firstDay.setDate(1);

var currentDay = new Date(firstDay);

// clear current calendar (if exists)
var calHTML = "";

// show calendar

if (calDivObj.style) {
	calDivObj.style.display = "block";
}
else {
	calDivObj.display = "block";
}


//================================================================
// Start of the Calendar table 
//================================================================
// write out calendar header
calHTML += '<table cellpadding="0" cellspacing="1" border="0" >';


//================================================================
// Start of the Close Calendar Row
calHTML += '<tr class="calHead"><th colspan="7" align="left"><a href="javascript:HideCalendar(' + "'" + calDivObj.id+ "'" + ');" title="Close">Close</a></th></tr>';
// End of the Close Calendar Row
//================================================================



//================================================================
// Start of the Month Row
calHTML += '<tr class="calHead">';

// This is the line that adds the << Previous Month link
calHTML += '<th colspan="2" align="left">&nbsp;<a href="" title="Previous Month" onclick="ShowCalendar(\''+FormatRawDate(prevMonth)+'\'); return false;">&lt;&lt;</a>&nbsp;';



// This is the line that adds the Current Month 
calHTML +=  '<th colspan="3" align="center">' +  monthArray[currentMonth] + '</th>' ;


// This is the line that adds the >> Next Month link
calHTML += '<th colspan="2" align="right">&nbsp;<a href="" title="Next Month" onclick="ShowCalendar(\''+FormatRawDate(nextMonth)+'\'); return false;">&gt;&gt;</a>&nbsp;</th> '


calHTML += '</tr>';
// End of the Month Row
//================================================================================


//================================================================================
// Start of the Year row 
calHTML += '<tr>';

// This is the line that adds the <<< Previous Year link
calHTML += '<th colspan="2" align="left">&nbsp;<a href="" title="Previous Year" onclick="ShowCalendar(\''+FormatRawDate(prevYear)+'\'); return false;">&lt;&lt;&lt;&nbsp;</a>';


// This is the line that adds the Current  Year 

calHTML += '<th colspan="3" align="center">' + currentYear + '</th>' ;


// This is the line that adds the >>> Next Year link
calHTML += '<th colspan="2" align="right">&nbsp;<a href="" title="Next Year" onclick="ShowCalendar(\''+FormatRawDate(nextYear)+'\'); return false;">&gt;&gt;&gt;</a>&nbsp;</th>'


calHTML += '</tr>';
// End of the Year Row
//================================================================================

	

//================================================================================
// Start of the Mo Tu We Th Fr row
calHTML += '<tr><th>Su</th><th>Mo</th><th>Tu</th><th>We</th><th>Th</th><th>Fr</th><th>Sa</th></tr>';

var curCell = 1;

// as long as we are in the current month, write out the calendar days
while(currentDay.getMonth() == firstDay.getMonth()) {
					
	// begin row
	calHTML += '<tr>';
	// iterate through each week
	for (var i=0; i<7; i++)
	{
//		calHTML += '<td>';
		// as long as this week is in the same month, write out days
		if ( currentDay.getMonth() == firstDay.getMonth() ) {
			
			if (currentDisplayDate == currentDay.getDate() ) {
				hilite = 'selectedOne' ;
			}
			else {
				hilite = '' ;
			}
			
	
			// if first day is not reached yet, write a blank
			if(curCell <= firstDay.getDay())
				{
				calHTML += '<td>&nbsp;</td>';
				}
			// otherwise write out the date
			else
				{
				calHTML += '<td><a class="' +hilite + '" href="" title="Click to choose date" onclick="SelectDate(' +  currentDay.getDate() + ',' + currentDay.getMonth() + ',' + currentDay.getFullYear() + '); return false;">' + currentDay.getDate() + '</a></td>';

				currentDay.setDate(currentDay.getDate() + 1);
				}
		}
		curCell++
	}
	calHTML += '</tr>';
}
// Start of the Mo Tu We Th Fr row
//================================================================================



calHTML += '</table>';
calDivObj.innerHTML = calHTML;
}


function SelectDate( selDay, selMo, selYear) {
	if (eval(selDay) < 10) { 
		selDay = "0" + selDay ;
	}
		
	// UK Date format  dd/mm/yyyy
	dateFieldObj.value = selDay + "/" + monthNumArray[selMo] + "/" +  selYear;

	if (calDivObj.style) {
		calDivObj.style.display = "none";
	}
	else {
		calDivObj.display = "none";
	}
	
}

function FormatDate(dateValue) {
// At this point all we have is a string like "28/02/2004" if UK format or "02/28/2004" if American format
// We must have a date object, so we make one based on the string date
// and return it to the main function
	var dateValArray = dateValue.split("/");

// new Date() takes argument yyyy/mm/dd
	var currentDate = new Date(dateValArray[2],dateValArray[1]-1,dateValArray[0]);
	return currentDate;
}

function FormatRawDate(rawDateValue) {
// The next/previous buttons have date object references. They need to be strings
// so we can send them to the function when the next/previous links are clicked.
// the string date is returned and placed into the link.
	var rawMonth = rawDateValue.getMonth()+1;
	var rawDay = rawDateValue.getDate();
	var rawYear = rawDateValue.getFullYear();
	
	// UK format dd/mm/yyyy
	var stringDate = rawDay + "/" + rawMonth + "/" +  rawYear;
	
	return stringDate;
}


/* End of Popup calendar functions */
/* =========================================================================================================== */


/* ===================================================================================== */
/* this finds an object with an ID and sets its class
/* ===================================================================================== */



function setClassName() {
		var theObj, theClass, args=setClassName.arguments ;
		
		if (args.length > 1) { 		
			if ((theObj=MM_findObj(args[0]))!=null) {
				theObj.className = args[1] ;
			}
		}
}


/* ===================================================================================== */

function selectAll() {
	var args, theForm, theBoxes, theCheckAll,  i ;
	args = selectAll.arguments ;
	
	if (args[0] != "") {
		theForm = document.getElementById(args[0])	
	}
	
	if (args[1] != "") {
		theCheckAll = document.getElementById(args[1].name)	
	}
	
	theBoxes = theForm.getElementsByTagName("input") ;
	for ( i = 0 ; i< theBoxes.length ; i++ ) {
		
//		alert("type=" + theBoxes[i].type + " \nname=" + theBoxes[i].name + "\nchecked=" + theBoxes[i].checked + "\n theCheckAll.name=" +  theCheckAll.name + "\ntheCheckAll.checked=" +  theCheckAll.checked) ; 
		
		if ( (theBoxes[i].type == "checkbox") && (theBoxes.name != theCheckAll.name ) ) { 
			if ( args[1].checked == "true") {
				theCheckAll.checked = "true" ;
			}
			else {
				theCheckAll.checked = "false" ;
			}
		}
	}
}

/* ============================================================ */
/* create global variables to store the original width and hieght of the image when it is first loaded */

var theImageWIDTHGlobal = 0
var theImageHEIGHTGlobal = 0 
var theRatio = 1


/* ============================================================ */

function getImageSize() {
// Arguments are theImage Name, the Width Field Name and the height Field name 
	var args, i, theImage, theForm, theWidth, theHeight, theInputs, x

	args		=	getImageSize.arguments

	theImage 	= MM_findObj(args[0]) ;
	theForm 	= MM_findObj(args[1]) ;
	theInputs 	= theForm.getElementsByTagName("input") ;
	
	for (i=0 ; i< theInputs.length ; i++) { 
		if (theInputs[i].name.toLowerCase().indexOf("height") > -1 ) {
			theHeight = theInputs[i]
		}
		
		if (theInputs[i].name.toLowerCase().indexOf("width") > -1 ) {
			theWidth = theInputs[i]
		}
	}

	if (theImage.width > 0 ) { 	
		theWidth.value = theImage.width ;
		theImageWIDTHGlobal = theImage.width ;
	}
	
	if (theImage.height > 0 ) { 	
		theHeight.value = theImage.height;
		theImageHEIGHTGlobal = theImage.height;
	}
	
	theRatio 		= eval(theHeight.value/theWidth.value);

}


/* ============================================================ */


function restoreLayerSize() {
	if (  (theImageWIDTHGlobal > 0 ) && (theImageHEIGHTGlobal > 0)) {
		var args, i, theDiv, theForm, theWidth, theHeight , theInputs 
	
		args		=	restoreLayerSize.arguments
		
		theDiv 		= MM_findObj(args[0]) ;
		theForm 	= MM_findObj(args[1]) ;
		theInputs 	= theForm.getElementsByTagName("input") ;
		
		for (i=0 ; i< theInputs.length ; i++) { 
			if (theInputs[i].name.toLowerCase().indexOf("width") > -1 ) {
				theWidth = theInputs[i]
			}
			if (theInputs[i].name.toLowerCase().indexOf("height") > -1 ) {
				theHeight = theInputs[i]
			}
		}


		if (theDiv.style) {
			theDiv = theDiv.style ; 
		}
		
		theDiv.width 		= theImageWIDTHGlobal  + "px" ; 
		theDiv.height 	= theImageHEIGHTGlobal + "px" ; 
		
		theWidth.value 		= theImageWIDTHGlobal ;
		theHeight.value 	= theImageHEIGHTGlobal ;
	}
	return false;
}


function restoreImageSize() {
	if (  (theImageWIDTHGlobal > 0 ) && (theImageHEIGHTGlobal > 0) ) {
		var args, i, theImage, theForm, theWidth, theHeight, theInputs
	
		args	=	restoreImageSize.arguments
	
		theImage 		= document.getElementById(args[0]) ;
		theForm 		= document.getElementById(args[1]) ;
		theInputs 		= theForm.getElementsByTagName("input") ;
		
		for (i=0 ; i< theInputs.length ; i++) { 
			if (theInputs[i].name.toLowerCase().indexOf("width") > -1 ) {
				theWidth = theInputs[i]
			}
			if (theInputs[i].name.toLowerCase().indexOf("height") > -1 ) {
				theHeight = theInputs[i]
			}
		}

		theImage.width = theImageWIDTHGlobal;
		theImage.height = theImageHEIGHTGlobal;
		
		theWidth.value = theImageWIDTHGlobal ;
		theHeight.value = theImageHEIGHTGlobal ;
	}
	return false;
}



/* ============================================ */
/* Create global variable to store the object for the setTimeOut in the other functions */

var resizeTimer ;
/* ============================================ */

/* ============================================ */

/* resize the images in the admin pages.  This resizes the LAYER over the top of the image
so that the dimensions are then used to crop the image */


function resizeLayer() {
// args eg. theDiv, the Direction 9 shrink/grow)  , dimension(width/height) , field(cropwidthbox/cropheightbox) , grow, speed	

	var args, i, theDiv, theField, theDirection , theDimension, theForm, theInputs, theMaxField , funcStr, theSpeed
	args = resizeLayer.arguments ;

	//if (args.length == 3 ) {
	theDiv	 		= MM_findObj(args[0]) ;
	theForm 		= MM_findObj(args[1]) ;
	theDimension 	= args[2] ;
	theDirection	= args[3] ;
	
	if (args[4]) {
		theSpeed		= args[4] ;
	}
	else {
		theSpeed		= 10;
	}
		
	if (theDiv.style) {
		theDiv = theDiv.style
	}
		
	theInputs 		= theForm.getElementsByTagName("input") ;
	
	for (i=0 ; i< theInputs.length ; i++) { 
		if (theInputs[i].name.toLowerCase().indexOf(theDimension) > -1 ) {
			theField = theInputs[i]
		}
	}
	
	theMaxField 	= 	"theImage" + theField.name.toUpperCase() + "Global"
		
	if (theDirection == "grow") {
		if (  eval(theMaxField) >  eval(theField.value)  ) {
			theField.value 	= eval(theField.value)	+ 1  ;
		}		
	}
	
	if (theDirection == "shrink") {
		if ( eval(theField.value) > 50  ) {
			theField.value 	= eval(theField.value)	- 1  ;
		}		
	}
		
	if (theField.name.toLowerCase() == "width" ) {
		theDiv.width = theField.value + "px"  ;
		if (theField.value < 100 ) {
			theSpeed = 50	;
		}
	}
		
	if (theField.name.toLowerCase() == "height") {
		theDiv.height = theField.value + "px"  ;
		if (theField.value < 100 ) {
			theSpeed = 50	;
		}
	}
		
	funcStr = "resizeLayer('" + args[0] + "','" + args[1] + "','" + args[2] + "','" + args[3] + "','" + theSpeed + "')" ;  
		
	resizeTimer = setTimeout(funcStr, theSpeed);
}



function resizeImage() {	
// resizeImage('shrinkimage','shrinkform','shrink')

	var args, i, theImage, theForm, theWidth, theHeight, theInputs, theDirection, funcStr

	args	=	resizeImage.arguments
	
	theImage 		= document.getElementById(args[0]) ;
	theForm 		= document.getElementById(args[1]) ;
	theInputs 		= theForm.getElementsByTagName("input") ;
	
	for (i=0 ; i< theInputs.length ; i++) { 
		if (theInputs[i].name.toLowerCase().indexOf("width") > -1 ) {
			theWidth = theInputs[i]
		}
		if (theInputs[i].name.toLowerCase().indexOf("height") > -1 ) {
			theHeight = theInputs[i]
		}
	}
	
//	theRatio 		= eval(theHeight.value/theWidth.value);
	theDirection 	= args[2] ;
	
//	alert("the ration is " + theRatio);
			
	if (theDirection == "grow") {
		if ( theImageWIDTHGlobal >  eval(theWidth.value)  ) {
			theWidth.value 	= eval(theWidth.value)	+ 1  ;
		}		
	theHeight.value 	= Math.round(eval(theWidth.value) *  theRatio);
	}
	
	if (theDirection == "shrink") {
		if (eval(theWidth.value) > 50 ) { 
			theWidth.value 	= eval(theWidth.value)	- 1  ;
		}
	theHeight.value 	= Math.round(eval(theWidth.value) *  theRatio);
	}


	if (theDirection == "w") {
			theHeight.value 	= Math.round(eval(theWidth.value) *  theRatio);
	}

	if (theDirection == "h") {
			theWidth.value 	= Math.round(eval(theHeight.value) /  theRatio);
	}


	
	
	theImage.width 		= theWidth.value   ;
	theImage.height 	= theHeight.value  ;
	
	funcStr = "resizeImage('" + args[0] + "','" + args[1] + "','" + args[2] + "')" ;  
		
	if  ((eval(theWidth.value) > 50 ) && ( eval(theWidth.value) < theImageWIDTHGlobal ) )  { 
		resizeTimer = setTimeout(funcStr, 10);
	}
	else {
		clearTimeout(resizeTimer);
	}
}


/* ============================================================ */

function resizeStop() {
	clearTimeout(resizeTimer);
}


function positionCropBackground() {
	var args, i, theDiv, theImage, theForm, thePosition

	args	=	positionCropBackground.arguments ;
	
		
	theDiv 			= MM_findObj(args[0]) ;
	theImage		= MM_findObj(args[1]) ;
	
	theInputs		= args[2].value.split("-") ;
	
	if (theDiv.style) {
		theDiv = theDiv.style
	}

//	theDiv.background = "url(" + theImage.src + ") no-repeat " + theInputs[0] + " " + theInputs[1]

	theDiv.backgroundPosition =  theInputs[0] + " " + theInputs[1]


}



/* ============================================================ */
/* ============================================================ */
/* ============================================================ */
/* ============================================================ */

/* Ths is the function that gets the Stockists from the database and writes them to the named DIV */

function ajaxGetStockists(){  

	var xmlHttp, theScript, theField, theSearch , args , urlString , theDIV;
	args = ajaxGetStockists.arguments ; 

	theSearch = args[0] ; 
	theDiv = args[1] ; 
	
	changeHTMLinner('Stockists in the ' + theSearch + ' region','pageheading_uk');
	
	try
	{    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();    
	}
	catch (e){    // Internet Explorer    
		try {      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e) {      
			try {        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e) {        
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function(theValue) {
		if(xmlHttp.readyState==4) {	
			if ((theDIV=MM_findObj(args[1]))!=null) {
//				theDIV = document.getElementById("stockist_list")		
				theDIV.innerHTML = xmlHttp.responseText;
				
								
	//			theDIV.className = "layer_visible" ; 
			}
		}
	}
	
	
	
/*	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {	
			var theDIV ;
		
			if ((theDIV=MM_findObj("prefetchcontacts"))!=null) {
							alert(theDIV);

				var theSelect = theDIV.getElementsByTagName("select")	
				var theOptions = theSelect[0].getElementsByTagName("option")	
				
				for (i=0 ; i < theOptions.length ; i = i + 1 ) {
				
					if ( i%2) {
						theOptions[i].className = "rowstyle_odd";
					}
					else {
						theOptions[i].className = "rowstyle_even";
					}
					
					theOptions[i].setAttribute("colour",theOptions[i].className);
				
					theOptions[i].onmouseover = function() {
						window.status = this.innerHTML ;
						this.className = "row_hover"; // row_hover is a new highlight
					}
				
					theOptions[i].onmouseout = function() {
						this.className = this.getAttribute("colour");
					}
					
					theOptions[i].onclick = function() {
						theField.theValue  = this.innerHTML;
					}
				}
			}	
		}		
	}
	
*/	
	urlString = "stockists_find.asp?region=" + theSearch ;
	xmlHttp.open("GET",urlString,true);
    xmlHttp.send(null);
	
	return false ;
}

/* =================================================================== */


/* ============================================================ */

/* Ths is the function that gets the Swatches from the database and writes them to the page */

function ajaxGetSwatchesInFabric(){  

	var xmlHttp, theScript, theField, theSearch , args , urlString , theDIV, 	theDivID ;
	args = ajaxGetSwatchesInFabric.arguments ; 

	theSearch = args[0] ; 
	theDiv = args[1] ; 
	theDivID = args[2] ; 
	
	try
	{    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();    
	}
	catch (e){    // Internet Explorer    
		try {      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e) {      
			try {        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e) {        
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function(theValue) {
		if(xmlHttp.readyState==4) {	
			if ((theDIV=MM_findObj(args[1]))!=null) {
				theDIV.innerHTML = xmlHttp.responseText;
			}
		}
	}
	
	
	urlString = "/ScriptLibrary/incSwatchesInFabric.asp?swatch_fabric_type_id=" + theSearch + "&theDivID=" + theDivID ;
	xmlHttp.open("GET",urlString,true);
    xmlHttp.send(null);
	
	return false ;
}

/* =================================================================== */

/* Ths is the function that gets a Swatch from the database, adds it to the cookies which contain all the swatches and writes them to the page */

function ajaxGetSwatchAddToBooklet(){  

	var xmlHttp, theScript, theField, theSearch , args , urlString , theDIV, 	theDivID ;
	args = ajaxGetSwatchAddToBooklet.arguments ; 
	
	alert(readCookie("booklet") ) ;
	

	theSearch = args[0] ; 
	theDiv = args[1] ; 
	theDivID = args[2] ; 
	
	try
	{    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();    
	}
	catch (e){    // Internet Explorer    
		try {      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e) {      
			try {        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e) {        
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function(theValue) {
		if(xmlHttp.readyState==4) {	
			if ((theDIV=MM_findObj(args[1]))!=null) {
				theDIV.innerHTML = xmlHttp.responseText;
			}
		}
	}
	
	
	urlString = "/ScriptLibrary/incSwatchesAddToBooklet.asp?id=" + theSearch + "&theDivID=" + theDivID ;
	xmlHttp.open("GET",urlString,true);
  xmlHttp.send(null);
	
	return false ;
}




/* =================================================================== */

/* This is the function that gets all the Colour Groups that are linked to a Swatch.
One Swatch can be in several colour groups and should be in AT LEAST 1 colour group
*/

function ajaxGetColourGroupsLinkedToSwatch(){  

	var xmlHttp, theScript, theField, theSearch , args , urlString , theDIV, theDivID ;
	args = ajaxGetColourGroupsLinkedToSwatch.arguments ; 
		

	theSearch = args[0] ; 
	theDiv = args[1] ; 
	theDivID = args[2] ; 
	
	try
	{    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();    
	}
	catch (e){    // Internet Explorer    
		try {      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e) {      
			try {        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e) {        
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function(theValue) {
		if(xmlHttp.readyState==4) {	
			if ((theDIV=MM_findObj(args[1]))!=null) {
				theDIV.innerHTML = xmlHttp.responseText;
			}
		}
	}
	
	
	urlString = "/ScriptLibrary/incColourGroupsLinkedToSwatch.asp?swatch_id=" + theSearch + "&theDivID=" + theDivID ;
	xmlHttp.open("GET",urlString,true);
  xmlHttp.send(null);
	
	return false ;
}





/* ===================================================================================== */
/* this adds a swatch to the swatch booklet DIV displayed at the top of the swatches page.
/* ===================================================================================== */

var theBookletObj
 
var theChoicesJSON = {} 

function addSwatchToBooklet() {
/* take in the arguments UniqueSwatchID, SwatchNumber, SwatchName, SwatchImage,  */	
	var theId,  theSwatchObj , theSwatchFormObj, theSwatchName , theSwatchNumber , theSwatchImage  
	var args = 	addSwatchToBooklet.arguments ;
	var theSwatchHTML = "" ;
							
	if ((theBookletObj=MM_findObj('swatch_booklet_scroller_content'))!=null) { 
		
		theSwatchHTML = theSwatchHTML + "<div style=\"visibility:hiddens;\" class=\"swatch_choice_container\" id=\"swatch_choice_" + args[0] + "\">" ;
		
		theSwatchHTML = theSwatchHTML + "<a href=\"#\"  onclick=\"deleteSwatchFromBooklet(" +args[0] + ") ; \" >" ; 
		
		theSwatchHTML = theSwatchHTML + "<img align=\"right\" src=\"images/button_x.png\" width=\"20\" height=\"20\" title=\"Remove Swatch " + args[0] + args[1] + args[2] + " From Booklet\" alt=\"Remove Swatch From  Booklet\" border=\"0\" />" ;
		
		theSwatchHTML = theSwatchHTML + "</a>" ;
		
		theSwatchHTML = theSwatchHTML + "<div class=\"swatch_thumbnail\" style=\"background-image:url('swatches/thumbs/" + args[3] + "')\" >"
						
		theSwatchHTML = theSwatchHTML +	"<a class=\"zoom\" href=\"swatch_view_one.asp?id=" + args[0] + "\" title=\"" + args[1] + " - " + args[2] + "\" ";
		
		theSwatchHTML = theSwatchHTML + " rel=\"dmxLightbox\" rev=\"{width:770, height:770, plugin:'url'}\" >&nbsp;</a>" ;
						
		theSwatchHTML = theSwatchHTML +	"	</div> " + args[1] + " - " + args[2] + "</div>" ;

		theBookletObj.innerHTML = theBookletObj.innerHTML + theSwatchHTML ;
	}
}


function deleteSwatchFromBooklet() {
	var args = 	deleteSwatchFromBooklet.arguments ;
	var theNewBookletHTML = "" ;
	var i = 0 ;
		
	$('swatch_choice_'+args[0]).fade(); 
	$('swatch_add_button_'+args[0]).appear();
		
			
	if ((theBookletObj=MM_findObj('swatch_booklet_scroller_content'))!=null) {
		
		if ( (theChoicesArray = theBookletObj.getElementsByTagName("div") ) != null ) { 
		
				for (i = 0 ; i< theChoicesArray.length ; i++ ) {
					if ( theChoicesArray[i].className == "swatch_choice_container") {
						
						alert("got a swatch_choice_container called" + theChoicesArray[i].name);
												
						if (theChoicesArray.id != "swatch_choice_" + args[0]) {
							theNewBookletHTML  = theNewBookletHTML +  "<div class=\"swatch_choice_container\" id=\"swatch_choice_" + args[0] + "\">"  + theChoicesArray[i].innerHTML + "</div>" 
						}
					}
				}
		}
				
		theBookletObj.innerHTML = theNewBookletHTML
		
	}		
	
}

/* =================================================================== */



document.MM_returnValue = false;

function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}

/* =========================================================================================================== */
/* 
function showPrintIcon() {
	if (window.print) {
		document.write("<a title=\"Print\" href=\"javascript:window.print();\" >" )
		document.write("<img src=../scripts//"images/print.gif/" alt=\"Print\" width=\"15\" height=\"15\" hspace=\"2\" vspace=\"1\" border=\"0\"><br />Print</a>")
	}
}


function showFavouriteIcon() {
	if (window.print) {
		document.write("<a title=\"Add to favorites\" ")
		document.write("href=\"javascript:window.external.AddFavorite(location.href,document.title);\" >")
		document.write("<img src=../scripts//"images/star.gif/" alt=\"Add to favorites\" width=\"15\" height=\"15\" hspace=\"2\" vspace=\"1\" border=\"0\"><br />Favorite</a>")
	}
}
*/



function changeHTMLinner() {
	var obj, i, args=changeHTMLinner.arguments;
	
 	if ((obj=MM_findObj(args[1]))!=null) { 	
		obj.innerHTML = args[0] ;
	}
		
}


function showFirstLayer() {
	var i, args=showFirstLayer.arguments;

/*  Go through all the layers in the arguments list and hide them
	then show the first one on the list.
*/

    for (i=1; i<(args.length); i=i+1) {
		MM_showHideLayers(args[i],'','hide') ;
	}
	MM_showHideLayers(args[0],'','show') ;
}



function showFirstLayerInDiv() {
	var i, args=showFirstLayerInDiv.arguments;
	
	var revealLayer = args[0].toLowerCase() ;
	
	var containerLayer = document.getElementById(args[1]) ;
	
//	alert(args[1] + "  " + containerLayer);
	
	var allLayers = containerLayer.getElementsByTagName("div") 
	
    for (i=0; i<(allLayers.length); i=i+1) {
		if (allLayers[i] == revealLayer ) {
			MM_showHideLayers(allLayers[i].id,'','show') ;
		}
		else {	
			MM_showHideLayers(allLayers[i].id,'','hide') ;
		}
	}



/*  Go through all the layers in the arguments list and hide them
	then show the first one on the list.
*/

    for (i=1; i<(args.length); i=i+1) {
		MM_showHideLayers(args[i],'','hide') ;
	}
	MM_showHideLayers(args[0],'','show') ;
}


function showSelectedTab() {
	var i, theList, theTabs, theSelectedTab,  args=showSelectedTab.arguments;
	
	theSelectedTab = document.getElementById(args[1]);
	
//	alert("about to change " + theSelectedTab.ID) ; 
	
	theList = document.getElementById(args[0]) ; 
	theTabs = theList.getElementsByTagName("a") ; 

/*  Go through all the tabs in the UL and set them all to "behind"  
	then set the first one on the list for be "infront"*/

    for (i=0; i<(theTabs.length); i=i+1) {
		theTabs[i].className = "behind"
	}
	theSelectedTab.className = "infront"
}



function initMenu() {
	var sublistArray ; 
	
	var menuObj = document.getElementById("menu") ;
	var listArray = menuObj.getElementsByTagName("li") ; 
	
	for (i = 0 ; i < listArray.length ; i = i + 1 ) {


//	Check every LI to see if it contains a UL.  If it does, then give that LI a class of SUB show 

// give every LI a class of sub_hide 

		if (listArray[i].getElementsByTagName("ul").length > 0) { ;
			listArray[i].className = "sub_hide" ; 
		}
		

		listArray[i].onmouseover = function() {
			if ( this.className == "sub_hide" ) {
				this.setAttribute("oldClass",this.className) ;
				this.className = "sub_show";
			}
		}
		
		listArray[i].onmouseout = function() {
			this.className = this.getAttribute("oldClass")  ; // restore the old class 
		}
		
	}
}

//========================================================== //

//Powered by Softery.com
//Ver: 3//
function FlashSolver()
	{
	n=navigator;
	nav=n.appVersion.toLowerCase();
	if ((nav.indexOf('win')!=-1) || (nav.indexOf('nt')!=-1)) 
		{
		if (navigator.appName == "Microsoft Internet Explorer")
			{
			var tmpObject = document.getElementsByTagName('object');
			if (tmpObject && tmpObject.length) 
				{
				for (var i = 0; i < tmpObject.length; i++) 
					{
					if (tmpObject[i].getAttribute('classid').toLowerCase() == 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000') 
						{
						var ps = tmpObject[i].getElementsByTagName('param');
						if (ps && ps != null)
							{
							for (var j = 0; j < ps.length; j++) 
								{
								if (ps[j].getAttribute('name').toLowerCase() == 'flashvars') 
									{
									var variables = ps[j].getAttribute('value');
									break;
									}
								}
							}
						var obj = tmpObject[i].outerHTML + "\n";
						obj = obj.replace(/FLASHVARS" VALUE=""/i,'FLASHVARS" value="'+variables+'"');
						tmpObject[i].outerHTML = obj;
						}
					}
				tmpObject = null;
				}
			}
		}
	}
window.onunload = function()
	{
	n=navigator;
	nav=n.appVersion.toLowerCase();
	if ((nav.indexOf('win')!=-1) || (nav.indexOf('nt')!=-1)) 
		{
		if (navigator.appName == "Microsoft Internet Explorer")
			{
			if (document.getElementsByTagName) 
				{
				var tmpObject = document.getElementsByTagName("object"); 
				for (i=0; i<tmpObject.length; i++)
					{
					tmpObject[i].outerHTML = ""; 
					}
				}
			}
		}
	}

/* end of flashsolver */
/* ======================================================================= */


function setCategories() {

/* first argument is whole checkbox and second arguments field to write to */

	var args, i , fieldValue, newStr , replaceStr ;	
	args = setCategories.arguments ; 	
	if ((fieldValue=MM_findObj(args[1]))!=null) {
			replaceStr =   args[0].value + " " ;
		if ( args[0].checked ) {
			fieldValue.value = fieldValue.value + replaceStr ;
		}
		else {			
			fieldValue.value = fieldValue.value.replace(replaceStr,"");
		}		
	}
}

/* ======================================================================= */


function writeCookie(cookieName, cookieValue, expiry) {
	var expDate = new Date();
	if(expiry) {
		expDate.setTime (expDate.getTime() + (1000 * 60 * 60* 24 * expiry));
		document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString();
	}
	else {
		document.cookie = cookieName + "=" + escape (cookieValue);
	}
}


function readCookie(name) {
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)  { 	
		offset = document.cookie.indexOf(search);
		if (offset != -1)   { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}



function readAllCookies() {
	var cookieList = "";
	var search = name + "=";
	if(document.cookie.length > 0)  { 
	
		var cookieArray = document.cookie.split(";") ;
		
		for ( i = 0 ; i <cookieArray.length ; i++  ) {
				cookieList = cookieList +  cookieArray[i] + "\n" ;
		}
	}
	return cookieList;
}



function cookieThis(theInput) {
	alert("writing " + theInput.name + " = " + theInput.value + " to cookie")
//	window.status("writing " + theInput.name + " = " + theInput.value + " to cookie" ) ;
	writeCookie(theInput.name, theInput.value, 180) ;
}


/* This change the background of the name element */
/* ============================================== */

function changeBackground() {
	var divObj , args = changeBackground.arguments ;
	
//		alert(" Changing "  + args[1] + " background to " + args[0] ) ;

	
	if ( ( divObj = window.document.getElementById(args[1]) ) != null ) {
		
		if (divObj.style) {
			divObj = divObj.style ; 
		}
		divObj.backgroundImage = "url('" + args[0] + "')" ;
		divObj.visibility = "visible" ;
		
	}
}

/* ================================================ */

function changePreview(fieldValue,imageName,folderName) { 

	alert(" Changing "  + imageName + " SRC to " + folderName + fieldValue ) ;

	if ((imageObj=MM_findObj(imageName))!=null) {
		if (fieldValue == "") { 
			imageObj.src = "/images/transpix.gif" ;
		}
		else {
			imageObj.src = folderName + fieldValue ;
		}
	}
}


function checkFileChars(field){
	var agt = navigator.userAgent.toLowerCase();
	var is_mac = (agt.indexOf("mac") != -1);
  	var is_ie = document.all;
	var is_ns6 = (!document.all && document.getElementById ? true : false);
	var fileURL = field.value;

//	window.alert("found " + field.name + " in form " + field.form.length )
//	window.alert("found formObj " +field.form.name )
	
	if (is_ie && is_mac) {
		begPos = fileURL.indexOf('/',1);
		if (begPos != -1) {
			fileURL = fileURL.substring(begPos+1,fileURL.length);
		}
	}

// loop through all the elements on the form and make sure the Submit button is visible
	var formname = field.form.name
	var formObj = MM_findObj(formname)
	
	for (j=0 ; j< formObj.length ; j++) { 
		obj = formObj.elements[j]
	
		if ( obj.type == "submit" ) {
			if (obj.style) { 
				obj=obj.style;
			}
			obj.visibility="visible";
		}
	}

	fileURL = 'file:///' + fileURL.replace(/:\\/gi,'|/').replace(/\\/gi,'/').replace(/:([^|])/gi,'/$1').replace(/"/gi,'').replace(/^\//,'');
	
	var fileParts = fileURL.split("/")
	
	var actualfilename = fileParts[fileParts.length-1]

//	window.alert("checking\n" + fileURL + "\n and actual file of " + actualfilename );
	
	var illegalchars = ",.~#:;+=-)(*&^%$£!'@|\<>/?¬"
	
	for ( i=0 ; i < illegalchars.length ; i++ ) {
		badChar = illegalchars.charAt(i) 
		
		if ( actualfilename.indexOf(badChar,0) > -1 ) {
			window.alert("File name cannot contain any of these characters:\n" + illegalchars )

			
			for (j=0 ; j< formObj.length ; j++) { 
				obj = formObj.elements[j]
//				alert( formObj.elements[j].name + " is type = " + formObj.elements[j].type )
			
				if ( obj.type == "submit" ) {
					if (obj.style) { 
						obj=obj.style;
					}
					obj.visibility="hidden";
					
					document.MM_returnValue = false;
					break 
					return false
				}	

			}
		}
	}
	document.MM_returnValue = true;
	return true
}


/* =================================================================== */
/* this sets the tab at the top of the ADMIN menu to be selected */

function setTab() {
	var tableObj 	= document.getElementById("admin_top_menu") 
	var thArr 		= tableObj.getElementsByTagName("TH")
	var ta , i
	for (i = 0 ; i < thArr.length ; i++ ) {
	
		if ((ta  = thArr[i].getElementsByTagName("a")) != null ) {
//			alert(ta[0].href + "\n" + window.document.location.href + "\n" + window.document.location.href.indexOf(ta[0].href)) 
			if ( window.document.location.href.indexOf(ta[0].href) > -1 ) {			
				thArr[i].className="sel" ;
			}
		}
	}
}


/* =================================================== */


/* 
var clickmessage="Right click disabled over images!"

function disableclick(e) {
if (document.all) {
	if (event.button==2 || event.button==3) {
		if (event.srcElement.tagName=="IMG"){
			window.alert(clickmessage);
			return false;
		}
	}
}
else if (document.layers) {
		if (e.which == 3) {
			window.alert(clickmessage);
			return false;
		}
	}
	else if (document.getElementById){
		if (e.which==3&&e.target.tagName=="IMG"){
			window.alert(clickmessage)
			return false
		}
	}
}

function locateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
	document.onmousedown=disableclick
else if (document.getElementById)
		document.onmouseup=disableclick
	else if (document.layers)
	locateimages()
	
*/
	


/* ================================================================ */
/* ================================================================ */
/* ================================================================ */
/* ================================================================ */
function initSupPageMenu() {
	var sublistArray ; 
	
	var menuObj = document.getElementById("subpage_tabs") ;
	var listArray = menuObj.getElementsByTagName("li") ; 
	
	for (i = 0 ; i < listArray.length ; i = i + 1 ) {


//	Check every LI to see if it contains a UL.  If it does, then gove that LI a class of SUB show 

// give every LI a class of sub_hide 

		if (listArray[i].getElementsByTagName("ul").length > 0) { ;
			listArray[i].className = "sub_hide" ; 
		}
		

		listArray[i].onmouseover = function() {
			if ( this.className == "sub_hide" ) {
				this.setAttribute("oldClass",this.className) ;
				this.className = "sub_show";
			}
		}
		
		listArray[i].onmouseout = function() {
			this.className = this.getAttribute("oldClass")  ; // restore the old class 
		}
		
	}
}


// window.onload = initMenu ; 
