var appVer = navigator.appVersion.toLowerCase();
var userAgt = navigator.userAgent.toLowerCase();
var mac = (appVer.indexOf("mac") != -1);
var win = (appVer.indexOf("win") != -1);
var nn = (navigator.appName == "Netscape");
var ie = (navigator.appName == "Microsoft Internet Explorer");
var aol = (userAgt.indexOf("aol") != -1);
var opera = (userAgt.indexOf("opera") != -1);
var v4 = (parseInt(appVer) >= 4);
var ver = (ie) ? parseFloat(appVer.substring((appVer.indexOf('msie') + 5), appVer.length)) : parseFloat(appVer);
var remote;
var URL;

function toSmall(imagename){
	var temp=imagename.replace(/_lrg/g,"_sml");
	temp=temp.replace(/\/med\//g,"/sml/");
	temp=temp.replace(/\/lrg\//g,"/sml/");
	temp=temp.replace(/_med/g,"_sml");
return temp;
}

function toLarge(imagename){
	var temp=imagename.replace(/_sml/g,"_lrg");
	temp=temp.replace(/_med/g,"_lrg");
	temp=temp.replace(/\/med\//g,"/lrg/");
	temp=temp.replace(/\/sml\//g,"/lrg/");
return temp;
}

function brandimage(brandname){
	var temp=brandname;
	temp='/common/image/brought_icons/'+brandname+'.gif';
	return temp;
}

function brandimage(brandname){
	var temp=brandname;
	temp='/common/image/10_common/brought_icons/'+brandname+'.gif';
	return temp;
}

function toSmall(imagename){
	var temp=imagename.replace(/_lrg/g,"_sml");
	temp=temp.replace(/\/med\//g,"/sml/");
	temp=temp.replace(/\/lrg\//g,"/sml/");
	temp=temp.replace(/_med/g,"_sml");
return temp;
}

function toLarge(imagename){
	var temp=imagename.replace(/_sml/g,"_lrg");
	temp=temp.replace(/_med/g,"_lrg");
	temp=temp.replace(/\/med\//g,"/lrg/");
	temp=temp.replace(/\/sml\//g,"/lrg/");
return temp;
}

function brandimage(brandname){
	var temp=brandname;
	temp='/common/image/brought_icons/'+brandname+'.gif';
	return temp;
}

function formHandler(){
if (nn && v4) {
  var formref = document.prodinfo.document.pinfo;
}
else {
  var formref = document.pinfo;
}
var URL = formref.site.options[formref.site.selectedIndex].value;
window.location.href = URL;
}

function formHandler1(){
if (nn && v4) {
  var formref = document.prodinfo.document.pinfo;
}
else {
  var formref = document.pinfo;
}
var URL = formref.report.options[formref.report.selectedIndex].value;
window.location.href = URL;
}

function formHandler2(){
if (nn && v4) {
  var formref = document.prodinfo.document.pinfo;
}
else {
  var formref = document.pinfo;
}
var URL = formref.productinfo.options[formref.productinfo.selectedIndex].value;
window.location.href = URL;
}

function formHandler3(){
if (nn && v4) {
  var formref = document.prodinfo.document.pinfo;
}
else {
  var formref = document.pinfo;
}
var URL = formref.fav.options[formref.fav.selectedIndex].value;
window.location.href = URL;
}
function formHandler4(){
if (nn && v4) {
  var formref = document.prodinfo.document.pinfo;
}
else {
  var formref = document.pinfo;
}
var URL = formref.site_feed.options[formref.site_feed.selectedIndex].value;
window.location.href = URL;
}


function stockpop(URL) {
	remote = window.open(URL,"pop","scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,width=325,height=275,screenX=200,screenY=240,left=200,top=220");
	remote.focus();
        if (remote.opener == null) remote.opener = self;
}

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()

/*
* FUNCTION: blurLinks
* utitility function for turning off link focus (lines drawn around an active link) in browsers such as ie4Win
*/
function blurLinks() {
if(!document.links || document.links.length <= 0 || !getObj('document.links[0].focus')) return;
  for(var i = 0; i < document.links.length; i++) {
  document.links[i].onfocus = document.links[i].blur;
  }
}



/*
* FUNCTION: swapImg
* Image Swapping function.
*/
function swapImg() {
if(!document.images) return;
//alert('test');
var args = swapImg.arguments;
  for(var i = 0; i < args.length; i+=2) {
  var imgSrc = (args[i + 1].indexOf('[') != -1) ? eval(args[i + 1] + '.src') : args[i + 1];
  if(getImgObj(args[i])) getImgObj(args[i]).src = imgSrc;
  }
}

function getImgObj(name, doc) {
var i, layer, imgs;
  if(!doc) doc = document;

  // retrieve ie dom image or non-layer image
  if(doc.images[name]) return doc.images[name];

  // retrieve nn layer image
  for(var i = 0; i < doc.layers.length; i++) {
  layer = doc.layers[i];
  imgs = layer.document.images;
  if(imgs.length > 0 && imgs[name]) return imgs[name];
  if(layer.document.layers.length > 0) layer = getImgObj(name, layer.document);
  }
return 0;
}

function moveLayer(lyr,t,l) {
eval("csspObj('" + lyr + "').setProperty('top'," + t + ")");
eval("csspObj('" + lyr + "').setProperty('left'," + l + ")");
}

function move1(){
swapImg('flag1','/common/image/flags_0_1.gif');
moveLayer('move','144','7');
}

function move2(){
swapImg('flag2','/common/image/korea_b.gif');
moveLayer('move','165','7');
}

function move3(){
swapImg('flag3','/common/image/flags_2_1.gif');
moveLayer('move','185','7');
}

function move4(){
swapImg('flag4','/common/image/flags_3_1.gif');
moveLayer('move','205','7');
}

function move5(){
swapImg('flag5','/common/image/flags_4_1.gif');
moveLayer('move','226','7');
}

function move6(){
swapImg('flag6','/common/image/flags_5_1.gif');
moveLayer('move','246','7');
}

function move7(){
swapImg('flag7','/common/image/flags_6_1.gif');
moveLayer('move','268','7');
}

function move8(){
swapImg('flag8','/common/image/flags_7_1.gif');
moveLayer('move','289','7');
}

function move9(){
swapImg('flag9','/common/image/flags_8_1.gif');
moveLayer('move','310','7');
}

function move10(){
swapImg('flag10','/common/image/kazakhstan.gif');
moveLayer('move','332','7');
}

function move11(){
swapImg('flag11','/common/image/kyrgyzstan.gif');
moveLayer('move','353','7');
}

function move12(){
swapImg('flag12','/common/image/mongolia.gif');
moveLayer('move','374','7');
}

function move13(){
swapImg('flag13','/common/image/turkmenistan.gif');
moveLayer('move','395','7');
}

function move14(){
swapImg('flag14','/common/image/uzbekistan.gif');
moveLayer('move','416','7');
}

function move15(){
swapImg('flag15','/common/image/russia.gif');
moveLayer('move','438','7');
}

function move16(){
swapImg('flag16','/common/image/ukraine.gif');
moveLayer('move','458','7');
}

function move17(){
swapImg('flag17','/common/image/turkey_b.gif');
moveLayer('move','479','7');
}


/*
* FUNCTION: handleResize
* window reloading function
* refreshs window upon minimizing or maximizing browser window
*/
//if(window.captureEvents) {
//window.captureEvents(Event.RESIZE);
//window.onresize = handleResize;
//window.onresize = reloadPage;
//}
/*
function handleResize() {
location.reload();
return false;
}
*/

//function reloadPage(init) {
//  if (init==true) with (navigator) {
//    if (nn && v4) {
//    document.pgW=innerWidth;
//    document.pgH=innerHeight;
//    onresize=reloadPage;
//    }
//  }
//  else if (innerWidth!=document.pgW || innerHeight!=document.pgH)
//location.reload();
//}
//reloadPage(true);

var onloadHandlers = [];
function loadEvents() {
//if((ver<5) && win && ie) blurLinks();
  for(var i=0; i<onloadHandlers.length;i++) {
  eval(onloadHandlers[i]);
  }
}
window.onload = loadEvents;

var onresizeHandlers = [];
function resizeEvents() {
 for(var i=0; i<onresizeHandlers.length;i++) {
  eval(onresizeHandlers[i]);
  }
}
window.onresize = resizeEvents;

function handleResize(init) {
if(!(nn && v4)) return;
  if(init==true) with (navigator) {
  document.pgW=innerWidth;
  document.pgH=innerHeight;
  onresizeHandlers[onresizeHandlers.length] = 'handleResize()';
  }
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
handleResize(true);

var Params1;

if (document.images != null) {
Params1 = "width=450,height=300,";
}else{
Params1 = "width=425,height=300,";
}
Params1 += "resizable=0,status=0,menubar=0,scrollbars=1,location=1";

function Certify(URL) {
  popupWin = window.open(URL, 'Participant', Params1)
  window.top.name = 'opener';
  popupWin.focus();
}
function formHandler3(){
if (nn && v4) {
  var formref = document.prodinfo.document.pinfo;
}
else {
  var formref = document.pinfo;
}
var URL = formref.site_feed.options[formref.site_feed.selectedIndex].value;
window.location.href = URL;
}

function formHandler(oSelect){
	var pos;
	var URL = oSelect.options[oSelect.selectedIndex].value;

	pos = oSelect.options[oSelect.selectedIndex].value.indexOf('javascript:interrupt_pop(\'');

	if (pos == -1) {
 
  pos = oSelect.options[oSelect.selectedIndex].value.indexOf('javascript:confirms_lang(\'');
  
  if (pos == -1) {
   pos = oSelect.options[oSelect.selectedIndex].value.indexOf('http:');
  
   if (pos == -1) {
 		 window.location.href = URL;
   }
   else {
    window.open(URL);
   }
  }  
  else {
   var ref = getref(URL, pos);
   if (confirm(englishRedirect)) {
    window.open(ref);
   }
  }  
	}
 
	else {
		var ref = getref(URL, pos);
  interrupt_pop(ref);
	}
}

function getref(URL, pos) {
	var start = pos+26; //9 is the length of the string that determines pos
	var end = URL.length-3;
	var splitStr = URL.substring(start, end );
	return splitStr;
}



function toMed(imagename){
	var temp=imagename.replace(/_sqr/g,"_med");

return temp;
}

function toSmall(imagename){

	var temp=imagename.replace(/_lrg/g,"_sml");

	temp=temp.replace(/\/med\//g,"/sml/");

	temp=temp.replace(/\/lrg\//g,"/sml/");

	temp=temp.replace(/_med/g,"_sml");

return temp;

}



function toSmall(imagename){
	var temp=imagename.replace(/_lrg/g,"_sml");
	temp=temp.replace(/\/med\//g,"/sml/");
	temp=temp.replace(/\/lrg\//g,"/sml/");
	temp=temp.replace(/_med/g,"_sml");
return temp;
}

function toLarge(imagename){
	var temp=imagename.replace(/_sml/g,"_lrg");
	temp=temp.replace(/_med/g,"_lrg");
	temp=temp.replace(/\/med\//g,"/lrg/");
	temp=temp.replace(/\/sml\//g,"/lrg/");
return temp;
}

function resulst_pop(url) {
	quizWin=window.open(url, "", "toolbar=no,directories=no,status=no,location=0,resizable=no,scrollbars=no,menubar=no,width=300,height=300,screenY=25,screenX=25,top=25,left=25"); 
quizWin.focus();
}

function resulst_pop_fr(url) {
	quizWin=window.open(url, "", "toolbar=no,directories=no,status=no,location=0,resizable=no,scrollbars=no,menubar=no,width=300,height=400,screenY=25,screenX=25,top=25,left=25"); 
quizWin.focus();
}

var flashVersion = 0;
function getFlashVersion() {
	var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;

function interrupt_pop(URL) {
 window.open(URL,"int","scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0,width=400,height=200,screenX=200,screenY=240,left=200,top=220");
}

function confirms_lang(URL) {
 if (confirm(englishRedirect)) {
  window.open(URL);
 }
}

var englishRedirect = "Vous êtes maintenant sur le point de quitter le site Web de P&G Canada. Vous serez dirigé vers le site Web mondial de P&G présenté en anglais seulement.";

function engRedirect() {
  var engCallout = confirm("Vous êtes maintenant sur le point de quitter le site Web de P&G Canada. Vous serez dirigé vers le site Web mondial de P&G présenté en anglais seulement.");

  if (engRedirect)
  {
   window.open("https://pg.sitebase.net/pg_images/taleo/stepsToSuccess.swf");
  }
 }
