function askQuestionButton() {
		var nameValue;
		var emailString;
		var emailString2;
		var emailLength;
		var emailExtension;
		var titleString;
		var zipString;
		var phoneString;
		var questionString;
		var formAnswers;
		var terms;
		var category;
		var sc;

		formAnswers = "";

		zipString = document.formage.zip.value;
		phoneString = document.formage.user_phone.value;
		nameValue = document.formage.user_name.value;
		emailString2 = document.formage.ruser_email.value;
		emailString2 = emailString2.toLowerCase();
		emailString = document.formage.user_email.value;
		emailString = emailString.toLowerCase();
		titleString = document.formage.user_title.value;
		questionString = document.formage.user_question.value;
		sc = document.formage.security_code.value;
		terms = document.formage.terms.checked;
		
		
		
		if (terms == false) {
			formAnswers += "Please read our Terms and Conditions of Use and check the box to signify you understand.\n";
		}
		
		if (nameValue == "") {
			formAnswers += "Please Fill in Your Name.\n";
		}
		
		// If the category field exists (i.e. front page) check it
		if (document.formage.category)
		{
			if (document.formage.category.value == 0) {
				document.formage.action = "index.php?m=0&page=question";
			}
		
			if (document.formage.category.value == -1) {
				formAnswers += "Please choose the appropriate question category.\n";
			}
		}
		
		if (emailString == "") {
			formAnswers += "Please Fill in Your Email Address.\n";
		} else {
			
			if ((emailString.search("@") == -1) ) {
				formAnswers += "Incorrect email format.\n";
			}
		}
		
		if (emailString != emailString2) 
		{
			formAnswers += "Email addresses do not match.\n";
		}

		if (titleString == "") {
			formAnswers += "Please Fill in a Quote Title.\n";
		}
		
		if (zipString == "") {
			formAnswers += "Please Fill in a Zip Code.\n";
		}

		if (phoneString == "") {
			formAnswers += "Please Fill in a Phone Number.\n";
		}

		if (questionString == "") {
			formAnswers += "Please Fill in a Quote description.\n";
		}

		if (sc == "") {
			formAnswers += "Please Fill in the security code.\n";
		}

		if (formAnswers != "") {
			window.alert("Sorry the form could not be submitted!\n\n" + formAnswers);
			return false;
		}

		else 
		{
			return true;
		}
}

function reload() { 
  window.location.reload();
  return true;
}

var cok = false; // global code to check security
function checkcode(sc,nameValue,emailString,titleString,questionString,citystate,category,phone) 
{
    document.getElementById('fisheyefool').innerHTML = "Emailing...";
	AjaxRequest.get(
      { 'url':'/process/nationalQuestion.php?sc='+sc+"&nameValue="+nameValue+"&emailString="+emailString+"&titleString="+titleString+"&questionString="+questionString+"&citystate="+citystate+"&category="+category+"&phone="+phone   
        ,'onSuccess': function(req) { handlecheckcode(req); }
      });
}

function handlecheckcode(req) { 
  var html = req.responseText.split('~');

  if(html[0] == 'bad')
  {
    alert("Security code did not match image.\nPlease re-enter the security code.");
    document.getElementById('fisheyefool').innerHTML = html[1]; 
  }
  else
  {
    document.getElementById('fisheyefool').innerHTML = html[1]; 
  } 
  return true;
}

function askQuestionButtonNational() {
//alert("test");
		var nameValue;
		var emailString;
		var emailString2;
		var emailLength;
		var emailExtension;
		var titleString;
		var questionString;
		var formAnswers;
		var terms;
		var citystate;
        var sc;
		var phone;
		formAnswers = "";
	
		phone = document.formage.user_phone.value;
		sc = document.formage.security_code.value;
		nameValue = document.formage.user_name.value;
		emailString = document.formage.user_email.value;
		emailString = emailString.toLowerCase();
		emailString2 = document.formage.ruser_email.value;
		emailString2 = emailString2.toLowerCase();
		titleString = document.formage.user_title.value;
		questionString = document.formage.user_question.value;
		terms = document.formage.terms.checked;
		citystate = document.formage.citystate.value;
        var lst = document.getElementById('category');
        var idx = document.getElementById('category').selectedIndex;
        var category = lst.options[idx].value+'';
		
        if((document.formage.ok[0].checked) && phone == "" )
	    {
			formAnswers += "Phone number required for quotes.\n";
		}
		if (sc == "") {
			formAnswers += "Please Fill in the security code.\n";
		}

		if (terms == false) {
			formAnswers += "Please read our Terms and Conditions of Use and check the box to signify you understand.\n";
		}
		
		if (nameValue == "") {
			formAnswers += "Please Fill in Your Name.\n";
		}
		
		if (citystate == "") {
			formAnswers += "Please Fill in Your City/State.\n";
		}

		// If the category field exists (i.e. front page) check it
		if (category == -1)
		{
			formAnswers += "Please select a category.\n";
		}
		
		if (emailString == "") {
			formAnswers += "Please Fill in Your Email Address.\n";
		} else {
			
			if ((emailString.search("@") == -1) ) {
				formAnswers += "Incorrect email format.\n"
			}
		}
		
		if (emailString != emailString2) 
		{
			formAnswers += "Email addresses do not match.\n";
		}

		if (titleString == "") {
			formAnswers += "Please Fill in a Question Title.\n";
		}
		
		if (questionString == "") {
			formAnswers += "Please Fill in a Question.\n";
		}

		if (formAnswers != "") {
			window.alert("Sorry the form could not be submitted!\n\n" + formAnswers);
			return false;
		}

		else 
		{
            cok = checkcode(sc,nameValue,emailString,titleString,questionString,citystate,category,phone);
			return cok;
		}
}

function checkForm()
{
	var errors = "";
	var form = document.formage;
	
	if(form.txtName.value == "") errors += "You must include your name.\n";
	if(form.txtEmail.value == "") errors += "You must include your email address.\n";
	if(form.txtTitle.value == "") errors += "You must include a question title.\n";
	if(form.txtQuestion.value == "") errors += "You must include a question.\n";
	if(!form.Terms.checked) errors += "You must agree to the Terms and Conditions of Use.\n";
	
	if(errors != "") {
		alert("Uh-oh, there have been some mistakes.\n\n" + errors);
		return false;
	} else {
		form.submit();
	}
}

function termsPopup(){
	var winX = 50;
	var winY = 50;
	
	var terms = window.open("/terms_popup.php", "terms", "left=" + winX + ",top=" + winY + ",width=730,height=600,scrollbars=yes,resize=yes");
	if(terms) terms.focus();
}


function popupWindowForVideo(x) {
    var winX = (screen.width/2) - 325;
    var winY = (screen.height/2) - 200;
   
    qWin = window.open(x, "blee", "left=" + winX + ",top=" + winY + ",width=350,height=300");
    //if(qWin) qWin.focus();
	return (false);
}

function popupWindow(x) {
	var winX = (screen.width/2) - 325;
	var winY = (screen.height/2) - 200;
	
	qWin = window.open(x, "blee", "left=" + winX + ",top=" + winY + ",width=750,height=400,scrollbars=yes,resizable=yes");
	if(qWin) qWin.focus();
}
function findmarket(mid)
{
  if (isInteger(mid))
  {
	  if(mid != 1 && mid != 0)
	  {
		window.location.href = 'http://www.myhomeimprovement.com/?m='+mid;
	  }
	  else if (mid == 1)
	  {
		window.location.href = 'http://www.myhomeimprovement.com/?page=new&m=24';
	  }
  }
  else
  {
	window.location.href = mid;
  }
}

function confirmNew(frm)
{
  var err = '';
  if(document.form1.user_name.value == '')
  {
    err += 'Please provide your name. \n';
  }
  
  if(document.form1.user_email.value == '')
  {
    err += 'Please provide your email address. \n';
  }
  if(document.form1.user_message.value == 'Please bring www.MyHomeImprovement.com to ...!')
  {
    err += 'Please send us your message. \n';
  }
  if(err == '')
  {
    return true;
  }
  else
  {
	alert(err);
    return false;
  }

}
