/*----------------------------------------*/
/*                IMv2.0                  */
/*----------------------------------------*/
/*----------------------------------------*/
/*  RELEASED:   2004-05-01                */
/*  MODIFIED:   2005-05-15                */
/*  BUILD DATE: 2005-05-22                */
/*  COPYRIGHT:  Sophiaknows.Com           */
/*----------------------------------------*/
/*----------------------------------------*/

/*----------------------------------------*\



\*----------------------------------------*/

/*----------------------------------------*\


\*----------------------------------------*/


/* A.1 GLOBAL: POP SELECTED: IMAGE PREVIEW */

function PopSelected(p) {
	if(p.options[p.selectedIndex].value.search(/\w+\.\w\w\w/)>-1) {
		PopImage(p.options[p.selectedIndex].value);
		}
	}

/* A.2 GLOBAL: POP IMAGE */

function PopImage(whereIsIt) {
	args=PopImage.arguments;
	pitchurUrl="http://www.sophiaknows.com/testbed/imv/preview.html?imgsrc="+whereIsIt;
	params="width="+(((args[1])?args[1]:500))+",height="+(((args[2])?args[2]:450))+",scrollbars=yes,resizable=yes"
	pitchurWindow=window.open(pitchurUrl,"",params);
	return false;
	}

/* A.3 GLOBAL: SET SELECTED TD BGCOLOR */
function setSelectedTdBgColor(hexColor,fieldName) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("td")[i]); i++) {
		if(a.getAttribute("name") && a.getAttribute("name").indexOf(fieldName)>-1) {a.bgColor=hexColor;}
		}
	}



// A.4 GLOBAL: GET INFO

function GetInfo(id) {
	query="info.html?item="+id;
	infowindow=window.open(query,'','width=550,height=450,scrollbars=yes,resizable=yes');
	}

// A.5 GLOBAL: SET SELECTED

function setselected(s,val) {
	for(i=0;i<s.length;i++) {
		if(s.options[i].value==val) s.selectedIndex=i;
		}
	return false;
	}

//	A6. SK1.0-4.0: GENERIC: POP TOOLS
function PopToolParams(url,w,h) {
	w=((w)?w:550);
	h=((h)?h:450);
	targetWindow = url;
	eval("helpWindow=window.open(targetWindow,\"\",\"width="+w+",height="+h+",scrollbars=yes,resizable=yes\")");
	}
//	A7. SK1.0-4.0: GENERIC: POP TOOLS
function PopTool(url) {
	w=550;
	h=450;
	targetWindow = url;
	eval("helpWindow=window.open(targetWindow,\"\",\"width="+w+",height="+h+",scrollbars=yes,resizable=yes\")");
	}



// 1.A INTIALIZE
function initcontrols() {
	if(document.getElementById && document.getElementById(mode)) {
		button=document.getElementById(mode);
		button.className='bezClearDwn';
		}
	
	if(document.forms['annotations']) {
		initinfo(0);
		}
	if(document.forms['metadata']) {
		initmetadata(document.forms['metadata']);
		}
	if(document.forms['thumbsettings']) {
		initthumbsform(document.forms['thumbsettings']);
		}
	if(document.forms['slidesettings']) {
		initslidesform(document.forms['slidesettings']);
		}
	}

// 1.A.1 INTIALIZE: SLIDE EXP
function initslidesform(f) {
	s=document.forms['state'];
	setSelectedTdBgColor(s.bgcolor.value,'bgcolor');
	setSelectedTdBgColor(s.textcolor.value,'textcolor');
	setselected(f.useheading,s.useheading.value)
	setselected(f.uselabel,s.uselabel.value)
	setselected(f.headingface,s.headingface.value)
	setselected(f.headingsize,s.headingsize.value)
	setselected(f.headingface,s.headingface.value)
	setselected(f.headingsize,s.headingsize.value)
	setselected(f.navbar,s.navbar.value)
	setselected(f.autoresize,s.autoresize.value)
	}

// 1.A.2 INTIALIZE: THUMBS EXP
function initthumbsform(f) {
	s=document.forms['state'];
	setSelectedTdBgColor(s.bgcolor.value,'bgcolor');
	setSelectedTdBgColor(s.textcolor.value,'textcolor');
	setselected(f.useheading,s.useheading.value)
	setselected(f.uselabel,s.uselabel.value)
	setselected(f.maxdimension,s.maxdimension.value)
	setselected(f.colalign,s.cols.value)
	setselected(f.colcount,s.colcount.value)
	setselected(f.headingface,s.headingface.value)
	setselected(f.headingsize,s.headingsize.value)
	setselected(f.headingface,s.headingface.value)
	setselected(f.headingsize,s.headingsize.value)
	f.layout[0].checked=(s.layout.value=='columns');
	f.layout[1].checked=(s.layout.value=='popup');
	f.colalign.disabled=(s.layout.value!='columns');
	f.colcount.disabled=(s.layout.value!='popup');
	}


/* 2.1 SLIDE CONTROLS: GLOBAL COUNT */
var count=0;

/* 2.2 SLIDE CONTROLS: IMAGE SWAP */
function SwapImage(imageName,imageSource) {
	eval("document."+imageName+".src=\'"+imageSource+"\'")
	}

/* 2.3 SLIDE CONTROLS: NEXT */
function Next() {
	count=((count<ImageList.length-1)?(count+1):0);
	ShowImage(count);
	}

/* 2.4 SLIDE CONTROLS: BACK */
function Back() {
	count=((count>0)?(count-1):ImageList.length-1);
	ShowImage(count);
	}

/* 2.5 SLIDE CONTROLS: SHOW */
function ShowImage(id) {
	count=id;
	SwapImage('baseimage',ImageList[id]);
	document.forms['vcr'].counter.value=id+1;
	document.forms['vcr'].images.selectedIndex=id;
	}


// 4.1.1 SETTINGS: FILE ORDER 1: REORDER (APPLY)
function reorder(s) {
	items=new Array();
	theupdate="";
	for(i=0;i<rows.length;i++) {
		items[rows[i].link]= rows[i].link+"\t"+rows[i].title+"\t"+rows[i].description+"\t"+rows[i].pubDate+"\t"+rows[i].category+"\t"+rows[i].author+"\t"+rows[i].guid+"\t"+rows[i].enclosure;
		}
	for(f=0;f<s.length;f++) {
		if(s.options[f].value) theupdate+=items[s.options[f].value]+"\n";
		}
	document.forms['update'].update.value=escape(theupdate);
	}



// 4.1.2 SETTINGS: FILE ORDER 2: ADD FIELD
function AddFile(f) {
	for(s=0;s<f.activefiles.options.length;s++) { 
		if(f.activefiles.options[s].value.search(/\w/)<0) {
			f.activefiles.options[s].text=f.allfiles.options[f.allfiles.selectedIndex].text;
			f.activefiles.options[s].value=f.allfiles.options[f.allfiles.selectedIndex].value;
			break;
			}
		}
	}

// 4.1.3 SETTINGS: FILE ORDER 3: ADD ALL
function AddAllFiles(f) {
	for(a=0;a<f.allfiles.options.length;a++) {
		f.activefiles.options[a].text=f.allfiles.options[a].text;
		f.activefiles.options[a].value=f.allfiles.options[a].value;
		}
	}

// 4.1.4 SETTINGS: FILE ORDER 4: DELETE FIELD
function DeleteFile(f) {
	activeList="";
	activeVals="";
	toSelect=f.activefiles;
	toSelect.options[toSelect.selectedIndex].text="";
	toSelect.options[toSelect.selectedIndex].value="";
	for(l=0;l<toSelect.options.length;l++) { 
		activeList+=((toSelect.options[l].text)?toSelect.options[l].text+";":"");
		activeVals+=((toSelect.options[l].text)?toSelect.options[l].value+";":"");
		}
	ActiveList=activeList.split(';');
	ActiveVals=activeVals.split(';');
	for(a=0;a<ActiveList.length-1;a++) {
		toSelect.options[a].text=ActiveList[a];
		toSelect.options[a].value=ActiveVals[a];		
		}
	for(z=ActiveList.length-1;z<toSelect.options.length;z++) {
		toSelect.options[z].value="";
		toSelect.options[z].text="";
		}	
	}

// 4.1.5 SETTINGS: FILE ORDER 5: DELETE ALL
function DeleteAllFiles(f) {
	status=0;
	if(confirm('Reset All?')) {
		for(a=0;a<f.activefiles.options.length;a++) {
			f.activefiles.options[a].text="\n";
			f.activefiles.options[a].value="";
			}
		}	
	}

// 4.2 SETTINGS: ANNOTATIONS

// 4.2.A MIME TYPES
types=new Array();
types[1]="GIF"
types[2]="JPEG"
types[3]="PNG"

// 4.2.1 SETTINGS: ANNOTATIONS: INIT INFO
function initinfo(id) {
	record=rows[id];
	xform=document.forms['annotations'];
	xform.counter.value=(parseInt(id)+1);
	xform.images.selectedIndex=id;
	xform.link.value=record.link;
	xform.title.value=record.title;
	xform.description.value=record.description;
	xform.pubDate.value=record.pubDate;
	xform.category.value=record.category;
	xform.author.value=record.author;
	xform.guid.value=record.guid;
	document.preview.src=record.link;
	if(record.enclosure) {
		atts=record.enclosure.split(',');
		document.preview.width=(atts[0]*(100/atts[1]));
		xform.xwidth.value=atts[0];
		xform.xheight.value=atts[1];
		xform.xsize.value=atts[3];
		xform.xtype.value=types[atts[2]];
		}
	}

// 4.2.2 SETTINGS: ANNOTATIONS: SAVE INFO
function saveinfo(id) {
	record=rows[id];
	xform=document.forms['annotations'];
	record.link=xform.link.value;
	record.title=xform.title.value;
	record.description=xform.description.value;
	record.pubDate=xform.pubDate.value;
	record.category=xform.category.value;
	record.author=xform.author.value;
	record.guid=xform.guid.value;
	update();
	}

function update() {
	var updata="";
	for(i=0;i<rows.length;i++) {	
		for(e=0;e<itemprops.length;e++) {
			tVal=eval("rows["+i+"]."+itemprops[e]);
			updata+=tVal+"\t";
			}
		updata+="\n";
		}
	document.forms['update'].update.value=escape(updata);
	}


var item=0;

// 4.2.3.1 SETTINGS: ANNOTATIONS: NEXT ITEMS
function NextItem() {
	saveinfo(item);
	item=((item<rows.length-1)?(parseInt(item)+1):0);
	initinfo(item);
	}

// 4.2.3.2 SETTINGS: ANNOTATIONS: BACK ITEMS
function BackItem() {
	saveinfo(item);
	item=((item>0)?(item-1):rows.length-1);
	initinfo(item);
	}

// 4.3 SETTINGS: METADATA:

// 4.3.1 SETTINGS: METADATA: INIT

function initmetadata(f) {
	s=document.forms['state'];
	f.title.value=s.title.value;
	f.description.value=s.description.value;
	f.pubDate.value=s.pubDate.value;
	f.copyright.value=s.copyright.value;
	}

// 4.3.1 SETTINGS: METADATA: STORE

function storemetadata(f) {
	s=document.forms['state'];
	s.title.value=f.title.value;
	s.description.value=f.description.value;
	s.pubDate.value=f.pubDate.value;
	s.copyright.value=f.copyright.value;
	}

/* 5.1 EXPORT: GLOBAL */

function ResetNavBarStyle(s) {
	document.forms['update'].navbar.value=s;
	}

/* 4.3 SETTINGS: */
function Toggle(whatNow) {
	if(eval(whatNow)) {eval(whatNow+"=0");}
	else {eval(whatNow+"=1")}
	}

/* 4.4.1 SETTINGS: */
function PopColor(which) {
	targetWindow='colorswatch.html?'+which;
	helpWindow=window.open(targetWindow,"","width=550,height=220,scrollbars=no,resizable=yes");
	}

/* 4.4.2 SETTINGS: */
function ResetColor(newcolor,fieldname) {
	field1=eval("document.forms['update']."+fieldname);
	field1.value=newcolor;
	}
	
/* 5. EXPORT: */

/* 5.1 EXPORT: SLIDESHOW */

function doslideshowexport(u,s) {
	for(i=0;i<u.length;i++) {
		s.elements[i].value=u.elements[i].value;
		}
	s.submit();
	}

function dothumbnailsexport(u,s) {
	for(i=0;i<u.length;i++) {
		s.elements[i].value=u.elements[i].value;
		}
	s.submit();
	}


function dothumbnailszip(u,s) {
	for(i=0;i<u.length;i++) {
		s.elements[i].value=u.elements[i].value;
		}
	s.submit();
	}


// EXPORT: TXT

function dotxtexport() {
	xWindow=window.open('',"_pop","width=640,height=450,scrollbars=yes,resizable=yes");	
	xWindow.document.writeln('<pre>');
	for(r=0;r<rows.length;r++) {
		for(i=0;i<itemprops.length;i++) {
			xWindow.document.write(eval('rows['+r+'].'+itemprops[i])+'\t');
			}
		xWindow.document.write('\n');
		}
	xWindow.document.close();
	}


// EXPORT: RSS

function dorssexport() {
	xForm=document.forms['update'];
	xWindow=window.open('',"_pop","width=640,height=450,scrollbars=yes,resizable=yes");	
	var xml="";
	xWindow.document.writeln('<pre>');
	xml+="<\?xml version=\"1.0\" encoding=\"US-ASCII\"\?>\n";
	xml+="<rss version=\"2.01\">\n";
	xml+="<channel>\n";
	xml+=((xForm.title.value)? "<title>"+unescape(xForm.title.value)+"</title>\n" :"");
	xml+=((xForm.description.value)? "<description>"+unescape(xForm.description.value)+"</description>\n" :"");
	xml+=((xForm.pubDate.value)? "<pubDate>"+unescape(xForm.pubDate.value)+"</pubDate>\n" :"");
	xml+=((xForm.copyright.value)? "<copyright>"+unescape(xForm.copyright.value)+"</copyright>\n" :"");
	for(r=0;r<rows.length;r++) {
		xml+="<item>\n";
		for(i=0;i<itemprops.length;i++) {
			if(itemprops[i]!='enclosure') { 
				xml+="\t<"+namespace(itemprops[i])+">"+eval('rows['+r+'].'+itemprops[i])+"</"+namespace(itemprops[i])+">\n"; 
				}
				else { 
					if(rows[r].enclosure) {
						props=rows[r].enclosure.split(',');
						xml+="\t<enclosure xwidth='"+props[0]+"' xheight='"+props[1]+"' mimetype='"+props[2]+"' xsize='"+props[3]+"' xurl='"+rows[r].link+"' />\n"; 
						}
					}
			}
		xml+="</item>\n";
		}
	xml+="</channel>\n";
	xml+="</rss>\n";
	xWindow.document.write(xml.replace(/</g,"&lt;"));
	xWindow.document.close();
	}

function namespace(nstring) {
	nstring=((!nstring.match(/^title$/i)
	   && !nstring.match(/^description$/i)
	   && !nstring.match(/^link$/i)
	   && !nstring.match(/^guid$/i)
	   && !nstring.match(/^category$/i)
	   && !nstring.match(/^enclosure$/i)
	   && !nstring.match(/^pubDate$/i)
	   && !nstring.match(/^author$/i)
		)? 'sk:'+ nstring : nstring);
	return nstring;
	}

