function toggle_visibility(id) {
    var e = document.getElementById(id);
    if(e.style.display == 'none')
        e.style.display = 'inline';
    else
        e.style.display = 'none';
}

function setVisible(id) {
	var e = document.getElementById(id);
    e.style.display = 'inline';
}

function setUnvisible(id) {
	var e = document.getElementById(id);
    e.style.display = 'none';
}

function addFileUploadField(formId, elementName, limit, addLink){
	
	var form = document.getElementById(formId); 
	
	if (form.elements.length < limit) {	
		var newElement = document.createElement('input');
		newElement.type = 'file';
		newElement.name =  elementName;
		newElement.size = 36;
		form.appendChild(document.createElement('br'));
		form.appendChild(newElement);
		
		if (form.elements.length == limit) {
			addLink.style.display = 'none';
		}
		
	}
}

function adjust_content_height() {
    
    win_y = getWindowHeight(); // the height of inner window
    content_y = document.getElementById('right').offsetHeight; // content height
    container_y = 660; // the height that fits all content
    
    if (content_y > container_y) {
        if (win_y > container_y) {
            diff = win_y - container_y;
            content_height = document.getElementById('content').offsetHeight;
            
            // make content higher
            document.getElementById('content').style.height = content_height + diff + "px";
        }
    }
    
}

function getWindowHeight() {
    myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

function openImage(src,x,y) {
    if (x == null || y == null){
        x = 800
        y = 600
    }
    if (x > screen.width){
        x = screen.width - 100
    }

    if (y > screen.height){
        y = screen.height - 100
    }
	win = window.open('', '', 'toolbar=0,menubar=0,scrollbars=yes,resizable=yes,status=0,location=0,directories=0,copyhistory=0,height='+y+',width='+x+'');
	win.document.open();
	win.document.writeln("<html><head><title></title></head>");
	win.document.writeln("<body><a href=\'javascript:window.close()\'><img src=\'" + src + "\' border=0></a></body></html>");
	win.document.close();
}


function updatePlan(largeimg, thumbimg) {
    // plan image
    var elem = document.getElementById('house_plans');
    elem.innerHTML = '<img src="'+thumbimg+'" />';
    
    // print action
    var a = document.getElementById('plan_print_link');
    a.href = 'javascript:openPlanImage(\''+largeimg+'\');';
}

function rotateRight() {
    
    if (rotate_imgs != null){
        current_rotate_img -= 1;
        if (current_rotate_img < 0) {
            current_rotate_img = rotate_imgs.length - 1;
        }
        updateRotateImg();
    }
    
}

function rotateLeft() {
    
    if (rotate_imgs != null) {
        current_rotate_img += 1;
        if (current_rotate_img >= rotate_imgs.length) {
            current_rotate_img = 0;
        }
        updateRotateImg(); 
    }
}

function updateRotateImg() {
    
    if (rotate_imgs != null) {
        var elem = document.getElementById('rotateImg');
        elem.innerHTML = '<img src="'+rotate_imgs[current_rotate_img]+'"/>';
    }
    
}

function openPlanImage(src,x,y) {
	
    if (x == null || y == null){
        x = screen.width - 100;
        y = screen.height - 100;
    }
    else {
    	if (x > screen.width) x = screen.width - 100;
    	if (y > screen.height) y = screen.height - 100;
    }
    win = window.open('', '', 'toolbar=0,menubar=yes,scrollbars=yes,resizable=yes,status=0,location=0,directories=0,copyhistory=0,height='+y+',width='+x+'');
    win.document.open();
    win.document.writeln("<html><head><title>Ambassador</title></head>");
    win.document.writeln("<body><a href=\'javascript:window.close()\'><img src=\'" + src + "\' border=0></a></body></html>");
    win.document.close();
}
