$(document).ready(function(){
    //alert("js");
    //rotateImages('A');
    //$('#HeaderTop').click(function(){window.location.assign("http://www.usacd.digitaldogs.com")});
    piclink();
    $('#phone1').keyup(function(){
        if( ($('#phone1').val()).length==3 )
            $('#phone2').focus();
    });
    $('#phone2').keyup(function(){
        if( ($('#phone2').val()).length==3 )
            $('#phone3').focus();
    });
    //$('#projectDesc').focus(function(){if($(this).val()=="Describe your project here (optional)") $(this).select()});
    $('#projectDesc').focus(function(){if($(this).val()=="Describe your project here (optional)") $(this).val('')});
});

function piclink()
{
    $('.Photo a').click(function(){
        $src = $(this).attr('href');
        $('body').append('<div id="imgPopout"><img src="'+$src+'" alt=""/><br/>Click to Close</div>')
        $('#imgPopout').click(function(){$(this).remove();});
        return false;
    });    
}


function PhotoLast()
{
    if(!$('.PhotoFrame').hasClass('load'))
    {
        $('#photoA').html($('#photoB').html());
        $('#photoB').html($('#photoC').html());
        $in = $('#photoB img').attr('class');
        $in = $in.replace('Photo','');
        $in = $in.replace('in','');
        $in = $in.replace(' ','');
        $in = parseInt($in);
        $('.PhotoFrame').addClass('load');
        $('#photoC').load('getthumb.php?pic='+($in+1),function(){$('.PhotoFrame').removeClass('load');piclink();});
    }
}
function PhotoNext()
{
    if(!$('.PhotoFrame').hasClass('load'))
    {
        $('#photoC').html($('#photoB').html());
        $('#photoB').html($('#photoA').html());
        $in = $('#photoB img').attr('class');
        $in = $in.replace('Photo','');
        $in = $in.replace('in','');
        $in = $in.replace(' ','');
        $in = parseInt($in);
        $('#photoA').load('getthumb.php?pic='+($in-1),function(){$('.PhotoFrame').removeClass('load');piclink()});
    }

/*    $temp = $('#photoE').html();
    $('#photoE').html($('#photoD').html());
    $('#photoD').html($('#photoC').html());
    $('#photoC').html($('#photoB').html());
    $('#photoB').html($('#photoA').html());
    $('#photoA').html($temp);*/
}
function rotateImages($image)
{
    if($image=='A')
        $temp = $('#photo'+$image).html();

    if($image=='A')
        $NL = 'B';
    if($image=='B')
        $NL = 'C';
    if($image=='C')
        $NL = 'D';
    if($image=='D')
        $NL = 'E';
    if($image=='E')
        $NL = 'A';

    $('#photo'+$image).wait(500).fadeOut(1000,function(){
        if($image=='E')
            $('#photo'+$image).html($temp);
        else
            $('#photo'+$image).html($('#photo'+$NL).html());
            
        $('#photo'+$image).fadeIn(1000,rotateImages($NL));
    });
}

    $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
function checkform3()
{
    if( (document.contact3.email.value.indexOf("@") == -1 || document.contact3.email.value == "") && (document.contact3.phone.value == "") )   
    {
	alert("Please include a proper email address OR Phone Number.");
	document.contact3.phone.focus();
        return false; 
    }
    return true;
}
function checkform2()
{
    if (document.contact.first.value == "") 
    {
        alert("Please enter your first name.");
        document.contact.first.focus(); 
        return false;
    }
    if (document.contact.last.value == "") 
    {
        alert("Please enter your first name.");
        document.contact.last.focus(); 
        return false;
    }
    /*if( (document.contact.email.value.indexOf("@") == -1 || document.contact.email.value == "") && (document.contact.phone.value == "") )   
    {
	alert("Please include a proper email address OR Phone Number.");
	document.contact.phone.focus();
        return false; 
    }*/
    if( document.contact.email.value.indexOf("@") == -1 )   
    {
	alert("Please include a proper email address .");
	document.contact.phone.focus();
        return false; 
    }
    if( document.contact.phone.value == "" )   
    {
	alert("Please include a Phone Number.");
	document.contact.phone.focus();
        return false; 
    }
    return true;
}

function cdformcheck()
{
    if (document.contact.first.value == "") 
    {
        alert("Please enter your first name.");
        document.contact.first.focus(); 
        return false;
    }
    if (document.contact.last.value == "") 
    {
        alert("Please enter your last name.");
        document.contact.last.focus(); 
        return false;
    }
    if( document.contact.email.value.indexOf("@") == -1 )   
    {
	alert("Please include a proper email address .");
	document.contact.email.focus();
        return false; 
    }
    if( document.contact.phone.value == "" )   
    {
	alert("Please include a Phone Number.");
	document.contact.phone.focus();
        return false; 
    }
    if( document.contact.license.value == "" )   
    {
	alert("Please include your License Number.");
	document.contact.license.focus();
        return false; 
    }
    if(document.contact.address.value == "")
    {
	alert("Please include a street address.");
	document.contact.address.focus(); 
	return false;  	
    }
    if((document.contact.city.value == "")||document.contact.city.value.length<3)
    {
	alert("Please include a city.");
	document.contact.city.focus(); 
	return false;  		
    }
    if(document.contact.state.value.length!=2||("AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA,PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY".indexOf(document.contact.state.value.toUpperCase())==-1))
    {
	alert("Please include a state code.");
	document.contact.state.focus(); 
	return false;  			
    }
    if((document.contact.zip.value == "")||!IsNumeric(document.contact.zip.value)||document.contact.zip.value.length<5)
    {
	alert("Please include a valid zipcode.");
	document.contact.zip.focus(); 
	return false;  				
    }
    return true;
}
function contactform()
{
    if (document.contact.first.value == "") 
    {
        alert("Please enter your first name.");
        document.contact.first.focus(); 
        return false;
    }
    if (document.contact.last.value == "") 
    {
        alert("Please enter your last name.");
        document.contact.last.focus(); 
        return false;
    }
    if( document.contact.email.value.indexOf("@") == -1 )   
    {
	alert("Please include a proper email address .");
	document.contact.email.focus();
        return false; 
    }
    if( document.contact.phone.value == "" )   
    {
	alert("Please include a Phone Number.");
	document.contact.phone.focus();
        return false; 
    }
    if(document.contact.address.value == "")
    {
	alert("Please include a street address.");
	document.contact.address.focus(); 
	return false;  	
    }
    if((document.contact.city.value == "")||document.contact.city.value.length<3)
    {
	alert("Please include a city.");
	document.contact.city.focus(); 
	return false;  		
    }
    if(document.contact.state.value.length!=2||("AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA,PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY".indexOf(document.contact.state.value.toUpperCase())==-1))
    {
	alert("Please include a state code.");
	document.contact.state.focus(); 
	return false;  			
    }
    if((document.contact.zip.value == "")||!IsNumeric(document.contact.zip.value)||document.contact.zip.value.length<5)
    {
	alert("Please include a valid zipcode.");
	document.contact.zip.focus(); 
	return false;  				
    }
    return true;
}
function backon()
{
    history.back();
    return false;
}