// JavaScript Document

var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";
	
function makeDaysOfMonth(){
  var i = 0;
  this[i++] = 0; // dummy
  this[i++] = 31;
  this[i++] = 29;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 30;
  this[i  ] = 31;
  this.length = i;
}
function getIdFromQstring() {

//Retrieve Document location and tear off the QueryString values for processing.
var url = document.location + '';
q=url.split('?');
if (q[1]) {
//Get all Name/Value pairs from the QueryString
var pairs = q[1].split('&');
for (i=0;i<pairs.length;i++) {

//Get the Name from given Name/Value pair
var keyval = pairs[i].split('=');

if (keyval[0] == 'cid') {
//Get the Value from given Name/Value pair and set to the return ID
var prusaid = keyval[1];
}//end if

}//end for
}//end if q[1]
return prusaid;
}

function calcAge(dd,mm,yy){
	
	var t, mon, day, year, DD, MM, YY, age;
	var MTB = new makeDaysOfMonth();
	YY   = parseInt(yy);	// year of birth (4 digits)
	MM   = parseInt(mm);	// month of birth (1-12)
	DD   = parseInt(dd,10);	// date of birth (1-31), 10 states for 'decimal'

	if (MTB[MM] < DD || DD < 1)
		return -1;
	
	t    = new Date();	// get current date
	year = t.getFullYear();	// get year of current
	mon  = t.getMonth() + 1;	// get month of current
	day  = t.getDate();	// get date of current
	if (MM == 2 && DD == 29){	// check leap year
		if (!(((YY % 4 == 0) && (YY % 100 != 0)) || (YY % 400 == 0))){
			alert("The year " +YY+ " ends at 28th of "+MM+" month\nPlease check the date.");
			return -1;
		}
	}
	
	age = year - YY;
	
	if ((MM > mon) || (MM == mon && day < DD)) age --;
  
	legalinfo=document.avs.fcountry.options[document.avs.fcountry.selectedIndex].value;
	legal=legalinfo.split("|");
	legalcountry=legal[0];
	legalage=legal[1];	

	if (age>=legalage)
		{age= 1;}
	else
		{age= -1;}
	
	if (legalage==0)
		{age= -1;}
	
	if (legalcountry=="0")
		{age= -1;}

	return age;
}
	
	function validate_and_submit(){

		if(document.avs.fyear.value < 1900 || calcAge(document.avs.fday.value,document.avs.fmonth.options[document.avs.fmonth.selectedIndex].value,document.avs.fyear.value)<1){
			alert('Sorry, due to legal restrictions of the country that you reside in, we cannot allow you access to our site.');
			document.location.href='http://www.pernod-ricard.com/PERNOD/servlet/pernod.Dispatcher?page=seeFiche.jsp&strFichesId=11975&strVisualisation=dynamic';
			return false;
		} else {
			gotourl = "intro.htm";
			document.location.href=gotourl;
			return false;
		}
		}	

