/**
 * functions.js
 *
 * General function list voor the 
 * webapplication of Time4Art (www.time4art.nl)
 *
 * Released at      : Oktober 2004                             
 * Last modified by :                                         
 * Date modified    :                                         
 * Copyright (c) 2004 Malibomba                               
 * IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF THIS SITE,  
 * WITHOUT THE PERMISION OF THE AUTHOR.                       
 * Info? Mail to info@malibomba.com
 */
var _D = this.document;


var _xmlhttp
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
  	try {
  		_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch(e) {
  		try {
    			_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} catch (E) {
   			_xmlhttp = false;
  		}
 	}
@else
 	_xmlhttp = false;
@end @*/
if(!_xmlhttp && document.createElement) {
 	try {
  		_xmlhttp = new XMLHttpRequest();
 	} catch(e) {
  		_xmlhttp = false;
 	}
}


/**
 * browserSniff()
 *
 * Check the current used platform and brower.
 * Currently only gecko and ie5.5 up are supported
 * by Bee|publish v2 .............................
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @return  [Object] accessable to determine wich platform and browser the user has.
 */
function browserSniff() {	
	this.version = parseInt(navigator.appVersion);
	this.agent = navigator.userAgent.toLowerCase();
	
	this.mac = (this.agent.indexOf('mac') != -1);
	this.win = ((!this.mac) && (this.agent.indexOf('wind') != -1 || this.agent.indexOf('16bit') != -1));
	
	this.safari = ((this.agent.indexOf('safari') != -1) && (this.mac));
	this.konq   = (this.agent.indexOf('konqueror') != -1);
	this.khtml  = (this.safari || this.konq);

	this.opera  = window.opera ? true : false;
	this.opera5 = ((this.agent.indexOf('opera 5') != -1) || (this.agent.indexOf('opera/5') != -1));
	this.opera6 = ((this.agent.indexOf('opera 6') != -1) || (this.agent.indexOf('opera/6') != -1));
	this.opera7 = (this.opera && document.createComment) ? true : false;

	this.ie5 = this.ie55 = this.ie6 = this.ie55up = false;
	this.ie = ((document.all) && (!this.opera && this.agent.indexOf('msie') != -1)) ? true : false;
	if(this.ie) {
		this.ie5    = !document.fireEvent ? true : false;
		this.ie55   = (document.fireEvent && !document.createComment) ? true : false;
		this.ie6    = (document.fireEvent &&  document.createComment)  ? true : false;
		this.ie55up = (this.ie55 || this.ie6);
	}
	this.gecko = (!this.khtml && !document.all && !this.opera && document.getElementById) ? true : false;	
} objIS = new browserSniff();



/**
 * window.onload = function test()
 *
 * Used to block all the javascript errors if they occur!
 *
 * @returns (Boolean) true
 */
window.onload = function test() {

	checkBrowserVersion();

}; // End of Function


function checkBrowserVersion() {
	var loc = _D.location.href;
// 	if( objIS.win && ( objIS.ie && objIS.ie55up || objIS.gecko ) ) {
 	if( ( objIS.ie && objIS.ie55up ) || objIS.gecko || objIS.safari ) {
 		return true;
	} else {
		if(loc.indexOf("toegankelijkheid.php") == -1) {
			document.location.replace('/toegankelijkheid.php');
			return false;
		}
	}
} // End of Function

 
 
/**
 * window.onerror = function blockException()
 *
 * Used to block all the javascript errors if they occur!
 *
 * @returns (Boolean) true
 */
window.onerror = function blockException() {

	return true;

}; // End of Function



function hiliteBlueRow(rowNum, selected) {

	_D.getElementById('row'+rowNum+'_1').className = selected ? 'hilite-menuitem-blue' : 'menuitem-blue';
	_D.getElementById('row'+rowNum+'_2').className = selected ? 'hilite-listitem-green' : 'listitem';
	
} // End of Function



function hiliteGreenRow(rowNum, selected) {

	_D.getElementById('row'+rowNum+'_1').className = selected ? 'hilite-menuitem-green' : 'menuitem-green';
	_D.getElementById('row'+rowNum+'_2').className = selected ? 'hilite-listitem-blue' : 'listitem-green';
	
} // End of Function


function hiliteOrangeRow(rowNum, selected) {

	_D.getElementById('row'+rowNum+'_1').className = selected ? 'hilite-menuitem-orange' : 'menuitem-orange';
	_D.getElementById('row'+rowNum+'_2').className = selected ? 'hilite-listitem-green' : 'listitem-orange';
	
} // End of Functio


function switchLocation(page) {

	_D.location.href = page;
	
} // End of Function



/**
 * setThumbnail(_identifier)
 *
 * Set the thumbnail images.
 * Values are based upon the thumbnail array which
 * is generated when the page loads.
 *
 * @returns void
 */
function setThumbnail(_identifier) {

	var identifier = 'small['+_identifier+']';	
	var _thumbnail = _root + _thumbnails[_identifier];
	var _background = _root + _backgrounds[_identifier];
	if(_thumbnail != '') {
		var thumbnail = _D.getElementById(identifier);
		thumbnail.value = _background;
		thumbnail.style.cursor = 'hand';
		thumbnail.style.backgroundColor = '#000';
		thumbnail.style.backgroundImage = 'url(' + _thumbnail + ')';
		thumbnail.style.backgroundPosition = 'center center';
		thumbnail.style.backgroundRepeat = 'no-repeat';
		
		//thumbnail.alt = _titles[_identifier];
	} else {
		return false;
	}

} // End of Function


/**
 * setBackground(_image)
 *
 * Set the background image.
 *
 * @returns void
 */
function setBackground(_identifier) {
	
	var image = _root + _backgrounds[_identifier];
	if(image != '') {
		var background = _D.getElementById('background');
		background.style.backgroundColor = '#000';
		background.style.backgroundImage = 'url(' + image + ')';
		background.style.backgroundPosition = 'center center';
		background.style.backgroundRepeat = 'no-repeat';
	} else {
		return false;
	}

} // End of Function


/**
 * change(_identifier)
 *
 * Change the background image.
 *
 * @returns void
 */
function change(_identifier) {

	if(_identifier != '') {
		//setTitle(_identifier.name);
		setBackground(_identifier.name);
	} else {
		return false;
	}

} // End of Function



/**
 * setTitle(_identifier)
 *
 * Change the background image.
 *
 * @returns void
 */
function setTitle(_identifier) {
	
	if(_titles[_identifier] != '') {
		_D.getElementById('artwork').innerHTML = _titles[_identifier];
		//_D.getElementById('background').alt = _titles[_identifier];
	} else {
		return false;
	}

} // End of Function



function submitForm(formName, offset) {
	var F = document.forms[formName];
	F['offset'].value = offset;
	F.submit();
} // End of Function


function previewKunstwerk(link) {

 	var leftPos = (screen.availWidth - 660) / 2;
	var topPos = (screen.availHeight - 510) / 2; 
   	var opts = "toolbar=no, status=no, location=no, menubar=no, resizable=yes,";
	    opts += "height=530, width=660, scrollbars=yes,";
	    opts += "top=" + topPos + ",left=" + leftPos;

	var popwin = window.open("", "", opts);
	popwin.focus();
	popwin.location = link;
	return false;

} // End of Function



function openKunstkaart() {

	var _canvas = _D.getElementById('canvas');
	var _layer = _D.getElementById('mailafriend');
	
	_layer.style.display = 'inline';
	_canvas.style.filter = 'alpha(opacity=50)';
	
} // End of Function


function closeKunstkaart() {

	var _canvas = _D.getElementById('canvas');
	var _layer = _D.getElementById('mailafriend');

	_canvas.style.filter = '';
	_layer.style.display = 'none';		
	
} // End of Function




function enableField(field) {

	if(field != '') {	
		_D.getElementById(field).className = '';
		_D.getElementById(field).disabled = false;
		_D.getElementById(field).focus();
		return true;
	} else {
		return false;
	}

} // End of Function


function disableField(field) {

	if(field != '') {
		_D.getElementById(field).className = 'disabled-area';
		_D.getElementById(field).disabled = true;
		return true;
	} else {
		return false;
	}

} // End of Function



function deleteFavorit(titel, identifier) {

	var agree = confirm("Weet u zeker dat u " + titel + " wilt verwijderen uit uw selectie?");
	if(agree) {
		var requestfile = './favorieten.delete.php?id=' + identifier;
		_xmlhttp.open('GET', requestfile, true);
 		_xmlhttp.onreadystatechange = function() {
  			if(_xmlhttp.readyState == 4) {  					
  				_D.location.reload();
  				return true;
			} else {
				return false;
  			}
 		} // End of Function
 		_xmlhttp.send(null);				
	} else {
		return false;
	}
}