// feed back related functions (dependency is jQuery)
// to send feed  feedback() should be called.
function sendfeedback(a,b){
	var x=$('#feedback')[0];
	var u='';
	for (var i=0;i<x.length;i++)
  	{
  		if(x.elements[i].checked==true) 
  			u = u+'&'+(x.elements[i].name)+'='+(x.elements[i].value);
		if(x.elements[i].type != 'radio'&& x.elements[i].type != 'checkbox')
			u = u+'&'+(x.elements[i].name)+'='+(escape(x.elements[i].value));
  	}
  	u=u+'&referrer='+escape(document.referrer)+'&current='+escape(document.URL)+'&postvar='+escape(b);
  	$.get('feedback.php?rAp='+a+u);
	
	var txt='<h3>Thank you</h3><div style="height:10px;"></div><div>Thank you for taking the time to write a feedback to us. We will send you a confirmation message to your trainchinese mailbox.</div>' + '<a  href=\'javascript:closefeedback()\'><img src="images/btn/close.gif" alt="Close" /></a>';
	includetxtfeedback(txt);
}

function feedback(a,b){ 
	var txt='<h3>Feedback</h3><form id="feedback"><div style="height:10px;"></div>'+'<div class="mec_line">What kind of feedback do you want to give?</div><div class="mec_line"><select id="Select1" name="typeFeedBack" size="1" ><option value="1">Suggest a new feature or improvement </option><option value="2">Report a technical problem with the site </option><option value="3">Found an error in the text (Chinese, Pinyin or English)</option><option value="4">I\'d like to ask a question </option></select></div><div class="mec_line">Please tell us your feedback as clearly as possible:</div><div class="mec_line"><textarea id="TextArea1" name="comment" style="width: 566px; height: 88px;"></textarea></div>'+'<div style="height:5px"></div><div class="mec_line"><a href="javascript:sendfeedback(\''+a+'\',\''+b+'\')"><img src="images/btn/send.gif" alt="Send feedback" /></a>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a  href=\'javascript:closefeedback()\'><img src="images/btn/close.gif" alt="Close" /></a></div>'+'<div style="height:5px"></div><div class="mec_line">Your username and the page you\'re viewing will be automatically included in the message. Thanks for your time.</div></form>';
includetxtfeedback(txt);	
}

var ie6OldOffset =0;
function includetxtfeedback(txt){
	var text='<center><div style="height:10px;"></div><div style="width:678px; height:auto"><div  style="width:678px; height:43px; background-image: url(\'images/back/alertbox_top.'+((browserVer=="ie6")?'gif':'png') +'\');"><div style=" width:100%; height:43px; text-align:right"><a href="javascript:closefeedback();" title="close window" style="position:relative"><img src="images/ico/exit.'+((browserVer=="ie6")?'gif':'png') +'" style="border:0px" /></a></div></div><div id="feedbackBody" style="width:678px; height:auto; background-image:url(\'images/back/alertbox_body.'+((browserVer=="ie6")?'gif':'png') +'\');"><div id="feedbackCntArea" style=" width:600px; margin:0px 20px 0px 20px; color:#666666; font-weight:bold; text-align:left; line-height:220%;">'+txt+'</div><div id="feedbackNoteArea" style="background-color:#878787"></div></div><div id="alb_foot"  style="width:678px; height:44px;"><img src="images/back/alertbox_foot.'+((browserVer=="ie6")?'gif':'png') +'" /></div></div></center>';
// check if feedbackSuperBox is there already
if(!$('#feedbackSuperBox').length){
	if(typeof document.body.style.maxHeight == "undefined"){
		$('body').prepend('<div id="feedbackSuperBox"><div id="feedbackBox"></div></div>');
	}else{
		$('body').prepend('<div id="feedbackSuperBox"></div><div id="feedbackBox"></div>');
	}
}
if(typeof document.body.style.maxHeight == "undefined"){
	$("#feedbackSuperBox").css({"top":"0","width":"100%","height":"100%","z-index":"1002","backgroundColor":"#333"});
	$("#feedbackBox").css({	"left":"15%", "top":"20%","z-index":"1003"});	
}else{
	$("#feedbackSuperBox").css({"position":"fixed","background":"transparent","top":"0","width":"100%","height":"100%","z-index":"1002","paddingTop":"100px","paddingLeft":"30%","backgroundColor":"#000","filter":"alpha(opacity=50)","-moz-opacity":"0.5","-khtml-opacity":"0.5","opacity":"0.5"});
	$("#feedbackBox").css({	"position": "fixed", "left":"15%", "top":"8%","z-index":"1003"});	
}

if(typeof document.body.style.maxHeight == "undefined"){
if(ie6OldOffset==0){
	// move to the top of the page
	if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant
    ie6OldOffset = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {  //DOM compliant
    ie6OldOffset = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { //IE6 standards compliant mode
    ie6OldOffset = document.documentElement.scrollTop;
  }
 }
	scroll(0,0);
}
$("#feedbackBox").html(text);
$("#feedbackBox h3").css({"width":"100%","backgroundColor":"#DD2F2F", "color":"#FFFFFF", "font-weight":"bold", "text-align":"center","padding":"3px 0px 3px 0px"}); 
if($("#feedbackBox").height()>screen.availHeight*3/4){
	$("#feedbackBox").css({'height':'50%','overflow':'auto'});
}
if (checkUserAgent('iPad')||checkUserAgent('iPod')||checkUserAgent('iPhone')) {
    $("#feedbackCntArea").css({'background-color':'#E1E1E1'});
    $("#feedbackNoteArea").html('If necessary use two fingers to scroll in the area above');
}	
$("#feedbackSuperBox").show();
$("#feedbackBox").show();
}
function checkUserAgent(vs) {
    var pattern = new RegExp(vs, 'i');
    return !!pattern.test(navigator.userAgent);
}

function closefeedback(){
	$("#feedbackBox").html('');
	$("#feedbackBox").hide();
	$("#feedbackSuperBox").hide();
	if(typeof document.body.style.maxHeight == "undefined"){
		$('#feedbackSuperBox').remove();	
		scrollTo(0,ie6OldOffset);
		ie6OldOffset=0; 
	}
	$('.ajaxtooltip').remove();
}
// end feed back related functions

