// kijk hoeveel er werd gescrolled zodat de positie van het object correct staat ingesteld
function getScrollY() 
{
    var scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}

var curHour = 0, curMinute = 0;

function setServerTime(hour, minute)
{
	curHour = hour;
	curMinute = minute;
	DrawServerTime();
	setTimeout('UpdateServerTime();', 60000);
}

function UpdateServerTime()
{
	curMinute++;
	if (curMinute >= 60)
	{
		curMinute-=60;
		curHour++;
		if (curHour >= 24)
			curHour -= 24;
	}
	DrawServerTime();
	setTimeout('UpdateServerTime();', 60000);
}

function convertToImg(nr, minlength)
{
	var msg = '';
	for (var x = 0; x < minlength - nr.length; x++)
	{
		msg += '<img src="./images/0.jpg" alt="0" border="0" align="absmiddle" style="margin: 0; padding: 0; border: 0;" />';
	}
	for (var x = 0; x < nr.length; x++)
	{
		msg += '<img src="./images/' + nr[x] + '.jpg" alt="' + nr[x] + '" border="0" align="absmiddle" style="margin: 0; padding: 0; border: 0;" />';
	}
	//alert(msg);
	return msg;
}

function DrawServerTime()
{
	var elem = document.getElementById('servertime');
	if (elem)
		elem.innerHTML = convertToImg('' + curHour + '', 2) + ':' + convertToImg('' + curMinute + '', 2);
}


//
// car array
//

var carArray = new Array();
var carCount = 0;
var carSelected = -1;
var curCarId = -1;

function addCar(carid, cardiv, nstyle)
{
	carArray[carCount] = new Array(3);
	carArray[carCount][0] = carid;
	carArray[carCount][1] = cardiv;
	carArray[carCount][2] = nstyle;
	carCount++;
}

function selectCell(divcont)
{
	var elem = document.getElementById(divcont);
	if (elem)
	{
		elem.className = 'selected';
	}
}

function deselectCell(divcont, nstyle)
{
	var elem = document.getElementById(divcont);
	if (elem)
	{
		elem.className = nstyle;
	}
}

function selectCar(carid)
{
	curCarId = carid;
	for (var x = 0; x < carCount; x++)
	{
		if (carArray[x][0] == carid)
		{
			selectCell(carArray[x][1]);
			carSelected = x;
			document.getElementById('txtCurrent').innerHTML = parseInt(x) + 1;
			document.getElementById('txtTotal').innerHTML = carCount;
			break;
		}
	}
}

function deselectCar()
{
	if (carSelected >= 0 && carSelected < carCount)
	{
		deselectCell(carArray[carSelected][1], carArray[carSelected][2]);
	}
}

function NextCar()
{
	deselectCar();
	carSelected++;
	if (carSelected < carCount)
	{
		showDetails(carArray[carSelected][0]);
	}
	else
	{
		alert('This is the last car on this list!');
		carSelected--;
	}
}

function PreviousCar()
{
	deselectCar();
	carSelected--;
	if (carSelected >= 0)
	{
		showDetails(carArray[carSelected][0]);
	}
	else
	{
		alert('This is the first car on this list!');
		carSelected++;
	}
}

function SetScrolling(isEnabled)
{
	if (document.all && document.createAttribute && document.compatMode != 'BackCompat') 
	{
	     document.getElementsByTagName('html')[0].style.overflow = isEnabled ? '' : 'hidden';
	} 
	else 
	{
	     document.body.style.overflow = isEnabled ? '' : 'hidden';
	}
}

// toon geselecteerde detailpagina
function showDetails(carid)
{
	selectCar(carid);
	SetScrolling(false);
	showLoading();
	var elem = document.getElementById('vehicleDetailWindow');
	var elem2 = document.getElementById('detailview');
	var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth && document.documentElement.clientWidth > 0 ? document.documentElement.clientWidth : document.body.clientWidth,
		height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight && document.documentElement.clientHeight > 0 ? document.documentElement.clientHeight : document.body.clientHeight;
	//
	width = parseInt(width) - 40;
	height = parseInt(height) - 40;
	elem.className = 'detailWinShown';
	elem.style.width = width + "px";
	elem.style.height = height + "px";
	elem.style.left = "50%";
	elem.style.marginLeft = "-" + (parseInt(width) / 2) + "px";
	elem.style.top = parseInt(getScrollY()) + 20 + "px";
	//
	elem2.style.width = (parseInt(width) - 20) + "px";
	elem2.style.height = (parseInt(height) - 60) + "px";
	elem2.src='PopupDetail.aspx?car=' + carid;
}

function showLoading()
{
	var loadpic = document.getElementById('loadpic');
	if (loadpic && loadpic.style && loadpic.style.display)
		loadpic.style.display = 'block';
	if (loadpic && loadpic.style && loadpic.style.visibility)
		loadpic.style.visibility = 'visible';
}

function hideLoading()
{
	var loadpic = document.getElementById('loadpic');
	if (loadpic && loadpic.style && loadpic.style.display)
		loadpic.style.display = 'none';
	if (loadpic && loadpic.style && loadpic.style.visibility)
		loadpic.style.visibility = 'hidden';
}

function CloseWin()
{
	SetScrolling(true);
	var elem = document.getElementById('vehicleDetailWindow');
	elem.className = 'detailWinHidden';
	deselectCar();
}

function PrintWin()
{
	detailview.print();
}

function EmailCar()
{
	var elem2 = document.getElementById('detailview');
	if (carArray[carSelected])
		elem2.src = "MailCar.aspx?car=" + carArray[carSelected];
	else
		elem2.src = "MailCar.aspx?car=" + curCarId;
}

function printElement(elemid)
{
	var win = window.open('printpage.aspx?elem=' + elemid, 'printpage', 'width=320,height=240');
	if (win.focus)
		win.focus();
}

function showUsers()
{
	var win = window.open('active_users.aspx', 'Active_Users', 'width=320,height=240,scrollbars=yes,left=' + (screen.width / 2 - 160) + ',top=' + (screen.height / 2 - 120));
	if (win.focus)
		win.focus();
}

function MoreInfo()
{
	window.frames['detailview'].showInfo();
}
    
function changeOffer(infield, outfield, multi)
{
    var elem = document.getElementById(outfield);
    if (elem != null)
    {
        if (elem.value == '' | elem.value == '0')
        {
            var inp = document.getElementById(infield);
            if (inp != null)
            {
                if (inp.value != '' & elem.value != '0')
                {
                    var tmp = parseInt(parseInt(inp.value) / parseFloat(multi));
                    elem.value = tmp;
                }
            }
        }
    }
}

function showChat()
{
	var win = window.open('CarXPChat.aspx', 'ChatWindow', 'width=400,height=300,left=' + (screen.width / 2 - 200) + ',top=' + (screen.height / 2 - 150));
	if (win.focus)
		win.focus();
}

var carconf = new Array();
var confirmDateSplit = new Array();

function createPopup(targeturl, cssclass, tagname, title, allowminimize, minimizecss, invoiceto, invoiceAddres, confirmButton, cancelButton)
{
	if (!document.getElementById(tagname))
	{
		var elem = document.createElement('div');
		elem.id = tagname;
		elem.className = cssclass;
		elem.innerHTML = '<table width="100%" cellpadding="2" cellspacing="1" class="popupWindow"><tr class="popupTitle" height=\"16px\"><td class="popupTekst">' + title + '</td><td class="popupButtons">' + (allowminimize ? '<a  id="' + tagname + '-minimize" href="javascript:MinimizePopup(\'' + tagname + '\',\'' + minimizecss + '\');">-</a>&nbsp;' : '') + '<a id="' + tagname + '-close"  href="javascript:ClosePopup(\'' + tagname + '\');">X</a></td></tr>' +
						 '<tr class="content"><td colspan="2" id="textconfirmation" valign="top"></td></tr><tr class="content"><td colspan="2" valign="top"><table><tr><td>' + invoiceto + '</td><td><input type="text" name="confITo" id="confITo" value="" size="50" /></td></tr><tr><td valign="top">' + invoiceAddres + '</td><td><textarea name="confIAddr" id="confIAddr" rows="3" cols="50"></textarea></td></tr></table></td></tr><tr class="content"><td colspan="2" id="dataconfirmation" valign="top"></td></tr><tr><td colspan="2" height="26px"><input type="button" class="btnSave" value="' + confirmButton + '" onclick="javascript:SubmitConf();" /><input type="button" class="btnCancel" value="' + cancelButton + '" onclick="javascript:ClosePopup(\'confirmation\');" /></td></tr></table><iframe id="conf-navi" name="conf-navi" border="0" src="' + targeturl + '" style="visibility: hidden; display: none;"></iframe>';
		document.body.appendChild(elem);
	}
	ClearConf();
}

function setAddress(to, addr)
{
	document.getElementById('confITo').value = to;
	document.getElementById('confIAddr').value = addr;
}

function addToConfirmation(message)
{
	var elem = document.getElementById('textconfirmation');
	if (elem)
	{
		elem.innerHTML += message;
	}
}

function SubmitConf()
{
	var elems = document.getElementsByName('chkConfirmCar');
	var param = '';
	var dates = '';
	for (var x = 0; x < elems.length; x++)
	{
		if (elems[x].checked)
		{
			var elY = document.getElementById('selectYear-' + elems[x].value),
				elM = document.getElementById('selectMonth-' + elems[x].value),
				elD = document.getElementById('selectDay-' + elems[x].value);
			
			var tmp_estPickupDate = new Date(elY.options[elY.selectedIndex].value, (elM.options[elM.selectedIndex].value - 1), elD.options[elD.selectedIndex].value);
			var confirmDateSplit_tmp = confirmDateSplit[x].split('/');			
			var confirmDate = new Date(confirmDateSplit_tmp[2].substring(0, 4), (confirmDateSplit_tmp[1] - 1), confirmDateSplit_tmp[0]);

			//Set 1 day in milliseconds
			var one_day=1000*60*60*24;

			var outputDate = Math.ceil((tmp_estPickupDate.getTime()-confirmDate.getTime())/(one_day));

			if(outputDate <= 31) {
				param += elems[x].value + ',';
				dates += '&date-' + elems[x].value + '=' + elY.options[elY.selectedIndex].value + '%2F' + elM.options[elM.selectedIndex].value + '%2F' + elD.options[elD.selectedIndex].value + '%2000%3A00%3A00';
			} else {
				alert('Estimated pickup date may not be sheduled 21 days after confirmation date!!');
			}
		}
	}
	if (param != '')
	{
		//alert('Parameters:\r\n' + param + '\r\n--\r\n' + dates);
		var elem = window.frames['conf-navi'];
		if (elem)
		{
			elem.document.getElementById('idInvoiceTo').value = document.getElementById('confITo').value;
			elem.document.getElementById('idInvoiceAddr').value = document.getElementById('confIAddr').value;
			elem.document.getElementById('ConfirmedCars').value = param;
			elem.document.forms[0].action = 'avconf.aspx?submit=1' + dates;
			elem.document.forms[0].submit();
		}
	}
	else
	{
		alert('Please select which cars you wish to confirm!');
	}
}

function addCarToConfirm(carid, refer, merk, model, price, confirmation_date)
{
	var index = carconf.length;
	carconf[index] = new Array();
	carconf[index][0] = carid;
	carconf[index][1] = refer;
	carconf[index][2] = merk;
	carconf[index][3] = model;
	carconf[index][4] = price;
	carconf[index][5] = confirmation_date;
}

function ClearConf()
{
	carconf = new Array();
}

function BuildConf(currentYear, currentMonth, currentDay)
{
	if (carconf.length <= 0)
	{
		ClosePopup('confirmation');
		return;
	}
	
	var selectYear = '<option value="' + currentYear + '" selected="selected">' + currentYear + '</option>', selectMonth = '', selectDay = '';
	if (currentMonth > 11)
		selectYear += '<option value="' + (parseInt(currentYear) + 1) + '">' + (parseInt(currentYear) + 1) + '</option>';
		
	for (var x = 1; x <= 31; x++)
	{
		selectDay += '<option ' + (parseInt(currentDay) == parseInt(x) ? 'selected="selected"' : '') + ' value="' + x + '">' + x + '</option>';
	}
	
	var months = [ "Januar", "Februar", "March", "April", "May", "June", "Juli", "August", "September", "October", "November", "December" ];
	
	selectMonth = '<option value="' + currentMonth + '" selected="selected">' + months[currentMonth-1] + '</option>';
	
	if (currentMonth < 12)
		selectMonth += '<option value="' + (parseInt(currentMonth) + 1) + '">' + months[currentMonth] + '</option>';
	else
		selectMonth += '<option value="1">Januar</option>';
	
	var msg = '<table class="listitems"><tr class="toprow"><td>#</td><td>Vehicle</td><td>Price</td><td>Confirmation date</td><td>Estimated Pickup date</td></tr>';
	for (var x = 0; x < carconf.length; x++)
	{
		//Store confir date in variabele
		confirmDateSplit[x] = carconf[x][5];

		msg += '<tr class="row' + x % 2 + '">';
		
		msg += '<td><input type="checkbox" checked="checked" id="chkConfirmCar" name="chkConfirmCar" value="' + carconf[x][0] + '" /></td>';
		msg += '<td><a href="javascript:showDetails(' + carconf[x][0] + ');">' + carconf[x][1] + ': ' + carconf[x][2] + '<br />' + carconf[x][3] + '</a></td>';
		msg += '<td><a href="javascript:showDetails(' + carconf[x][0] + ');">&euro; ' + carconf[x][4] + '</a></td>';
		msg += '<td><a href="javascript:showDetails(' + carconf[x][0] + ');">' + carconf[x][5] + '</a></td>';
		msg += '<td>';
		msg += '<select id="selectYear-' + carconf[x][0] + '">';
		msg += selectYear;
		msg += '</select>';
		msg += '<select id="selectMonth-' + carconf[x][0] + '">';
		msg += selectMonth;
		msg += '</select>';
		msg += '<select id="selectDay-' + carconf[x][0] + '">';
		msg += selectDay;
		msg += '</select>';
		
		msg += '</tr>';
		addCar(carconf[x][0]);
	}
	msg += '</table>';
	var elem = document.getElementById('dataconfirmation');
	if (elem)
		elem.innerHTML = msg;
}

function MinimizePopup(tagname, cssclass)
{
	var elem = document.getElementById(tagname);
	if (elem)
	{
		var oldclass = elem.className;
		elem.className=cssclass;
		var minlink = document.getElementById(tagname + '-minimize');
		if (minlink)
		{
			minlink.href = "javascript:MinimizePopup('" + tagname + "','" + oldclass + "');";
		}
	}
}

function ClosePopup(tagname)
{
	var elem = document.getElementById(tagname);
	if (elem)
	{
		document.body.removeChild(elem);
	}
}

function PageEdit()
{
	var elem2 = document.getElementById('detailview');
	if (elem2)
	{
		elem2.src = 'editcar.aspx?id=' + curCarId;
	}
}

var newsItems = new Array();
var newsInterval = 150, newsTimeout = 5000, newsBlink = 750, blink = 6;

function AddNews(id, title, message)
{
	var index = newsItems.length;
	newsItems[index] = new Array();
	newsItems[index][0] = id;
	newsItems[index][1] = title;
	newsItems[index][2] = message;
	newsItems[index][3] = 0; // current cursor index
	newsItems[index][4] = (index == 0); // is active item
}

var newsDialog;

function showNewsItem(index)
{
	if (!newsDialog)
	{
		newsDialog = document.createElement('div');
		newsDialog.id = 'newsdialog';
	}
	newsDialog.style.position = 'absolute';
	newsDialog.style.display = 'block';
	newsDialog.style.border = 'solid #a0a0a0 1px';
	newsDialog.style.backgroundColor = '#efefef';
	newsDialog.style.left = '50%';
	newsDialog.style.top = '50px';
	newsDialog.style.marginLeft = '-200px';
	newsDialog.style.width = '400px';
	document.body.appendChild(newsDialog);
	newsDialog.innerHTML = '<table class="listitems"><tr class="toprow"><td>' + newsItems[index][1] + '</td></tr><tr class="row0"><td>' + newsItems[index][2] + '</td></tr><tr class="toprow"><td align="right"><input type="button" onclick="javascript:closeNews();" value="Ok" class="btnSave" /></td></tr></table>';
}

function closeNews()
{
	document.body.removeChild(newsDialog);
	newsDialog = null;
}

function RunNews()
{
	var ni = -1;
	for (var x = 0; x < newsItems.length; x++)
	{
		if (newsItems[x][4])
		{
			ni = x;
		}
	}
	if (ni > -1)
	{
		var inQuote = false, sign = false;
		var elem = document.getElementById('newscontent');
		if (elem.innerHTML == '')
		{
			elem.innerHTML = '<a href="javascript:showNewsItem(' + ni + ');"><img src="../images/page_find.gif" align="absmiddle" alt="Open news item" /></a>&nbsp;';
		}
		if (parseInt(newsItems[ni][3]) < newsItems[ni][1].length)
		{
			var newtext = newsItems[ni][1].substring(newsItems[ni][3]).split(' ')[0];
			var quote = false;
			for (var q = 0; q < newtext.length; q++)
			{
				if (!quote & newtext.charAt(q) == '<')
					quote = true;
				if (quote & newtext.charAt(q) == '>')
					quote = false;
			}
			if (quote)
			{
				newtext += newsItems[ni][1].substring(newsItems[ni][3]+newtext.length).split('>')[0] + '>';
			}
			if (newtext != '')
				newsItems[ni][3] += newtext.length + 1;
			else
			{
				newsItems[ni][3] = newtext.length;
			}
			elem.innerHTML += newtext + '&nbsp;';
		}
		
		if (parseInt(newsItems[ni][3]) < newsItems[ni][1].length)
		{
			setTimeout('RunNews();', newsInterval);	
		}
		else
		{
			if (blink > 0)
			{
				blink--;
				elem.style.visibility = blink % 2 == 0 ? 'visible' : 'hidden';
				setTimeout('RunNews();', blink != 0 ? newsBlink : newsTimeout);
			}
			else
			{
				blink = 6;
				newsItems[ni][3] = 0;
				newsItems[ni][4] = false;
				if (ni < newsItems.length-1)
					ni++;
				else
					ni = 0;
				newsItems[ni][4] = 1;
				elem.innerHTML = '';
				setTimeout('RunNews();', newsInterval);
			}
		}
	}
}

//popup emailselection
var emails = new Array();
var emailSend = false;

function ClearEmails() {
	emails = new Array();
}

function AddEmail(gebruikerid, naamFirma, email, adres, telefoon, fax, gsm) {
	var index = emails.length;
	emails[index] = new Array();
	emails[index][0] = gebruikerid;
	emails[index][1] = naamFirma;
	emails[index][2] = email;
	emails[index][3] = adres;
	emails[index][4] = telefoon;
	emails[index][5] = fax;
	emails[index][6] = gsm;
}

function createPopupEmails(targeturl, tagname, cssclass, wb1, wb2) {
	if (!document.getElementById(tagname))
	{
		var elem = document.createElement('div');
		elem.id = tagname;	
		elem.className = cssclass;
		elem.innerHTML = '<table width="100%" cellpadding="2" cellspacing="1" class="popupWindow"><tr class="popupTitle" height="16px"><td class="popupTekst">' + wb1 + '</td></tr>' +
						 '<tr class="content"><td colspan="2" class="popupTekstEmail" valign="top">' + wb2 + '</td></tr><tr class="content"><td colspan="2" id="dataEmailSelection" valign="top"></td></tr><tr><td colspan="2" height="26px"><input type="button" class="btnSave" value="OK" onclick="javascript:SubmitConfEmailSelection();" /><input type="button" class="btnCancel" value="Cancel" onclick="javascript:ClosePopupEmailselection();" /></td></tr></table><iframe id="selection-email" name="selection-email" border="0" src="' + targeturl + '" style="visibility: hidden; display: none;"></iframe>';

		document.body.appendChild(elem);
	}
	ClearEmails();
}

function BuildConfEmailselection(wb1, wb2, wb3, wb4, wb5, wb6)
{
	if (emailSend == true)
	{
		ClosePopupEmailselection();
		emailSend = false;
		return;
	}
	
	var msg = '<table class="listitems"><tr class="toprow"><td>#</td><td>' + wb1 + '</td><td>' + wb2 + '</td><td>' + wb3 + '</td><td>' + wb4 + '</td><td>' + wb5 + '</td><td>' + wb6 + '</td></tr>';
	for (var x = 0; x < emails.length; x++)
	{
		msg += '<tr class="row' + x % 2 + '">';
		msg += '<td><input type="radio" name="groupEmail" value="' + emails[x][0] + '">' + emails[x][0] + '</td>';
		msg += '<td>' + emails[x][1] + '</td>';
		msg += '<td>' + emails[x][2] + '</td>';
		msg += '<td>' + emails[x][3] + '</td>';
		msg += '<td>' + emails[x][4] + '</td>';
		msg += '<td>' + emails[x][5] + '</td>';
		msg += '<td>' + emails[x][6] + '</td>';
		msg += '</tr>';
		addCar(emails[x][0]);
	}
	msg += '</table>';
	
	var elem = document.getElementById('dataEmailSelection');
	
	if (elem)
		elem.innerHTML = msg;
		
	emailSend = true;
}

function ClosePopupEmailselection()
{
	var elem = document.getElementById('emailPopup');
	if (elem)
	{
		document.body.removeChild(elem);
	}
}

function SubmitConfEmailSelection() {
	var elems = document.getElementsByName('groupEmail');
	var param = '';
	var dates = '';
	for (var x = 0; x < elems.length; x++)
	{
		if (elems[x].checked)
		{
			param += elems[x].value;
		}
	}
	if (param != '')
	{
		var elem = window.frames['selection-email'];
		if (elem)
		{
			elem.document.forms[0].action = 'emailSelectPopup.aspx?id=' + param;
			elem.document.forms[0].submit();
		}
	}
	else
	{
		alert('Please select which email belongs to you!');
	}
}

//crop Image popup
function createCropImagePopup(targeturl, tagname, cssclass, userpic, wb1, wb2) {
	if (!document.getElementById(tagname))
	{
		var container;
		if(!document.getElementById('container')) {		
			container = document.createElement('div');
	        container.id = 'container';
	        container.style.position = 'absolute';
	        container.style.top = '0px';
	        container.style.left = '0px';
	        container.style.width = '100%';
	        container.style.height = '1100px';
	        container.style.backgroundImage = "url('./images/pattern_back.png')";
	        container.style.backgroundRepeat = 'repeat';
	        container.style.display = 'block';
	        document.body.appendChild(container);
		}

		var elem = document.createElement('div');
		elem.id = tagname;	
		elem.className = cssclass;
		elem.innerHTML = '<table width="250px" cellpadding="2" cellspacing="1" class="popupWindow"><tr class="popupTitle" height="16px"><td class="popupTekst">' + wb1 + '</td></tr>' +
						 '<tr class="content"><td colspan="2" class="popupTekstEmail">' + wb2 + '</td></tr><tr><td>x1:<input id="x1" name="x1" type="text" style="width: 50px; margin-left: 5px; margin-right: 5px;" disabled />y1:<input id="y1" name="y1" type="text" style="width: 50px; margin-right: 5px;" disabled />x2:<input id="x2" name="x2" type="text" style="width: 50px; margin-right: 5px;" disabled />y2:<input id="y2" name="y2" type="text" style="width: 50px; margin-right: 5px;" disabled />width:<input id="width" name="width" type="text" style="width: 50px; margin-right: 5px;" disabled />height:<input id="height" name="height" type="text" style="width: 50px; margin-right: 5px;" disabled /></td></tr><tr class="content"><td colspan="2" class="popupTekstEmail" valign="top"><img src="' + userpic + '" style="width: 500px;" id="testImage" alt="picture" border="0" /></td></tr><tr><td><input type="button" class="btnSave" value="' + wb1 + '" onclick="javascript:CropImage();" /><input type="button" class="btnCancel" value="Cancel" onclick="javascript:clearCropPopup();" /></td></tr></table><iframe id="crop-image" name="crop-image" border="0" src="' + targeturl + '" style="visibility: hidden; display: none;"></iframe>';

		container.appendChild(elem);
	}
	ClearEmails();
}

function CropImage() {
	var x1 = document.getElementById('x1').value;	
	var y1 = document.getElementById('y1').value;
	var x2 = document.getElementById('x2').value;
	var y2 = document.getElementById('y2').value;
	var width = document.getElementById('width').value;
	var height = document.getElementById('height').value;
	
	if(width < 100 || height < 100) {
		alert('Please select area that is bigger than 100x100 pixels');
	} else {
		var elem = window.frames['crop-image'];
		if (elem)
		{
			elem.document.forms[0].action = 'cropImage.aspx?x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2 + '&width=' + width + '&height=' + height;
			elem.document.forms[0].submit();
		}
	}
}

function clearCropPopup() {
	document.body.removeChild(document.getElementById('container'));
}

//Show emailpopup + eventuele mogelijkheid tot email aanpassen
var emailUser

function ClearEmails() {
	emailUser = "";
}

function AddEmailUser(email) {
	var index = email;
}

function createCheckMailPopup(targeturl, tagname, cssclass, wb1, wb2, wb3) {
	if (!document.getElementById(tagname))
	{
		var elem = document.createElement('div');
		elem.id = tagname;	
		elem.className = cssclass;
		elem.innerHTML = '<table width="100%" cellpadding="2" cellspacing="1" class="popupWindow"><tr class="popupTitle" height="16px"><td class="popupTekst">' + wb1 + '</td></tr>' +
						 '<tr class="content"><td colspan="2" class="popupTekstEmail" valign="top">' + wb2 + 'Email: <input type="text" id="userEmail" value="" /></td></tr><tr class="content"><td colspan="2" id="dataEmailSelection" valign="top"></td></tr><tr><td colspan="2" height="26px"><input type="button" class="btnSave" value="' + wb3 + '" onclick="javascript:SendActivationMail();" /><input type="button" class="btnCancel" value="Cancel" onclick="javascript:ClosePopupEmailUserAttention();" /></td></tr></table><iframe id="attention-email" name="attention-email" border="0" src="' + targeturl + '" style="visibility: hidden; display: none;"></iframe>';

		document.body.appendChild(elem);
	}
	ClearEmails();
}

function ClosePopupEmailUserAttention()
{
	var elem = document.getElementById('checkMailSettings');
	if (elem)
	{
		document.body.removeChild(elem);
	}
}

function SendActivationMail() {
	var email = document.getElementById('userEmail').value;

	if (email != '')
	{
		var elem = window.frames['attention-email'];
		if (elem)
		{
			elem.document.forms[0].action = 'checkMailSettings.aspx?email=' + email;
			elem.document.forms[0].submit();
		}
		
		ClosePopupEmailUserAttention();
	}
	else
	{
		alert('Please fill in your email!');
	}
}