
// this is the common file for the turkey website


// check content of form, the full name, e-mail address and
// phone number and url, etc
function wof_form_verified(da_form) {


  var content_req_array = new Array();
  content_req_array[0] = da_form.signup_full_name.value;
  content_req_array[1] = da_form.signup_local_code.value;
  content_req_array[2] = da_form.signup_4digit_code.value;
  content_req_array[3] = da_form.signup_email.value;


  for (i = 0; i < content_req_array.length; i++) {
    if (content_req_array[i] == "") {
      alert('You have not filled in all the required fields, please check and rekey.');
	  document.wof_signup.signup_full_name.focus();	      
	  return false;
    }
  }



  // recheck to make sure that the e-mail is correctly formated
  var this_valid_email = checkEMail(da_form.signup_email.value,3);
  if (!this_valid_email){
    return false;
  }

  // recheck the phone number to see if any error are still there
  var this_valid_area_code = checkAreaPhone(da_form.signup_area_code.value);
  if (!this_valid_area_code) {
	return false;  
  }

  // recheck the phone number to see if any error are still there
  var this_valid_phone = checkPhone(da_form.signup_local_code.value);
  if (!this_valid_phone) {
	return false;  
  }

  // recheck the phone number to see if any error are still there
  var this_valid_phone_local = checkPhoneLocal(da_form.signup_4digit_code.value);
  if (!this_valid_phone_local) {
	return false;  
  }
  
  
  
  
  
  
/* 

  // recheck the fax phone number to see if any error are still there
  var this_valid_area_code = checkAreaPhone(da_form.guest_fax_area_Code.value);
  if (!this_valid_area_code) {
	return false;  
  }

  // recheck the fax phone number to see if any error are still there
  var this_valid_phone = checkPhone(da_form.guest_fax_home_Phone_Group.value,1);
  if (!this_valid_phone) {
	return false;  
  }

  // recheck the fax phone number to see if any error are still there
  var this_valid_phone_local = checkPhoneLocal(da_form.guest_fax_home_Phone_Local.value,1);
  if (!this_valid_phone_local) {
	return false;  
  }
*/



  // recheck to see that they have not entered specific database commands in some fields


  var this_valid_text_entry = checkTextData(da_form.signup_full_name.value.toUpperCase(),3);
  if (!this_valid_text_entry) {
	return false;  
  }

  // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextData(da_form.signup_address.value.toUpperCase(),3);
  if (!this_valid_text_entry) {
	return false;  
  }

  // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextData(da_form.signup_city.value.toUpperCase(),3);
  if (!this_valid_text_entry) {
	return false;  
  }

  // check the postal code, zip code area for proper data
  var this_valid_postal_zip = checkPostal(da_form.signup_postal_code.value, 1);
  if (!this_valid_postal_zip) {
	return false;  
  }


/*
  // recheck the state province to see if any error are still there
  var this_valid_state_province = checkStateProvince(da_form.guest_state_province.value);
  if (!this_valid_state_province) {
	return false;  
  }

  // recheck the country to see if any error are still there
  var this_valid_country = checkStateProvince(da_form.guest_country.value);
  if (!this_valid_country) {
	return false;  
  }

  // recheck the year to make sure that it is entered correctly
  var this_valid_year = checkYears(da_form.years.value);
  if (!this_valid_year) {
	return false;  
  }
*/

}




// check content of form, the full name, e-mail address and
// phone number and url, etc
function search_verified(search_form) {

  // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextSearchData(search_form.search_info.value.toUpperCase());
  if (!this_valid_text_entry) {
	return false;  
  }

}


// this function will check the area phone number against a regular Expression
// to see if it is valid.  
function checkAreaPhone(phone_num) {
  var msg = "That is not a valid area code for the phone number. Please re-type it.";

  // Check to see if the phone number has been entered properly
  var checked_phone = new RegExp("[0-9][0-9][0-9]");

  if (phone_num != '') {
    // checking the phone number against a regular expression
    if (phone_num.match(checked_phone) != null) {
      return true;  
    } else {
      alert(msg);
	  document.wof_signup.signup_area_code.focus();	
      return false;
    }
  }
  return true;
}


// this function will check the phone number group against a regular Expression
// to see if it is valid.  
function checkPhone(phone_num) {
  var msg = "That is not a valid 3 number group phone number. Please re-type it.";

  // Check to see if the phone number has been entered properly
  var checked_phone = new RegExp("[0-9][0-9][0-9]");

  if (phone_num != '') {
    // checking the phone number against a regular expression
    if (phone_num.match(checked_phone) != null) {
      return true;  
    } else {
      alert(msg);
	  document.wof_signup.signup_local_code.focus(); 
      return false;
    }
  }
  return true;
}

// this function will check the phone number local against a regular Expression
// to see if it is valid.  
function checkPhoneLocal(phone_num) {
  var msg = "That is not a valid 4 number local phone number. Please re-type it.";

  // Check to see if the phone number has been entered properly
  var checked_phone_Local = new RegExp("[0-9][0-9][0-9][0-9]");

  if (phone_num != '') {
    // checking the phone number against a regular expression
    if (phone_num.match(checked_phone_Local) != null) {
      return true;  
    } else {
      alert(msg);
      document.wof_signup.signup_4digit_code.focus();
      return false;
    }
  }
  return true;
}



// check to make sure that the person is in grades 5, 6, 7, 8 only.
// field already checked to make sure is not empty
function checkGrade(grade_entered) {
  var msg = "You have to be either in grade 5, 6, 7, or 8 to participate.";

  // Check to see if the phone number has been entered properly
  var checked_grade = new RegExp("[5-8]");

  if (grade_entered != '') {
    // checking the grade number against a regular expression
    if (grade_entered.match(checked_grade) != null) {
      return true;  
    } else {
      alert(msg);
	  document.turkey_contest.student_grade.focus();	
      return false;
    }
  }
  return true;
}



// this function will check the email information for the @ sign and the 
// period.  Also the @ sign could not be at the start of the email address
// or the period be anywhere near the end of the address.
function checkEMail(email_address, email_group) {
  // set up message variables
  var msg1 = 'You have entered an e-mail address with an improper "@", please rekey.';
  var msg2 = 'You have entered an e-mail address with an improper ".", please rekey.';

  if (email_address != '') {
    // check for the @ sign in the field
    if ((email_address.indexOf('@') == -1)||
        (email_address.charAt(0) == '@')||
	    (email_address.charAt(email_address.length-1) == '@')) {
      alert(msg1);

      switch (email_group) {
        case 1:
          document.man_tky_guestbook_form.guest_email.focus();
          break;
        case 2:
          document.turkey_contest.school_email.focus();
          break;
        case 3:
          document.wof_signup.signup_email.focus();
          break;
        default:
          document.turkey_contest.student_email.focus();
      }

      return false;
    }


    // check for the "period" in the second portion of the info
    if ((email_address.indexOf('.') == -1)||
        (email_address.charAt(0) == '.')||
	    (email_address.charAt(email_address.length-1) == '.')||
  	    (email_address.charAt(email_address.length-2) == '.')) {
      alert(msg2);

      switch (email_group) {
        case 1:
          document.man_tky_guestbook_form.guest_email.focus();
          break;
        case 2:
          document.turkey_contest.school_email.focus();
          break;
        case 3:
          document.wof_signup.signup_email.focus();
          break;
        default:
          document.turkey_contest.student_email.focus();
      }


      return false;
    }
  }
  return true;	
}


// check to make sure that state province has been selected
// cannot leave it as the first entry in the select area
function checkStateProvince(state_Province) {

  // set up message variables
  var msg1 = 'You must select a state or province or country, please re-select.';
  var incorrect_entry = 'incorrect';

  if (state_Province == 'incorrect') {
	alert(msg1);
	return false;
  } else {
	return true;
  }

}


// check to make sure that the data entered in some text fields does not contain
// any commands that can be used against databases in mysql
function checkTextData(sText, return_page) {
	
  var error_holder = 0;

  var msg1 = 'You may not use certain command words such as SELECT in these fields, please re-key.';   
  var msg2 = 'You may not use certain command words such as DROP in these fields, please re-key.'; 
  var msg3 = 'You may not use certain command words such as DELETE in these fields, please re-key.'; 
  var msg4 = 'You may not use certain command words such as INSERT in these fields, please re-key.'; 
  var msg5 = 'You may not use certain command words such as LOAD DATA in these fields, please re-key.'; 
  var msg6 = 'You may not use certain command words such as REPLACE in these fields, please re-key.'; 
  var msg7 = 'You may not use certain command words such as UPDATE in these fields, please re-key.'; 
  var msg8 = 'You may not use certain command words such as SHOW in these fields, please re-key.'; 
  var msg9 = 'You may not use certain command words such as DESCRIBE in these fields, please re-key.'; 
  var msg10 = 'You may not use certain command words such as EXPLAIN in these fields, please re-key.'; 
  var msg11 = 'You may not use certain command words such as CHECK in these fields, please re-key.'; 
  var msg12 = 'You may not use certain command words such as ANALYZE in these fields, please re-key.'; 
  var msg13 = 'You may not use certain command words such as REPAIR in these fields, please re-key.';
  var msg14 = 'You may not use certain command words such as OPTIMIZE in these fields, please re-key.';  

  var select_text = new RegExp("SELECT");
  var drop_text = new RegExp("DROP");
  var delete_text = new RegExp("DELETE");
  var insert_text = new RegExp("INSERT");
  var load_text = new RegExp("LOAD DATA");
  var replace_text = new RegExp("REPLACE");
  var update_text = new RegExp("UPDATE");
  var show_text = new RegExp("SHOW");
  var describe_text = new RegExp("DESCRIBE");
  var explain_text = new RegExp("EXPLAIN");
  var check_text = new RegExp("CHECK");
  var analyze_text = new RegExp("ANALYZE");
  var repair_text = new RegExp("REPAIR");
  var optimize_text = new RegExp("OPTIMIZE");


// check to make sure that there is data in the field
  if (sText != '') {

    if (select_text.test(sText)) {
        alert(msg1);
		error_holder = 1;
	}
    if (drop_text.test(sText)) {
        alert(msg2);
		error_holder = 1;
	}
    if (delete_text.test(sText)) {
        alert(msg3);
		error_holder = 1;
	}
    if (insert_text.test(sText)) {
        alert(msg4);
		error_holder = 1;
	}
    if (load_text.test(sText)) {
        alert(msg5);
		error_holder = 1;
	}
    if (replace_text.test(sText)) {
        alert(msg6);
		error_holder = 1;
	}
    if (update_text.test(sText)) {
        alert(msg7);
		error_holder = 1;
	}
    if (show_text.test(sText)) {
        alert(msg8);
		error_holder = 1;
	}
    if (describe_text.test(sText)) {
        alert(msg9);
		error_holder = 1;
	}
    if (explain_text.test(sText)) {
        alert(msg10);
		error_holder = 1;
	}
    if (check_text.test(sText)) {
        alert(msg11);
		error_holder = 1;
	}
    if (analyze_text.test(sText)) {
        alert(msg12);
		error_holder = 1;
	}
    if (repair_text.test(sText)) {
        alert(msg13);
		error_holder = 1;
	}
    if (optimize_text.test(sText)) {
        alert(msg14);
		error_holder = 1;
	}

  }

// an error has occured, return to specific page
  if (error_holder != 0) {
	  
    switch (return_page) {
      case 1:
        document.man_tky_guestbook_form.guest_email.focus();
        break;
      case 2:
        document.turkey_contest.school_email.focus();
        break;
      case 3:
        document.wof_signup.signup_full_name.focus();
        break;
      default:
        document.turkey_contest.student_email.focus();
    }	  
	  
    return false;  
  } else {
    return true;
  }

  
}

// check to make sure that the data entered in some text fields does not contain
// any commands that can be used against databases in mysql
function checkTextSearchData(sText) {

  var msg1 = 'You may not use certain command words such as SELECT in these fields, please re-key.';   
  var msg2 = 'You may not use certain command words such as DROP in these fields, please re-key.'; 
  var msg3 = 'You may not use certain command words such as DELETE in these fields, please re-key.'; 
  var msg4 = 'You may not use certain command words such as INSERT in these fields, please re-key.'; 
  var msg5 = 'You may not use certain command words such as LOAD DATA in these fields, please re-key.'; 
  var msg6 = 'You may not use certain command words such as REPLACE in these fields, please re-key.'; 
  var msg7 = 'You may not use certain command words such as UPDATE in these fields, please re-key.'; 
  var msg8 = 'You may not use certain command words such as SHOW in these fields, please re-key.'; 
  var msg9 = 'You may not use certain command words such as DESCRIBE in these fields, please re-key.'; 
  var msg10 = 'You may not use certain command words such as EXPLAIN in these fields, please re-key.'; 
  var msg11 = 'You may not use certain command words such as CHECK in these fields, please re-key.'; 
  var msg12 = 'You may not use certain command words such as ANALYZE in these fields, please re-key.'; 
  var msg13 = 'You may not use certain command words such as REPAIR in these fields, please re-key.';
  var msg14 = 'You may not use certain command words such as OPTIMIZE in these fields, please re-key.';  

  var select_text = new RegExp("SELECT");
  var drop_text = new RegExp("DROP");
  var delete_text = new RegExp("DELETE");
  var insert_text = new RegExp("INSERT");
  var load_text = new RegExp("LOAD DATA");
  var replace_text = new RegExp("REPLACE");
  var update_text = new RegExp("UPDATE");
  var show_text = new RegExp("SHOW");
  var describe_text = new RegExp("DESCRIBE");
  var explain_text = new RegExp("EXPLAIN");
  var check_text = new RegExp("CHECK");
  var analyze_text = new RegExp("ANALYZE");
  var repair_text = new RegExp("REPAIR");
  var optimize_text = new RegExp("OPTIMIZE");


// check to make sure that there is data in the field
  if (sText != '') {

    if (select_text.test(sText)) {
        alert(msg1);
        document.search_site.search_info.focus();
        return false;
	}
    if (drop_text.test(sText)) {
        alert(msg2);
        document.search_site.search_info.focus();
        return false;
	}
    if (delete_text.test(sText)) {
        alert(msg3);
        document.search_site.search_info.focus();
        return false;
	}
    if (insert_text.test(sText)) {
        alert(msg4);
        document.search_site.search_info.focus();
        return false;
	}
    if (load_text.test(sText)) {
        alert(msg5);
        document.search_site.search_info.focus();
        return false;
	}
    if (replace_text.test(sText)) {
        alert(msg6);
        document.search_site.search_info.focus();
        return false;
	}
    if (update_text.test(sText)) {
        alert(msg7);
        document.search_site.search_info.focus();
        return false;
	}
    if (show_text.test(sText)) {
        alert(msg8);
        document.search_site.search_info.focus();
        return false;
	}
    if (describe_text.test(sText)) {
        alert(msg9);
        document.search_site.search_info.focus();
        return false;
	}
    if (explain_text.test(sText)) {
        alert(msg10);
        document.search_site.search_info.focus();
        return false;
	}
    if (check_text.test(sText)) {
        alert(msg11);
        document.search_site.search_info.focus();
        return false;
	}
    if (analyze_text.test(sText)) {
        alert(msg12);
        document.search_site.search_info.focus();
        return false;
	}
    if (repair_text.test(sText)) {
        alert(msg13);
        document.search_site.search_info.focus();
        return false;
	}
    if (optimize_text.test(sText)) {
        alert(msg14);
        document.search_site.search_info.focus();
        return false;
	}

  }
  return true;

  
}

// this function will check the postal code to make sure that they have
// entered the correct sequence of letters and numbers
function checkPostal(postal_Info, country) {


  // set up message variables
  var postal_mess2 = 'You have entered an incorrect postal code, please rekey.';
  var zip_code_mess = 'You have entered an incorrect zip code, please rekey';
  var country_mess = 'You have to select a country to process the postal code/zip code, please rekey';

  // set up the regular expression
  var checked_Postal_End = new RegExp("[A-Z][0-9][A-Z] [0-9][A-Z][0-9]");
  var checked_Start = new RegExp("[A-Z][0-9][A-Z]");
  var checked_End = new RegExp("[0-9][A-Z][0-9]");
  var checked_Zip_Code = new RegExp("[0-9][0-9][0-9][0-9][0-9]");


  postal_type = postal_Info.toUpperCase();

  postal_start = postal_type.substr(0,3);

  postal_middle = postal_type.substr(3,1);



// make sure that entry has data
  if (postal_middle != " ") {
    postal_end = postal_type.substr(3,3);
  } else {
	postal_end = postal_type.substr(4,3);  
  }


  if (postal_Info != '') { 

// the check here is that 1 is Canada, 2 is USA, default is country not picked
    switch (country) {
      case 1:
        if (postal_start.match(checked_Start) != null && postal_end.match(checked_End) != null ) {
	      return true;  
        } else {
          alert(postal_mess2);
          document.wof_signup.signup_postal_code.focus();
          return false;
	    }	
        break;
      case 2:
        // checking the start postal against a regular expression
        if (postal_Info.match(checked_Zip_Code) != null) {
	      return true;  
        } else {
          alert(zip_code_mess);
          document.man_tky_guestbook_form.guest_postal_zip.focus();
          return false;
	    }
        break;
      default:
        // the country has not been selected 
        alert(country_mess);
        document.man_tky_guestbook_form.guest_country.focus();
        return false;	
    }	  
	

/*
// old code, to be removed later
    if (country == 'Canada') {


	  if (postal_start.match(checked_Start) != null && postal_end.match(checked_End) != null ) {
	    return true;  
      } else {
        alert(postal_mess2);
        document.man_tky_guestbook_form.guest_postal_zip.focus();
        return false;
	  }	

 
	} else if (country == 'USA') {

      // checking the start postal against a regular expression
      if (postal_Info.match(checked_Zip_Code) != null) {
	    return true;  
      } else {
        alert(zip_code_mess);
        document.man_tky_guestbook_form.guest_postal_zip.focus();
        return false;
	  }

	} else {

	  // the country has not been selected 
      alert(country_mess);
      document.man_tky_guestbook_form.guest_country.focus();
      return false;		
	}
*/
  }

  return true;
}




// build a footer so that I only have to update this to make the footer the same on all pages
function create_footer() {

    var current_date = new Date().getFullYear();

    document.write('Copyright '+current_date+'. Windows of Fashion. All rights Reserved.<br />Website Design and Integration by <a href="http://www.swj.cc" target="_blank">&copy;swj strategic marketing &amp; advertising</a>');

}




// create a method of switching the flash on the main page
function random_flash_link() {

// put url's for randomly selected graphics here, as in the example
  
  var gfx = new Array();

  gfx[0] = 'flash/main_page/AboutUs.swf';
  gfx[1] = 'flash/main_page/Bedding_Bath.swf';
  gfx[2] = 'flash/main_page/Furniture.swf';
  gfx[3] = 'flash/main_page/Home.swf';
  gfx[4] = 'flash/main_page/Products.swf';
  gfx[5] = 'flash/main_page/Services.swf';


  var ry=Math.floor(Math.random()*gfx.length);

//  document.writeln('<a href="'+linkInfo[ry]+'" target="_blank"><img src="'+gfx[ry]+'" width="106" height="389" alt="Strategic info image" /></a>')

	document.writeln('      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'); 
	document.writeln('                codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'); 
	document.writeln('		        width="540"'); 
	document.writeln('		        height="306"'); 
	document.writeln('		        align="middle">');
	document.writeln('	      <param name="allowScriptAccess" value="sameDomain" />');
	document.writeln('		  <param name="wmode" value="transparent" />');
	document.writeln('	      <param name="movie" value="'+gfx[ry]+'" />');
	document.writeln('	      <param name="quality" value="high" />');
	document.writeln('	      <param name="bgcolor" value="#FFFFFF" />');
	document.writeln('	      <embed src="'+gfx[ry]+'" quality="high" bgcolor="#FFFFFF"'); 
	document.writeln('		         width="540"'); 
	document.writeln('				 height="306"'); 
	document.writeln('		         name="webtop" align="middle"'); 
	document.writeln('		         allowScriptAccess="sameDomain"'); 
	document.writeln('			     type="application/x-shockwave-flash"');
	document.writeln('		         pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.writeln('	    </object>');

}




//  random_imglink()  this call to random_imglink needs to be put in the actual file to work properly.


// create a method to call up a window with a larger image
function openResizableWindow(page) {

//	window.open(page, "comicsWindowNonResizable", "width=610,innerwidth=610,height=460,innerheight=460,toolbar=no,titlebar=no,menubar=no,location=no,scrollbars=no,resizable=no");

    window.open(page, "StatusBar", 
"toolbar=no,resizable=yes,scrollbars=yes,width=650,height=450,left=175,top=100");

}


// build a footer so that I only have to update this to make the footer the same on all pages
function create_footer() {

    var current_date = new Date().getFullYear();

    document.write(current_date);
}
