// JavaScript Document
function BugWindow(divid) {
	this.divid = divid
	this.div
	this.Init = function() {
		var div = AJS.$(divid)
		this.div = div
		
		
		//div.offsetWidth
		
	}
	this.show= function(hook) {
		if ( AJS.isElementHidden(this.div) ) 
		{
			AJS.showElement(this.div)
			AJS.setOpacity(AJS.$('tool_container'),0.3)
			}
		else {
			AJS.hideElement(this.div)
			AJS.resetOpacity(AJS.$('tool_container'),0.3)
			return 0;
		}
		
		if (hook) {
			var pos = getAnchorPosition(hook) 
			pos.x -= this.div.offsetWidth - hook.offsetWidth
			pos.y -= 30 + this.div.offsetHeight
			PosMill.InforcePos(this.div,pos)
			
		} else {
			
			
				var pos = PosMill.GetCenterView(this.div.offsetWidth,this.div.offsetHeight)
		
		}
		//alert(pos.y)
		PosMill.InforcePos(this.div,pos)
	},
	this.send = function() {
		
		var comment = AJS.$('bug_comment').value
		var subject = AJS.$('bug_subject').value
		var pageurl = AJS.$('lookupURL').value
		var from = AJS.$('bug_from').value
		
		comment = comment.replace(/\n/g,'^br^')

		
		//validate
		
		if ( !from.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/gi) ) {
			
			alert('Please retype your email an invalid email address was detected')
			return 0
		}
		
	
		
		_ajax = new microAjax('../ajax/ajaxmail.aspx?from='+from+'&comment='+comment+'&bugurl='+pageurl+'&subject='+subject+'&req=bug',AJS.bind(function(answer) {
																																	
				//var xmlroot = AJS.$bytc('root',null,answer																													  )[0]
				//answer.getElementsByTagName('answer')[0].firstChild.nodeValue
				
				var result = answer.getElementsByTagName('answer')[0].firstChild.nodeValue
				
				
				
				if (result != 'send') {
					alert('Send Failed ... You can manualy send bugs to bugs@best-seo-tools.net')
				} else {
					this.show()	
				}
																																	  },this),null,'xml')
		
	}
}