function swapImg(imgObj) {
	var src = imgObj.src;
	var onoff = src.match(/_off/);
	if ( onoff ) {
		src = src.replace(/_off/,"_on");
	} else {
		src = src.replace(/\_on/,"_off");		
	}
	imgObj.src = src;
}


function showPopup( popup, getData, option ) {
	if (getData.indexOf("th_dummy.jpg") == -1 ) 
		var obj = window.open("./popups/popup_" +popup+".php?"+getData,"_blank", option);
}

function sendBack( Value ) {
	picId = window.location.search.substring(1);
	window.opener.document.getElementById(picId).src = Value;
	window.close();
}

function sendBack2( Img ) {
	elementId = window.location.search.substring(1);
	for ( var i in opener.document.forms[0] ) {
		alert(i);
	}

	opener.document.getElementById(elementId).value  = document.getElementById(Img).src;
	window.close();
	//win.document.forms[0].elements[field_name].value = "someurl.htm";
}


function insertURL(url) {
	var win, close = false;

	if (window.opener) {
		win = window.opener;
		close = true;
	} else
		win = parent;

	// Crop away query
	if ((pos = url.indexOf('?')) != -1)
		url = url.substring(0, url.indexOf('?'));

	// Handle custom js call
	if (win && js != "") {
		eval("win." + js + "(url);");

		if (close)
			top.close();

		return;
	}

	// Handle form item call
	if (win && formname != "") {
		var elements = elementnames.split(',');

		for (var i=0; i<elements.length; i++) {
			var elm = win.document.forms[formname].elements[elements[i]];
			if (elm && typeof elm != "undefined")
				elm.value = url;
		}

		if (close)
			top.close();
	}


	if (close)
		top.close();
} 

function setInfos() {
	document.getElementById("pInfo1").value = document.getElementById("previewPic1").src;
	document.getElementById("pInfo2").value = document.getElementById("previewPic2").src;	
}

function changePreviewPic( picId, selectObj, Path) {
	window.document.getElementById(picId).src = Path + selectObj.options[ selectObj.selectedIndex ].value;
}

/* String URL encodieren */
function urlencode_string( estring ) {
    hex = '0123456789ABCDEF';
    encString = '';
    e_char = '';
    e_len = estring.length;
    for( e_i = 0; e_i < e_len; e_i++ )
    {
        e_char = parseInt( estring.charCodeAt( e_i ) );
        encString += '%' + hex.charAt( (e_char >> 4) % 16 ) + hex.charAt( e_char % 16 );
    }
    return encString;
}

function deleteFile( fileSelector ) {
	var currentLocation = urlencode_string( window.location.href );
	var filetoDelete = urlencode_string(fileSelector.options[fileSelector.selectedIndex].value);
	window.location.href= "../dbupdate.php?redirect=" + currentLocation + "&file=" + filetoDelete + "&action=delete";
}

