/*Image fade plugin*/
$(document).ready(function() {	
	$("#bannerimg").delay(3000).fadeOut(1500, "swing", function() {
	});
});

//	Hover Intent Plugin
//	hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
//	<http://cherne.net/brian/resources/jquery.hoverIntent.html>
//	hoverIntent is currently available for use in all personal or commercial 
//	projects under both MIT and GPL licenses. This means that you can choose 
//	the license that best suits your project, and use it accordingly.
(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options don't use it, use the settings further down
		var cfg = {
			sensitivity: 70,
			interval: 1000,
			timeout: 5000
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

//functions to call for hover intent
function showmenu(){
	$(this).children("ul.subnav").slideDown('fast').show(); 
}
function hidemenu(){
	$(this).children("ul.subnav").slideUp('fast');
}

//Custom settings for hover intent, modify this and not the default (time in milliseconds)
var config = {
	interval: 100,	//time delay for mouseover to be called
	sensitivity: 4,	//how many pixels to move before doing a new call
	over: showmenu,	//call function
	timeout: 600,	//time delay for mouseout to be called
	out: hidemenu	//call function
};

$(document).ready(function(){
	//create navigation
//	$("ul.topnav li").hover(function() { //When trigger is clicked...
//		//Following events are applied to the subnav itself (moving subnav up and down)
//		$(this).children("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
//		$(this).hover(function() {
//		}, function(event){
//			$(this).children("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
//		});
//		});
	//hiding language selection
	$("ul.topnav li").hoverIntent(config)	//calls for hover intent
	$("#languages").css({"position":"absolute", "left": -1000,"display":"none" });
	$("#change_country").click(function(event){
										event.preventDefault();
										var offset=$(this).offset();
										var el = $("#languages");
										el.css({ top: offset.top-120, left: offset.left });
										el.toggle(500);
										});
        $("#languages").mouseleave(function(event){
										var offset=$("#change_country").offset();
										$(this).css({ top: offset.top-120, left: offset.left });
										$(this).toggle(500);
										});
	/**/
});
function MembersShow()
{
var HHSize,KIDS,oForm;
oForm = document.myForm;
HHSize = oForm.HHSIZE.selectedIndex;
KIDS = oForm.KIDS.selectedIndex;

if(HHSize > 1)
{
oForm.KIDS[1].checked = false;
oForm.KIDS[0].checked = false;
    //document.getElementById('KIDS').className = 'showMe';

}
else
{
oForm.KIDS[1].checked = true;
    //document.getElementById('KIDS').className = 'hideMe';
}
/*
if(oForm.KIDS[0].checked == true)
 {
for(var i=2;i<=10;i++)
 {
  if(i<=HHSize)
   document.getElementById('Member'+(i-1)).className = 'showMe';
  else
   {  
   hideDemo(i)
   }
  }
 }
 else
 {
 for(var i=2;i<=10;i++)
 {
   hideDemo(i)
 } 
 }
 */
}
function hideDemo(i)
{
var oForm = document.myForm;
   eval('oForm.FIRSTNAMEH__'+(i-1)).value = '';
   eval('oForm.GENDERH__'+(i-1))[0].checked = false;
   eval('oForm.GENDERH__'+(i-1))[1].checked = false;
   eval('oForm.DATEOFBIRTHH__'+(i-1)+'_month').selectedIndex = 0;
   eval('oForm.DATEOFBIRTHH__'+(i-1)+'_day').selectedIndex = 0;
   eval('oForm.DATEOFBIRTHH__'+(i-1)+'_year').selectedIndex = 0;
   document.getElementById('Member'+(i-1)).className = 'hideMe';
}
function CheckValue(obj, obj_type)
 {
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
 	{
     	if (obj.value.length == 0) 
       		return false;
     	else 
       		return true;
     	}
     else if (obj_type == "SELECT")
 	{
        for (i=1; i < obj.length; i++)
 	    {
 			if (obj.options[i].selected)
 			return true;
 		}
 		return false;	
 	}
 	else if (obj_type == "RADIO")
 	{
 		for (i=0; i < obj.length; i++)
 		{
 		if (obj[i].checked)
 				return true;
 		}
 	   	return false;	
 	}
 }
function ProcessError(ErrorMsg)
{
alert(ErrorMsg);
return false;
}
function validateKidsForm()
{
var HHSize,KIDS,oForm;
oForm = document.myForm;
HHSize = oForm.HHSIZE.selectedIndex;
KIDS = oForm.KIDS.selectedIndex;
if(KIDS == 1)
{
for(var i=2;i<=10;i++)
 {
  if(i<=HHSize)
  {
  var Kid = 'oForm.DATEOFBIRTHH__'+(i-1);
  if((CheckValue(eval(Kid+'_day'),"SELECT")) || (CheckValue(eval(Kid+'_month'),"SELECT")) || (CheckValue(eval(Kid+'_year'),"SELECT")))
    {
    if (!CheckValue(eval('oForm.DATEOFBIRTHH__'+(i-1)+'_day'), "SELECT"))
	  return ProcessError("Please Select Day of DOB for Your HouseHold Member #" + (i-1));
    else if (!CheckValue(eval('oForm.DATEOFBIRTHH__'+(i-1)+'_month'), "SELECT"))
	  return ProcessError("Please Select Month of DOB for Your HouseHold Member #" + (i-1));
    else if (!CheckValue(eval('oForm.DATEOFBIRTHH__'+(i-1)+'_year'), "SELECT"))
	  return ProcessError("Please Select Year of DOB for Your HouseHold Member #" + (i-1));	 
    else
    {
        var dateString = eval(Kid+'_month').value + '/' + eval(Kid+'_day').value + '/' + eval(Kid+'_year').value;
        var KidDOB = new Date(dateString);
        if(KidDOB > new Date())
        {
        alert('Incorrect DOB for HouseHoldMember #'+(i-1));
        return false;
        }
    }
   }
  }
 }
 }
}
function validatefstpage()
{
 var oForm;
 oForm = document.myForm;
 if (!CheckValue(oForm.FIRSTNAME, "TEXT"))
	  return ProcessError("Please Enter Your FirstName");
 else if (!CheckValue(oForm.DATEOFBIRTH_day, "SELECT"))
	  return ProcessError("Please Enter Day of your DOB");
 else if (!CheckValue(oForm.DATEOFBIRTH_month, "SELECT"))
	  return ProcessError("Please Enter Month of your DOB");
 else if (!CheckValue(oForm.DATEOFBIRTH_year, "SELECT"))
	  return ProcessError("Please Enter Year of your DOB");
 else if (!CheckValue(oForm.GENDER, "RADIO"))
	  return ProcessError("Please Enter Your Gender");

var sdv = $('select[name=DATEOFBIRTH_day]').val();
var smv = $('select[name=DATEOFBIRTH_month]').val();
var syv = $('select[name=DATEOFBIRTH_year]').val();
var today = new Date();
var age = today.getFullYear() - syv;
var age_month = today.getMonth()+1-smv;
var	age_day = today.getDate()-sdv;
today.setTime(today.getTime()+1000*60*60);
  if ((age<18)||(age == 18 && age_month <0) ||(age == 18 && age_month ==0 && age_day<0))
{
document.cookie="av="+""+";expires="+"-1";
document.cookie="av=1;expires="+today.toGMTString();
}
else if ((age == 18 && age_month ==0 && age_day>=0) || (age == 18 && age_month >0))
{
document.cookie="av="+""+";expires="+"-1";
document.cookie="av=2;expires="+today.toGMTString();

}
else
{
document.cookie="av="+""+";expires="+"-1";
document.cookie="av=2;expires="+today.toGMTString();


}

}

function showSmokeFreq()
{
  var oForm,smoke;
  oForm = document.myForm;
  smoke = oForm.SMOKE.selectedIndex;
  if(smoke == 1 || smoke == 2)
  document.getElementById('SMOKEFREQ').className = 'showMe';
  else
  {
  oForm.SMOKEFREQ.selectedIndex = 0;
  document.getElementById('SMOKEFREQ').className = 'hideMe';
  }
}
function showSMSMobileNumber()
{
  var oForm;
  oForm = document.myForm;
  if((oForm.CONTACT[2].checked == true) || (oForm.ADDITIONALRESEARCH[1].checked == true))
  document.getElementById('MOBILENUMBER').className = 'showMe';
  else
  {
  oForm.MOBILENUMBER.value = '';
  document.getElementById('MOBILENUMBER').className = 'hideMe';
  } 
}
function showOccupation()
{
var oForm,Emp;
oForm = document.myForm;
Emp = oForm.EMPLOYMENTSTATUS.selectedIndex;
if(Emp == 1 || Emp == 2 || Emp == 3 || Emp == 8 || Emp == 9)
document.getElementById('OCCUPATION').className = 'showMe';
else
{
oForm.OCCUPATION.selectedIndex = 0;
document.getElementById('OCCUPATION').className = 'hideMe';
}
}
function showIncBig(str)
{
var oForm,PerInc,HHInc,showobj,selobj,selind;
oForm = document.myForm;
if(str == 'PER')
{
selobj = 'PERSONALINCOME';
showobj = 'PERSONALINCOMEBIG';
}
else if(str == 'HH')
{
selobj = 'HOUSEHOLDINCOME';
showobj = 'HOUSEHOLDINCOMEBIG';
}
selind = eval('oForm.'+selobj).selectedIndex;
if(selind == 13 || selind == 14)
document.getElementById(showobj).className = 'showMe';
else
{
eval('oForm.'+showobj).selectedIndex = 0;
document.getElementById(showobj).className = 'hideMe';

}
}
function showVehicleItems()
{
var veh,oForm;
oForm = document.myForm;
veh = oForm.VEHICLEPURCHASE.selectedIndex;
 if(veh > 0 && veh < 4)
 {
 document.getElementById('VEHICLEPURDECINVOL').className = 'showMe';
 document.getElementById('VEHICLEMAKE').className = 'showMe'; 
 }
 else
 {
 oForm.VEHICLEPURDECINVOL.selectedIndex = 0;
 oForm.VEHICLEMAKE.selectedIndex = 0;
 document.getElementById('VEHICLEPURDECINVOL').className = 'hideMe';
 document.getElementById('VEHICLEMAKE').className = 'hideMe';  
 }
}
function showMobileItems()
{
var mob,oForm;
oForm = document.myForm;
mob = oForm.MOBILEPAY.selectedIndex;
 if(mob > 0 && mob < 7)
 {
 document.getElementById('MOBILEHOWPAY').className = 'showMe';
 document.getElementById('MOBILENETWORK').className = 'showMe'; 
 }
 else
 {
 oForm.MOBILEHOWPAY.selectedIndex = 0;
 oForm.MOBILENETWORK.selectedIndex = 0;
 document.getElementById('MOBILEHOWPAY').className = 'hideMe';
 document.getElementById('MOBILENETWORK').className = 'hideMe';  
 }
}
function showConAlcoholWr()
{
var Alc,oForm;
oForm = document.myForm;
   
    if(oForm.CONSUMPTIONALCOHOL[13].checked == false)
      document.getElementById('CONSUMPTIONALCOHOLWHERE').className = 'showMe';
    else
    {
    oForm.CONSUMPTIONALCOHOLWHERE.selectedIndex = 0;
    document.getElementById('CONSUMPTIONALCOHOLWHERE').className = 'hideMe';
    }
}

function showSmkOtherBrnds()
{
var oForm,smkBrnds;
oForm = document.myForm;
smkBrnds = oForm.SMOKINGOTHERBRANDS.selectedIndex;
 if(smkBrnds == 21)
  document.getElementById('SMOKINGOTHERSUBBRANDS').className = 'showMe';
 else
 {
 oForm.SMOKINGOTHERSUBBRANDS.selectedIndex = 0;
 document.getElementById('SMOKINGOTHERSUBBRANDS').className = 'hideMe';
 }
}
function showItems()
{
if(document.getElementById('KIDS') != null)
  MembersShow(); 
if(document.getElementById('SMOKEFREQ') != null)
 showSmokeFreq();
if(document.getElementById('MOBILENUMBER') != null)
 showSMSMobileNumber();
if(document.getElementById('PERSONALINCOME') != null)
 {
 showOccupation();
 showIncBig('PER');
 showIncBig('HH');
 }

/*if ( ($("select[name=SMOKE]").val() != undefined) && ($.cookie("av")==1) ) 
	  document.getElementById('SMOKE').className = 'hideMe';
else 
document.getElementById('SMOKE').className = 'showMe';*/
if ($("select[name=SMOKE]").val() != undefined)
{
if ($.cookie("av")==1){
document.getElementById('SMOKE').className = 'hideMe';
}
else{
document.getElementById('SMOKE').className = 'showMe';
}
}

	  	 
}
function smokeValidate(){
//if ($.cookie("av")==2 && (document.myForm.SMOKE.selectedIndex != 1 || document.myForm.SMOKE.selectedIndex!=2 ||document.myForm.SMOKE.selectedIndex!=3))
if ($.cookie("av")==2 && (document.myForm.SMOKE.selectedIndex == 0) )
	{ 
alert("Please Answer the smoke question");
return false;
}
}

function collectionLoad()
{
 if(document.getElementById('VEHICLEPURCHASE') != null)
 showVehicleItems();
 if(document.getElementById('MOBILEPAY') != null)
 showMobileItems();
 if(document.getElementById('CONSUMPTIONALCOHOL') != null)
 showConAlcoholWr();
 if(document.getElementById('SMOKINGOTHERBRANDS') != null)
 showSmkOtherBrnds();
}
