﻿var popped;
var popw = 665;
var poph = 565;
var popscroll = 1;
  
function propimagesload(mainimage, thumbs){  
  //image = document.getElementById(mainimage).firstChild;
  image = document.getElementById(mainimage);
  
  document.getElementById('contentheader').style.height = image.height + 'px';  
  var tthumbs = document.getElementById(thumbs);
  if(tthumbs){
    tthumbs.style.left = (image.width + 1) + 'px';
  
    /* fix thumbs positions, only proceed if:
     - main image is landscape
     - >= 3 thumbnails are available */  
    var thethumbs = $$('.thumbs a');  
    if(thethumbs.length >= 3 && image.height < image.width) {
	    for (i = 0; i < thethumbs.length; i++){    		
		    //thethumbs[i].style.height = (Math.ceil((image.height+1)/thethumbs.length) - 1) + 'px';
		    thethumbs[i].style.height = (Math.ceil((image.height+1)/3) - 1) + 'px';
	    }	
    }
    tthumbs.style.display = 'block';
  }
}

function pop(src, neww, newh, newscroll) {
  
  loc = src.getAttribute('href');
  
  if(neww)
    popw = neww;
  if(newh)
    poph = newh; 
  if(newscroll == 0)
    scroll = 0;
  
  popped = window.open(loc, 'popped', 'toolbar=0,scrollbars=' + popscroll + ',location=0,statusbar=0,menubar=0,resizable=1,width=' + popw + ',height=' + poph + ',left=50,top=50');
  if(window.focus)
    popped.focus();
}

/*
function requestform(pid, aid, aname) {    
  loc = '/requestform.aspx?pid=' + pid + '&aid=' + aid + '&aname=' + aname;
  popped = window.open(loc, 'popped', 'toolbar=0,scrollbars=' + popscroll + ',location=0,statusbar=0,menubar=0,resizable=1,width=' + popw + ',height=' + poph + ',left=50,top=50');  
}
*/

function download(file){
    //eraseCookie("user");
    //alert(readCookie("user"));
    
    var url = '/download.aspx?file=' + file;
    if(readCookie('user') != null){
        //alert(readCookie('user'));
        document.location = url;
    } else
        popped = window.open(url, 'popped', 'toolbar=0,scrollbars=' + popscroll + ',location=0,statusbar=0,menubar=0,resizable=1,width=480,height=400,left=50,top=50');        
}

function sendfile(url){    
    document.location = url;
    //popped.close();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
