// Gets url-metadata via ajax-request and returns response to form

function getUrlMetaData(_url) {
	
	var request = new AjaxRequest(pathPrefix + "/Ajax/ptdGetUrlData" + firstSeperator + "url=" + _url + sid2, true);
	request.doRequest();
	
	if(request.getResponseText()) {
		
		var responseText = request.getResponseText();
		var parts = responseText.split("###");
		
	}
	
	return parts;
	
}

// Handles action requests from the acp part of ptdListLinksPage

function ptdAction(_action) {

	var isChecked = false;
	
	var checkBoxes = getById('ptdForm').elements["checkBox[]"];

	if(checkBoxes) {

		var count = checkBoxes.length;

		if(!count)
			if(checkBoxes.checked == true)
				isChecked = true;
			else
				isChecked = false;
	
		else
			for(var i = 0; i < count; i++)
				if(checkBoxes[i].checked == true)
					isChecked = true;

	}
	else
		isChecked = false;	

	if(isChecked == true) {
		
		var form = getById('ptdForm');
		
		form.elements["action"].value = _action;
				
		// Get action texts from form and submit action to class ptd
				
		if(_action == "deleteLinkStats") {
			var deleteLinkStatsText = getById('deleteLinkStatsText').innerHTML;
			if(confirm(deleteLinkStatsText)) {
				form.submit();
			}
		}
		else if(_action == "delete") {
			var deleteText = getById('deleteText').innerHTML;
			if(confirm(deleteText)) {
				form.submit();
			}
		} 
		else if(_action == "unlock") {
			var unlockText = getById('unlockText').innerHTML;
			if(confirm(unlockText)) {
				form.submit();
			}
		}  
		else if(_action == "lock") {
			var lockText = getById('lockText').innerHTML;
			if(confirm(lockText)) {
				form.submit();
			}
		} 
		else if(_action == "changeCategories")  {
			form.action = pathPrefix + "/" + lngAdministration + "/ptdLinkCategoryChangeForm/" + sid1;
			form.submit();
		}
		else {
			form.submit();
		}
		
	}
}

// Handles popup of big thumbnails

function showPopup(_id, _sender, _path) {
	
	if(!getById("largeThumb_" + _id)) {
		
		var image = document.createElement("img");
		image.src = _path;
		image.id = "largeThumb_" + _id;
		image.style.display = "none";
		image.style.padding = "5px";
		image.style.backgroundColor = "white";
		image.style.border = "1px solid #CCCCCC";
		image.style.maxWidth = "320px";
		
		document.body.appendChild(image);
				
		image.style.position = "absolute";
		image.style.left = posX(_sender) + 150 + "px";
		image.style.top = posY(_sender) - 6 + "px";
		
		image.style.display = "";
		
	} else {
		getById("largeThumb_" + _id).style.display = "";
	}

}

function hidePopup(_id) {
	getById("largeThumb_" + _id).style.display = "none";
}