var lastscroll = 0;
var d = document;
var ie = /MSIE (\d+\.\d+);/.test(navigator.userAgent);

var debugDiv = false;

var code2 = '';
var code3  = '';

function addslashes(str) {
    return str.replace('/(["\'\])/g', "\\$1").replace('/\0/g', "\\0");
}

function bugReportHandler(x){
	if(x.responseText != ''){     		 
		var alertText = '';
		if(x.responseText.indexOf('|') > 0) {   		 
			var list = x.responseText.split('|');        		 
			var newLocation = list[1];
			alertText = list[0];        		 
		 }else{        		 
			alertText = x.responseText; 
		 }
	
		 alert(alertText);
	
		 if (newLocation) {    			 
			 document.location.href = newLocation;
			 return;
		 }
	
		 if ( x.responseText.indexOf('thank') > 0) {
			$('#loading').addClass('hidden');
			$('#captcha99').setValue('');
			$('#bugReportMessage').setValue('');
	 		updateCaptcha(99,'',110,50);
		 }
		 
		 if ( x.responseText.indexOf('captcha') > 0) {
			$('#loading').addClass('hidden');
			$('#captcha99').setValue('');
	 		updateCaptcha(99,'',110,50);
		 }
	
		$('#loading').addClass('hidden');
	}
}

function sendBugReport() {
	var message  = $('#bugReportMessage').getValue();
	var code     = $('#captcha99').getValue();
	var data     = $('#bugReportData').getValue();
	var userpage = $('#userpage').getValue();
	
    if(message != '' && code != '') {
		//make request
		$ajax('post',
					'/include/bug.php',
					{
						code : code,
						message : message,
						bdata : data,
						userpage : userpage
					},
					{
						success : bugReportHandler
					}
		);
		
		$('#loading').removeClass('hidden');
    } else {
    	if(message == ''){
        	alert('Please provide a description of the bug');
        	$('#loading').addClass('hidden');
    	} else if(code == ''){
    		alert('Please enter the letters in the captcha image');
    		$('#loading').addClass('hidden');

    	}
    }
}

window.size = function() {
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		h = window.innerHeight;
	}

	return h;
}

function getScrollTop(){
    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B = document.body; //IE 'quirks'
        var D = document.documentElement; //IE with doctype
        D = (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

function floatDebug() {
	if(document.getElementById('feedbackFloat')){
		debugDiv = document.getElementById('feedbackFloat');
		debugDiv.style.position = 'absolute';
		var scrolled = getScrollTop();
		var docHeight = window.size();
		debugDiv.style.top = docHeight - 75 + scrolled + 'px';
	}
}

if(ie == true) {
	//setInterval('floatDebug()',300);
}


function bugreportHideFloat() {
	var t = new Date();
	t = new Date(t.getTime() +1000*60*60*24*30);
	document.cookie = 'bugreport_hide_float=true; expires='+t.toGMTString()+';';
	document.getElementById('feedbackFloat').style.display = 'none';
}
//--End--//
