/* */
function displayItem(theitem) {
var theid = document.getElementById(theitem);
theid.style.display = "";
}
function hideItem(theitem) {
var theid = document.getElementById(theitem);
theid.style.display = "none";
}
function changeClassName(theitem,theclass) {
var theid = document.getElementById(theitem);
theid.className = theclass;
}
function updateText(theitem,thetext) {
document.getElementById(theitem).innerHTML = thetext;
}

function openwin(url,width,height) {
win=window.open(url,"smallwin","width=" + width + ",height=" + height + ",scrollbars,resizable,left=30,top=30");
}

function clearValue(theid) {
document.getElementById(theid).value = "";
}

function oPixOption(theurl) {
window.location.href = theurl;
}

/* */
var loadingWidget = '<div style="position:absolute; width:400px;"><div style="position:relative; left:140px; top:60px; width:120px; border:1px dashed #BBBBBB; background-color:#444444; color:#FFFFFF; font-weight:600; padding:5px;">Loading.<blink>.</blink>.<br>Please Wait!</div></div>';




function establishPageDims(calledfrom) {
var pgbody = document.getElementById("pgbody");
var heading = document.getElementById("heading");
var navigation = document.getElementById("navigation");
var footer = document.getElementById("footer");
var contentzone = document.getElementById("content-container");
if (document.all) {document.body.scroll='auto';}
contentzone.style.height = pgbody.clientHeight - heading.clientHeight - navigation.clientHeight - footer.clientHeight - 4;
document.getElementById("closeoverlay").style.height = pgbody.clientHeight - 6;
document.getElementById("closeoverlay").style.width = pgbody.clientWidth - 12;
if (screen.width < 1000) {
document.getElementById("overlay").style.left = 0;
} else {
document.getElementById("overlay").style.left = ((pgbody.clientWidth / 2) - (1000 / 2));
}
var overlayTop = 28;
if (screen.height < 850) { 
overlayTop = 0;
document.getElementById("viewPictures-current").style.height = pgbody.clientHeight;
} else {
document.getElementById("viewPictures-current").style.height = pgbody.clientHeight - 70;
}
document.getElementById("overlay").style.top = overlayTop;
var picScroll = pgbody.clientHeight - 28 - overlayTop;

}

function displayOver(theid) {
if (theid.title != "") {
var items = theid.href.split('/');
theid.innerHTML = '<div class="ovr-prod"><img src="http://pix.mdmpix.com/125/' + items[3] + '/' + items[4] + '.jpg"></div>' + theid.innerHTML; 
theid.title = "";
}
}


function gradeDisplayTog(grade) {
var current = document.getElementById('picdataspill').className.split(' ');
var gradewason = 0;
var setclass = "";
for (i = 0; i < current.length; i++) {
if (current[i] == 'hideG' + grade) {
gradewason++;
} else {
setclass = setclass + ' ' + current[i];
}
}
if (gradewason == 0) setclass = setclass + ' hideG' + grade;
document.getElementById('picdataspill').className = setclass;
}

function closeOverlay() {
changeClassName('container','');
hideItem('overlay');
hideItem('closeoverlay');
changeClassName('page','');
}

function openOverlay() {
displayItem('closeoverlay');
displayItem('overlay');
changeClassName('page','overlayIsOn');
}

function doMap(theid,theurl) {
document.getElementById(theid).innerHTML = "<iframe frameborder=0 style='width:100%; height:550px; border:1px solid #000000;' src='" + theurl + "'></iframe>";
}



/* Search */

function checkSearch() {
var thequery = document.getElementById("qsearch").value;
if (thequery.length > 2) {
hideItem('searcherror');
return true;
} else {
displayItem('searcherror');
return false;
}
}

/* PIX */


function mdmUpdateTab(theid) {
hideItem("mdm-print-table");
hideItem("mdm-license-table");
changeClassName("mdm-print","");
changeClassName("mdm-license","");
changeClassName("mdm-" + theid,"mdmtabon");
displayItem("mdm-" + theid + "-table");
}

function performNav(thenum) {
location.href = document.getElementById("picviewLink-" + thenum).href;
}
function updatePicSize(thesize,thecurrent) {
picsize = thesize;
var curr = thecurrent.split(',');
lastcurrentpicview = ''
picDisplay(curr[0],curr[1],picsize,curr[2]);
}

function showcase(imgpath) {
} // intentionally blank





function createPictureOverlay(itemnum) {
displayItem('viewPictures');
var thetarget = pgP[itemnum].split('.jpg');
if (document.subdomain == '') {
thetarget = thetarget[0] + '/?meta[suppress]=1';
} else {
thetarget = 'http://' + document.subdomain + '/utils/pix.php?pix=' + thetarget[0] + '/';
}
getThePart('picdata',thetarget);
var isvert = "";
var maxpic = pgP.length - 1;
itemNext = itemnum + 1;
if (itemNext > (pgP.length - 1)) {itemNext = 1;}
itemBack = itemnum - 1;
if (itemBack < 1) {itemBack = (pgP.length - 1);}
document.getElementById("viewPictures-status").innerHTML = 'Viewing ' + itemnum + ' of ' + maxpic + ' of ' + pageTitle + ' Pictures';
if (maxpic == 1) {
document.getElementById("viewPictures-browse").innerHTML = '<em>No more pictures of ' + pageTitle + ' are available at this time.</em>';
} else if (maxpic == 2) {
document.getElementById("viewPictures-nextLink").href = "javascript:createPictureOverlay(" + itemNext + ")";
document.getElementById("viewPictures-nextImage").innerHTML = '<img src="http://pix.mdmpix.com/125' + pgP[itemNext] + '" alt="">';
document.getElementById("viewPictures-nextImageTitle").innerHTML = pgPT[itemNext];
document.getElementById("viewPictures-backLink").style.display = "none";
} else {
document.getElementById("viewPictures-nextLink").href = "javascript:createPictureOverlay(" + itemNext + ")";
document.getElementById("viewPictures-nextImage").innerHTML = '<img src="http://pix.mdmpix.com/125' + pgP[itemNext] + '" alt="">';
document.getElementById("viewPictures-nextImageTitle").innerHTML = pgPT[itemNext];
document.getElementById("viewPictures-backImageTitle").innerHTML = pgPT[itemBack];
document.getElementById("viewPictures-backLink").href = "javascript:createPictureOverlay(" + itemBack + ")";
document.getElementById("viewPictures-backImage").innerHTML = '<img src="http://pix.mdmpix.com/125' + pgP[itemBack] + '" alt="">';
}
document.getElementById("viewPictures-current").scrollTop = 0;
document.getElementById("picdata").scrollTop = 0;
document.getElementById("viewPictures-current").scrollTop = 0;
openOverlay();
showcase(pgP[itemnum]);
}


var setPause;
function rollPicDisplay(startat,endat,picsize,picview) {
setPause = setTimeout("picDisplay(" + startat + "," + endat + "," + picsize + "," + picview + ")",100); 
}
function rollPicDisplayNot() {
clearTimeout(setPause);
}





function picDisplay(startat,endat,picsize,picview) {
currentpicview = startat + ',' + endat + ',' + picview;
if (lastcurrentpicview == currentpicview) {} else {
lastcurrentpicview = currentpicview;
document.getElementById("pictoolbar").innerHTML = origPicToolbar;
document.getElementById("picview-" + picview).className = "tabon";
if (pnotfeatured) {
if(picview == 'all') {
document.getElementById("picturesall").style.display = "none";
} else {
document.getElementById("picturesall").style.display = "";
}
}
if (endat > pcount) endat = pcount;
var browselinks = '';
if (picview > 1) {
var picviewBack = picview - 1;
browselinks = browselinks + '<a href="javascript:performNav(' + picviewBack + ');">Back</a> <span class="divider">|</span> ';
} else {
browselinks = browselinks + '<span>Back</span> <span class="divider">|</span> ';
}
if (picpagecount > picview) {
var picviewNext = picview + 1;
browselinks = browselinks + '<a href="javascript:performNav(' + picviewNext + ');">Next</a>';
} else {
browselinks = browselinks + '<span>Next</span>';
}
document.getElementById("picstatusbar").innerHTML = '<div class="browsenav">' + browselinks + '</div>' + 'Viewing ' + startat + ' to ' + endat + ' of ' + pcount + ' Pictures';
document.getElementById("picstatusbar2").innerHTML = '<div class="browsenav">' + browselinks + '</div>';
var picbox = document.getElementById("picturebox");
var picboxHTML = '<table class="imgbox"><tr>';
var newrow = 1;
for(var i = 1; i < (pgP.length); i++) {
if ((i >= startat) && (i <= endat)) {
if (newrow > 5) {newrow = 1; picboxHTML = picboxHTML + '</tr><tr>'}
picboxHTML = picboxHTML + '<td class="imgbox"><a href="javascript:createPictureOverlay(' + i + ');" title="' + pgPT[i] + '"><img src="http://pix.mdmpix.com/' + picsize + '' + pgP[i] + '" alt="[Thumbnail]"></a></td>';
newrow++;
}
}
while (newrow < 5) {picboxHTML = picboxHTML + '<td></td>';newrow++;}
picbox.innerHTML = '<div style="width:100%;">' + picboxHTML + '</tr></table></div>';
}
}










/* */
function makeHttpObject() {
    var xmlHttpObj;
    // branch for Activex version (Microsoft IE)
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlHttpObj = false;
            }
        }
    @else
        xmlHttpObj = false;
    @end @*/
    // branch for native XMLHttpRequest object (Mozilla & Safari)
    if (!xmlHttpObj && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlHttpObj = new XMLHttpRequest();
        } catch (e) {
            xmlHttpObj = false;
        }
    }
    return xmlHttpObj;
}
var httpObj = makeHttpObject(); // create the HTTP Object

function getHttpResponse() {
if (httpObj.readyState == 4) {
if (httpObj.status == 200) {
var theHTML = httpObj.responseText;
var idname = document.thetargetid;
if (idname == 'picdata') {
var picparts = theHTML.split('^~^');
document.getElementById(idname).innerHTML = picparts[0];
document.getElementById('picinfo').innerHTML = picparts[1];
} else {
document.getElementById(idname).innerHTML = theHTML;
}


} else {
alert("There was a problem with the response: " + 
httpObj.statusText);
}
}
}
document.last = "";
document.laststartat = 0;

function getThePart(thetarget,theurl) {
var tarit = document.getElementById(thetarget);
tarit.innerHTML = loadingWidget + tarit.innerHTML;
document.thetargetid = thetarget;
document.therecipid = "";
httpObj.open("GET", theurl, true);
httpObj.onreadystatechange = getHttpResponse;
httpObj.send(null);
}





