yajax.complain=function(whine) {
    alert(whine);
}

yajax.recoverInstance=true;

yajax.complainWaiting=function() {
    return confirm('The server is having trouble catching up.  Do you wish to leave this page, even though you may \
lose your most recent changes?');
}

function cmpdates(x,y) {
    x=x.split('-');
    y=y.split('-');
    y1=parseInt(x[0],10);
    m1=parseInt(x[1],10);
    d1=parseInt(x[2],10);
    y2=parseInt(y[0],10);
    m2=parseInt(y[1],10);
    d2=parseInt(y[2],10);
    if(y1>y2) return(1);
    if(y1<y2) return(-1);
    if(m1>m2) return(1);
    if(m1<m2) return(-1);
    if(d1>d2) return(1);
    if(d1<d2) return(-1);
    return(0);
}

function submit_q1(ev) {
    sd=document.getElementById('startdate');
    ed=document.getElementById('enddate');
    if(cmpdates(sd.value,ed.value)>0) {
        yajax.complain('End date cannot be earlier than Start date');
        eventHandler.stopHandling();
    }
}

function add_q2b(ev) {
    var form=this.form;
    var id=this.id;
    var obj=eventHandler.eObj;
    var param=id.split(':');
    p=':'+param[1]; 
    obj.yajaxUp=[form['item'+p].value,
        form['qsd'+p].value,
        form['qed'+p].value,
        form['iq'+p].value];
}

function set_add_q2b(e,obj) {
    eventHandler.handleEvent(obj,'click').unshift(add_q2b);
}

function submit_q6(ev) {
    var res=yajax.yajaxForm.checkElements(['name','email','phone']);
    if(res!==true) { 
        yajax.complain(res);
        eventHandler.stopHandling();
    }
}

function getgst(ev) {
    var obj=eventHandler.eObj;
    var id=this.id;
    var param=id.split(':');
    var gttm=document.getElementById('gttm:'+param[1]+':'+param[2]);
    var gqty=document.getElementById('gqty:'+param[1]+':'+param[2]);
    var gst=document.getElementById('gst:'+param[1]+':'+param[2]);
    obj.yajaxUp=[gttm.value,gqty.value,gst.value];
}

function upgst(e,obj) {
    eventHandler.handleEvent(obj,'change').unshift(getgst);
}

function init() {
    yajax.init();
    var e;
    if(e=document.getElementById('nojssubmit')) e.style.display='none';
    if(document.getElementById('q1_form')) {
        eventHandler.handleEvent('q1_form','submit').unshift(submit_q1);
    }
    else if(document.getElementById('q6_form')) {
        eventHandler.handleEvent('q6_form','submit').unshift(submit_q6);
    }
}

eventHandler.handleEvent(window,'load').push(init); 

