// JavaScript Document

<!-- Lou's Baseball Line Convertor JavaScript -->
// Created by Joe MacDonald
// Copyright CSI, 1997


function CalcLine(form)
{
       if (Check(form.Percent) && Check(form.Line))
  {
       p1 = parseFloat(form.Percent.value);
          v1 = parseFloat(form.Line.value);

     if (p1 < 0)
     {
       p1 = -p1;
               form.Percent.value = p1;
     }

     if (p1 > 50)
                       v1 = -(p1 * 100) / (100 - p1);
     else if (p1 < 50)
     {
                       p1 = 100 - p1;
        v1 = ((p1 * 100) / (100 - p1));
     }
     else v1 = 100;

          form.Line.value = v1;
       }
  else form.Percent.value = 'Error';
}

function CalcPercent(form)
{
       if (Check(form.Percent) && Check(form.Line))
  {
       p1 = parseFloat(form.Percent.value);
             v1 = parseFloat(form.Line.value);

                if (v1 < 0)
           {
               v1 = -v1;
              p1 = v1 / (v1 + 100);
                       form.Percent.value = p1 * 100;
           }
           else
           {
              p1 = v1 / (v1 + 100) * 100;
                       form.Percent.value = 100 - p1;
           }

       }
       else form.Percent.value = 'Error';
}

function Check(infield)
{   flag = 0;
   var str = infield.value;
   for ( i = 0; i < str.length; i++)
   {
                var chr = str.substring(i, i+1);
      if (((chr < "0") || (chr > "9")) && (chr != ".") && (chr != "-") && (chr != "+"))
      flag = 1;
   }
   if ((flag == 1) || (str.length == 0))
   {   infield.value = 'Error';
       return false;}
   else return true;
}

function clearForm(form)
{    form.Percent.value = "0";
   form.Line.value = "0";
}


<!-- End of Script -->


//var baseurl = '/sbastias'
var baseurl = ''

var submitEmail = function(val){
	
	$.ajax({
		url: baseurl+'/catchEmail.php',
		method: 'GET',
		data: 'email='+val,
		success: function(data) {
				if(data == 'domainFail') alert('Please enter a valid email address.')
				if(data == 'emailExists') alert('That email address already exists in our system!')
				if(data == 'success'){
					alert('Thanks! Now you\'ll get exclusive tips sent to your email. Learn the hints from the best!')
					$('#emailaddress').val('')
				}
			},
		complete: function(){},
		error: function(){
				alert('Error!')
			}
	});
}


var validEmail = function(email){
	ind_at = email.indexOf('@')
	usernme = email.substring(0, ind_at)
	domain = email.substring(ind_at+1)
	
	ind_dot = domain.indexOf('.')
	domainname = domain.substring(0, ind_dot)
	domainext = domain.substring(ind_dot+1)
	
	if(!usernme || !domainname || !domainext || domainext.length < 2 || domainext.length > 4) return false
	else return true
}

/*
var doLogin = function(user,pass,remember){
	if(remember){
		$.cookie('useremail', user)
		$.cookie('passcode', pass)
	}
	else{
		$.cookie('useremail', null)
		$.cookie('passcode', null)
	}
}
*/

$(document).ready(function(){
	//alert($('.goldLinks > li').length + ':' + $('.goldLinks').width())
	$('.goldLinks > li')
		.width(($('.goldLinks').width() / $('.goldLinks > li').length))
	$('.garnetLinks > li')
		.width(($('.garnetLinks').width() / $('.garnetLinks > li').length))
	
	$('.goldLinks > li').children('.goldLink').css('backgroundPosition', 'center top')
		.mouseover(function(){$(this).css('backgroundPosition', 'center -49px')})
		.mouseout(function(){$(this).css('backgroundPosition', 'center top')})
	$('.goldLinks > li:first').children('.goldLink')
		.css('backgroundPosition', 'left top')
		.mouseover(function(){$(this).css('backgroundPosition', 'left -49px')})
		.mouseout(function(){$(this).css('backgroundPosition', 'left top')})
	$('.goldLinks > li:last').children('.goldLink')
		.css('backgroundPosition', 'right top')
		.mouseover(function(){$(this).css('backgroundPosition', 'right -49px')})
		.mouseout(function(){$(this).css('backgroundPosition', 'right top')})
		
		
	$('.garnetLinks > li').children('.garnetLink')
		.mouseover(function(){$(this).css('background', 'url('+baseurl+'/images/menuBarGarnet_on.gif) no-repeat center top')})
		.mouseout(function(){$(this).css('background', 'none')})
	$('.garnetLinks > li:last').children('.garnetLink')
		.mouseover(function(){$(this).css('background', 'url('+baseurl+'/images/menuBarGarnet_on.gif) no-repeat right top')})
		
	$(document).pngFix()
	
	
	$('.topLink:first').before('<div class="floatspacer"><img src="'+baseurl+'/images/topBar_spacerBar.gif" height="27" width="2" border="0"></div>')
	$('.topLink').after('<div class="floatspacer"><img src="'+baseurl+'/images/topBar_spacerBar.gif" height="27" width="2" border="0"></div>')
	
	$('.topLink')
		.mouseover(function(){$(this).addClass('active')})
		.mouseout(function(){$(this).removeClass('active')})
		
	/*
	if($.cookie('useremail')){
		$('#useremail').val($.cookie('useremail'))
		$('#passcode').val($.cookie('passcode'))
		$('#rememberme').attr('checked', true)
	}
	*/
	
	$('.loginButton')
		.mouseover(function(){$(this).addClass('active')})
		.mouseout(function(){$(this).removeClass('active')})
		.click(function(){
			useremail = $('#useremail').val()
			passcode = $('#passcode').val()
			rememberme = $('#rememberme').is(':checked')
			//alert(useremail+":"+passcode+":"+rememberme)
			doLogin(useremail, passcode, rememberme)
		})
		
	$('#lleague').change(function(){
		var url, urlparts, newurl
		url = location.href
		if(url.indexOf('lleague') > 0){
			urlparts = url.split('lleague=')
			if(urlparts[1].indexOf('&') > 0) urlparts[1] = '&'+urlparts[1].substring(urlparts[1].indexOf('&'))
			else urlparts[1] = ''
			newurl = urlparts[0]+'lleague='+$(this).val()+urlparts[1]
		}
		else{
			urlparts = url.split('?')
			urlparts[0] += '?'
			urlparts[1] ? newurl = urlparts[0]+urlparts[1]+'&lleague='+$(this).val() : newurl = urlparts[0]+'lleague='+$(this).val()
		}
		location.href = newurl
	})
	
	$('#period').change(function(){
		$('.linesDiv').hide()
		$('.period_'+$(this).val()).show()
		//alert('.period_'+$(this).val())
	})
	
	$('#emailSubmitButton')
		.mouseover(function(){$(this).css('backgroundPosition', '0 -24px')})
		.mouseout(function(){$(this).css('backgroundPosition', '0 0')})
		.click(function(){
			var useremail = $('#emailaddress').val()
			if(!$('#emailaddress').hasClass('default') && validEmail(useremail)) submitEmail($('#emailaddress').val())
			else alert('Please enter a valid email address.')
		})
		
	$('#emailaddress')
		.addClass('default')
		.focus(function(){
			if($(this).hasClass('default')) $(this).val('').removeClass('default')
		})
		.blur(function(){
			if(!$(this).hasClass('default') && $(this).val() == '') $(this).val('your.email@address.com').addClass('default')
		})
	
	if($('.emailAlertOverlay').height() < 100){
		$('.emailAlertOverlay').css({height: $('#emailCatchBox').height()+2, width: $('#emailCatchBox').width()+2, left: $('#emailCatchBox').css('left')-1})
	}
	
	$('#morescores')
		.mouseover(function(){$(this).removeClass('off').addClass('on')})
		.mouseout(function(){$(this).removeClass('on').addClass('off')})
		.click(function(){location.href= baseurl+'/scores/'})
		
	$('#moretrends')
		.mouseover(function(){$(this).removeClass('off').addClass('on')})
		.mouseout(function(){$(this).removeClass('on').addClass('off')})
		.click(function(){
			if($('.trend.hidden').length){
				$('.trend.hidden').removeClass('hidden').addClass('shown')
				$(this).text('Click here for less trends!')
			}
			else{
				$('.trend.shown').removeClass('shown').addClass('hidden')
				$(this).text('Click here for more trends!')
			}
		})
	
	
	$('#link_livelines').click(function(){location.href= baseurl+'/'})
	$('#link_matchups').click(function(){location.href= baseurl+'/schedules/'})
	$('#link_recentnews').click(function(){location.href= baseurl+'/recentnews/'})
	
	$('#link_previews').click(function(){location.href= baseurl+'/previews/'})
	$('#link_topbooks').click(function(){location.href= baseurl+'/topbooks/'})
	$('#link_articles').click(function(){location.href= baseurl+'/articles/'})
	
	$('#link_bettools').click(function(){location.href= baseurl+'/bettools/'})
	$('#link_schedules').click(function(){location.href= baseurl+'/schedules/'})
	$('#link_scores').click(function(){location.href= baseurl+'/scores/'})
	$('#link_soccer').click(function(){location.href= 'http://www.thesoccerfield.com/'})
	
	//$('#leftAdSpace').click(function(){location.href="http://affiliates.youwager.com/aspx/affiliateStoreClick.aspx?ID_SC=873&ID_I=535"})
	//$('.adSpace').click(function(){location.href="http://affiliates.youwager.com/aspx/affiliateStoreClick.aspx?ID_SC=873&ID_I=534"})
	
})
