// Forms
// Check username

function validateUsername(fld) {
    var error = "";
    var illegalChars = /[^a-zA-Z0-9_ ]/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Naam vergeten?.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 25)) {
        fld.style.background = 'Yellow'; 
        error = "Naam moet tussen de 2 en 25 karakters lang zijn.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Naam bevat incorrecte karakters.\nAlleen alfanumerieke karakter, een spatie en de underscore zijn toegestaan\n";
    } else {
        fld.style.background = 'White';
    }
    if (error != "") {
    alert("Fout!\n\n" + error);	
    return false;
  }
}

function validateEmail(fld) 
{
	var illegalChars = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	var error = "";
    if (fld.value == "") 
    {
        fld.style.background = 'Yellow'; 
        error = "Emailadres vergeten?.\n";
    } 
    else if (!fld.value.match(illegalChars))
    {
        fld.style.background = 'Yellow'; 
        error = "Emailadres lijkt niet geldig te zijn\n";
    } 
    else 
    {
        fld.style.background = 'White';
    }
    
    if (error != "") 
    {
    	alert("Fout!\n\n" + error);
    	return false;
    }
}

// Quote text 
function quoteid(oObjectID, UserName)
{
    // oObjectID
    var iText = document.getElementById(oObjectID).innerHTML;
	var re = /<[^>]*>/g;
	iText = iText.replace("\r\n", "");
	iText = iText.replace("\n", "");
	iText = iText.replace("\r", "");
	iText = iText.replace("<blockquote>", "[quote]")
	iText = iText.replace("</blockquote>", "[/quote]")
	iText = iText.replace(re, "");
	iText = iText.replace("quote:", "");
	iText = iText.replace(/^\s+/, "");
	iText = iText.replace(/\s+$/, "");
	iText = "[quote][b]"+UserName+" schreef:[/b]"+"\n\n"+iText+"[/quote]";
    document.forms['frmcomments'].elements['CommentText'].value += iText;
}

function ajaxSubmit(url, processingDiv, targetDiv)
{
	// alert (url +' '+ processingDiv +' '+ targetDiv);
	
targetArea = document.getElementById(targetDiv);
processingArea = document.getElementById(processingDiv);
 
var xmlHttp;
try
{ xmlHttp=new XMLHttpRequest(); }
catch (e)
{
 try
  { xmlHttp=new ActiveXObject('Msxml2.XMLHTTP'); }
   catch (e)
    {
    try
     { xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); }
    catch (e)
     {
      alert('Bravo! Your browser does not support AJAX!');
      return false;
     }
   }
 }
 
xmlHttp.onreadystatechange=function()
 {
  if(xmlHttp.readyState==4)
   {
    processingArea.style.display = 'none';
    targetArea.innerHTML = '(' + xmlHttp.responseText + ')';
   }
}

processingArea.style.display = 'block';
xmlHttp.open('GET',url,true);
xmlHttp.send(null);


}
 
function SubmitVote(type, id, score, scoretype, onwhat)
{
	ajaxSubmit("scorecomment/"+id+"/"+score+"/"+scoretype+"/"+onwhat, 'postid-'+id, 'postscore-'+id);
}


// Resize images
var resized_images_width = new Array();
var resized_images_height = new Array();
function fullscreen()
{
	scrollbars = 0;
	var oSource = window.event.srcElement.src;
	width = resized_images_width[oSource];
	height = resized_images_height[oSource];
	url = oSource;
	if(width > screen.availWidth){
		width = screen.availWidth;
		scrollbars = 1;
	}
	if(height > screen.availHeight){
		height = screen.availHeight;
		scrollbars = 1;
	}
	fullscr = window.open(url, "_blank","toolbar=no,location=no,menubar=no,fullscreen="+scrollbars+",channelmode="+scrollbars+",scrollbars="+scrollbars+",status=no,left=0,top=0,width="+width+",height="+height);
}

function resize(image)
{
	if(!image){
		var image = window.event.srcElement;
	}

	width = image.width;
	height = image.height;
	var url = image.src;
	
	if(width>420){
		resized_images_width[url] = width;
		resized_images_height[url] = height;
		image.width = 420;
		image.alt = "Klik om te vergroten naar : "+width+"x"+height;
		image.style.border = "dashed 1px black";
		image.style.cursor = "hand";
		image.onclick = fullscreen;
		image.height = Math.floor(height/(width/420));
	}
}

function check_images()
{
	count = document.images.length;
	i = 0;
	while(count>i){
		url = document.images[i].src;

		if(!url.match(/(zqcentral.com)/) && !url.match(/www.zqcentral.com/)){
			if(document.images[i].complete){
				resize(document.images[i]);
			}else{
				document.images[i].onload = resize;
			}
		}
		i++;
	}
}

//-- Message box editing functions
var target = null;
function initMessageBox(controlname)
{
	target = document.getElementById(controlname);
	if (target)
	{
		target.focus();
	}
}

function det_replace(type, text)
{
	var val = '';
	switch (type)
	{
		case 'plain':
			break;
		case 'AND':
			if (text != '')	text = text.replace(/(\w+)\s+/g, '$1 AND ');
			else text = ' AND ';
			break;
		case 'OR':
			if (text != '')	text = text.replace(/(\w+)\s+/g, '$1 OR ');
			else text = ' OR ';
			break;
		case 'brackets':
			if (text != '')	text = '('+text+')';
			else text = '()';
			break;
		case 'title':
			if (text != '')	text = 'title:('+text+')';
			else text = 'title:';
			break;
		case 'start':
			if (text != '')	text = 'start:('+text+')';
			else text = 'start:';
			break;
		case 'bold':
			text = '[b]'+text+'[/b]';
			break;
		case 'italic':
			text = '[i]'+text+'[/i]';
			break;
		case 'underline':
			text = '[u]'+text+'[/u]';
			break;
		case 'strike':
			text = '[s]'+text+'[/s]';
			break;
		case 'sub':
			text = '[sub]'+text+'[/sub]';
			break;
		case 'sup':
			text = '[sup]'+text+'[/sup]';
			break;
		case 'small':
			text = '[small]'+text+'[/small]';
			break;
		case 'left':
			text = '[left]'+text+'[/left]';
			break;
		case 'center':
			text = '[center]'+text+'[/center]';
			break;
		case 'right':
			text = '[right]'+text+'[/right]';
			break;
		case 'listbullet':
			text = '[list]\r\n[*]'+(text.split(/\r?\n/).join('\r\n[*]'))+'\r\n[/list]';
			break;
		case 'listnum':
			text = '[list=1]\r\n[*]'+(text.split(/\r?\n/).join('\r\n[*]'))+'\r\n[/list]';
			break;
		case 'bgcolor':
			val = prompt('Voer een hexadecimale kleurcode in:','#');
			if (val !== null) text = '[bgcolor='+val+']'+text+'[/bgcolor]';
			break;
		case 'color':
			val = prompt('Voer een hexadecimale kleurcode in:','#');
			if (val !== null) text = '[color='+val+']'+text+'[/color]';
			break;
		case 'url':
			if (/^(http:\/\/|www\.)/i.test(text))
			{
				val = prompt('Voer omschrijving in:', text);
				if (val !== null && val != '') text = '[url='+text+']'+val+'[/url]';
			}
			else
			{
				val = prompt('Voer de URL in:','http:\/\/');
				if (val !== null && val != 'http:\/\/')
				{
					if (text == '') text = '[url]'+val+'[/url]';
					else text = '[url='+val+']'+text+'[/url]';
				}
			}
			break;
		case 'img':
			if (text == '')
			{
				val = prompt('Voer de URL in:','http:\/\/');
				if (val !== null && val != 'http:\/\/') text = '[img]'+val+'[/img]';
			}
			else
			{
				text = '[img]'+text+'[/img]';
			}
			break;
		case 'table':
			text = '[table border=1 width=350 cellpadding=2 bordercolor=#000000]\r\n[tr]\r\n[td]'+(text.split(/\r?\n/).join('[/td]\r\n[/tr]\r\n[tr]\r\n[td]'))+'[/td]\r\n[/tr]\r\n[/table]';
			break;
		case 'hr':
			text += '[hr]';
			break;
		case 'quote':
			text += '[/quote]\r\n[quote]';
			break;
	}

	return text;
}

function putStr(text)
{
	putExt('plain', text);
}

function putExt(type, text)
{
	
	if (target)
	{
		if (typeof target.cursorPos != 'undefined')
		{
			var cursorPos = target.cursorPos;
			if (type != 'plain') text = cursorPos.text;
			cursorPos.text = det_replace(type, text);
		}
		else if (typeof target.selectionStart != 'undefined')
		{
			// remember scrollposition
			var scrollTop = target.scrollTop;

			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			if (type != 'plain') text = target.value.substring(sStart, sEnd);
			text = det_replace(type, text);
			target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd);
			var nStart = sStart == sEnd ? sStart + text.length : sStart;
			var nEnd = sStart + text.length;
			target.setSelectionRange(nStart, nEnd);

			// reset scrollposition
			target.scrollTop = scrollTop;
		}
		else
		{
			if (type != 'plain') text = '';
			target.value += det_replace(type, text);
		}
		target.focus();
		if (typeof target.cursorPos != 'undefined') target.onselect();
	}
}

function showsmlwindow() 
	{
 		//remove a attribute if you don't want it to show up
 		var popit = window.open('/smlwindow.php','console','status,width=400,height=350');
 	}

function addSml( text )
			{
				var target = document.getElementById( "text" );
				if ( target )
				{
					if ( document.all && target.cursorPos)
					{
						var cursorPos = target.cursorPos;
						cursorPos.text = cursorPos.text.charAt(cursorPos.text.length - 1) == 'a ' ? text + ' ' : text;
						target.focus();
					}
					else
					{
						target.value += text;
						target.focus();
					}
				}
			}
					

function storeCursor(element)
			{
				if ( document.all && element.createTextRange )
					element.cursorPos = document.selection.createRange().duplicate();
			}
			
function WhichClicked(ww) {
        window.document.CommentText.waction.value = ww;
}

function submitonce(theform) {
        // if IE 4+ or NS 6+
        if (document.all || document.getElementById) {
                // hunt down "submit" and "reset"
                for (i=0;i<theform.length;i++) {
                        var tempobj=theform.elements[i];
                        if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
                                //disable it
                                tempobj.disabled=true;
                        }
                }
        }
}

function AddText(NewCode) {
        document.postmodify.text.value+=NewCode;
        document.postmodify.text.focus();
}

function smile() {
        AddTxt=" :) ";
        AddText(AddTxt);
}

function cry() {
        AddTxt=" :'( ";
        AddText(AddTxt);
}

function puh2() {
        AddTxt=" :P ";
        AddText(AddTxt);
}

function redface() {
        AddTxt=" :O ";
        AddText(AddTxt);
}

function biggrin() {
        AddTxt=" :D ";
        AddText(AddTxt);
}

function pukey() {
        AddTxt=" :r ";
        AddText(AddTxt);
}

function wink() {
        AddTxt=" ;) ";
        AddText(AddTxt);
}

function rc5() {
        AddTxt=" }:O ";
        AddText(AddTxt);
}

function frusty() {
        AddTxt=" |:( ";
        AddText(AddTxt);
}

function frown() {
        AddTxt=" :( ";
        AddText(AddTxt);
}


function devil() {
        AddTxt=" >:) ";
        AddText(AddTxt);
}

function sleepey() {
        AddTxt=" :Z ";
        AddText(AddTxt);
}

function bier() {
        AddTxt=" :b ";
        AddText(AddTxt);
}

function shiny() {
        AddTxt=" *D ";
        AddText(AddTxt);
}

function hippy() {
        AddTxt=" |) ";
        AddText(AddTxt);
}

function rasta() {
        AddTxt=" :% ";
        AddText(AddTxt);
}

function soulsmiley() {
        AddTxt=" :soul: ";
        AddText(AddTxt);
}

function ok() {
        AddTxt=" :ok: ";
        AddText(AddTxt);
}

function tfs() {
        AddTxt=" :tfs: ";
        AddText(AddTxt);
}

function confused() {
        AddTxt=" :? ";
        AddText(AddTxt);
}

function worshippy() {
        AddTxt=" _O_ ";
        AddText(AddTxt);
}

function bier2() {
        AddTxt=" )-8 ";
        AddText(AddTxt);
}

function thumbsup() {
        AddTxt=" :TUP: ";
        AddText(AddTxt);
}

function notgood() {
        AddTxt=" :TDW: ";
        AddText(AddTxt);
}

function shutup() {
        AddTxt=" :X ";
        AddText(AddTxt);
}

function fuckyou() {
        AddTxt=" :TF: ";
        AddText(AddTxt);
}

function anti() {
        AddTxt=" (A) ";
        AddText(AddTxt);
}

function bangyourhead() {
        AddTxt=" :BANG: ";
        AddText(AddTxt);
}

function bonk() {
        AddTxt=" 8)7 ";
        AddText(AddTxt);
}

function bye() {
        AddTxt=" :W ";
        AddText(AddTxt);
}

function dj() {
        AddTxt=" :LP: ";
        AddText(AddTxt);
}

function huh() {
        AddTxt=" :HUH: ";
        AddText(AddTxt);
}

function link() {
        AddTxt=" :LINK: ";
        AddText(AddTxt);
}

function no() {
        AddTxt=" :NO: ";
        AddText(AddTxt);
}

function yes() {
        AddTxt=" :YES: ";
        AddText(AddTxt);
}

function shout() {
        AddTxt=" :BRUL: ";
        AddText(AddTxt);
}

function bangyourheadhard() {
        AddTxt=" :HBANG: ";
        AddText(AddTxt);
}

function gaap() {
        AddTxt=" :GAAP: ";
        AddText(AddTxt);
}
