  function makediv()
  {
     document.getElementById('thediv').innerHTML='';
     var lines=document.getElementById('sequal').value.split("\n");
     document.getElementById('queries').value=(document.getElementById('sequal').value.split("\n").length-1)+' opdracht'+((document.getElementById('sequal').value.split("\n").length-1>1)?'en':'')+' verzenden';
     for (x in lines)
     {
       var opdracht1=lines[x].split("=");
       var opdracht=lines[x].split(" ");
       if(opdracht[0]=="DELETE")
       {
        document.getElementById('thediv').innerHTML+=(lines[x]!='')?'<a href="javascript:removefromsequal(\''+x+'\');"><font color="red">X</font></a> Product <a href="javascript:popup1(\''+(opdracht[4].split("=")[1])+'\');" class="cart"><span>#'+(opdracht[4].split("=")[1])+'</span></a> Verwijderen<br>':'';
       }
       else
       {
        document.getElementById('thediv').innerHTML+=(lines[x]!='')?'<a href="javascript:removefromsequal(\''+x+'\');"><font color="red">X</font></a> Product <a href="javascript:popup1(\''+(opdracht1[2].replace(" LIMIT 1;",""))+'\');" class="cart"><span>#'+(opdracht1[2].replace(" LIMIT 1;",""))+'</span></a> wijzigen: '+((lines[x].split("=")[0]).split(" ")[(lines[x].split("=")[0]).split(" ").length-1]+' = '+(lines[x].split("=")[1]).split("' ")[0])+'\'<br>':'';
       }
     }
  }

  function removefromsequal(line)
  {
     var lines=document.getElementById('sequal').value.split("\n");
     document.getElementById('sequal').value='';
     for (x in lines)
     {
       if(x!=line)
        document.getElementById('sequal').value+=lines[x]+'\n';
     }
     makediv();
  }

function popup(kaartid) {
  day = new Date();
  id = day.getTime();
  URL = "/newphp/popup.php?&kaart="+kaartid;
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500,left = 240,top = 262');");
}

function alert2(kaartid) {
  day = new Date();
  id = day.getTime();
  URL = "/newphp/alert.php?&id="+kaartid;
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=380,height=230,left = 400,top = 400');");
}

function viewpopup(p) {
  var toload=(p==1)?"backup":"restore";
  day = new Date();
  id = day.getTime();
  URL = "/newphp/MySQL.php?viewpopup=yes&viewpopup="+toload;
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,location=no,statusbar=0,menubar=0,resizable=0,width=500,height=239,left = 240,top = 257');");
}

function js(id,veld,value)
{
 document.getElementById('sequal').value+="UPDATE kaarten SET "+veld+"='"+value+"' WHERE kaartID="+id+" LIMIT 1;\n";
 makediv();
}

function js1(set,veld,value)
{
 document.getElementById('sequal').value+="UPDATE kaarten SET "+veld+"='"+value+"' WHERE sets='"+set+"';\n";
 makediv();
}

function popup1(URL1) {
  day = new Date();
  id = day.getTime();
  URL = "/newphp/popup.php?id="+URL1;
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500,left = 240,top = 262');");
}

function editor(URL1) {
  day = new Date();
  id = day.getTime();
  URL = "/newphp/editcards.php?cmd=edit&id="+URL1;
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500,left = 240,top = 262');");
}

function removeItem(item) {
    var answer = confirm ('Weet je zeker dat je dit product wilt verwijderen?')
    if (answer)
    window.location="winkelmandje.php?action=deleteItem&item=" + item;
  }
function removeCart() {
    var answer = confirm ('Weet je zeker dat je de winkelwagen wilt leeghalen?')
    if (answer)
    window.location="?action=delete_cart";
  }
function bank() {
    var answer = confirm ('Betaling via Bank of giro: U gaat nu door naar het bevestigen van uw order, als u nog producten wilt toevoegen aan uw winkelmandje, druk dan op annuleren en navigeer via de grijze balk hier links van.\n U moet ook geregisteerd zijn op deze site om een order te kunnen plaatsen.')
    if (answer)
    window.location="?checkout=checkorder";
  }
function paypal() {
    var answer = confirm ('Betaling via Paypal: U gaat nu door naar het bevestigen van uw order, als u nog producten wilt toevoegen aan uw winkelmandje, druk dan op annuleren en navigeer via de grijze balk hier links van.\n U moet ook geregisteerd zijn op deze site om een order te kunnen plaatsen.')
    if (answer)
    window.location="?checkout=checkorder";
  }
function logout() {
   $.ajax({
            url: "http://" + window.location.hostname + "/newphp/acolyte.php",
            data: {deletecookies : 1},
            type: 'GET',
            async: true,
            dataType: 'text',
            success: function(){
              console.info('success!');
              parent.main.location.href = "home.php?action=LogOut";
              parent.rechts.location.href = "menu-rechts.php";
            }
        });
}

function submitForm() {
  document.status.submit();
}

function showCancelledOrders() {
  var table = document.getElementById('orderTable').tBodies[0];
  for (i=1; i < table.rows.length; i++)
  {
    table.rows[i].style.display = 'block';
  }
  document.getElementById('showCOButton').style.display = 'none';
}

function deletekaart(item) {
  var answer = confirm ('Weet je zeker dat je dit product wilt verwijderen?')
  if (answer)
    window.location="editcards.php?cmd=del&kaartID=" + item;
}


function savethiscart()
{
  var question 	= prompt("Geef uw winkelmandje een naam.", "Winkelmandje");
  window.location="winkelmandje.php?checkout=savecart&naam=" + question;
}
function mouseX(evt)
{
 if (!evt)
  evt = window.event;
 if (evt.pageX)
  return evt.pageX;
 else if (evt.clientX)
  return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
 else
  return 0;
}

function mouseY(evt)
{
 if (!evt)
  evt = window.event;
 if (evt.pageY)
  return evt.pageY;
 else if (evt.clientY)
  return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
 else
  return 0;
}

function follow(evt)
{
 if (document.getElementById)
 {
  var obj = document.getElementById(divName).style;     obj.left = (parseInt(mouseX(evt))+offX) + 'px';     obj.top = (parseInt(mouseY(evt))+offY) + 'px';
 }
}

function wachtwoordReset() {
	email = prompt('Type uw e-mail adres');
	if(email === '' || email === false){
		return false;
	}
	if(validateEmailAddress(email) === false) {
		window.parent.main.$('<p id="warning"><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Het door u opgegeven e-mail adres in incorrect, controleer dit adres en probeer opnieuw.</p>').dialog({																																																	 					autoOpen: true,
					title: 'Fout tijdens resetten wachtwoord',
					modal: true,
					resizable: false,
					buttons: {
						'Opnieuw proberen': function () {
							window.parent.main.$(".ui-dialog-content").dialog("destroy");
							console.info(this);
							wachtwoordReset();
						},
						'Annuleren': function () {
							window.parent.main.$(".ui-dialog-content").dialog("destroy");
						}
					}
				});
		return false;
	}
	console.info('valid');
	$.ajax({
		   	url: 'http://www.acolyte-magic.nl/newphp/password_reset.php',
			data: {
				email : email
			},
			dataType: 'json',
			type: 'POST',
			async: false,
			cache: false,
			error: function (data) {
				window.parent.main.$('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Er ging iets fout tijdens het resetten van uw wachtwoord, probeer opnieuw.<br />Bij herhaling neem contact op met de beheerder van de site via de pagina contact.</p>').dialog({																																																	 					autoOpen: true,
					title: 'Fout tijdens resetten wachtwoord',
					close: function () {
						window.parent.main.$(".ui-dialog-content").dialog("destroy");
					},
					modal: true,
					resizable: false,
					buttons: {
						ok: function () {
							window.parent.main.$(".ui-dialog-content").dialog("destroy");
						}
					}
				});
				console.info(data);
				return false;
			},
			success: function (data) {
				if(data.success === false) {
					window.parent.main.$('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Uw wachtwoord is niet gereset: <br /><i>' + data.message + '</i><br />Probeer opnieuw.</p>').dialog({																																																	 					autoOpen: true,
						title: 'Fout tijdens resetten wachtwoord',
						close: function () {
							window.parent.main.$(".ui-dialog-content").dialog("destroy");
						},
						modal: true,
						resizable: false,
						buttons: {
							ok: function () {
								window.parent.main.$(".ui-dialog-content").dialog("destroy");
							}
						}
					});
				} else {
					window.parent.main.$('<p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>Er is een tijdelijk wachtwoord gegenereerd en per e-mail naar u opgestuurd.</p>').dialog({																																																	 					autoOpen: true,						
						close: function () {
							window.parent.main.$(".ui-dialog-content").dialog("destroy");
						},
						resizable: false,
						title: 'Nieuw wachtwoord toegezonden.',
						modal: true,
						buttons: {
							ok: function () {
								window.parent.main.$(".ui-dialog-content").dialog("destroy");
							}
						}
					});
				}
				console.info(data);
			}
		   });	
}

function validateEmailAddress(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}

function generatePassword() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}
