function cp(event){
	event = Event.extend(event?event:window.event);
	event.stop();
}

function addScrollPosition(link) {
	var windowScrollPositions = getWindowScrollPositions();
	
	link.href +=
		(link.href.search(/\?/) > 0?'&':'?')
		+ 'pc3Scroll='
		+ windowScrollPositions['left']
		+ 'x'
		+ windowScrollPositions['top']
	;
}

function applyScrollPosition(){
	var key;
	var match = document.location.search.match('pc3Scroll=([0-9]+)x([0-9]+)');
	if ( !match ) return;
	
	setWindowScrollPositions(match[1], match[2]);
}

/**
 * 20080822.acn : set the scrollposition of the window
 * 
 * @param {int} left position from left of the top-left corner of the window
 * @param {int} top position from top of the top-left corner of the window
 */
function setWindowScrollPositions(left, top) {
	if ( typeof window.pageXOffset != 'undefined' && typeof window.pageYOffset != 'undefined' ) {
		window.scrollTo(left, top);
	}
	else if ( typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat' ) {
		document.documentElement.scrollLeft = left;
		document.documentElement.scrollTop = top;
	}
	else if ( typeof document.body != 'undefined' ) {
		document.body.scrollLeft = left;
		document.body.scrollTop = top;
	}
}

/**
 * 20080822.acn : get the scrollposition of the window
 * 
 * @return {array} windowScrollPositions['left'] and windowScrollPositions['top']
 */
function getWindowScrollPositions() {
	var windowScrollPositions = {};
		windowScrollPositions['left'] = 0;
		windowScrollPositions['top']  = 0;
	
	if (  typeof window.pageXOffset != 'undefined' && typeof window.pageYOffset != 'undefined' ) {
		windowScrollPositions['left'] = window.pageXOffset;
		windowScrollPositions['top'] = window.pageYOffset;
	}
	else if ( typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat' ) {
		windowScrollPositions['left'] = document.documentElement.scrollLeft;
		windowScrollPositions['top'] = document.documentElement.scrollTop;
	}
	else if ( typeof document.body != 'undefined' ) {
		windowScrollPositions['left'] = document.body.scrollLeft;
		windowScrollPositions['top'] = document.body.scrollTop;
	}
	
	return windowScrollPositions;
}

function pc3CreateElementsByHTML(html,parent,parentTag){
	if ( !html ) return new Array(); //empty html
	
	var nestingLevel = 0;
	var content = document.createElement('div');
	
	parentTag = (parent?parent.nodeName:parentTag);
	
	switch( parentTag ) {
		case 'TR':
			html = '<table><tbody><tr>'+ html +'</tr></tbody></table>';
			nestingLevel = 3;
			break;
			
		case 'TBODY':
			html = '<table><tbody>'+ html +'</tbody></table>';
			nestingLevel = 2;
			break;
			
		case 'TABLE':
			html = '<table>'+ html +'</table>';
			nestingLevel = 1;
			break;
	}
	
	content.innerHTML = html;
	
	if ( !content.firstChild ) {
		// 20081223.acn : BUG #437 : why ever, but under some circumstances, there isn't a content.firstChild and because of that, the alert message was shown (a.e. at vpbank ...)?
		// alert('failed to create: '+ html + ' within '+ parentTag);
		return null;
	}
	
	while ( nestingLevel-- > 0 ) {
		content = content.removeChild(content.firstChild);
	};
	
	var childs = new Array();
	
	while( content.firstChild ) {
		var child = content.removeChild(content.firstChild);
		
		if ( parent ) parent.appendChild(child);
		childs.push(child);
	}
	
	return childs;
}