jQuery(document).ready(function(){
    
	$(function() {
		/*$("input.file_1").filestyle({
			image: "http://bcteal.org/wp-content/themes/BCTEAL/images/choosefile.png",
			imageheight : 21,
			imagewidth : 98,
			width : 200,
			cssClass : 'fileStyle'
		});
		*/
		$("input.attachFile").filestyle({
			image: "/wp-content/themes/BCTEAL/images/attachfile.png",
			imageheight : 31,
			imagewidth : 58,
			width : 300
			//cssClass : 'attachFileStyle'
		});
	}); 
	/*
	$('.select').sSelect();
	
	$('.select_js').sSelect({
		containerClass:'select-long',
		ddMaxHeight: '239px'
	});
	$('.select_js_short').sSelect({
		containerClass:'select-short',
		ddMaxHeight: '194px'
	});
	$('.select_js_filter').sSelect({
		containerClass:'select-filter',
		ddMaxHeight: '194px'
	});
*/	
    $('#contactform').ajaxForm({
        url: '/wp-admin/admin-ajax.php?action=contact_us',
        type: 'post',
        //iframe: true,
        success: function(data) {
            $('#contactform').hide();
            $('#thanks').show();
            return true;
        },
        beforeSubmit: function() {

			isValid = formValidation('contactform', 'email');
			if ( isValid ) {
                $('#submitForm').hide();
                $('#formstatus').show();
                return true;
            } else {
                return false;
            }

        }
    });
	
	$('#proposalSubmissionform').ajaxForm({
        url: '/wp-admin/admin-ajax.php?action=proposal',
        //iframe: true,
        type: 'post',
        success: function(data) {

            $('#proposalSubmissionform').hide();
            $('#thanks').show();
			window.scroll(0,150); 
            return true;
        },
        beforeSubmit: function() {

			isValid = proposalFormValidation('proposalSubmissionform', 'email');
			if ( isValid ) {
                $('#submitProposalSubmissionform').hide();
                $('#formstatus').show();
                return true;
            } else {
                return false;
            }

        }
    });

    $('.txtInp').click(function(el){
        $('.err').css('display','none');
    }).focus(function(el){
        $('.err').css('display','none');
    });

    $('.txtArea').click(function(el){
        $('.err').css('display','none');
    }).focus(function(el){
        $('.err').css('vdisplay','none');
    });
   
   $('#content2 ul li:odd').addClass('odd');

	
	$('#loginBoxOpen').click(function(){	
		$('#loginBox').show();	
		$('#user_login').focus();
		return false;
	});
	$("#loginBox").click(function(e){
		e.stopPropagation();
	});
	$(document).click(function(event){
		$('#loginBox').hide();	
	});
	$('#loginBoxClose').click(function(){
		$('#loginBox').hide();	
	});
	

addTooltip();	

var newImg = new Image();
newImg.src = '/wp-content/themes/BCTEAL/images/loginForm.gif';

// Cufon.replace('h1, #sidebarLeft .content h2');

});


 
function formValidation(formId, emailId) {
	

            var isValid = true;

            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = $('#'+emailId).val();
            $('.err').hide();

            $('#'+formId+' .required').each(function(){

             checkVal = $(this).val();
             if (checkVal.length<2) {
                    isValid = false;
                    $('#'+$(this).attr('id')+'Err').focus();
					$('#'+$(this).attr('id')+'Err').show();
                    return false;
                }
            });

            if ( isValid ) {
                if ( reg.test(address) == false ) {
                    isValid = false;
                    $('#'+emailId).focus();
                    $('#'+emailId+'Err').html('Invalid email address!');
					$('#'+emailId+'Err').show();
                }
            }

	
return isValid;
}


function proposalFormValidation(formId, emailId) {
	

            var isValid = true;

            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = $('#'+emailId).val();
            $('.err').hide();
			$('.topErr').hide();
			$('.topError').css('display','none');
			
            $('#'+formId+' .required').each(function(){

             checkVal = $(this).val();
             if (checkVal.length<2) {
                    isValid = false;
                    $('#'+$(this).attr('id')+'Err').focus();
					$('#'+$(this).attr('id')+'Err').show();
					$('#'+$(this).attr('id')+'Error').show();
					$('.topError').css('display','block');
                    return false;
                }
            });
            if ( isValid ) {
                if ( reg.test(address) == false ) {
                    isValid = false;
                    $('#'+emailId).focus();
                    $('#'+emailId+'Err').html('Invalid email address!');
					$('#'+emailId+'Err').show();
                }
            }

	
return isValid;
}



function addTooltip(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = $(this).children('span').text();
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){ 
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	
};

function externalLinks() {  if (!document.getElementsByTagName) return;  var anchors = document.getElementsByTagName("a");  for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];  if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external")  anchor.target = "_blank";  }  }  

window.onload = externalLinks;  
 

