// cookie handlers
// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

var playStat = true;
var muteStat = "false";
// set mute status
if(getCookie("muteStat") != null){
	muteStat = getCookie("muteStat");
} else {
	muteStat = "false";
}

function sel_playlist_mute_icon(){
	if(muteStat == "true") {
		$('img#soundOptBtn').attr('src','/images/sound_off_btn.jpg');
	} else {
		$('img#soundOptBtn').attr('src','/images/sound_btn.jpg');
	}
}

function sel_playlist_mute(){
	if(muteStat == "true") {
		muteStat = "false";
		player.sendEvent("MUTE", "false");
		setCookie("muteStat",false,365);
		$('img#soundOptBtn').attr('src','/images/sound_btn.jpg');
	} else {
		muteStat = "true";
		player.sendEvent("MUTE", "true");
		setCookie("muteStat",true,365);
		$('img#soundOptBtn').attr('src','/images/sound_off_btn.jpg');
	}
}

$(document).ready(function() {
	
//	$("#getapprovedpaw").click( function() {
//		$("#approvedSelect").fadeIn("slow", function() {
//			$("#closeApproval").click( function() {
//				$("#approvedSelect").fadeOut("slow");
//			});
//		});
//	});
	
	sel_playlist_mute_icon();
	
	$("a.imgHlper").fancybox();
		
	var container = $('#validate');
	// validate the form when it is submitted
	var validator = $("#shareInv").validate({
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate",
		invalidHandler: function(form, validator) {
			$( "#validate" ).dialog();
        }
	});

	var validator = $("#approvalFrm").validate({
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate",
		invalidHandler: function(form, validator) {
			$( "#validate" ).dialog();
        }
//		submitHandler: function() {
//			approvalSub();
//		}
	});
 $('#redClose').click( function() {
	var cssObj = {
      'position' : 'absolute',
      'top' : '82px',
      'left' : '233px',
      'width' : '339px',
      'height' : '243px',
      'z-index' : '70'
    }
	$('#video-container').css(cssObj);
	$('#closeVid').css('display','none');
 });
});

// AJAX form no longer used
function approvalSub(){
	var hearAbout = $('#hearAbout').val();
	var firstName = $('#firstName').val();
	var lastName = $('#lastName').val();
	var email = $('#email').val();
	var phone = $('#phone').val();
	var otherphone = $('#otherphone').val();
	var city = $('#city').val();
	var state = $('#state').val();
	var lengthArea = $('#lengthArea').val();
	var carPayments = $('#carPayments').val();
	var bankruptcy = $('#bankruptcy').val();
	var downPayment = $('#downPayment').val();
	var employment = $('#employment').val();
	var lengthJob = $('#lengthJob').val();
	var hourlyWage = $('#hourlyWage').val();
	var monthlyWage = $('#monthlyWage').val();
	var ppAgree = $('#ppAgree').val();
	
	var dataStr = "hearAbout="+hearAbout+"&firstName="+firstName+"&lastName="+lastName+"&email="+email+"&phone="+phone+"&otherphone="+otherphone+"&city="+city+"&state="+state+"&lengthArea="+lengthArea+"&carPayments="+carPayments+"&bankruptcy="+bankruptcy+"&downPayment="+downPayment+"&employment="+employment+"&lengthJob="+lengthJob+"&hourlyWage="+hourlyWage+"&monthlyWage="+monthlyWage+"&ppAgree="+ppAgree;
	
	$.ajax({  
   type: "POST",  
   url: "/form-proc/approval/",  
   data: dataStr,  
   success: function(msg) { 
   		$('#opDone').html(msg);
   }  
 });  
}

// control current playing video file
function sel_playlist_item(plitem){
	player.sendEvent('ITEM', plitem);
}

function sel_playlist_next(){
	player.sendEvent('NEXT');
}

function sel_playlist_fs(){
	var cssObj = {
      'position' : 'absolute',
      'top' : '0',
      'left' : '0',
      'width' : $('#vidboxWrap').width(),
      'height' : $('#vidboxWrap').height(),
      'z-index' : '999'
    }
	$('#video-container').css(cssObj);
	$('#closeVid').css('display','block');
}

function sel_playlist_prev(){
	player.sendEvent('PREV');
}

function sel_playlist_pause(){
	if(playStat == true) {
		playStat = false;
		player.sendEvent("PLAY", false);
	} else {
		playStat = true;
		player.sendEvent("PLAY", true);
	}
}

function switchTab(selTab){
	$('.tabs').css('display','none');
	$('#tab'+selTab).show(300);
}

// used on faq page
$(function() {
	$('#faqQuests a').click(function(){
		$('#faqQuests a').removeClass('faqSel');
		$(this).addClass('faqSel');
	});
});

function showFaq(id){
	$('.faqCopy').css('display','none');
	$('#faqCopy'+id).css('display','block');
}

// used on service page
$(function() {
	$('.servCopyBlock').mouseover(function(){
		$(this).css('z-index','999');
	});
	$('.servCopyBlock').mouseleave(function(){
		$(this).css('z-index','10');
	});
});

// used on mack mack page
$(function() {
	$('.vidListLnk').click(function(){
		$('#mackDance ul ul').css('display','none');
		$(this).next('ul').css('display','block');
	});
});

