function wvFeedbackClass(){

var wv_feedback_site_url = 'http://worldviewer.com/feedback';
var _self = this;

var wv_feedbac_background_div, wv_feedback_iframe, wv_feedback_window_id, ajax_busy, wv_feedback_ajax, wv_feedback_placehoder, wv_feedback_frm_display_btn, wv_feedback_frm_placeholder, wv_feedback_body_elem, wv_feedback_frame, wv_feedback_useful_stat, wv_feedback_button_caption, wv_feedback_button_class, wv_feedback_placehoder_id;

var wv_feedback_temp = document.getElementsByTagName('body');
wv_feedback_body_elem = wv_feedback_temp[0];

var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 
var olderBowser;
if (window.XMLHttpRequest) {
	olderBowser = false;
} else {
	olderBowser = true;
}
var opera = (navigator.userAgent.indexOf("opera") != -1);

this.setFrame = function(feedbackFrame){
	PRVsetFrams(feedbackFrame);
}

this.userName = '';
this.userEmail = '';

this.setUserName = function(userName){
	_self.userName = userName;
}

this.setUserEmail = function(userEmail){
	_self.userEmail = userEmail;
}

function PRVsetFrams(feedbackFrame){
	if(typeof(feedbackFrame)!='object'){
		feedbackFrame = Array();
	}
	if(typeof(feedbackFrame['width'])!='number'){
		feedbackFrame['width'] = 300;
	}
	if(typeof(feedbackFrame['height'])!='number'){
		feedbackFrame['height'] = 400;
	}
	
	if(typeof(feedbackFrame['border_width'])!='number'){
		feedbackFrame['border_width'] = 1;
	}
	if(typeof(feedbackFrame['border_color'])!='string' || (feedbackFrame['border_color'].length!=7 && feedbackFrame['border_color'].length!=6)){
		feedbackFrame['border_color'] = "CCCCCC";
	}
	else if(feedbackFrame['border_color'].length == 7){
		feedbackFrame['border_color'] = feedbackFrame['border_color'].slice(1);
	}
	
	if(typeof(feedbackFrame['background_color'])!='string' || (feedbackFrame['background_color'].length!=7 && feedbackFrame['background_color'].length!=6)){
		feedbackFrame['background_color'] = "FFFFFF";
	}
	else if(feedbackFrame['background_color'].length == 7){
		feedbackFrame['background_color'] = feedbackFrame['background_color'].slice(1);
	}
	wv_feedback_frame = feedbackFrame;
}

this.setUsefulStats = function(usefulStat){
	PRVsetUsefulStats(usefulStat);
}

function PRVsetUsefulStats(usefulStat){
	if(typeof(usefulStat)!='boolean'){
		usefulStat = false;
	}
	wv_feedback_useful_stat = usefulStat;
}
	
function PRVsetButtonCaption(caption){
	if(typeof(caption)!='string'){
		caption = 'Contact / Feedback';
	}
	wv_feedback_button_caption = caption;
	if(typeof(wv_feedback_frm_display_btn)=='object'){
		wv_feedback_frm_display_btn.value = caption;
	}
}
	
this.setButtonCaption = function(caption){
	PRVsetButtonCaption(caption);
}

this.setButtonClassName = function(btnClassName){
	PRVsetButtonClassName(btnClassName);
}
	
function PRVsetButtonClassName(btnClassName){
	if(typeof(btnClassName)!='string'){
		var btnClassName = false;
	}
	wv_feedback_button_class = btnClassName;
	if(typeof(wv_feedback_frm_display_btn)=='object'){
		wv_feedback_frm_display_btn.className = btnClassName;
	}
}

this.setPlaceholderId = function(placeholderId){
	PRVsetPlaceholderId(placeholderId);
}

function PRVsetPlaceholderId(placeholderId){
	if(typeof(placeholderId)!='string'){
		placeholderId = false;
	}
	wv_feedback_placehoder_id = placeholderId;
}


this.init = function(){
	var wv_feedback_old_onload = window.onload;
	window.onload = function(){
		if(typeof(wv_feedback_old_onload)=='function'){
			try{
				wv_feedback_old_onload();
			}
			catch(err){}
		}
		wv_feedback_init();
	}
	
	if(typeof(wv_feedback_placehoder_id)!='string'){
		self.document.write("<input type='button' id='wv_feedback_frm_display_btn'>");
		wv_feedback_frm_display_btn = document.getElementById('wv_feedback_frm_display_btn');
		wv_feedback_set_frm_display_btn(false);
		wv_feedback_placehoder = wv_feedback_frm_display_btn.parentNode;
	}
}


function wv_feedback_set_frm_display_btn(set_type){
	if(set_type){
		wv_feedback_frm_display_btn.type = 'button';
	}
	
	if(typeof(wv_feedback_button_caption)!='string'){
		PRVsetButtonCaption(false);
	}
	
	wv_feedback_frm_display_btn.value = wv_feedback_button_caption;
	
	if(typeof(wv_feedback_button_class)!='string'){
		PRVsetButtonClassName(false);
	}
	
	if(wv_feedback_button_class){
		wv_feedback_frm_display_btn.className = wv_feedback_button_class;
	}
	wv_feedback_frm_display_btn.onclick = _self.wv_feedback_display_form;
}


function wv_feedback_init(){
	
	if(typeof(wv_feedback_frame)!='object'){
		PRVsetFrams(false);
	}
	
	if(typeof(wv_feedback_placehoder_id)=='string'){
		wv_feedback_placehoder = document.getElementById(wv_feedback_placehoder_id);
		if(!wv_feedback_placehoder){
			return false;
		}
		wv_feedback_frm_display_btn = document.createElement('input');
		wv_feedback_set_frm_display_btn(true);
		wv_feedback_placehoder.appendChild(wv_feedback_frm_display_btn);
	}
	
	wv_feedback_frm_placeholder = document.createElement('div');
	wv_feedback_frm_placeholder.id = 'wv_feedback_frm_placeholder';
	wv_feedback_frm_placeholder.style.display = 'none';
	wv_feedback_frm_placeholder.style.border = "solid #"+wv_feedback_frame['border_color']+" "+wv_feedback_frame['border_width']+"px;";
	if(ie4){
		wv_feedback_frm_placeholder.style.position = 'absolute';
	}
	else{
		wv_feedback_frm_placeholder.style.position = 'fixed';
	}
	wv_feedback_body_elem.appendChild(wv_feedback_frm_placeholder);
}

_self.wv_feedback_display_form = function(){
	var wv_feedback_frm_placeholder_y_offset = 0;
	wv_feedback_frm_placeholder.innerHTML = '';
	
	
	wv_feedbac_background_div = document.createElement('div');
	wv_feedbac_background_div.id = 'wv_feedbac_background_div';
	wv_feedbac_background_div.style.zIndex = 199;
	wv_feedbac_background_div.style.width = '100%';
	wv_feedbac_background_div.style.height = '100%';
	wv_feedbac_background_div.style.backgroundColor = '#000000';
	if(ie4 && olderBowser){
		wv_feedbac_background_div.style.position = 'absolute';
		if(document.compatMode=='BackCompat'){
			wv_feedbac_background_div.style.top = document.body.scrollTop+'px';
			wv_feedback_frm_placeholder_y_offset = document.body.scrollTop;
		}
	}
	else{
		wv_feedbac_background_div.style.position = 'fixed';
	}
	
	if(!wv_feedbac_background_div.style.top){
		wv_feedbac_background_div.style.top = 0;
	}
	
	wv_feedbac_background_div.style.left = 0;
	wv_feedbac_background_div.style.filter = "alpha(opacity=85)";
	wv_feedbac_background_div.style.opacity = 0.85;
	wv_feedbac_background_div.style.MozOpacity = 0.85;
	
	wv_feedback_body_elem.appendChild(wv_feedbac_background_div);
	
	
	//close button
	var wv_feedback_frm_title_bar = document.createElement('div');
	wv_feedback_frm_title_bar.style.background = "url("+wv_feedback_site_url+"/images/title_bar_bg.gif) repeat-x";
	wv_feedback_frm_title_bar.style.textAlign = 'right';
	wv_feedback_frm_title_bar.style.paddingRight = '10px';
	var wv_feedback_temp = document.createElement('span');
	wv_feedback_temp.onclick = function(){ wv_feedback_close(); };
	wv_feedback_temp.innerHTML = 'Close';
	wv_feedback_temp.style.cursor = 'pointer';
	wv_feedback_temp.style.fontWeight = 'bold';
	wv_feedback_temp.style.color = '#BD1A1A';
	wv_feedback_frm_title_bar.appendChild(wv_feedback_temp);
	wv_feedback_frm_placeholder.appendChild(wv_feedback_frm_title_bar);
	

	
	wv_feedback_window_id = Math.random()+""+Math.random();
	wv_feedback_iframe =  document.createElement('iframe');
	wv_feedback_iframe.width = wv_feedback_frame['width'];
	wv_feedback_iframe.height = wv_feedback_frame['height']-22; // -22 for the title bar
	wv_feedback_iframe.scrolling = 'no';
	wv_feedback_iframe.frameborder = 0;
	
	var iframe_src = wv_feedback_site_url+"/index.php";
	iframe_src += "?op=reply";
	iframe_src += "&bg_color="+escape(wv_feedback_frame['background_color']);
	iframe_src += "&frame_height="+(wv_feedback_frame['height']-22); // -22 for the title bar
	iframe_src += "&window_id="+wv_feedback_window_id;
	iframe_src += "&page_url="+escape(window.location);
	
	if(_self.userName){
		iframe_src += "&name="+escape(_self.userName);
	}
	
	if(_self.userEmail){
		iframe_src += "&email="+escape(_self.userEmail);
	}
	
	if(typeof(wv_feedback_useful_stat)!='boolean'){
		PRVsetUsefulStats(false);
	}
	
	if(wv_feedback_useful_stat){
		iframe_src += "&useful_stat=1";
	}
	
	wv_feedback_iframe.src = iframe_src;
	
	wv_feedback_frm_placeholder.appendChild(wv_feedback_iframe);
	
	var windowHeight, windowWidth;
	if(ie4 && olderBowser){
		if(document.compatMode=='BackCompat'){
			windowHeight = document.body.clientHeight;
			windowWidth = document.body.clientWidth;
		}
		else{
			windowHeight = document.documentElement.clientHeight;
			windowWidth = document.documentElement.clientWidth;
		}
	}
	else if(ie4 && !olderBowser){
		windowHeight = document.documentElement.clientHeight;
		windowWidth = document.documentElement.clientWidth;
			
		/*if(opera){
			windowHeight = document.documentElement.clientHeight;
			windowWidth = document.documentElement.clientWidth;
		}
		else{
			windowHeight = document.body.clientHeight;
			windowWidth = document.body.clientWidth;
		}*/
		document.documentElement.scrollTop = 0;
	}
	else{
		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;
	}
	wv_feedback_frm_placeholder.style.top = ((windowHeight - wv_feedback_frame['height']) / 2 + wv_feedback_frm_placeholder_y_offset) + 'px';
	wv_feedback_frm_placeholder.style.left = ((windowWidth - wv_feedback_frame['width']) / 2) + 'px';
	
	wv_feedback_frm_placeholder.style.zIndex = 200;
	wv_feedback_frm_placeholder.style.display = 'block';
	
	makeScrollingBody();
}


//modify styles for IE
function makeScrollingBody(){
	if(ie4 && olderBowser){
		var html = document.getElementsByTagName('html');
		var bodyElem = document.getElementsByTagName('body');
		
		html[0].style.setAttribute('height','100%');
		html[0].style.setAttribute('overflow','auto');
		bodyElem[0].style.setAttribute('height','100%');
		bodyElem[0].style.setAttribute('overflow','auto');
	}
}

function makeUnScrollingBody(){
	if(ie4 && olderBowser){
		var html = document.getElementsByTagName('html');
		var bodyElem = document.getElementsByTagName('body');
		
		html[0].style.setAttribute('height','');
		html[0].style.setAttribute('overflow','');
		bodyElem[0].style.setAttribute('height','');
		bodyElem[0].style.setAttribute('overflow','');
	}
}

function wv_feedback_close(){
	wv_feedback_body_elem.removeChild(wv_feedbac_background_div);
	wv_feedback_frm_placeholder.style.display = 'none';
	makeUnScrollingBody();
}
}