
///////////////////////////////////////
//                                   //
//        Updated: 23-02-2007        //
//           Graffiti Wall           //
//      FileName: function.js        //
//    Written by midnightfun.co.uk   //
//       www.midnightfun.co.uk       //
//            Version 2.0            //
//     License: See license.html     //
//              © 2007               //
//                                   //
///////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
//                                                                         //
//             Editing is NOT allowed to any of the code below!            //
//                                                                         //
//   If you edit any of the code below this part the script may not work   //
//              and you will be in violation of the licence!               //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////

// Disable autocomplete on wall.
function autocomplete() {
	if (!document.getElementById) return false;
	var q = document.getElementById('graffiti');
	var z = q.elements[0];
	q.setAttribute("autocomplete", "off");
	z.focus();
}

// Disable page reload on post.
function empty() {
	return false;
}

// Disable paste in tag feild.
function validateKey(event) {
	if (event.keyCode==17 || event.keyCode==18 || event.keyCode==93 || event.keyCode==96) {
		document.getElementById("graffiti").painttext.value=""
		document.getElementById('bttnsubmit').disabled=true
        toggleLayer('hiddenLayerPaste');
		return false;
	}
}

// Disable right click in tag feild.
function right(event) {
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
var EnableRightClick = 0;
if(isNS) 
document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler() {
  if(EnableRightClick==1){ return true; }
  else {
return false; 
}
}
function mousehandler(e) {
  if(EnableRightClick==1) { return true; }
  var myevent = (isNS) ? e : event;
  var eventbutton = (isNS) ? myevent.which : myevent.button;
  if((eventbutton==2)||(eventbutton==3)) return false;
}
function keyhandler(e) {
  var myevent = (isNS) ? e : window.event;
  if (myevent.keyCode==96)
    EnableRightClick = 1;
  return;
}
document.oncontextmenu = mischandler;
document.onkeypress = keyhandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
} 

// Open update window.
function openwindowupdate() {
	window.open ("./update.php","update","width=600,height=175,scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,");
}

// Open userlog window.
function openwindowuserlog() {
	window.open ("./log.php","userlog","width=730,height=500,scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,");
}

// Open help window.
function openwindowhelp() {
	window.open ("./help.php","help","width=300,height=400,scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,");
}

// Open info window.
function openwindowinfo() {
	window.open ("./info.php","info","width=300,height=400,scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,");
}

// Open last wall window.
function openwindowwall() {
	window.open ("./last_wall.php","wall","width=440,height=330,scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,");
}

// Enable tag button.
function enableField(f,v){ 
	v.length<1?f['bttnsubmit'].setAttribute('disabled',true):f['bttnsubmit'].removeAttribute('disabled'); 
} 

// Read cookies.
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Post function.
function postLimit() {
    if (readCookie('graffiti_wall')) {
        toggleLayer('hiddenLayerPost')
        document.getElementById('bttnsubmit').disabled=true
        document.getElementById("graffiti").painttext.value=""
    } else {
        toggleLayer('hiddenLayerLoad')
        createCookie('graffiti_wall',1)
        addtag(this.value)
		document.getElementById('last-tag').innerHTML="Last Graffiti Tag Was: 0 minutes ago"
    }
}

// Wipe function.
function wipeLimit() {
	createCookie('post',1);
    if (readCookie('post')) {
    if (readCookie('graffiti_wall')) {
        toggleLayer('hiddenLayerWipe')
    } else {
        toggleLayer('hiddenLayerUserwipe')
        createCookie('graffiti_wall',1)
		clearwall(this.value)
		document.getElementById('last-tag').innerHTML="Last Graffiti Tag Was: 0 minutes ago"
    }
    } else {
		disable()
        toggleLayer('hiddenLayerCookie')
	}
}

// Validate tag input.
function validate(f) {
	createCookie('post',1);
    if (readCookie('post')) {
    if(f['painttext'].value.split(' ').length<2) {
        toggleLayer('hiddenLayer')
        document.getElementById('bttnsubmit').disabled=true
        document.getElementById("graffiti").painttext.value=""
    } else {
        postLimit()
    } 
    } else {
		disable()
        toggleLayer('hiddenLayerCookie')
	}    
} 

// Switch layers on and off.
function toggleLayer(whichLayer) {
	if (document.getElementById) {
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
} else if (document.all) {
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display? "":"block";
} else if (document.layers) {
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display? "":"block";
  }
}

// Javasript error handling.
var errorHandler = function(msg, url, linenumber) {
 alert("Error: " + msg + " for " + url + " at " + linenumber);
};
window.onerror = errorHandler;
