// JavaScript Document


function checkSignupQuestion(form)
{
	var fouten = "The following error(s) were found:\n\n";
	var fout = false;

	


    	
    if (form.username.value == "")
  	{
	   fout = true;
	   fouten = fouten + "The profile name is missing\n";
    }
    

    if (form.username.value != "")
    {
	var illegalChars = /\W/;
  	// allow only letters, numbers, and underscores
    	if (illegalChars.test(form.username.value)) {
	   fout = true;
	   fouten = fouten + "The profile name contains illegal characters.\n";
    	} 
    
    }
    
    
    

    if (form.Password.value != "")
    {

        if (form.confirmPassword.value != form.Password.value)
        {
            fout = true;
            fouten = fouten + "The passwords do not match\n";
        }
    }


    if(form.email.value == "")
    {
        fout = true;
        fouten = fouten + "The email addresss is missing\n";
    } else
    if(!check(form.email.value, "", 1))
    {
        fout = true;
        fouten = fouten + "The email addresss is incorrect\n";
    }



	if (form.category.value == 0)
	{
	   fout = true;
	   fouten = fouten + "Please select a category\n";
	}


	if (form.question.value == "")
	{
	   fout = true;
	   fouten = fouten + "The question is missing\n";
	}    	

    	
    	
    	
	if (fout)
		alert(fouten);
	else
		form.submit();
		
		
}




function checkSendQuestion(form)
{
	var fouten = "The following error(s) were found:\n\n";
	var fout = false;

	


	if (form.category.value == 0)
	{
	   fout = true;
	   fouten = fouten + "Please select a category\n";
	}


	if (form.question.value == "")
	{
	   fout = true;
	   fouten = fouten + "The question is missing\n";
	}    	

    	
    	
    	
	if (fout)
		alert(fouten);
	else
		form.submit();
		
		
}






function checkChangeQuestion(form)
{
		var fouten = "The following error(s) were found:\n\n";
		var fout = false;
		var fckQuestion = FCKeditorAPI.GetInstance('question');
	

  	if (fckQuestion.GetHTML() == "<br type=\"_moz\" />")
  	{
		fout = true;
		fouten = fouten + "The question is missing\n";	   
    	}


    
	if (form.category.value == 0)
	{
	   fout = true;
	   fouten = fouten + "Please select a category\n";
    	}
    	    	
	if (form.SEO_URL.value == "")
	{
		fout = true;
		fouten = fouten + "The Rewrite URL is missing\n";
	} else
	if (form.SEO_URL.value.match(" ") == " ")
	{
		fout = true;
		fouten = fouten + "Don't use spaces in the Rewrite URL\n";
	}



    	
	if (fout)
		alert(fouten);
	else
		form.submit();
		
		
}
    


function checkChangeQuestionFrontEnd(form)
{
		var fouten = "The following error(s) were found:\n\n";
		var fout = false;

	
	if (form.title.value == "")
  	{
	   fout = true;
	   fouten = fouten + "The title is missing\n";
    	}
    
	if (form.category.value == 0)
	{
	   fout = true;
	   fouten = fouten + "Please select a category\n";
    	}
    	
	if (form.test_img.value.toString().length <= 0) {
	   if (form.Image.value == "")
		{
		   fout = true;
		   fouten = fouten + "The image is missing\n";
		}
	}
    	

    	
	if (fout)
		alert(fouten);
	else
		form.submit();
		
		
}



function checkChangeQuestionComment(form)
{
		var fouten = "The following error(s) were found:\n\n";
		var fout = false;
		var fckComment = FCKeditorAPI.GetInstance('comment');
	
  	if (fckComment.GetHTML() == "<br type=\"_moz\" />")
  	{
        fout = true;
        fouten = fouten + "The comment is missing\n";	   
    }
    	
    	
	if (fout)
		alert(fouten);
	else
		form.submit();
		
		
}



function checkChangeQuestionCommentFrontEnd(form)
{
		var fouten = "The following error(s) were found:\n\n";
		var fout = false;
	
	if (form.comment.value == "")
  	{
	   fout = true;
	   fouten = fouten + "The comment is missing\n";
    	}
    	
	if (fout)
		alert(fouten);
	else
		form.submit();
		
		
}





var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads()
{
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	var inP = document.createElement('input');
	inP.className = 'fakeFileButton';
	fakeFileUpload.appendChild(inP);
	var image = document.createElement('img');
	image.src='img/btn_browse.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].relatedElement.size = '35';
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

