//Poppelino's Motif Checker v2.0 July 2010

function otherRelatedSections(sectionid){
 	var sectionParent;
 	var sectionChild='';
 	var sectionParent1Name='';
 	var sectionParent2Name='';
 	
	for (var i=1;i<=section_tree.length;i++) {
		if (section_tree[i].nSectionId == sectionid) {
			sectionParent=0; 
			sectionLevel=0;
	 	}
	 	if(section_tree[i].pChild!=null) {
			for (var j=1;j<=section_tree[i].pChild.length;j++) {
				if (section_tree[i].pChild[j].nSectionId == sectionid) {
					sectionParent=i; 
					sectionParentName=section_tree[i].sName;
					sectionLevel=1;
				}
			 	if(section_tree[i].pChild[j].pChild!=null) {
					for (var k=1;k<=section_tree[i].pChild[j].pChild.length;k++) {
						if (section_tree[i].pChild[j].pChild[k].nSectionId == sectionid) {
							sectionParent=i;
							sectionParent2=j;
							sectionParentName=section_tree[i].sName + ' - ' + section_tree[i].pChild[j].sName;
							sectionLevel=2;
						}
					}
				}
			}
		}
	}
	
	if(sectionLevel==0) {
		sectionChild='';
	}

	if(sectionLevel==1) {
		for (var i=1;i<=section_tree[sectionParent].pChild.length;i++) {
			if(section_tree[sectionParent].pChild[i].nSectionId != sectionid) {
				sName=section_tree[sectionParent].pChild[i].sName
				sNameOriginal=sName;
				if(sName.length>24){
					sName=sName.substr(0,24) + '...';
				}
				sectionChild+='- <a href="'+ section_tree[sectionParent].pChild[i].sURL + '" alt="" title="' + sNameOriginal + '">' + sName + '</a><br/>';
			}
		}
	}

	if(sectionLevel==2) {
	 	if(section_tree[sectionParent].pChild[sectionParent2].pChild!=null) {
			for (var j=1;j<=section_tree[sectionParent].pChild[sectionParent2].pChild.length;j++) {
				if(section_tree[sectionParent].pChild[sectionParent2].pChild[j].nSectionId != sectionid) {
					sName=section_tree[sectionParent].pChild[sectionParent2].pChild[j].sName;
					sNameOriginal=sName;
					if(sName.length>24){
						sName=sName.substr(0,24) + '...';
					}
					sectionChild+='- <a href="' + section_tree[sectionParent].pChild[sectionParent2].pChild[j].sURL + '" alt="" title="' + sNameOriginal + '">' + sName + '</a><br/>';
				}
			}
		}
	}
	
	if(sectionLevel>0) {
		sectionHTML='<p class="title2">Other Ranges in ' + sectionParentName + '</p>';
		sectionHTML+='<p class="subtitle2">';
		sectionHTML+=sectionChild;
		sectionHTML+='</p>';
	}
	
	if(sectionChild!=''){
		document.getElementById('related').innerHTML=sectionHTML;
	}
}

function ChangeMotifMainImage(item) {
	var selected_text = document.getElementById('motif_selection').options[item].text;
	selected_text=  selected_text.replace(/ /g,'');
	document.getElementById('main1').src='http://www.louispotts.com/acatalog/Motifs/' + selected_text + '.jpg';
}

function CreateMotifsList() {
	MotifNames = new Array();
	MotifNames2 = new Array();
	NumMotifs = 0;
}

function AddToMotifsList(MotifName,MotifName2) {
	NumMotifs = MotifNames.push(MotifName);
	MotifNames2.push(MotifName2);
}

function WriteMotifImages() {
	//Create the Before and after html
	var Concat1 = '<img width="120" title="'; 
	var Concat3 = '" src="http://www.louispotts.com/acatalog/Motifs/_'; 
	var Concat5 = '.jpg" onclick="document.getElementById(\'main1\').src=\'http://www.louispotts.com/acatalog/Motifs/';
	var Concat6 = '.jpg\'; document.getElementById(\'motif_selection\').value=\'';
	var Concat7 = '\';" style="cursor:pointer;" />'; 
	var TablePre = '<table style="background-color: #FFFFFF; text-align:center; border: 0px solid #000000;"><tr>';
	var Table1 = '<td style="width:140px;border: 0px solid #000000;" valign="top">';
	var Table2 = '<br />';
	var Table3 = '<br /><br /></td>';
	var TableInterim = '</tr><tr>';
	var TableApres = '</tr></table><br/><br/></td>';
	var MotifsPerRow = 3;

	var MotifNoSpaces = '';
	var MotifWithSpaces = '';
	var BreakLine='<br />'
	
	var MotifTitle = '<td valign="top" style="text-align:left; width:440px;"><p class="title2">More Motifs Available</p><p class="subtitle2">Select a Motif</p>';

	//Print title when motif available
	if(NumMotifs>1) {
		document.write(MotifTitle);
	
		document.write(TablePre);
	 	
		//Loop until the end of the array
		for(i=0;i<NumMotifs;i++){
	  		MotifNoSpaces = MotifNames[i].toString().replace(/ /g,'');
	  		MotifWithSpaces = MotifNames[i].toString();
	  		MotifWithSpaces2 = MotifNames2[i].toString();
	  		Number=i+1;
	  		
	  		document.write(Table1);
	  		document.write(Concat1+MotifWithSpaces2+Concat3+MotifNoSpaces+Concat5+MotifNoSpaces+Concat6+Number+Concat7);
	  		document.write(Table2+MotifWithSpaces2+Table3);
	  		if(i%MotifsPerRow == 2){
	   			document.write(TableInterim);
	  		}  
	 	}
		document.write(TableApres);
	}

}

function EYMainSectionsOnly(ar) {
	var strIDs = '';

	strIDs = '<select onchange="window.open(this.value,\'_self\');" style="width:155px;">';
	strIDs += '<option value="http://www.louispotts.com">Select a Range</option>';
	for (var i=1;i<=ar.length-2;i++) {
		if (ar[i].sURL != null) {
			strIDs += '<option value="' + ar[i].sURL + '">' + ar[i].sName + '</option>';
		}
	}
	strIDs += '</select>';

	return strIDs
}

function EYMainSectionsImagesOnly(ar) {
	var strIDs = '<table cellpadding="0" cellspacing="0" border="0"><tr>';
	for (var i=1;i<=ar.length;i++) {
		if (ar[i].sURL != null) {
			strIDs += '<td style="width:180px; padding-bottom:24px; text-align:left;"><a style="border-color: #00FF00;" href="' + ar[i].sURL + '">' + '<img class="reflect" src="http://www.louispotts.com/acatalog/' + ar[i].sImage + '" alt="" title="" border="" /></a></td>';
    
			if (i%4 == 0) {
				strIDs += '</tr><tr> ';
			}
		}
	}
	strIDs += '</tr></table> ';
	return strIDs
}

