//var isSet = 0;
var strErrorMsg = '';
var intIconID   = 0;

function showSubnav(thisNav) {
	jQuery('#subnav1, #subnav2, #subnav3, #subnav4, #subnav5, #subnav6').hide();
	if(thisNav) {
		jQuery('#subnav'+thisNav).show(); 
	}
}

function displayCell(id) {
    if(document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display = 'block';
    } else {
        document.getElementById(id).style.display = 'none';
    }
}

function openPopup(popup_name, popup_url, popup_height, popup_width) {
    popHeight   = popup_height;
    popWidth    = popup_width;
    popY        = (screen.height/2)-(popHeight/2);
    popX        = (screen.width/2)-(popWidth/2);
    popup       = window.open(popup_url, popup_name, 'scrollbars=yes,resizable=no,width='+ popWidth +',height='+ popHeight +',left='+ popX +',top='+ popY + '');
}

function closeTeaser() {
    popup.close();
}

function closePopup() {
    popup.close();
}

function openTeaserPage(strURL) {
    if( strURL != '') {
        if(window.opener && !window.opener.closed) {
        window.opener.location.href = strURL;
        } else {
            window.open(strURL, '_blank');
        }
    }
    window.close();
}

function submitContact() {

    strErrorMsg     = '';
    var postData    = '';
    var fields      = Array(
    
        Array('DID',            1),
        Array('refID',          1),
        Array('salutation',     1),
        Array('title',          1),
        Array('surname',        1),
        Array('firstname',      1),
        Array('email',          1),
        Array('phone',          1),
        Array('msg',            1),
        Array('adrDealerMail',  1),
        Array('isprivacy',      2)
    );

    for( i = 0; i < fields.length; i++ ) {
         if( fields[i][1] == 1 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +"").val() ) + '&';

        } else if( fields[i][1] == 2 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +":checked").length ) + '&';
        
        }
    }
    
    jQuery.ajax({
        type: 'POST',
        url: '/proc/contact.asp',
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'json',
        data: postData,
        success: function(j){
            
            for(i = 0; i < fields.length; i++) {
                if( fields[i][1] == 1 || fields[i][1] == 3 ) {
                    checkField(j, fields[i][0]);
                }
            }

            if (j.isprivacy == 1) {
                jQuery("#privacylink").css("color","#E50000");
                strErrorMsg = strErrorMsg + '-	' + aError['isprivacy']+'<br />';
            } else {
                jQuery("#privacylink").css("color","#333");
            }
            
            if( j.is_error != 1 ) {
                jQuery('#formContent').hide();
                jQuery('#confirmContent').show();
                
                SWFReplace();
         
            } else {
                writeErrMsg(strErrorMsg, 0);
            }
        }
    });
}


function submitEvent() {

    strErrorMsg     = '';
    var postData    = '';
    var fields      = Array(
        Array('DID',            1),
        Array('refID',          1),
        Array('salutation',     1),
        Array('title',          1),
        Array('surname',        1),
        Array('firstname',      1),
        Array('company',        1),
        Array('profession',     1),
        Array('birthday',       3),
        Array('birthdaydd',     1),
        Array('birthdaymm',     1),
        Array('birthdayyyyy',   1),
        Array('street',         1),
        Array('zip',            1),
        Array('city',           1),
        Array('email',          1),
        Array('phone',          1),
        Array('phone_mobile',   1),
        Array('register',       2),
        Array('accompanist',    1),
        Array('dealerMail',     1),
        Array('isprivacy',      2)
    );
        
    for( i = 0; i < fields.length; i++ ) {
         if( fields[i][1] == 1 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +"").val() ) + '&';

        } else if( fields[i][1] == 2 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +":checked").length ) + '&';

        } else {
            postData += 'birthday='+ escape(jQuery("#birthdayyyyy").val()) +'-'+ escape(jQuery("#birthdaymm").val()) +'-'+ escape(jQuery("#birthdaydd").val()) + '&';
        }
    }


    jQuery.ajax({
        type: 'POST',
        url: '/proc/event.asp',
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'json',
        data: postData,
        success: function(j){
            
            for(i = 0; i < fields.length; i++) {
                if( fields[i][1] == 1 || fields[i][1] == 3 ) {
                    checkField(j, fields[i][0]);
                }
            }

            if (j.isprivacy == 1) {
                jQuery("#privacylink").css("color","#E50000");
                strErrorMsg = strErrorMsg + '-	' + aError['isprivacy']+'<br />';
            } else {
                jQuery("#privacylink").css("color","#333");
            }
                        
            if( j.is_error != 1 ) {
                jQuery('#formContent').hide();
                jQuery('#confirmContent').show();
                
                SWFReplace();
         
            } else {
                writeErrMsg(strErrorMsg, 0);
            }
        }
    });
}

function submitEventAttendance() {

    strErrorMsg     = '';
    var postData    = '';
    var fields      = Array(
        Array('DID',            1),
        Array('refID',          1),
        Array('dealerMail',     1),
        Array('dealerSubject',  1),
        Array('event_type',     1),
        Array('FID',            1),
        Array('Subnavi',        1),

        Array('salutation',     1),
        Array('title',          1),
        Array('firstname',      1),
        Array('surname',        1),
        Array('company',        1),
        Array('occupation',     1),
        Array('birthday',       3),
        Array('birthdaydd',     1),
        Array('birthdaymm',     1),
        Array('birthdayyyyy',   1),
        Array('street',         1),
        Array('zip',            1),
        Array('city',           1),
        Array('email',          1),
        Array('phone',          1),
        Array('phone_mobile',   1),

        Array('asalutation',    1),
        Array('atitle',         1),
        Array('afirstname',     1),
        Array('asurname',       1),
        Array('acompany',       1),
        Array('aoccupation',    1),
        Array('abirthday',      3),
        Array('abirthdaydd',    1),
        Array('abirthdaymm',    1),
        Array('abirthdayyyyy',  1),
        Array('astreet',        1),
        Array('azip',           1),
        Array('acity',          1),
        Array('aemail',         1),

        Array('isattendance',   2),
        Array('isprivacy',      2)
    );

    for( i = 0; i < fields.length; i++ ) {
         if( fields[i][1] == 1 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +"").val() ) + '&';

        } else if( fields[i][1] == 2 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +":checked").length ) + '&';

        }
    }

    postData += 'birthday='+ escape(jQuery("#birthdayyyyy").val()) +'-'+ escape(jQuery("#birthdaymm").val()) +'-'+ escape(jQuery("#birthdaydd").val()) + '&';
    postData += 'abirthday='+ escape(jQuery("#abirthdayyyyy").val()) +'-'+ escape(jQuery("#abirthdaymm").val()) +'-'+ escape(jQuery("#abirthdaydd").val()) + '&';

    jQuery.ajax({
        type: 'POST',
        url: '/proc/eventAttendance.asp',
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'json',
        data: postData,
        success: function(j){

            for(i = 0; i < fields.length; i++) {
                if( fields[i][1] == 1 || fields[i][1] == 3 ) {
                    checkField(j, fields[i][0]);
                }
            }

            if (j.isprivacy == 1) {
                jQuery("#privacylink").css("color","#E50000");
                strErrorMsg = strErrorMsg + '-	' + aError['isprivacy']+'<br />';
            } else {
                jQuery("#privacylink").css("color","#333");
            }

            if( j.is_error != 1 ) {

                jQuery('#responseContent').html(j.confirm_msg);
                jQuery('#formContent').hide();
                jQuery('#confirmContent').show();

                SWFReplace();

            } else {
                writeErrMsg(strErrorMsg, 0);
            }
        }
    });
}


function submitKWK() {

    strErrorMsg     = '';
    var postData    = '';
    var fields      = Array(
        Array('DID',            1),
        Array('refID',          1),
        Array('dealerMail',     1),
        Array('dealerSubject',  1),
        Array('event_type',     1),
        Array('FID',            1),
        Array('Subnavi',        1),

        Array('customer',       1),
        Array('salutation',     1),
        Array('title',          1),
        Array('firstname',      1),
        Array('surname',        1),
        Array('company',        1),
        Array('occupation',     1),
        Array('birthdaydd',     1),
        Array('birthdaymm',     1),
        Array('birthdayyyyy',   1),
        Array('street',         1),
        Array('zip',            1),
        Array('city',           1),
        Array('email',          1),
        Array('phone',          1),

        Array('asalutation',    1),
        Array('atitle',         1),
        Array('afirstname',     1),
        Array('asurname',       1),
        Array('acompany',       1),
        Array('aoccupation',    1),
        Array('abirthdaydd',    1),
        Array('abirthdaymm',    1),
        Array('abirthdayyyyy',  1),
        Array('astreet',        1),
        Array('azip',           1),
        Array('acity',          1),
        Array('aemail',         1),
        Array('aphone',         1),
        Array('acar',           1),
        Array('abuild',         1),

        Array('isprivacy',      2)
    );

    for( i = 0; i < fields.length; i++ ) {
         if( fields[i][1] == 1 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +"").val() ) + '&';

        } else if( fields[i][1] == 2 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +":checked").length ) + '&';

        }
    }

    postData += 'birthday='+ escape(jQuery("#birthdayyyyy").val()) +'-'+ escape(jQuery("#birthdaymm").val()) +'-'+ escape(jQuery("#birthdaydd").val()) + '&';
    postData += 'abirthday='+ escape(jQuery("#abirthdayyyyy").val()) +'-'+ escape(jQuery("#abirthdaymm").val()) +'-'+ escape(jQuery("#abirthdaydd").val()) + '&';

    jQuery.ajax({
        type: 'POST',
        url: '/proc/kwk.asp',
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'json',
        data: postData,
        success: function(j){

            for(i = 0; i < fields.length; i++) {
                if( fields[i][1] == 1 || fields[i][1] == 3 ) {
                    checkField(j, fields[i][0]);
                }
            }

            if (j.isprivacy == 1) {
                jQuery("#privacylink").css("color","#E50000");
                strErrorMsg = strErrorMsg + '-	' + aError['isprivacy']+'<br />';
            } else {
                jQuery("#privacylink").css("color","#333");
            }

            if( j.is_error != 1 ) {

                var confirmMessage = 'Ihre Anfrage werden wir schnellstm&ouml;glich bearbeiten.<br /><br />Bei einem erfolgreichen Abschluss kontaktieren wir Sie telefonisch. Nat&uuml;rlich w&uuml;rden wir uns auch &uuml;ber einen Besuch Ihrerseits bei uns im '+ jQuery('#dealerConfirm').val() +', freuen. Besuchen Sie uns doch einfach auf einen guten Cappuccino.';

                jQuery('#responseContent').html(confirmMessage);
                jQuery('#formContent').hide();
                jQuery('#confirmContent').show();

                SWFReplace();

            } else {
                writeErrMsg(strErrorMsg, 0);
            }
        }
    });
}


function updateUserData() {

    strErrorMsg     = '';
    var postData    = '';
    var fields      = Array(
        Array('DID',            1),
        Array('user_uid',       1),
        Array('event_id',       1),
        Array('event_type',     1),
        Array('dealerMail',     1),
        Array('dealerSubject',  1),
        Array('FID',            1),
        Array('Subnavi',        1),

        Array('salutation',     1),
        Array('title',          1),
        Array('surname',        1),
        Array('firstname',      1),
        Array('company',        1),
        Array('occupation',     1),
        Array('birthdaydd',     1),
        Array('birthdaymm',     1),
        Array('birthdayyyyy',   1),
        Array('street',         1),
        Array('zip',            1),
        Array('city',           1),
        Array('email',          1),
        Array('phone',          1),
        Array('phone_mobile',   1),
        Array('car',            1),
        Array('build',          1),

        Array('isprivacy',      2)
    );

    for( i = 0; i < fields.length; i++ ) {
         if( fields[i][1] == 1 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +"").val() ) + '&';

        } else if( fields[i][1] == 2 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +":checked").length ) + '&';

        }
    }

    postData += 'birthday='+ escape(jQuery("#birthdayyyyy").val()) +'-'+ escape(jQuery("#birthdaymm").val()) +'-'+ escape(jQuery("#birthdaydd").val()) + '&';

    jQuery.ajax({
        type: 'POST',
        url: '/proc/updateUserData.asp',
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'json',
        data: postData,
        success: function(j){

            for(i = 0; i < fields.length; i++) {
                if( fields[i][1] == 1 || fields[i][1] == 3 ) {
                    checkField(j, fields[i][0]);
                }
            }

            if (j.isprivacy == 1) {
                jQuery("#privacylink").css("color","#E50000");
                strErrorMsg = strErrorMsg + '-	' + aError['isprivacy']+'<br />';
            } else {
                jQuery("#privacylink").css("color","#333");
            }

            if( j.is_error != 1 ) {
                jQuery('#formContent').hide();
                jQuery('#confirmContent').show();

                SWFReplace();

            } else {
                writeErrMsg(strErrorMsg, 0);
            }
        }
    });
}

function submitService() {

    strErrorMsg     = '';
    var postData    = '';
    var fields      = Array(
        Array('DID',            1),
        Array('refID',          1),
        Array('salutation',     1),
        Array('title',          1),
        Array('firstname',      1),
        Array('surname',        1),
        Array('email',          1),
        Array('street',         1),
        Array('zip',            1),
        Array('city',           1),
        Array('phone',          1),
        Array('phone_mobile',   1),
        Array('customerno',     1),
        Array('service_date',   3),
        Array('service_year',   1),
        Array('service_month',  1),
        Array('service_day',    1),
        Array('service_time',   1),
        Array('constructor',    1),
        Array('carmodel',       1),
        Array('registration',   1),
        Array('adrDealerMail',  1),
        Array('isprivacy',      2)
    );
        
    for( i = 0; i < fields.length; i++ ) {
         if( fields[i][1] == 1 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +"").val() ) + '&';

        } else if( fields[i][1] == 2 ) {
            postData += fields[i][0] + '=' + escape( jQuery("#"+ fields[i][0] +":checked").length ) + '&';
        
        } else {
            postData += 'service_date='+ escape(jQuery("#service_year").val()) +'-'+ escape(jQuery("#service_month").val()) +'-'+ escape(jQuery("#service_day").val()) + '&';
        }
    }
    

    jQuery.ajax({
        type: 'POST',
        url: '/proc/service.asp',
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'json',
        data: postData,
        success: function(j){
            
            for(i = 0; i < fields.length; i++) {
                if( fields[i][1] == 1 || fields[i][1] == 3 ) {
                    checkField(j, fields[i][0]);
                }
            }
            
            if (j.isprivacy == 1) {
                jQuery("#privacylink").css("color","#E50000");
                strErrorMsg = strErrorMsg + '-	' + aError['isprivacy']+'<br />';
            } else {
                jQuery("#privacylink").css("color","#333");
            }

            if( j.is_error != 1 ) {
                jQuery('#formContent').hide();
                jQuery('#confirmContent').show();
                
                SWFReplace();
         
            } else {
                writeErrMsg(strErrorMsg, 0);
            }
        }
    });
}

function checkField(j,field_name) {
    if( eval('j.'+ field_name +'') == 1 ) {
        jQuery("#"+ field_name +"").addClass("error");
        if( aError[field_name] ) {
            strErrorMsg = strErrorMsg + '-	' + aError[field_name] +'<br />';
        }
    } else {
        jQuery("#"+ field_name +"").removeClass("error");
    }
}


function displayService(dealer_id, service_id, service_title) {
    jQuery('#serviceText').html('<img src="/img/loading_modalbox.gif" alt="" width="50" height="50" style="margin-left: 150px;" border="0">');
    
    jQuery.ajax({
        type: 'POST',
        url: '/proc/getService.asp',
        data: 'dealer_id='+ dealer_id +'&service_id='+ service_id +'',
        dataType: 'html',
        success: function(html){
        
            if( intIconID > 0 ) {
                jQuery('#icon_'+ intIconID +'').attr({
                    src: '/img/services/small/icon_'+ intIconID +'.gif'
                });
            }
            
            jQuery('#icon_'+ service_id +'').attr({ 
                src: '/img/services/small_on/icon_'+ service_id +'.gif'
            });
            
            intIconID = service_id;

            jQuery('#serviceText').html(html);
        },
        error: function(o,e,k){
            jQuery('#serviceText').html('<strong>Fehler!</strong><br>Es ist leider ein Fehler aufgetreten. Bitte versuchen Sie es noch <a href="javascript:displayService(\''+ dealer_id +'\', '+ service_id +', \''+ service_title +'\');">einmal</a>.');
        }
    });
}

function displayAttendance() {
    if (jQuery("#isattendance:checked").length == 1) {
        jQuery("#attendanceElements").show();
    } else {
        jQuery("#attendanceElements").hide();
    }
}
function getFloodlightTag(dealer_name, tag_type, tag_model) {
    var axel    = Math.random() + "";
    var a       = axel * 10000000000000;
    return '<iframe src="http://fls.doubleclick.net/activityi;src=795234;type=lexus;cat=hndle767;u3='+ dealer_name +';u2='+ tag_type +';u1='+ tag_model +';ord=' + a +'?" width="1" height="1" frameborder="0"></iframe><img style="width:1px; height:1px;" src="http://servedby.flashtalking.com/spot/380;1781;175/?ftXName=' + dealer_name + '" width="1" height="1" border="0"><iframe src="http://video.flashtalking.com/container/1781/1781_iFrame.html" width="1" height="1" scrolling="no" frameborder="0" margin="0"></iframe>';
}