var windowCounter = 0;
var wname;
var parameters;
var imageData = new Array();


function buildImgData(imagenumber, filesuffix, iwidth, iheight, alt, thumbW, thumbH) {
var windowW = parseInt(iwidth) + 20;
var windowH = parseInt(iheight) + 20;
this.imagenumber = imagenumber;
this.filesuffix = filesuffix;
this.filename = imagenumber + "." + filesuffix;
this.iheight = parseInt(iheight);
this.iwidth = parseInt(iwidth);
this.windowW = parseInt(windowW);
this.windowH = parseInt(windowH);
this.alt = alt;
this.thumbW = parseInt(thumbW);
this.thumbH = parseInt(thumbH);
}

function dWin(imgDataObj, basedir) {
wname = "dwindow" + windowCounter;
// alert("opening a new window with width/height: " + imgDataObj.windowW + " / " + imgDataObj.windowH + "\n");
parameters = "resizable=yes,toolbar=no,status=yes,width=" + imgDataObj.windowW + ",height=" + imgDataObj.windowH + ",location=no,scrollbars=yes";
dWindow = window.open('',wname,parameters);
dWindow.document.open();
dWindow.document.write("<HTML>\n<HEAD>\n");
// dWindow.document.write("<base href=\"http://www.dharmatrading.com\">\n");
dWindow.document.write("<TITLE>Image Detail");
dWindow.document.write("</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\">");
dWindow.document.write("<CENTER>\n<IMG WIDTH=" + imgDataObj.iwidth + " HEIGHT=" + imgDataObj.iheight + " \nSRC=\"http:\/\/images.dharmatrading.com/images/public/brochures/" + basedir + "/images/" + imgDataObj.filename + "\" \nALT=\"" + imgDataObj.alt + "\" ");
dWindow.document.write("></CENTER>\n</BODY>\n</HTML>");
dWindow.document.close();
dWindow.focus();
windowCounter++;
}

function showThumbnails(basedir) {
var rows = 1;
var cols = 1;
var imagecounter = 0;
var tempText = "";

if (imageData[0]) {
	tempText += ("Click on an image for a bigger version in a new window.");
}

tempText += ("<TABLE BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"2\" WIDTH=\"100\%\">");
while ((imageData[imagecounter])) {
	cols = 1;
	tempText += ("<TR>");
	while ((cols <= maxCols) && (imageData[imagecounter])) {
		var previewSRC = ("http:\/\/images.dharmatrading.com/images/public/brochures/" + basedir + "/preview/" + imageData[imagecounter].filename);
		tempText += ("<TD WIDTH=\"" + parseInt(100 / maxCols)  + "%\" ALIGN=\"CENTER\">");
		tempText += ("<A onMouseOut=\"window.status=''; return true;\" ");
		tempText += (" onMouseOver=\"window.status='Click for a bigger version.';");
		tempText += (" return true;\" HREF='javascript:dWin(imageData[" + imagecounter + "], \"" + basedir + "\");'>");
		tempText += ("<IMG ");
		tempText += ("SRC=\"" + previewSRC + "\" ALIGN=\"CENTER\" BORDER=\"" + thumbnailBorder + "\" ");
		tempText += (" WIDTH=\"" + imageData[imagecounter].thumbW + "\" HEIGHT=\"" + imageData[imagecounter].thumbH + "\"></A></TD>");
		cols++;
		imagecounter++;
	}
	tempText += ("</TR>");	
	rows++; }
tempText += ("</TABLE></CENTER>");
document.write(tempText);
}




function checkFormSubmit(theForm) {
var retval = true;
numErrors = 0;
// alert("validating form fields");
formerrorValidator("title", theForm.title.value, "isNotEmpty");

retval = formerrorHandler();
// alert("checkFormSubmit returning:" + retval);

return(retval);

}



function popWindow(inWindowname, opener, URL, inParams) {
var defaultParams = "width=600,height=500.scrollbars=0,menubar=0,location=0,status=0";
var defaultWindowname = "Popup Window";
var params;
var windowname;

if (!inParams) {
 params = defaultParams;
} else {
 params = inParams;
}
if (!inWindowname) {
 windowname = defaultWindowname;
} else {
 windowname = inWindowname;
}
var uWindow = window.open(URL,windowname,params);
uWindow.opener = opener;
return(false);
}




function relocate(targetform, elemname) {
var newloc = "";
var formElem= targetform.elements[elemname];
var idx = formElem.selectedIndex;
var locval = formElem.options[idx].value;
newloc += locval;
if (locval) {
 document.location.href = newloc;
 return true;
} else {
 return false;
}

}



function generatePage(id) {

if (id != "") {
	var linkurl = ("/cgi-bin/admin_brochures.cgi?mode=generate&id=" + id);
	var popupWindow = window.open(linkurl,'GeneratorWindow','width=300,height=300');
	popupWindow.opener = this.window;
}

return(false);
}


function viewPage(id) {

if (id != "") {
	var linkurl = ("/autogen/brochures/html/" + id + "/index.html");
	var popupWindow = window.open(linkurl,'ViewingWindow','resizable,location=yes,scrollbars=auto,status=yes');
	popupWindow.opener = this.window;
}

return(false);
}



function openFTP(id) {

if (id != "") {
	var linkurl = ("ftp://website@images.dharmatrading.com//usr/local/www/images/public/brochures/" + id);
	document.location.href = linkurl;
	// var popupWindow = window.open(linkurl,'UploadWindow','resizable,location=yes,scrollbars=auto,status=yes');
	//popupWindow.opener = this.window;
}

return(false);
}



function fillTodaysDate(theElem) {
var today = new Date();
var theYear = today.getYear();
if (theYear < 1000) {
	theYear += 1900;
}
var theMonth = (today.getMonth() + 1);
var dateval = (theYear + "-" + theMonth + "-" + today.getDate());

theElem.value = dateval;
return(false);
}




