﻿$(document).ready(function() {

    detect();

    var COOKIE_NAME = "BayerCropScienceCALang";
    var currentCultureCopy, currentCultureMaxLength;

    (COOKIE_NAME == 'en-CA') ? currentCultureMaxLength = 21 : currentCultureMaxLength = 25;

    $(".localRep").focus(function() {
        if ($(this).val() == currentCultureCopy) {
            $(this).attr('value', '');
            $(this).css({ color: "black" });
            $(this).attr('maxlength', 7);
        }
    });

    $(".localRep").blur(function() {
        if ($(this).val() == "") {
            $(this).attr('value', currentCultureCopy);
            $(this).css({ color: "#999999" });
            $(this).attr('maxlength', currentCultureMaxLength);
        }
    });

    doWatermac();
    doWatermark();

    $('#ltaOnlineTraining').attr('href', '#');
    $('#ltaOnlineTraining').click(function() {
        showPopup();
    });
});

function doWatermac()
{    
    $('form').submit(function(){        
        $('.textWatermark').each(function(){
            if($(this).attr('value') == $(this).attr('defaultvalue'))
                $(this).attr('value', '');                
        });        
    }); 
        
  $('.textWatermark').each(function(){    
        if($(this).attr('value') == '')
            $(this).attr('value', $(this).attr('defaultvalue'));                
            
        if ($(this).attr('value') == $(this).attr('defaultvalue'))
            $(this).css('color', $(this).attr('watermarkcolor'));
  });
  
  $('.textWatermark').focus(function(){
    if($(this).attr('defaultvalue') == $(this).attr('value'))
    {
        $(this).attr('value', '');        
        $(this).css('color', 'black');
    }
  });
    
  $('.textWatermark').blur(function(){
    if($(this).attr('value') == '')
    {
        $(this).attr('value', $(this).attr('defaultvalue'));        
        $(this).css('color', $(this).attr('watermarkcolor') );
    }
  }); 
}

function doWatermark()
{    
    $('form').submit(function(){        
        $('.textWatermark2').each(function(){
            if($(this).attr('value') == $(this).attr('defaultvalue'))
                $(this).attr('value', '');                
        });        
    }); 
        
  $('.textWatermark2').each(function(){    
        if($(this).attr('value') == '')
            $(this).attr('value', $(this).attr('defaultvalue'));                
            
        if ($(this).attr('value') == $(this).attr('defaultvalue'))
            $(this).css('color', $(this).attr('watermarkcolor'));
  });
  
  $('.textWatermark2').focus(function(){
    if($(this).attr('defaultvalue') == $(this).attr('value'))
    {
        $(this).attr('value', '');        
        $(this).css('color', 'black');
    }
  });
    
  $('.textWatermark2').blur(function(){
    if($(this).attr('value') == '')
    {
        $(this).attr('value', $(this).attr('defaultvalue'));        
        $(this).css('color', $(this).attr('watermarkcolor') );
    }
  }); 
}
function numbersonly(myfield, e, dec)
{
    var key;
    var keychar;

    if (window.event)
       key = window.event.keyCode;
    else if (e)
       key = e.which;
    else
       return true;
    keychar = String.fromCharCode(key);

    // control keys
    if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) )
       return true;

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1))
       return true;

    // decimal point jump
    else if (dec && (keychar == "."))
       {
       myfield.form.elements[dec].focus();
       return false;
       }
    else
       return false;
}



function detect()
{
    if(!navigator.cookieEnabled)
    {
       alert('Your browser has cookies disabled. \nTo view this site, cookies must be enabled');
    }
}

function ConfirmDelete(value)
{
    return confirm("Are you sure you want to delete this " + value + "?");
}

function ConfirmDeleteFull(value)
{
    return confirm(value);
}

function HasBaseURLPopUp(URL, title, width, height) {

    var url = RM_BASEURL + 'flash/default.aspx?path='+ URL  + '&w=' + width + '&h=' + height+ '&title=' + title;
    
	day = new Date();
	id = day.getTime();
	
    var screen_left = (screen.width)?(screen.width-width) / 2 : 100;
    var screen_top = (screen.height) ? (screen.height - height) / 2 : 100;

	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=" + width + ",height=" + height + ",left = " + screen_left +  " ,top = " + screen_top + "');");
}

function hasBaseURLPopUp(URL,description,width,height) {

    URL = RM_BASEURL + URL;    
    
	day = new Date();
	id = day.getTime();
	
    var screen_left = (screen.width)?(screen.width-width)/2:100;
    var screen_top = (screen.height) ? (screen.height - height) / 2 : 100;

	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=" + width + ",height=" + height + ",left = " + screen_left +  " ,top = " + screen_top + "');");
}

function VideoPlayer(title, description, width, height)
{ 
	day = new Date();
	id = day.getTime();

    var screen_left = (screen.width)?(screen.width-width)/2:100;
    var screen_top =(screen.height)?(screen.height-height)/2:100;
    
    var url = RM_BASEURL + 'video-player/default.aspx?title=' + title + '&w=' + width + '&h=' + height;
    
    eval("page" + id + " = window.open(url, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=" + width + ",height=" + height + ",left = " + screen_left +  " ,top = " + screen_top + "');");
}

function newWindow(url, windowName, width, height, toolbar, location, status, menubar, scrollbars, resizable) {
    //set the defaults for the params
    if(!windowName) windowName = "popup";
    if(!width) width = "400";
    if(!height) height = "300";
    if(!toolbar) toolbar = "no";
    if(!location) location = "no";
    if(!status) status = "no";
    if(!menubar) menubar = "no";
    if(!scrollbars) scrollbars = "no";
    if(!resizable) resizable = "no";
    
    url = RM_BASEURL + url;
    
    var windowProperties = 'height='+height+',width='+width+',toolbar='+toolbar+',location='+location+',status='+status+',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;
    win = window.open(url, windowName, windowProperties);
}




function redirectSite(value) {
    window.location.href = value;
}






//TODO:  this needs to create the stop timers dynamically
function stopTimer() {
    //alert('<%= countDownTimer.ClientID %>');
    //var b = $find('<%= countDownTimer.ClientID %>');

    var a = $find('ctl00_callToAction_ctaPromoControl_countDownTimer_countDownTimer');
    var b = $find('ctl00_callToAction2_ctaPromoControl_countDownTimer_countDownTimer');
    var c = $find('ctl00_callToAction3_ctaPromoControl_countDownTimer_countDownTimer');
    var d = $find('ctl00_callToActionCombined_control1_ctaPromoControl_countDownTimer_countDownTimer');
    var e = $find('ctl00_callToActionCombined_control2_ctaPromoControl_countDownTimer_countDownTimer');

    if (a != null) {
        // alert(a);
        a._stopTimer();
    }
    if (b != null) {
        //  alert(b);
        b._stopTimer();
    }
    if (c != null) {
        // alert(c);
        c._stopTimer();
    }
    if (d != null) {
        // alert(c);
        d._stopTimer();
    }
    if (e != null) {
        // alert(c);
        e._stopTimer();
    }

}