var custommode;
function I(obj) {
	if (editmode=="content" || custommode=="content") {
		activeImg=obj;

		str="";
		propertiesWindow=window.open("?window=pb_properties&menuid="+menuid,"propertiesWindow","status,scrollbars,resizable=yes,height=500,width=650");
		propertiesWindow.focus();
	}
	else {
		what=obj.getAttribute('action');
		if (what==1) {
			return true;
		}
		if (what==3) {
			imgBig=window.open('?window=enlarge&dirStr='+encodeURI(obj.src),'big','menubar=no, status=no, location=no, scrollbars=no');imgBig.focus();
		}
		if (what==2) {
			newBrowser=window.open(obj.getAttribute('url'),'newBrowser');
			newBrowser.focus();
		}
		if (what==4) {
			document.location.href=obj.getAttribute('url');
		}
	}
}

function setSession(){
	var itemcount = setSession.arguments.length;
	var requestStr="";
  for (i = 0;i < itemcount;i+=2){
  	requestStr+="&name[]="+setSession.arguments[i]+"&value[]="+setSession.arguments[i+1];
	}
	sessionImage = new Image();
	sessionImage.src="blueprint/session.php?"+requestStr;
}

function init() {

	createSpecialHTML(((editmode=='content')?true:false));
	if (editmode!='content') createMP3Links();



}
function custom_functions_after_paste() {

}

$(function(){
	var posCTRL = false;
	if (editmode) {
		$(document).keypress(function(event){
			if(event.keyCode==17) {
				if (cmenu)hideContextMenu();
				else{
					if (editmode=="content" || custommode=="content") {
						knoppressed=true;
						if (changed) {
							if  (confirm('Are you sure you want to go back and discard changes?')) url('?menuid='+menuid+'&editmode=start');
						}
						else url('?menuid='+menuid+'&amp;editmode=start');
					}
					else if (editmode=="menu") url('?menuid='+menuid+'&amp;editmode=start');
					else if (editmode=="start") if (confirm("Are you sure you want to log out?")) url('?menuid='+menuid+'&login=logout');
				}
			}
		});
	}
	$(document).keydown(function(event){

		if(event.keyCode==17) {
			posCTRL = true;
		}
		else if (posCTRL && event.keyCode == 13) {
			jumpToEditMode();
			posCTRL = false;
		}


	});
	$(document).keyup(function(event){
		posCTRL = false;

	});


	$("select[extendable='true']").each(function(){

		var new_input_id='extend_'+$(this).attr('name');
		var optionwidth = this.offsetWidth;
		$(this).before('<input type="text" name="'+$(this).attr('name')+'" id="'+new_input_id+'" />');
		this.name=new_input_id;
		$('input#'+new_input_id).css({
			position:'absolute',

			width:(optionwidth-22)+'px'
		});

		$(this).change(function(){
			$('input#'+this.name).val(this.options[this.selectedIndex].text);
		}).change();

	});

	$('#linked form').each(function(){
		this.onsubmit = function() {
			var allfieldsok=true;
			$('#linked form input.required').each(function(){
				if (this.value=='') {
					this.style.backgroundImage='url(blueprint/img/required.gif)';
					allfieldsok=false;
				}
				else {
					this.style.backgroundImage='url(blueprint/img/required_ok.gif)';

				}
			});
			if (!allfieldsok) {
				alert('Niet alle verplichte velden zijn ingevuld!');
				return false;
			}
		}
	});
	$('input#gebruikersnaam').focus();


});

function check_live_required() {
	inputobjs=document.getElementsByTagName('input');
	var t=inputobjs.length;
	var i;
	for(i=0; i<t; i++) {
		if(inputobjs[i].className.match(/required/)) {
			inputobjs[i].onchange=check_me;
		}
	}
}

function required_message(str) {
		var obj;
		if (obj=d('requiredmessage')) {
			obj.style.backgroundImage="url(site/img/required_msg.gif)";
			obj.innerHTML=str;
		}
}


function check_me() {
	if (this.type=='checkbox') {
		if (this.checked) {
			this.parentNode.style.border="";
		}
		else {
			this.parentNode.style.border="1px solid #ff0000";
		}
	}
	else {
		if (this.value=="") this.style.backgroundImage="url('site/img/required.gif')";
		else this.style.backgroundImage="url('site/img/required_ok.gif')";
	}
}



function check_fields() {
	var spamprotect=document.getElementById('spamprotect');
	if (spamprotect) spamprotect.value='ok';
	inputobjs=document.getElementsByTagName('input');
	var t=inputobjs.length;
	var i;
	var allok=true;
	for(i=0; i<t; i++) {
		if(inputobjs[i].className.match(/required/)) {

			if (inputobjs[i].type=='checkbox') {
				if (!inputobjs[i].checked) {
					inputobjs[i].parentNode.style.border="1px solid #ff0000";
					allok=false;
				}
				else {
					inputobjs[i].parentNode.style.border="";
				}
			}
			else {

			if (inputobjs[i].value=="") {
				inputobjs[i].style.backgroundImage="url('site/img/required.gif')";
				allok=false;

			}
			else {
				if (inputobjs[i].getAttribute('check_type')=='email'){
					if (jsGvldtEmail(inputobjs[i].value)) {
						inputobjs[i].style.backgroundImage="url('site/img/required_ok.gif')";
					}
					else {
						allok=false;
						inputobjs[i].style.backgroundImage="url('site/img/required.gif')";
					}
				}
				else {
					inputobjs[i].style.backgroundImage="url('site/img/required_ok.gif')";
				}
			}
			}

		}
	}
	if (!allok) alert("Niet alle verplichte velden zijn ingevuld!");
	return allok;
}


//Global Validation for Email Address , allowing only "@","_", "." as special characters

function jsGvldtEmail(aString)
{
  var i=0;
  atSigns = 0;
  dots = 0;

	if(jsGvldtCheckMailChars(aString))
	{
	for (i = 0; i < aString.length; i++)
	{
		if ((aString.charAt(i) == '@') && (i > 0) && (i < aString.length - 1))
		  ++atSigns;
	    if ((aString.charAt(i) == '.') && (i > 0) && (i < aString.length - 1))
	      ++dots;
		if (aString.charAt(i) == ' ')  			// Never any blanks allowed!
			return false;

	}
	}
	else
		return false;


	if ((atSigns == 1) && (dots > 0) && (aString.charAt(aString.length - 1) !=
                 '.') && (aString.charAt(0) != '.'))
	{
         return true;
	}
    else
        return false;

}


/*
	Function Name: jsGvldtCheckMailChars
	Function Desc: This function checks the special characters "@","_","-","." for checking emails addresses.
*/
    function jsGvldtCheckMailChars(str)
    	{
        var count;

       	if(str != " " && str !="")
    	 {

          	     var alpha = new Array("A","B","C","D","E","F","G","H","I","J",

                   "K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","@","_",".","-","/");

           		for (j = 0; j < str.length; j++)

    	   	{

    	    	count = 0;

                		for (i = 0; i < 32; i++)
    				{
    				      count++;

           	    		  		if (str.charAt(j).toUpperCase() == alpha[i])

    		 			  break;
    				}

    	   			if (count == 32)
    				{
    	   			if (isNaN(str.charAt(j)))
    					{

                    		  	return false;

    	   				}
    				}
    		}
    		  	//this.value = str.toUpperCase();
      	}
         return true;
     }
