// JavaScript Document
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;}
/*function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}*/
function validate_form(){
  var fname = document.getElementById('fname').value;
  var lname = document.getElementById('lname').value;
  var companyname = document.getElementById('companyname').value;
  var email = document.getElementById('email').value;
  var phone = document.getElementById('phone').value;
  var fax = document.getElementById('fax').value;
  var country = document.getElementById('country').value;
  var security = document.getElementById('security_code').value;
  var state = ''
  if(document.getElementById('state2').value != ''){
    state = document.getElementById('state2').value;
  }else if(document.getElementById('state3').value != ''){
    state = document.getElementById('state3').value;
  }else{
    state = 'not applicable';}
  var error = '';
  if(fname.search(/[a-zA-Z]+[\-]?[a-zA-Z]+/) == -1){
    error += 'First name\n';}
  if(lname.search(/[a-zA-Z]+[\-']?[a-zA-Z]+/) == -1){
    error += 'Last name\n';}
  if(companyname != ''){
    if(companyname.search(/[a-zA-Z0-9]+[-' ]?[a-zA-Z0-9]+/) == -1){
      error += 'Company name\n';}}
  if(email.search(/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/) == -1){
    error += 'Email address\n';}
  if(phone.search(/^[0-9 \. \(\)\-]+$/) == -1){
    error += 'Phone number\n';}
  if(fax != ''){
    if(fax.search(/^[0-9 \. \(\)\-]+$/) == -1){
      error += 'Fax number\n';}}
  if(country.search(/[a-zA-Z ]+/) == -1){
    error += 'Country\n';}
  if(state.search(/[a-zA-Z ]+/) == -1){
    error += 'State/Province\n';}
  if(security.search(/[a-zA-Z0-9]+/) == -1){
    error += 'Security Code\n';}
  if(error != ''){
    alert("The following fields were not filled out correctly:\n" + error);
    return false;}
  return true;}
function toggle_hide(){
  var country = document.getElementById('country').value;
  var us = document.getElementById('drop_us');
  var can = document.getElementById('drop_can');
  var empty = document.getElementById('drop_empty');
  document.getElementById('state1').selectedIndex = 0;
  document.getElementById('state2').selectedIndex = 0;
  /*Should be a function*/					
  if(country == 'Canada'){
    us.style.display = 'none';
	empty.style.display = 'none';
    can.style.display = 'block';
  }else if(country == 'United States of America'){
    can.style.display = 'none';
	empty.style.display = 'none';
    us.style.display = 'block';
  }else{
    can.style.display = 'none';
    us.style.display = 'none';
    empty.style.display = 'block';
  } }
function rollTD(id1,id2,color1,color2){
  document.getElementById(id1).style.backgroundColor = color1;
  document.getElementById(id2).style.backgroundColor = color2;}
function show_info(array_pos){
  var info_text = new Array();
  info_text [0] = '<div class="checkBoxheader">Website Development</div>Design & Integration, Programming & Core Implementation, User Experience, Interactivity Scripting & Animation, Updates & Maintenance, Hosting & Domain Registration, Content Management System, Ecommerce Platform.';
  info_text [1] = '<div class="checkBoxheader">Print &amp; Media Design</div>Annual Report, Catalogue Design, Brochure Design, Flyer Design, Label Design, Stationery Design,	Newsletter Design, Packaging Design, Postcard Design, Poster Design, Presentation Folder Design, Manuals, Illustrations, Exhibit Display Design, Logo Design, Pamphlet Design, Menu Designs, Other Designs.';	 
  info_text [2] = '<div class="checkBoxheader">Branding</div>Advertising Consulting, Advertising Media Strategies, Direct Mail Advertising, Billboard & Transit Advertising, Point of Purchase Advertising, Advertising Design, Positioning Strategies, Event Marketing & Planning, Promotional Concepts, Marketing Mix Analysis, Marketing Strategies';
  info_text [3] = '<div class="checkBoxheader">Advertising &amp; Marketing</div>Advertising Media Strategies, Direct Mail Advertising, Billboard & Transit Advertising, Point of Purchase Advertising, and Advertising Design';
  info_text [4] = '<div class="checkBoxheader">Social Network Design &amp; Development</div>Facebook Design, Twitter Design, Youtube Design.';
  info_text [5] = '<div class="checkBoxheader">Internet &amp; Social Media Marketing</div>Online Marketing Consulting, Search Engine Optimization, Keyword Research, Social Marketing, Natural Link Buliding, Stategic Link Baiting, SEO Copywriting, Banner Ad Design, Article Syndication, HTML Newsletters, Pay Per Click Management, Email Campaigns, Infographics.';
  info_text [6] = '<div class="checkBoxheader">Copywriting</div>Web Copywriting, SEO Copywriting & Copyediting, Press Release Writing, Speech Writing, Newsletter & Blog Copywriting, Technical Writing, Promotional Material Writing.';
  info_text [7] = '<div class="checkBoxheader">Video Production &amp; Photography</div>Video Production, Corporate Videos, Tradeshow Videos, TV Commcercial Scripts, Product Photography, Staff Photography, Photo Manipulation.';	 	  	 
  info_text [8] = 'Roll over the check box or name for more info on our services.';
  
  document.getElementById('info_box').innerHTML = info_text[array_pos];
  if(array_pos == 11){
    document.getElementById('info_box').style.backgroundColor = '#F0F0F0';
  }else{
    document.getElementById('info_box').style.backgroundColor = '#f69040';
  }}
function create_request(){
  var request;
  try{
    // Firefox, Opera 8.0+, Safari
    request = new XMLHttpRequest();
  }catch (e){
    // Internet Explorer
    try{
      request = new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      try{
        request = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
        alert("Your browser does not support AJAX!");
        return false;
      }}}
  return request;}
function check_email_duplicate(){
  request = create_request();
  var emailAddress = document.getElementById('email').value;
  request.onreadystatechange = email_duplicate
  request.open("GET", "checkMail.php?email=" + emailAddress, true);
  request.send(null);}
function email_duplicate(){
  if(request.readyState==4){
    if(request.responseText == 'true'){
	  document.getElementById('email').value = 'Already registered!';
	  document.getElementById('email').style.backgroundColor = '#cc0000';
	  document.getElementById('email').style.color = '#FFFFFF';
	  document.getElementById('email').style.fontWeight = 'bold';}}}
function clear_email_field(){
  document.getElementById('email').style.backgroundColor = '#ffffff';
  document.getElementById('email').style.color = '#000000';
  document.getElementById('email').style.fontWeight = 'normal';}
