
function siteIsUp() {
  return true;
}

function QnB_cv() {
  return true;
}


function navigateQnB(product_name, mediaTag) {
  if (siteIsUp()) {
    if (product_name == 'commercial_vehicle') {
        if (QnB_cv()) {
            product_name = 'cv1';
            window.open( qnb_path()+'qualification.jsp?brandId=PREML&product_name='+product_name+'&mediaTag='+mediaTag,
                '',
                'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
        return;
        } else {
             window.location = ('http://www.premierlinedirect.co.uk/scripts/quote.cgi?product_name='+product_name+'');
        return;
        }
    }
    window.open( qnb_path()+'qualification.jsp?brandId=PREML&product_name='+product_name+'&mediaTag='+mediaTag,
                '',
                'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    return false;
  }
  else {
    window.location = ('http://www.premierlinedirect.co.uk/scripts/quote.cgi?product_name='+product_name+'');
    // alert ("We are sorry we have had to take this section of our site down for a while.  Please try again later or call the number at the top of the page for personal assistance.");
  }

}


function quickLinks(elem) {
    var destinationUrl = elem.options[elem.selectedIndex].value;
    if(destinationUrl) location.href = destinationUrl;
    return;
}

function resetAlerts(fieldinput){
    var errorNameToReset = fieldinput + '_error';
    //alert(errorNameToReset);
    if (document.getElementById(errorNameToReset)){
      document.getElementById(errorNameToReset).style.visibility = 'hidden';
    } else{
      //alert("! Tamar Debug\r\r" + "Check document errors for: " + errorNameToReset)
    }
}

function nextSection(sectionId){
    document.forms['section_form'].next_section.value = sectionId;
}

function checkForm(form){
    var error = 0;
    var arrErrors = new Array();

    for (var i in mandFields) {
      var name = 'attr_' + mandFields[i];
      var value = form.elements[name].value;
      document.getElementById(name + "_error").style.visibility = 'hidden';

      //alert(name + " " + value);

      if (value) {
        if (value == '') {
            error += 1;
            errorName = name + '_error';
            arrErrors[arrErrors.length] = errorName;
        }
      } else {
        var radioError = 1
        for (var r=0; r < form.elements[name].length; r++){
          if (form.elements[name][r].checked){
            radioError = 0;
          }
        }
        if (radioError) { 
          error += 1
          errorName = name + '_error';
          arrErrors[arrErrors.length] = errorName;
        } 
      }
    }
    
    if (error > 0) {
        showErrors(arrErrors);
        alert('Please complete all mandatory fields ');
        return false;
    }
    else {
        return true;
    }
}

function showErrors(myErrorArray){
  for (t=0; t < myErrorArray.length; t++){
    //alert("here " + t);
    myErrorName = myErrorArray[t];
    //alert(myErrorName);
    if (document.getElementById){
      //alert(myErrorName);
      document.getElementById(myErrorName).style.visibility = 'visible';
    }
  }
}

function retrieveQuoteAppearance(mode){
  var email = document.getElementById('email_row');
  var postcode = document.getElementById('postcode_row');
 
  //if(mode=='hide'){
    // email.style.visibility = 'hidden';
    // postcode.style.visibility = 'hidden';
  //}
  if(email.style.visibility != 'visible'){
    email.style.visibility = 'hidden';         
    postcode.style.visibility = 'hidden';     
  }

 

  //else if(document.getElementById('quote_ref').value.match(/^\d{7,8}$/)){
  if(document.getElementById('quote_ref').value.match(/^\d{6,9}$/)){

  	if (siteIsUp()) {
    		window.open('https://secure.premierlinedirect.co.uk/qnb/faces/login.jsp?brandId=PREML&CustNo='+document.getElementById('quote_ref').value,
			    '','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    		return false;
  	}
  	else {
    		alert ("We are sorry we have had to take this section of our site down for a while.  Please try again later or call the number at the top of the page for personal assistance.");
    		return false;
  	}
  }
  else if(document.getElementById('quote_ref').value.match(/[a-zA-z]+/) && email.style.visibility == 'hidden'){
    email.style.visibility = 'visible';
    postcode.style.visibility = 'visible';
    return false;
  }
  else {
    return true;
  }
}
