// JavaScript Document


// this is the common file for the Prairie Global Management website
//
// Author: Jacques J. Bosc
// Date:   November, 2007
// Project: Create javascript to be used for the site.
//

// this code would normally by placed in a external javascript file to handle any
// errors that would come up.

//onerror=handleErr;
var txt="";


function handleErr(msg,url,l) {
  txt="There was an error in the logic of this page.\n\n";
  txt+="Error: " + msg + "\n";
  txt+="URL: " + url + "\n";
  txt+="Line: " + l + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  return true;
}



// this code will light up the button on a mouseover
if (document.images) {
    pic1on= new Image(41,17);
    pic1on.src="images/navigation_btns/home_grey.jpg";  
    pic2on= new Image(61,17);
    pic2on.src="images/navigation_btns/philosophy_grey.jpg";  
    pic3on= new Image(42,17);
    pic3on.src="images/navigation_btns/history_grey.jpg";  
    pic4on= new Image(50,17);
    pic4on.src="images/navigation_btns/services_grey.jpg";  
    pic5on= new Image(51,17);
    pic5on.src="images/navigation_btns/contact_us_grey.jpg";
    pic6on= new Image(47,17);
    pic6on.src="images/navigation_btns/portofolio_grey.jpg";
    pic7on= new Image(44,17);
    pic7on.src="images/navigation_btns/awards_grey.jpg";
    pic8on= new Image(34,17);
    pic8on.src="images/navigation_btns/news_grey.jpg";
    pic9on= new Image(35,17);
    pic9on.src="images/navigation_btns/login_grey.jpg";

    pic1off= new Image(41,17);
    pic1off.src="images/navigation_btns/home_white.jpg";
    pic2off= new Image(61,17);
    pic2off.src="images/navigation_btns/philosophy_white.jpg";
    pic3off= new Image(42,17);
    pic3off.src="images/navigation_btns/history_white.jpg";
    pic4off= new Image(50,17);
    pic4off.src="images/navigation_btns/services_white.jpg";
    pic5off= new Image(51,17);
    pic5off.src="images/navigation_btns/contact_us_white.jpg";
    pic6off= new Image(47,17);
    pic6off.src="images/navigation_btns/portofolio_white.jpg";
    pic7off= new Image(44,17);
    pic7off.src="images/navigation_btns/awards_white.jpg";
    pic8off= new Image(34,17);
    pic8off.src="images/navigation_btns/news_white.jpg";
    pic9off= new Image(35,17);
    pic9off.src="images/navigation_btns/login_white.jpg";
}


// this is for the portfolio page which is one directory down
if (document.images) {
    picport1on= new Image(41,17);
    picport1on.src="../images/navigation_btns/home_grey.jpg";  
    picport2on= new Image(61,17);
    picport2on.src="../images/navigation_btns/philosophy_grey.jpg";  
    picport3on= new Image(42,17);
    picport3on.src="../images/navigation_btns/history_grey.jpg";  
    picport4on= new Image(50,17);
    picport4on.src="../images/navigation_btns/services_grey.jpg";  
    picport5on= new Image(51,17);
    picport5on.src="../images/navigation_btns/contact_us_grey.jpg";
    picport6on= new Image(47,17);
    picport6on.src="../images/navigation_btns/portofolio_grey.jpg";
    picport7on= new Image(44,17);
    picport7on.src="../images/navigation_btns/awards_grey.jpg";
    picport8on= new Image(34,17);
    picport8on.src="../images/navigation_btns/news_grey.jpg";
    picport9on= new Image(35,17);
    picport9on.src="../images/navigation_btns/login_grey.jpg";

    picport1off= new Image(41,17);
    picport1off.src="../images/navigation_btns/home_white.jpg";
    picport2off= new Image(61,17);
    picport2off.src="../images/navigation_btns/philosophy_white.jpg";
    picport3off= new Image(42,17);
    picport3off.src="../images/navigation_btns/history_white.jpg";
    picport4off= new Image(50,17);
    picport4off.src="../images/navigation_btns/services_white.jpg";
    picport5off= new Image(51,17);
    picport5off.src="../images/navigation_btns/contact_us_white.jpg";
    picport6off= new Image(47,17);
    picport6off.src="../images/navigation_btns/portofolio_white.jpg";
    picport7off= new Image(44,17);
    picport7off.src="../images/navigation_btns/awards_white.jpg";
    picport8off= new Image(34,17);
    picport8off.src="../images/navigation_btns/news_white.jpg";
    picport9off= new Image(35,17);
    picport9off.src="../images/navigation_btns/login_white.jpg";
}


function lightup(imgName) {
   if (document.images)
    {
      imgOn=eval(imgName + "on.src");
      document[imgName].src= imgOn;
    }
 }

function turnoff(imgName) {
   if (document.images)
    {
      imgOff=eval(imgName + "off.src");
      document[imgName].src= imgOff;
    }
 }
 
function loadDetails(set, div) {
	var block = top.document.getElementById(div);
	if (set =='open') {
		block.style.display = "block";
	  } else {
	    block.style.display = "none";
	  }
 }
 
 
 // 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/SWJ-Intro1.swf';
  gfx[1] = 'flash/SWJ-Intro2.swf';
/*
  gfx[2] = '../images/home2_new3.jpg';
  gfx[3] = '../images/home3_new3.jpg';
  gfx[4] = '../images/home4_new3.jpg';
  gfx[5] = '../images/home5_new3.jpg';
*/

  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="748"'); 
	document.writeln('			height="366"'); 
	document.writeln('			id="IntroMovie"'); 
	document.writeln('			align="bottom">');
    document.writeln('      <param name="allowScriptAccess" value="sameDomain" />');
    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"'); 
	document.writeln('	         bgcolor="#ffffff"'); 
	document.writeln('	         width="748"'); 
	document.writeln('			 height="366"'); 
	document.writeln('			 name="IntroMovie" align="bottom" allowScriptAccess="sameDomain"'); 
	document.writeln('			 type="application/x-shockwave-flash" 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 of switching the flash on the main page
// this uses a new flash entry that has a wider text and thus a wider flash swf 
function random_flash_link_2(){

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

  gfx[0] = 'flash/SWJ-New_Text_Intro1.swf';
  gfx[1] = 'flash/SWJ-New_Text_Intro2.swf';
/*
  gfx[2] = '../images/home2_new3.jpg';
  gfx[3] = '../images/home3_new3.jpg';
  gfx[4] = '../images/home4_new3.jpg';
  gfx[5] = '../images/home5_new3.jpg';
*/

  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="785"'); 
	document.writeln('			height="366"'); 
	document.writeln('			id="IntroMovie"'); 
	document.writeln('			align="bottom">');
    document.writeln('      <param name="allowScriptAccess" value="sameDomain" />');
    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"'); 
	document.writeln('	         bgcolor="#ffffff"'); 
	document.writeln('	         width="785"'); 
	document.writeln('			 height="366"'); 
	document.writeln('			 name="IntroMovie" align="bottom" allowScriptAccess="sameDomain"'); 
	document.writeln('			 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.writeln('    </object>');

}




// 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('Web site design and integration by SWJ Strategic Marketing &amp; Advertising<br /> Copyright '+current_date+'. All rights reserved.');
}





// build a footer so that I only have to update this to make the footer the same on all pages
function create_docket_footer() {
    var current_date = new Date().getFullYear();
    document.write('SWJ Strategic Marketing & Advertising. Copyright '+current_date+'. All rights reserved.');
}





// verify that the name and email from the news page has data when subscribe entered
function verify_email(da_reg_form) {

  var register_req_array = new Array();
  register_req_array[0] = document.getElementById("username_data").value;
  register_req_array[1] = document.getElementById("email_data").value;
  
// check the first array to make sure that the info is there
  for (i = 0; i < register_req_array.length; i++) {
    if (register_req_array[i] == "") {
      alert('You have not filled in either the name or email prompt, please check and rekey.');
	  document.receive_mail.name_to_sendto.focus();	      
	  return false;
    }
  }

}


// this function will check to see if you are on an iPhone coming to the site
// it will also check if a blackberry is coming to the site
// this check is here to show an image if either a iphone or blackberry comes to the page
// this code was supplied by this   http://www.askdavetaylor.com/detect_apple_iphone_user_web_site_server.html    website

function iPhoneCheck() {

  var agent;
  var is_iphone;
  var is_blackberry;

  agent = navigator.userAgent.toLowerCase();

//alert ("inside the iPHoneCheck function, display agent = " + agent);

  is_iphone = agent.indexOf("iphone");
  
  is_blackberry = agent.indexOf("blackberry");

//alert ("inside the iPHoneCheck function, display is_iphone = " + is_iphone); 

//alert ("inside the iPHoneCheck function, display is_blackberry = " + is_blackberry);

  if (is_iphone > 0) { 
    document.getElementById("web_flash_display").style.display = "none";
    document.getElementById("web_no_flash_iPhone").style.display = ""; 
  } else if (is_blackberry > 0) {
      document.getElementById("web_flash_display").style.display = "none";
      document.getElementById("web_no_flash_iPhone").style.display = ""; 	  
  }

}




// this function will check to see if you are on an iPhone coming to the site
// it will also check if a blackberry is coming to the site
// this check is here to show an image if either a iphone or blackberry comes to the page
// this code was supplied by this   http://www.askdavetaylor.com/detect_apple_iphone_user_web_site_server.html    website

function iCampaignPhoneCheck() {

  var agent;
  var is_iphone;
  var is_blackberry;

  agent = navigator.userAgent.toLowerCase();

//alert ("inside the iPHoneCheck function, display agent = " + agent);

  is_iphone = agent.indexOf("iphone");
  
  is_blackberry = agent.indexOf("blackberry");

//alert ("inside the iPHoneCheck function, display is_iphone = " + is_iphone); 

//alert ("inside the iPHoneCheck function, display is_blackberry = " + is_blackberry);

  if (is_iphone > 0) { 
    document.getElementById("web_victory_flash_display").style.display = "none";
    document.getElementById("web_victory_no_flash_iPhone").style.display = "";
    document.getElementById("web_boys_flash_display").style.display = "none";
    document.getElementById("web_boys_no_flash_iPhone").style.display = "";
    document.getElementById("web_i_believe_flash_display").style.display = "none";
    document.getElementById("web_i_believe_no_flash_iPhone").style.display = "";
    document.getElementById("web_pork_BBQ_flash_display").style.display = "none";
    document.getElementById("web_pork_BBQ_no_flash_iPhone").style.display = "";
    document.getElementById("web_pork_jingle_flash_display").style.display = "none";
    document.getElementById("web_pork_jingle_no_flash_iPhone").style.display = "";	
  } else if (is_blackberry > 0) {
      document.getElementById("web_victory_flash_display").style.display = "none";
      document.getElementById("web_victory_no_flash_iPhone").style.display = "";
      document.getElementById("web_boys_flash_display").style.display = "none";
      document.getElementById("web_boys_no_flash_iPhone").style.display = "";
      document.getElementById("web_i_believe_flash_display").style.display = "none";
      document.getElementById("web_i_believe_no_flash_iPhone").style.display = "";
      document.getElementById("web_pork_BBQ_flash_display").style.display = "none";
      document.getElementById("web_pork_BBQ_no_flash_iPhone").style.display = "";
      document.getElementById("web_pork_jingle_flash_display").style.display = "none";
      document.getElementById("web_pork_jingle_no_flash_iPhone").style.display = "";	  
  }

}


// this function will check to see if you are on an iPhone coming to the site
// it will also check if a blackberry is coming to the site
// this check is here to show an image if either a iphone or blackberry comes to the page
// this code was supplied by this   http://www.askdavetaylor.com/detect_apple_iphone_user_web_site_server.html    website

function iPhoneRadioCheck() {

  var agent;
  var is_iphone;
  var is_blackberry;

  agent = navigator.userAgent.toLowerCase();

//alert ("inside the iPHoneCheck function, display agent = " + agent);

  is_iphone = agent.indexOf("iphone");
  
  is_blackberry = agent.indexOf("blackberry");

//alert ("inside the iPHoneCheck function, display is_iphone = " + is_iphone); 

//alert ("inside the iPHoneCheck function, display is_blackberry = " + is_blackberry);

  if (is_iphone > 0 || is_blackberry > 0) { 
    document.getElementById("radio_cargill_boys_flash_display").style.display = "none";
    document.getElementById("radio_cargill_boys_no_flash_iPhone").style.display = "";
    document.getElementById("radio_pork_jingle_flash_display").style.display = "none";
    document.getElementById("radio_pork_jingle_no_flash_iPhone").style.display = "";
    document.getElementById("radio_can_cancer_flash_display").style.display = "none";
    document.getElementById("radio_can_cancer_no_flash_iPhone").style.display = "";
	document.getElementById("radio_pork_BBQ_flash_display").style.display = "none";
    document.getElementById("radio_pork_BBQ_no_flash_iPhone").style.display = "";
	document.getElementById("radio_shoppers_flash_display").style.display = "none";
    document.getElementById("radio_shoppers_no_flash_iPhone").style.display = "";
	document.getElementById("radio_schriemers_flash_display").style.display = "none";
    document.getElementById("radio_schriemers_no_flash_iPhone").style.display = "";
	document.getElementById("radio_winners_flash_display").style.display = "none";
    document.getElementById("radio_winners_no_flash_iPhone").style.display = "";
	document.getElementById("radio_man_egg_flash_display").style.display = "none";
    document.getElementById("radio_man_egg_no_flash_iPhone").style.display = "";
	document.getElementById("radio_mercedes_flash_display").style.display = "none";
    document.getElementById("radio_mercedes_no_flash_iPhone").style.display = "";
  } 

}


// this javascript was developed by November Group to send emails
// code on page is <a href="javascript:sendToMe('info@no', 'abc', 'vgrou', '123', 'p.com', '.ca');">General Enquiries</a>
function sendToMe(one, two, three, four, five, six, seven) { 
	// 'two', 'four' and 'six' are ignored - just junk.
  switch (seven) {
    case 1:
	  window.location = 'mailto:'+ one + three + five + '?subject=SWJ Information Request';
	  break;
	case 2:
	  window.location = 'mailto:'+ one + three + five + '?subject=SWJ Careers';
	  break;
  }
	
}




// check content of search form to see if any unauthorized words were used
// 
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;  
  }

}


// 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 this search field, please re-key.';   
  var msg2 = 'You may not use certain command words such as DROP in this search field, please re-key.'; 
  var msg3 = 'You may not use certain command words such as DELETE in this search field, please re-key.'; 
  var msg4 = 'You may not use certain command words such as INSERT in this search field, please re-key.'; 
  var msg5 = 'You may not use certain command words such as LOAD DATA in this search field, please re-key.'; 
  var msg6 = 'You may not use certain command words such as REPLACE in this search field, please re-key.'; 
  var msg7 = 'You may not use certain command words such as UPDATE in this search field, please re-key.'; 
  var msg8 = 'You may not use certain command words such as SHOW in this search field, please re-key.'; 
  var msg9 = 'You may not use certain command words such as DESCRIBE in this search field, please re-key.'; 
  var msg10 = 'You may not use certain command words such as EXPLAIN in this search field, please re-key.'; 
  var msg11 = 'You may not use certain command words such as CHECK in this search field, please re-key.'; 
  var msg12 = 'You may not use certain command words such as ANALYZE in this search field, please re-key.'; 
  var msg13 = 'You may not use certain command words such as REPAIR in this search field, please re-key.';
  var msg14 = 'You may not use certain command words such as OPTIMIZE in this search field, 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.getElementById("search_info").focus();
        return false;
	}
    if (drop_text.test(sText)) {
        alert(msg2);
        document.getElementById("search_info").focus();
        return false;
	}
    if (delete_text.test(sText)) {
        alert(msg3);
        document.getElementById("search_info").focus();
        return false;
	}
    if (insert_text.test(sText)) {
        alert(msg4);
        document.getElementById("search_info").focus();
        return false;
	}
    if (load_text.test(sText)) {
        alert(msg5);
        document.getElementById("search_info").focus();
        return false;
	}
    if (replace_text.test(sText)) {
        alert(msg6);
        document.getElementById("search_info").focus();
        return false;
	}
    if (update_text.test(sText)) {
        alert(msg7);
        document.getElementById("search_info").focus();
        return false;
	}
    if (show_text.test(sText)) {
        alert(msg8);
        document.getElementById("search_info").focus();
        return false;
	}
    if (describe_text.test(sText)) {
        alert(msg9);
        document.getElementById("search_info").focus();
        return false;
	}
    if (explain_text.test(sText)) {
        alert(msg10);
        document.getElementById("search_info").focus();
        return false;
	}
    if (check_text.test(sText)) {
        alert(msg11);
        document.getElementById("search_info").focus();
        return false;
	}
    if (analyze_text.test(sText)) {
        alert(msg12);
        document.getElementById("search_info").focus();
        return false;
	}
    if (repair_text.test(sText)) {
        alert(msg13);
        document.getElementById("search_info").focus();
        return false;
	}
    if (optimize_text.test(sText)) {
        alert(msg14);
        document.getElementById("search_info").focus();
        return false;
	}

  }
  return true;
  
}




// this function will trigger the submit on the news page if the user hits either update or
// delete.  The delete button will check to see if the user wants to return to the page
// before removing the news article
function submitthisform(submitentry, form_extension, id_num) {


  var form_text;
  var pdf_text;
  var delete_pdf;
  var delete_director;
  var delete_director_image;
  var reinstate_director;
  var update_abstract;
  var set_highest_priority;
  var re_activate_docket;
  var check_box;
	  
  form_text = "update_delete_article_";
  form_text = form_text + form_extension;
  
  pdf_text = "process_pdf_files_";
  pdf_text = pdf_text + form_extension;
  
  delete_pdf = "delete_pdf_";
  delete_pdf = delete_pdf + form_extension;
  
  delete_director = "update_delete_director_";
  delete_director = delete_director + form_extension;
  
  delete_director_image = "delete_director_image";
  
  reinstate_director = "reinstate_director_";
  reinstate_director = reinstate_director + form_extension;
  
  update_abstract = "update_abstract_";
  update_abstract = update_abstract + form_extension;
  
  set_highest_priority = "set_hightest_priority";
  
  re_activate_docket = "re-activate_docket_";
  re_activate_docket = re_activate_docket + id_num;
  
  check_box = "re_activate_";
  check_box = check_box + id_num;
  
	
  switch (submitentry) {
    case 1:
	  document.forms[form_text].submit();
      break;
    case 2:
	  doIt = confirm('Do you wish to re-activate docket '+ form_extension +' ?');
      if (doIt) {
        document.forms[re_activate_docket].submit();
      } else {
		document.getElementById(check_box).checked=false;
	    return false;
	  }
	  break;
    case 3:
	  doIt = confirm('Do you wish to delete this pdf?');
      if (doIt) {
        document.forms[pdf_text].submit();
      } else {
	    return false;
	  }
	  break;
 
  }
	    	  
}



