/*
 * Company		: Opzet V.O.F..
 * Programmer	: Guus Sprokkereef
 * Email		: guus@opzet.nl
 * 
 * Date			: 01-03-2005
 * Version		: 1.0
 * 
 * History:
 * 
 * 
 */

function executeURL(u, m)
{
	// m = message
	// u = url
	
	if (window.confirm(m))
	{
		//location.href=u;
		location.replace(u);
	}
}

var oForm = document.forms['imageEdit']; // the form from the imageEditor

// na klik op preview
function preview()
{
	if (oForm['scale_0'].checked || oForm['scale_2'].checked) // schalen kader
	{
		scaleFrame();
	}
	if (oForm['scale_1'].checked || oForm['scale_2'].checked) // schalen foto
	{
		scalePhoto();
	}
}

function doPreset(w,h)
{
	if (oForm['scale_0'].checked || oForm['scale_2'].checked) // schalen kader
	{
		scaleFame(w,h);
	}
	if (oForm['scale_1'].checked || oForm['scale_2'].checked) // schalen foto
	{
		scalePhoto(w,h);
	}
	updateWidthHeigth(w,h);
}

function scaleFrame(w,h)
{
	
}

// updaten van de invoer velden voor breedte en hoogte
function updateWidthHeight(w,h)
{
	if (w && h)
	{
		oForm['breedte'].value = w;
		oForm['hoogte'].value = h;
	}

}

function setPosition(o)
{
	// clip(top right bottom left)
	oForm['clipTop'].value = replaceChar(o.style.top,"px","");
	var r = oForm['clipRight'].value = eval(oForm['breedte'].value)-eval(replaceChar(document.getElementById('cropper').style.width,"px",""))-eval(replaceChar(o.style.left,"px",""));
	var b = oForm['clipBottom'].value = eval(oForm['hoogte'].value)-eval(replaceChar(document.getElementById('cropper').style.height,"px",""))-eval(replaceChar(o.style.top,"px",""));
	var l = oForm['clipLeft'].value = replaceChar(o.style.left,"px","");

	setCropper(oForm['breedte'].value,oForm['hoogte'].value);
}

function updateClipping()
{
	var w = eval(oForm['clipBreedte'].value);
	var h = eval(oForm['clipHoogte'].value);

	var t = eval(oForm['clipTop'].value);
	var l = eval(oForm['clipLeft'].value);

	oForm['clipRight'].value = eval(oForm['breedte'].value) - w - l;
	oForm['clipBottom'].value = eval(oForm['hoogte'].value) - h - t;

	document.getElementById('cropper').style.width = w;
	document.getElementById('cropper').style.height = h;
}

function resetImage()
{
	/*
	oForm.reset();	
	document.getElementById('previewImage').width = <%=Request("w")%>;
	document.getElementById('previewImage').height = <%=Request("h")%>;

	setCropper(<%=Request("w")%>,<%=Request("h")%>);
	*/
}

function scaleImage()
{
	var orgW = oForm['newW'].value;
	var orgH = oForm['newH'].value;

	var maxW = oForm['breedte'].value;
	var maxH = oForm['hoogte'].value;
	/*
	if (orgW!=maxW)
	{
		maxH = (maxW/<%=Request("w")%>)*<%=Request("h")%>;
		maxW = (maxH/<%=Request("h")%>)*<%=Request("w")%>;
	} else {
		maxW = (maxH/<%=Request("h")%>)*<%=Request("w")%>;
		maxH = (maxW/<%=Request("w")%>)*<%=Request("h")%>;
	}
	*/
	oForm['newW'].value = Math.round(maxW);
	oForm['newH'].value = Math.round(maxH);
	oForm['breedte'].value = Math.round(maxW);
	oForm['hoogte'].value = Math.round(maxH);
	document.getElementById('previewImage').width = Math.round(maxW);
	document.getElementById('previewImage').height = Math.round(maxH);

	oForm['clipBreedte'].value = eval(oForm['breedte'].value)-eval(oForm['clipLeft'].value)-eval(oForm['clipRight'].value);
	oForm['clipHoogte'].value = eval(oForm['hoogte'].value)-eval(oForm['clipTop'].value)-eval(oForm['clipBottom'].value);
	
	setCropper(oForm['breedte'].value,oForm['hoogte'].value);
	
}

function setCropper(w,h) // width height
{
	document.getElementById('cropper').style.width = w;
	document.getElementById('cropper').style.height = h;
	
	// clip(top right bottom left)
	var t = oForm['clipTop'].value
	var r = oForm['clipRight'].value
	var b = oForm['clipBottom'].value
	var l = oForm['clipLeft'].value

	//alert(eval(l)+3);
	document.getElementById('cropper').style.width = w-r-l;
	document.getElementById('cropper').style.height = h-t-b;
	document.getElementById('cropper').style.left = eval(l)+3;
	document.getElementById('cropper').style.top = t;
}


function checkRadio(w,h)
{
	if (w && h)
	{
		oForm['breedte'].value = w;
		oForm['hoogte'].value = h;
	}
	scaleImage();
}

