/**
 * Oeffnet die URL eines Test in einer angegebenen Groesse
 **/
function openGoalwallshooting(site) {

	var w = 550;
	var h = 400;
	var x = screen.availWidth/2-w/2;
	var  y = screen.availHeight/2-h/2;
	var popupWindow = window.open('http://www.skppsc.ch/games/goalwallshooting','tests','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars=no');
}

/**
 * Oeffnet die URL eines Test in einer angegebenen Groesse
 **/
function openTests(site) {

	var w = 690;
	var h = 520;
	var x = screen.availWidth/2-w/2;
	var  y = screen.availHeight/2-h/2;
	var popupWindow = window.open(site,'tests','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars=no');
}

/**
 * Oeffnet die URL eines Test in einer angegebenen Groesse
 **/
function openFrappr() {

	var site = '';
	var w = 320;
	var h = 320;
	var x = screen.availWidth/2-w/2;
	var  y = screen.availHeight/2-h/2;
	var popupWindow = window.open('http://www.skppsc.ch/blog/index.php/weblog/frappr_popup','tests','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars=no');
}

/**
 * Oeffnet die URL eines Test in einer angegebenen Groesse
 **/
function openPopup(site) {

	var w = 690;
	var h = 560;
	var x = screen.availWidth/2-w/2;
	var  y = screen.availHeight/2-h/2;
	var popupWindow = window.open(site,'tests','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars=no');
}

var ie = !!document.all;


/**
 * A clipboard that can write and read from the system clipboard.
 */
function Clipboard()
{
	if ( ie )
    {
        this.clipboard = document.createElement( 'INPUT' );
        with ( this.clipboard.style )
        {
            position = 'absolute';
            left = '0px';
            top = '0px';
            visibility = 'hidden';
        }
        document.body.appendChild( this.clipboard );
    }

    this.copy = Clipboard_copy;
}

/**
 * Copies a text to the system clipboard. Priveleges are necessary.
 * @param text the text
 */
function Clipboard_copy( text )
{
	if ( ie )
    {
        this.clipboard.value = text;
        this.clipboard.select();
        var textRange = this.clipboard.createTextRange();
        textRange.execCommand( 'copy' );
    }
}

function getImageFromSrc(tagId) {
	try {
		if (document.all && !window.opera) {
			var imageNodeId = 1;
			var textNodeId = 3;
		} else {
			var imageNodeId = 3;
			var textNodeId = 6;
		}
		document.getElementById(tagId).childNodes[ textNodeId ].nextSibling.id = randomHtmlId();
		caps = new Object();
		caps.captionId = document.getElementById(tagId).childNodes[ textNodeId ].nextSibling.id;
		var imagePath = '';
		var imageElement = document.getElementById(tagId).childNodes[ imageNodeId ].src.split('/');
		var imageName = imageElement[imageElement.length-1];
		var imageType = imageName.split('.');
		for (i = 0;i < imageElement.length - 1;i++) {
			imagePath += imageElement[i] + '/';
		}
		imageName = imageName.replace(/\.jpg/g, '_full.' + imageType[1]);
		document.getElementById(tagId).href = imagePath + imageName;
	} catch (error) {
		alert(error);
	} finally {
		return;
	}
}

function randomHtmlId() {
	return 1 + 10000*(Math.random());
}

function setAlt2Text() {
	if (document.all && !window.opera) {
		var nodeId = 1;
	} else {
		var nodeId = 3;
	}
		
	for (i=0; i < document.getElementsByTagName("a").length;i++) {
		if (document.getElementsByTagName("a")[i].className == 'highslide') {
			var pTag = document.createElement("p");
			var text = document.createTextNode( document.getElementsByTagName("a")[i].childNodes[ nodeId ].alt );
			pTag.appendChild(text);
			document.getElementsByTagName("a")[i].parentNode.appendChild(pTag);
		}
	}
}

