var cont_window = ' '+
'<div id="contact_window">'+
'<div class="jw_inner">'+
'<div class="jw_header" style="">Contact us</div>'+
'<div id="cont_sent_report" class="jw_body" >'+
    '<div id="sent_message">Sent!</div>'+
    '<input type="button" value="Close" onclick="close_cont();" style="position: absolute; bottom: 10px; left: 102px;">'+
'</div>'+
'<div id="cont_form" class="jw_body" style="">'+
    '<label for="cont_name">Name:</label><br>'+
    '<input value=" " id="cont_name" class="cont_input"><br>'+
    '<label for="cont_email">E-mail:</label><br>'+
    '<input value="" id="cont_email" class="cont_input"><br>'+
    '<label for="cont_message">Message:</label><br>'+
    '<textarea id="cont_message" class="cont_input"></textarea><br>'+
    '<span style="color: red; font-size: 12px;" id="cont_send_error"></span>'+
    '<br>'+
    '<input type="submit" onclick="cont_send(); return false;" value="Send">'+
    '<input type="button" value="Close" onclick="close_cont();" id="cont_close_button">'+
'</div>'+
'</div></div>';

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function close_cont()
{
    $('#contact_window')[0].parentNode.removeChild($('#contact_window')[0]);
}
function show_cont() {
    var height=getDocHeight() - 300;
    $('body').append(cont_window);
    $('#contact_window').css('top',height.toString()+'px');
    //$('#cont_sent_report').hide();
    //$('#cont_form').show();
    //$('#cont_send_error').html('');
    $('#contact_window').show();
}

function cont_send() {
     var fields=$('#cont_form').find('.cont_input').get();
     var error=false;
     for (var key in fields)
     {
         if(!$(fields[key]).attr('value'))
         {
            $('#cont_send_error').text('All fields should be filled');
            error=true;
            break;
         }
     }
     if(!error)
     {
         $.getJSON('contactus'
                +'?cont_name='+$('#cont_name').val()
                +'&cont_email='+$('#cont_email').val()
                +'&cont_message='+$('#cont_message').val()
                +'&cont_location='+(window.location.href).replace(/#.*/, '')
                +'&cont_uid=0000'
                +'&cont_profile_name=+',
                    function (data)
                    {


                    }
                );


        $('#cont_form').hide();
        $('#cont_sent_report').show();
     }
}
