////////////////////////////////////////////////////////////
//                                                        //
//                 Jquery Plugins                         //
//                                                        //
////////////////////////////////////////////////////////////

/*
 * jQuery Cycle Plugin
 * Examples and documentation at: http://malsup.com/jquery/cycle/
 * Copyright (c) 2007-2008 M. Alsup
 * Version 2.21
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4($){7 m=\'2.21\';7 n=$.1o.1p&&/2k 6.0/.2l(2m.2n);4 Z(){3(1q.1r&&1q.1r.Z)1q.1r.Z(\'[B] \'+2o.2p.2q.2r(2s,\'\'))};$.E.B=4(l){x 8.O(4(){l=l||{};3(l.1P==1Q){2t(l){1s\'2u\':3(8.C)17(8.C);8.C=0;x;1s\'1t\':8.M=1;x;1s\'2v\':8.M=0;x;2w:l={P:l}}}3(8.C)17(8.C);8.C=0;8.M=0;7 c=$(8);7 d=l.1u?$(l.1u,8):c.2x();7 e=d.2y();3(e.q<2){Z(\'2z; 2A 2B 2C: \'+e.q);x}7 f=$.2D({},$.E.B.1R,l||{},$.1S?c.1S():$.2E?c.2F():{});3(f.1v)f.1w=f.1x||e.q;f.H=f.H?[f.H]:[];f.I=f.I?[f.I]:[];f.I.2G(4(){f.1y=0});3(f.U)f.I.11(4(){Q(e,f,0,!f.R)});3(n&&f.18&&!f.1T)1z(d);7 g=8.2H;f.y=19((g.1a(/w:(\\d+)/)||[])[1])||f.y;f.r=19((g.1a(/h:(\\d+)/)||[])[1])||f.r;f.A=19((g.1a(/t:(\\d+)/)||[])[1])||f.A;3(c.D(\'1b\')==\'2I\')c.D(\'1b\',\'2J\');3(f.y)c.y(f.y);3(f.r&&f.r!=\'1c\')c.r(f.r);3(f.V){f.W=[];1U(7 i=0;i<e.q;i++)f.W.11(i);f.W.2K(4(a,b){x 2L.V()-0.5});f.S=0;f.J=f.W[0]}N 3(f.J>=e.q)f.J=0;7 h=f.J||0;d.D({1b:\'1V\',2M:0,2N:0}).2O().O(4(i){7 z=h?i>=h?e.q-(i-h):h-i:e.q-i;$(8).D(\'z-2P\',z)});$(e[h]).D(\'12\',1).1W();3($.1o.1p)e[h].1X.1Y(\'1A\');3(f.K&&f.y)d.y(f.y);3(f.K&&f.r&&f.r!=\'1c\')d.r(f.r);3(f.1t)c.2Q(4(){8.M=1},4(){8.M=0});7 j=$.E.B.1Z[f.P];3($.20(j))j(c,d,f);N 3(f.P!=\'1B\')Z(\'2R 2S: \'+f.P);d.O(4(){7 a=$(8);8.22=(f.K&&f.r)?f.r:a.r();8.23=(f.K&&f.y)?f.y:a.y()});f.T=f.T||{};f.13=f.13||{};f.14=f.14||{};d.24(\':1C(\'+h+\')\').D(f.T);3(f.25)$(d[h]).D(f.25);3(f.A){3(f.G.1P==1Q)f.G={2T:2U,2V:2W}[f.G]||2X;3(!f.1d)f.G=f.G/2;2Y((f.A-f.G)<2Z)f.A+=f.G}3(f.1D)f.1E=f.1F=f.1D;3(!f.1e)f.1e=f.G;3(!f.1f)f.1f=f.G;f.26=e.q;f.L=h;3(f.V){f.9=f.L;3(++f.S==e.q)f.S=0;f.9=f.W[f.S]}N f.9=f.J>=(e.q-1)?0:f.J+1;7 k=d[h];3(f.H.q)f.H[0].1g(k,[k,k,f,27]);3(f.I.q>1)f.I[1].1g(k,[k,k,f,27]);3(f.15&&!f.F)f.F=f.15;3(f.F)$(f.F).1G(\'15\',4(){x 1H(e,f,f.R?-1:1)});3(f.1I)$(f.1I).1G(\'15\',4(){x 1H(e,f,f.R?1:-1)});3(f.X)28(e,f);f.30=4(a){7 b=$(a),s=b[0];3(!f.1x)f.1w++;e.11(s);3(f.29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(b,c){7 d=$(c.X);$.O(b,4(i,o){7 a=(1h c.1N==\'4\')?$(c.1N(i,o)):$(\'<a 34="#">\'+(i+1)+\'</a>\');3(a.35(\'36\').q==0)a.2a(d);a.1G(c.2e,4(){c.9=i;7 p=b[0].1i,A=p.C;3(A){17(A);p.C=0}3(1h c.1O==\'4\')c.1O(c.9,b[c.9]);Q(b,c,1,!c.R);x 1k})});$.E.B.1M(c.X,c.J)};4 1z(b){4 1m(s){7 s=19(s).37(16);x s.q<2?\'0\'+s:s};4 2f(e){1U(;e&&e.38.39()!=\'3a\';e=e.1i){7 v=$.D(e,\'2g-2h\');3(v.3b(\'3c\')>=0){7 a=v.1a(/\\d+/g);x\'#\'+1m(a[0])+1m(a[1])+1m(a[2])}3(v&&v!=\'3d\')x v}x\'#3e\'};b.O(4(){$(8).D(\'2g-2h\',2f(8))})};$.E.B.1B=4(a,b,c,d){7 e=$(a),$n=$(b);$n.D(c.T);7 f=4(){$n.2i(c.13,c.1e,c.1E,d)};e.2i(c.14,c.1f,c.1F,4(){3(c.1n)e.D(c.1n);3(!c.1d)f()});3(c.1d)f()};$.E.B.1Z={2j:4(a,b,c){b.24(\':1C(\'+c.J+\')\').D(\'12\',0);c.H.11(4(){$(8).1W()});c.13={12:1};c.14={12:0};c.T={12:0};c.1n={3f:\'3g\'}}};$.E.B.3h=4(){x m};$.E.B.1R={P:\'2j\',A:3i,U:0,G:3j,1e:u,1f:u,F:u,1I:u,1l:u,X:u,1O:u,2e:\'15\',1N:u,H:u,I:u,1K:u,1D:u,1E:u,1F:u,3k:u,13:u,14:u,T:u,1n:u,1L:u,r:\'1c\',J:0,1d:1,V:0,K:0,1t:0,1v:0,1x:0,2c:0,1u:u,18:0,1j:0}})(3l);',62,208,'|||if|function|||var|this|nextSlide|||||||||||||||||length|height|||null|||return|width||timeout|cycle|cycleTimeout|css|fn|next|speed|before|after|startingSlide|fit|currSlide|cyclePause|else|each|fx|go|rev|randomIndex|cssBefore|continuous|random|randomMap|pager|curr|log||push|opacity|animIn|animOut|click||clearTimeout|cleartype|parseInt|match|position|auto|sync|speedIn|speedOut|apply|typeof|parentNode|nowrap|false|prevNextClick|hex|cssAfter|browser|msie|window|console|case|pause|slideExpr|autostop|countdown|autostopCount|busy|clearTypeFix|filter|custom|eq|easing|easeIn|easeOut|bind|advance|prev|setTimeout|end|fxFn|updateActivePagerLink|pagerAnchorBuilder|pagerClick|constructor|String|defaults|metadata|cleartypeNoBg|for|absolute|show|style|removeAttribute|transitions|isFunction||cycleH|cycleW|not|cssFirst|slideCount|true|buildPager|els|appendTo|onAddSlide|delay|activeSlide|pagerEvent|getBg|background|color|animate|fade|MSIE|test|navigator|userAgent|Array|prototype|join|call|arguments|switch|stop|resume|default|children|get|terminating|too|few|slides|extend|meta|data|unshift|className|static|relative|sort|Math|top|left|hide|index|hover|unknown|transition|slow|600|fast|200|400|while|250|addSlide|find|removeClass|addClass|href|parents|body|toString|nodeName|toLowerCase|html|indexOf|rgb|transparent|ffffff|display|none|ver|4000|1000|shuffle|jQuery'.split('|'),0,{}));

////////////////////////////////////////////////////////////
//                                                        //
//                 Site Specific Code                     //
//                                                        //
////////////////////////////////////////////////////////////

function add_row() {
    row = $('#quote-item1').clone();
    $('input',row).val('');
    row_num++;
    row[0].id = row[0].id.substring(0,row[0].id.length-1)+row_num;

    $('input',row).hide();
    $('#quote-item-table').append(row);
    $('input',row).show(200);
    $('input',row).show();
    row.css('display',row_css);
    $('input',row).each(function(){
            this.name=this.name.substring(0,this.name.length-1)+row_num;
            });
}

function show_comments() {
    $('#comments textarea ').toggle(200);
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateCounty(fld) {
    var error=false;
    if (fld.value == "") {
        error = "You didn't enter a county.";
    }
    return error;
}

function validatePhone(fld) {
    var error=false;
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
   if (fld.value == "") {
        error = "You didn't enter a phone number.";
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains unexpected characters.";
    } else if (stripped.length < 6) {
        error = "The phone number is too short.";
    }
    return error;
}

function validateEmail(fld) {
    var error=false;
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if (fld.value == "") {
        error = "You didn't enter an email address.";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = "Please enter a valid email address.";
    } else if (fld.value.match(illegalChars)) {
        error = "The email address contains illegal characters.";
    } else {
    }
    return error;
}
function changeform() {
    $('#form-errors').empty();
    $('#quote-form input, #quote-form select').css({ backgroundColor: "white" });
}
function validate() {
    var reason = "";
    theForm = $('#quote-form')[0];
    county_error = validateCounty(theForm.county);
    email_error = validateEmail(theForm.email);
    phone_error = validatePhone(theForm.telephone);
    //error = email_error+'<br />'+phone_error;
    if (county_error) {
        error = "Please enter your county"
        $('#form-errors').empty().append(error);
        $('#id_county').css({ backgroundColor: "#fbc7c7" });
        return false;
    }
    if (email_error!=false && phone_error!=false) {
        error = "Please enter either a valid email address or phone number"
        $('#form-errors').empty().append(error);
        $('#id_email, #id_telephone').css({ backgroundColor: "#fbc7c7" });
        return false;
    }
    return true;
}

row_num = 1;

function init() {
    row_css = $('#quote-item1').css('display');
    $('#add-row').bind("click",add_row)
    $('#show-comments').bind("click",show_comments)
    $('#quote-form input, #quote-form select').bind("change", changeform)
    $('#quote-form').bind("submit",validate)
    $('#sidebar-images').cycle({fx:'fade',speed:2000,timeout:10000,random:1});
}

$(document).ready(init);