// Used to display popup windows...
function popup(u,n,w,h,s) {
    var l = (screen.width)  ? (screen.width  - w)/2 : 0;
    var t = (screen.height) ? (screen.height - h)/2 : 0;
    var p = window.open(u,n,'width='+w+',height='+h+',scrollbars='+s+',left='+l+',top='+t+',resizable');
    p.focus();
}

// Used to display the image slideshow within the projects area...
function showSlideShow(projectID) {
	popup('/projects/slideshow.php?pid='+projectID, 'slidePopup', 500, 590, 0);
}

// Used to display the image slideshow within the commercial projects area...
function showCommercialSlideShow(projectID) {
	popup('/commercial/slideshow.php?cid='+projectID, 'slidePopup', 500, 590, 0);
}

// Used to display the calendar pop-up div...
function displayCalendar(destTextbox, defmonth, defyear) {

    // Grab the location of the destination textbox...
    ourPosition = new getAnchorWindowPosition(destTextbox+'anchor');    // In the '/extas/anchor_position.js' file...

    childWindow = window.open('/cms/services/calendar.php?datedest='+destTextbox+'&month='+defmonth+'&year='+defyear, 'Calendar', 'width=160,height=165,top='+ourPosition.y+',left='+ourPosition.x+',resizable=no,scrollbars=no,toolbar=no,status=no,');
    childWindow.opener = self;
    childWindow.focus();
}

// Used within the calendar utils class...
function setCalendarText(textboxid, datevalue) {
    opener.document.getElementById(textboxid).value = datevalue;
    window.close();
    return true;
}

// Used to output a confirmation dialog...
function showConfirm(text, destination) {
	var returnState = confirm(text);
	if (returnState) document.location=destination;
}

// Used to set the source image for the specified element...
function setSourceImage(element, source) {
	document.getElementById(element).src = source;
}

// Used to set the source innerHTML for the specified elements...
function setSourceData(element, data) {
	document.getElementById(element).innerHTML = data;
}

// Used to display the full size popup image with the projects area...
function showImagePopup() {
	
	// Grab the current image...
	var currentSource = String(document.getElementById('mainimage').src);
	currentSource = currentSource.replace("_medium", "_large");
	popup('/projects/popup.php?content='+currentSource, 'imagePopup', 500, 560, 0);
	
	//window.status = 'currentSource: '+currentSource;
}

// Used to display the full size resource image with the projects area...
currentResourceID = 0;
function showResourcePopup() {
	popup('/projects/popup.php?resid='+currentResourceID, 'floorplanPopup', 600, 600, 'yes');
}


// Used to swap the CMS order of images...
function swapImageOrder(sourcenumber, destnumber) {
	
	var sourceImage = document.getElementById('imagethumb_'+sourcenumber).src;
	var sourceResID = document.getElementById('imageresid_'+sourcenumber).value;
	var sourceName = document.getElementById('imagename_'+sourcenumber).innerHTML;
	var destImage = document.getElementById('imagethumb_'+destnumber).src;
	var destResID = document.getElementById('imageresid_'+destnumber).value;
	var destName = document.getElementById('imagename_'+destnumber).innerHTML;

	//window.status = 'sourceID: '+sourceResID+', destID: '+destResID;

	document.getElementById('imagethumb_'+sourcenumber).src = destImage;
	document.getElementById('imageresid_'+sourcenumber).value = destResID;
	document.getElementById('imagename_'+sourcenumber).innerHTML = destName;
	document.getElementById('imagethumb_'+destnumber).src = sourceImage;
	document.getElementById('imageresid_'+destnumber).value = sourceResID;
	document.getElementById('imagename_'+destnumber).innerHTML = sourceName;
}


// Used to manage display of tabbed divs...
currentTab = 0;
function showTab(tabNo) {
   
    if (tabNo != currentTab) {
        // *** DEBUG ****
        //window.status = 'showTab - Want to show '+tabNo+' and disable '+currentTab;
        
        // Update tab content...
        hideDiv('tabcontent_'+currentTab);      // Hide current div content...
        showDiv('tabcontent_'+tabNo);           // Show tab content...

        // Update tabs...
        newSelection = document.getElementById('tab_'+tabNo);
        oldSelection = document.getElementById('tab_'+currentTab);
        
        //newSelection.style.backgroundColor='#608CAE';
        //oldSelection.style.backgroundColor='#79A5C7';

        newSelection.className = "tab_on"; 
        oldSelection.className = "tab_off"; 

		// Store this selection...
		document.getElementById('tabber').src = "/cms/services/tabber.php?tabname="+window.location.pathname+"&default="+newSelection.innerText;

        currentTab = tabNo;                     // Update global...
    }

    return true;
}


// Used to toggle the visibility of a div..
function toggleDivVisibility(divname) {
    if (document.getElementById(divname).style.visibility == "hidden") showDiv(divname);
    else hideDiv(divname);
}


// Used to show a div...
function showDiv(divname) {
    document.getElementById(divname).style.visibility="visible";
    document.getElementById(divname).style.display="inline";
}


// Used to hide a div...
function hideDiv(divname) {
    document.getElementById(divname).style.visibility="hidden";
    document.getElementById(divname).style.display="none";
}