﻿jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// Open links with a class of blank in new window
$(document).ready(function(){
    $('a.blank').click(function(){
       window.open(this.href);
       return false;
    });
    
    ///$(window).resize(function(){ flash_width(); });
});

function convertToDate(d, m, y) {
  var dd = parseInt(d.options[d.selectedIndex].value);
  var mm = parseInt(m.options[m.selectedIndex].value) - 1;
  var yy = parseInt(y.options[y.selectedIndex].value);
  var dt = new Date(yy, mm, dd);	  
  // Detection for bad dates (e.g. feb 31st)
  if(dt.getDate() != dd || dt.getMonth() != mm  || dt.getFullYear() != yy)
    dt = "Invalid Date";
  return dt;
}

function submitValidationDob()
{
  var dobD = $(".pg-dob .inputDOB")[0];
  var dobM = $(".pg-dob .inputDOB")[1];
  var dobY = $(".pg-dob .inputDOBY")[0];            
  return validateDob(dobD, dobM, dobY)
}

function changeValidationDob()
{
  var dobD = $(".pg-dob .inputDOB")[0];
  var dobM = $(".pg-dob .inputDOB")[1];
  var dobY = $(".pg-dob .inputDOBY")[0];
  if (dobD.selectedIndex > 0
        && dobM.selectedIndex > 0
        && dobY.selectedIndex > 0)
  {
    var dt = convertToDate(dobD, dobM, dobY) 
    if(dt != "Invalid Date") {
        var now = new Date();
        var years = now.getFullYear() - dt.getFullYear();	    
        if(now.getMonth() < dt.getMonth() || (now.getMonth() == dt.getMonth() && now.getDate() < dt.getDate())) {
          years--;	      
        }	    
        if(years >= 18) {
            $("#pg-optin").show();
        }
        else 
        {
            $("#pg-optin").hide();
        }
    } else {
        $("#pg-optin").hide();
    }
    return (dt != "Invalid Date");
  } else {
    return true;
  }             
}

function validatePassword(source, args) {
  var pwd = String(args.Value);
  args.IsValid = pwd.length >= 6; 
}

function flash_width(){
						
							var width=$(window).width();
							
							if(width > 1200){
								var flash_width_size=1200;
							} else {
								var flash_width_size=width;
							}
							
							$('#flash_content').css({'width': flash_width_size});
						
						return flash_width_size;
				}