var defaultStr = 'Type your question here.';
var defaultTxt = 'Please note that this space is only for feedback for this web site. If you require a response, please chat, email or call us by clicking on the icons on the left menu.';
var defaultTxtfr = 'Si vous souhaitez obtenir une réponse à vos questions au sujet de cette page ou de votre service Internet, choisissez une option dans le menu gauche pour nous contacter par clavardage, courriel ou téléphone.';
var d = document.questionForm;

function isBlank(q) {
  var d = document.questionForm;  
  var whitespace = new String(" \t\n\r");

  for (var i = 0; i<q.length; i++) {
    if (whitespace.indexOf(q.charAt(i)) == -1) {
      return false;
    }
  }

  return true;
}

function submitForm(){
  var d = document.questionForm;  
  
  if (!isValidForm())
    return;

  d.submit();
}

function isValidForm(){
  var d = document.questionForm;
    
  if (d.question.value==defaultStr  ||  isBlank(d.question.value)) {
    return false;
  }

  d.requestType.value='NormalRequest';
  return true;
}

function topTen(){
  var d = document.questionForm;
    
  d.requestType.value='TopQuestionsRequest';    
  d.submit();
}

function clearForm(){
  var d = document.questionForm;
  
  d.id.value=-1;
  d.reset();
  d.question.focus();
  d.question.value='';
}

function goTo(select, source) {
  var d = document.questionForm;
  var question = select.options[select.selectedIndex].text;
    
  d.requestType.value='NormalRequest';
  d.id.value=select.options[select.selectedIndex].value;
  d.question.value=question;
  d.source.value=source;    
  d.submit();
}

function ask(){
  var d = document.questionForm;
    
  d.requestType.value='ManualRequest';
  d.submit();
}

function irLink(id,title){
    var d = document.questionForm;
      
  d.id.value=id;
  d.question.value=title;
  d.submit();
}

function submitRating(){
	var d = document.ratingFormComment;  
	d.submit();
}

function submitRating2(rating){
	var d = document.ratingForm;
	d.ourRating.value = rating;
	d.submit();
}


var win_handle;
function openflashabsolute(filename, width, height, show_close) {
	// show_close: boolean value to indicate to show close buttons on bottom of popup,
	// new flash have these as part of the movies, older ones do not
	if(typeof(show_close) == 'undefined') {show_close = true;}

	if(show_close != true && show_close != false) {show_close = true;}

	window_width = width;
	// make popup higher in height, so account for bottom exit buttons
	if(show_close)
	{
		window_height = height + 50;
	}
	else
	{
		window_height = height;
	}

	win_handle = window.open ("http://service.sympatico.ca/tutorial/flashpopup.cfm?flashwidth=" + width + "&flashheight=" + height + "&filename=" + filename + "&show_close=" + show_close, "win_handle", "toolbar=no,dependent=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=yes,width=" + window_width + ",height=" + window_height);
}

function fontSize(){

//alert ('entering function');
var d = document.getElementById("textSize");
var size = d.options[d.selectedIndex].value;
//alert (size);

if (document.getElementById("mainInner")){
		var containerDiv = document.getElementById("mainInner");
		containerDiv.style.fontSize = size +"em";
		var containerDiv1 = document.adminSuggestionForm;
		if(containerDiv1 != null)
			containerDiv1.id.style.fontSize = size +"em";
		var containerDiv2 = document.suggestionForm;
		if(containerDiv2 != null)
			containerDiv2.id.style.fontSize = size +"em";

	}

}

function submitRatingYes(){
	var d = document.ratingFormComment; 
	var email = d.b1_email.value; 
	var comment = trim(d.longComments.value);
	var categoryArray = ["I would have...", "called Bell", "chatted with an online representative", "emailed Bell", "asked someone else", "left without an answer"];
	var e = document.forms['ratingFormComment'].processQuestionShort;
	
	if(checkSelect(e.options[e.selectedIndex].value) ){
	
		var selectList = categoryArray[e.options[e.selectedIndex].value];
		d.comment.value = comment + ' | ' + selectList + ' | ' + email;
		d.submit();
	}
}

function submitRatingOui(){
	var d = document.ratingFormComment; 
	var email = d.b1_email.value; 
	var comment = trim(d.longComments.value);
	var categoryArray = ["J'aurais...", "appelé Bell", "clavardé avec un représentant", "envoyé un courriel à Bell", "demandé de l'aide à quelqu'un d'autre", "quitté sans réponse"];
	var e = document.forms['ratingFormComment'].processQuestionShort;
	
	if( checkSelect(e.options[e.selectedIndex].value) ){
	
		var selectList = categoryArray[e.options[e.selectedIndex].value];
		d.comment.value = comment + ' | ' + selectList + ' | ' + email;
		d.submit();
	}
}

function submitRatingNo(){
	var d = document.ratingFormComment; 
	var feedback = trim(d.longComments.value);
	var email = d.b1_email.value;
	var radioBtn = '';
	var radioBtnsLen = d.pageFeedback.length;
	var e = document.forms['ratingFormComment'].processQuestionShort;
	
	var categoryArray = ["I will...", "chat with an online representative", "call Bell", "email Bell", "ask someone else"];
	var feedbackArray = ["Answer is incorrect", "Information is hard to understand or incomplete", "Content has spelling or grammatical mistakes", "Page did not display correctly"];
		
	for(i = 0; i < radioBtnsLen; i++){
		if(d.pageFeedback[i].checked){
			radioBtn = feedbackArray[i];
			i = radioBtnsLen;
		}
	}
	
	if(checkComment(feedback) &&  checkSelect(e.options[e.selectedIndex].value) ){
		var selectList = categoryArray[e.options[e.selectedIndex].value];
		d.comment.value =	selectList +
							' | '+ radioBtn +
							' | '+ feedback +
							' | '+ email;
		d.submit();
	}
}

function submitRatingNon(){
	var d = document.ratingFormComment; 
	var feedback = trim(d.longComments.value);
	var email = d.b1_email.value;
	var radioBtn = '';
	var radioBtnsLen = d.pageFeedback.length;
	var e = document.forms['ratingFormComment'].processQuestionShort;
	
	var categoryArray = ["J'aurais...", "clavardé avec un représentant", "téléphoner à Bell (310-SURF / 310-7873)", "envoyer un courriel à Bell ", "demander de l'aide à quelqu'un d'autre"];
	var feedbackArray = ["La réponse est inexacte", "L'information est difficile à comprendre ou incomplète", "Le texte contient des fautes de français", "La page ne s’est pas affichée correctement"];
		
	for(i = 0; i < radioBtnsLen; i++){
		if(d.pageFeedback[i].checked){
			radioBtn = feedbackArray[i];
			i = radioBtnsLen;
		}
	}
	
	if(checkComment(feedback) &&  checkSelect(e.options[e.selectedIndex].value) ){
		var selectList = categoryArray[e.options[e.selectedIndex].value];
		d.comment.value =	selectList +
							' | '+ radioBtn +
							' | '+ feedback +
							' | '+ email;
		d.submit();
	}
}

function checkComment(comment){
	var divs = document.ratingFormComment.getElementsByTagName("div");
	var errDiv;
	for(i = 0; i < divs.length; i++){
		if(document.ratingFormComment.getElementsByTagName("div")[i].getAttribute("id") == 'noCommentError'){
			errDiv = document.ratingFormComment.getElementsByTagName("div")[i];
		}
	}

	if (comment.length == 0){
		showError(errDiv);
		return false;
	}else{
		hideError(errDiv);
		return true;
	}
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function checkSelect(num){
	var divs = document.ratingFormComment.getElementsByTagName("div");
	var errDiv;
	for(i = 0; i < divs.length; i++){
		if(document.ratingFormComment.getElementsByTagName("div")[i].getAttribute("id") == 'noSelectError'){
			errDiv = document.ratingFormComment.getElementsByTagName("div")[i];
		}
	}
	
	if(num == 0){
		showError(errDiv);
		return false;
	}else{
		hideError(errDiv);
		return true;
	}
}

function showError(divId){
   divId.style.display="block";
}

function hideError(divId){
   divId.style.display="none";
}

