// JavaScript Document

$(document).ready(function(){
	
	Cufon.replace('.cufon-text')('#nav ul li a')('#brag')('.white')('h3')('h4')('.page h1.entry-title')('.post h1.entry-title');
	
	$('#s4').cycle({
		fx: 'fade',
		speed: 750,
		timeout: 4000,
		next:   '#next2', 
		prev:   '#prev2'
		/*pager: '#slideshow-nav',
		pagerAnchorBuilder: function(idx, slide) {
			return '#slideshow-nav li:eq(' + (idx) + ')';
		}*/
	});

	/*$('#slideshow-nav li').bind('click',function() { 
		$('#slideshow').cycle('pause'); 
	});
	
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
		$(pager).find('li').removeClass('activeLI') 
			.filter('li:eq('+currSlideIndex+')').addClass('activeLI'); 
	}; */

	$("#die").simpletip({ // Configuration properties 
	
		content: 'My Simpletip',
		
		fixed: true 
	
	});
	
	$("a[rel^='prettyPhoto']").bind('click',function(e){e.preventDefault();
 showVideo($(this).attr('href')); return false; });
 
	$('#contact-mini-form').bind('submit',function(){ showRequestForm(); return false; });
	$('#minisubmit').bind('click',function(){ showRequestForm(); return false; });
	$('.requestform').bind('click',function(){ showRequestForm(); return false; });
	
	$('.commercialform').bind('click',function(){ showCommercialForm(); return false; });
	
});

function makeClear(input, orig){
	if(input.value == orig)
	{
		input.value = '';
		input.style.color = '#000';
		input.style.fontStyle = 'normal';
		input.value = '';
	}
	return true;
}

function undoClear(input, orig){
	if(input.value == '')
	{
		input.value = orig;
		input.style.color = '#666666';
		input.style.fontStyle = 'italic';
		input.value = orig;
	}
	return true;
}

function showVideo(clicked){

	$('#lighbox-style-generator').prettyPhoto({
			social_tools : '',
			theme: 'dark_square' /* light_rounded / pp_default / light_square / dark_rounded / facebook */
	});
	
	$.prettyPhoto.open(clicked);
}

function showRequestForm(){
	var movefrom = $('#minimovingfrom').val();
	var moveto = $('#minimovingto').val();
	var mdate = $('#minimovedate').val();
	if(movefrom == 'undefined')
	{
		movefrom = '';
	}
	if(moveto == 'undefined')
	{
		moveto = '';
	}
	if(mdate == 'undefined')
	{
		mdate = '';
	}
	
	//$.prettyPhoto.close();
	
	ref = window.location;
	
	section = location.pathname.substr(1,8);
	if(section){
		switch(section){
			case 'resident' : size = 640; break;
			case 'employee' : size = 600; break;
			case 'internat' : size = 640; break;
			case 'commerci' : size = 600; break;
			case 'governme' : size = 670; break;
			default : size = 670; break;
			
		}
	} 
	
	if(!size){
		size = 670;
	}
	
	$('#lighbox-style-generator').prettyPhoto({
		social_tools : '',
		theme:'light_rounded',
		keyboard_shortcuts: false
	});
	
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		 if (ieversion<=7){
			 size += 100;
		 }
	}
	
	$.prettyPhoto.open('/lightboxform.php?ajax=true&width=500&height='+size+'&ref='+ref+'&movefrom='+movefrom+'&moveto='+moveto+'&mdate='+mdate); 
	
	
	if(mdate){
		$('#lightbox-form-move-date').css('color','#000');
		$('#lightbox-form-move-date').css('fontStyle','normal');
	}
		
}

function showCommercialForm(){
	$('#lighbox-style-generator').prettyPhoto({
		social_tools : '',
		theme:'light_rounded',
		keyboard_shortcuts: false
	});
	
	ref = escape('html://fill.com/commercial');
	size = 600;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		 if (ieversion<=7)
		 	size += 100;
	}
	
	$.prettyPhoto.open('/lightboxform.php?ajax=true&width=500&height='+size+'&ref='+ref); 
	
}

function validateForm(form)
{
	
	if (form.name.value == "" || form.name.value == "Name")
	{
		alert ("Please fill in your Name.");
		form.name.focus();
		return false;
	}
	else if (form.phone.value == "" || form.phone.value == "Phone")
	{
		alert ("Please fill in your Phone.");
		form.phone.focus();
		return false;
	}
	else if (checkPhone(form.phone.value) == false)
	{
		alert ("Please enter a valid Phone Number (Include area code)");
		form.phone.focus();
		return false;
	}
	else if (form.email.value == "" || form.email.value == "Email")
	{
		alert ("Please fill in your Email Address.");
		form.email.focus();
		return false;
	}
	else if (checkEmail(form.email.value) == false)
	{
		alert ("Please enter a valid Email Address.");
		form.email.focus();
		return false;
	}
	else if (form.moving_from.value == "" || form.moving_from.value == "City")
	{
		alert ("Please fill in where your moving from.");
		form.moving_from.focus();
		return false;
	}
	else if (form.moving_to.value == "" || form.moving_to.value == "City")
	{
		alert ("Please fill in where your moving to.");
		form.moving_to.focus();
		return false;
	}
	else if (form.moving_date.value == "" || form.moving_date.value == "Move Date") {
		alert("Please fill in projected moving date.");
		form.moving_date.focus();
		return false;
	}
	
	var to_state = '';
	var to_zip = '';
	var from_state = '';
	var from_zip = '';
	if(form.moving_from_state && form.moving_from_state.value != 'State')
	{
		from_state = form.moving_from_state.value;
	}
	if(form.moving_from_zip && form.moving_from_zip.value != 'Zip')
	{
		from_zip = form.moving_from_zip.value;
	}
	if(form.moving_to_state && form.moving_to_state.value != 'State')
	{
		to_state = form.moving_to_state.value;
	}
	if(form.moving_to_zip && form.moving_to_zip.value != 'Zip')
	{
		to_zip = form.moving_to_zip.value;
	}
	
	form.moving_from.value = form.moving_from.value + ' ' + from_state + ' ' + from_zip;
	form.moving_to.value = form.moving_to.value + ' ' + to_state + ' ' + to_zip;
	
	return true;            
}

function validateGovernmentForm(form)
{	
	if (form.name.value == "" || form.name.value == "Employee's Name")
	{
		alert ("Please fill in Employee Name.");
		form.name.focus();
		return false;
	}
	else if (form.home_phone.value == "" || form.home_phone.value == "Employee's Home Phone") {
		alert("Please fill in Employee Home Phone Number.");
		form.home_phone.focus();
		return false;
	}
	else if (form.cell_phone.value == "" || form.cell_phone.value == "Employee's Cell Phone") {
		alert("Please fill in Employee Cell Phone Number.");
		form.cell_phone.focus();
		return false;
	}
	else if (form.gsa_contact.value == "" || form.gsa_contact.value == "GSA Contact/Information Officer") {
		alert("Please fill in GSA Contact.");
		form.gsa_contact.focus();
		return false;
	}
	else if (form.contact_phone.value == "" || form.contact_phone.value == "Contact's Phone") {
		alert("Please fill in Contact Phone.");
		form.contact_phone.focus();
		return false;
	}
	else if (form.contact_email.value == "" || form.contact_email.value == "Contact's Email") {
		alert("Please fill in Contact Email.");
		form.contact_email.focus();
		return false;
	}
	else if (form.origin_address.value == "" || form.origin_address.value == "Origin Address") {
		alert("Please fill in Origin Address.");
		form.origin_address.focus();
		return false;
	}
	else if (form.destination_address.value == "" || form.destination_address.value == "Destination Address") {
		alert("Please fill in Destination Address.");
		form.destination_address.focus();
		return false;
	}
	else if (form.approx_weight.value == "" || form.approx_weight.value == "Approximate Weight") {
		alert("Please fill in Approx. Weight.");
		form.approx_weight.focus();
		return false;
	}
	else if (form.pack_date.value == "" || form.pack_date.value == "Pack Date") {
		alert("Please fill in Pack Date.");
		form.pack_date.focus();
		return false;
	}
	else if (form.move_date.value == "" || form.move_date.value == "Move Date") {
		alert("Please fill in Move Date.");
		form.move_date.focus();
		return false;
	}
	else if (checkPhone(form.contact_phone.value) == false)
	{
		alert ("Please enter a valid Phone Number. (Include area code)");
		form.contact_phone.focus();
		return false;
	}
	else if (checkEmail(form.contact_email.value) == false)
	{
		alert ("Please enter a valid Email Address.");
		form.contact_email.focus();
		return false;
	}
	
	form.spouse_name.focus();
	form.employee_email.focus();
	
	return true;            
}

function checkEmail(str)
{
	return true;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){		       
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		       
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		        
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){		        
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		        
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){		        
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){		        
		return false;
	 }
	
	 return true;					
}


function checkPhone(str)
{
	
	cleaned = str.replace('/[-()\*\. ]/','');
	alphacheck = cleaned.replace('/[^0-9ext]/','');
	if(alphacheck != cleaned)
	{
		return false;
	}
	if(cleaned.length > 30)
	{
		return false;
	}
	if(cleaned.length < 10)
	{
		return false;
	}

	 return true;					
}

