﻿var __DOMAIN = 'http://act-agency-media.com';
var _ERRORALERT = 'Ein unbekannter Fehler ist aufgetreten. Bitte versuchen Sie es erneut.';

	// Download
function download(id, res){
	if(res == 'low')
		location.href = __DOMAIN+"/download,low:"+id;
	else if(res == 'pre')
		location.href = __DOMAIN+"/download,pre:"+id;
	else
		location.href = __DOMAIN+"/download:"+id;
}

	// Lightbox
function addLightbox(id){
	new Ajax.Request(__DOMAIN+"/lightbox,add:"+id, {
		method: 'post',
		postBody: "post="+Math.round(Math.random()*100000)+"&id="+encodeURIComponent(id),
		onSuccess: function(transport){
			if(transport.responseText && transport.responseText != document.getElementById('LIGHTBOX').innerHTML) 
				document.getElementById('LIGHTBOX').innerHTML = transport.responseText;
		},
		onFailure: function(){ 
			alert(_ERRORALERT);
		}
	});
}

function deleteLightbox(){
	new Ajax.Request(__DOMAIN+"/lightbox,delete:"+id, {
		method: 'post',
		postBody: "post="+Math.round(Math.random()*100000)+"&id="+encodeURIComponent(id),
		onSuccess: function(transport){
			if(transport.responseText && transport.responseText != document.getElementById('LIGHTBOX').innerHTML) 
				document.getElementById('LIGHTBOX').innerHTML = transport.responseText;
		},
		onFailure: function(){ 
			alert(_ERRORALERT);
		}
	});
}

	// IMAGE
function IMAGEdetail(pid){
	IMAGE = window.open(__DOMAIN+"/photo,"+pid, pid, "width=800,height=560,top=60,left=30,scrollbars=yes")
}

function IMAGEclose(url) {
	var valid = (window.opener && (typeof window.opener.closed == "boolean") && !window.opener.closed);
	if(!valid){
		window.location.href = url;
		window.focus();
	}
	else{
		window.opener.location.href = url;
		window.close();
	}
}

	// Else
function link(url){
	window.location.href = url;
}

function str_replace(search, replace, subject){
    return subject.split(search).join(replace);
}

function inputFocus(obj, vue){
	if (obj.value == vue) obj.value = '';
}

function inputBlur(obj, vue){
	if (obj.value == '') obj.value = vue;
}

function GETSIZEscroll(){
	var yScroll = 0;
	if(document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	}
	else if(document.body && document.body.scrollTop){
		yScroll = document.body.scrollTop;
	}
	else if(window.pageYOffset){
		yScroll = window.pageYOffset;
	}
	else if (window.scrollY){
		yScroll = window.scrollY;
	}
	return yScroll;
}

	// Fehler
onerror = stopError;
function stopError() {
	return true;
}
