function getInfo(id)
{

    $.ajax({
        url: "/application/views/aebrus/files/registrationlist/registrationlistsystem/ajax.php",
        type: "POST",
        dataType: "html",
        data: "id="+id,
        beforeSend: function (){
            $("div#more").hide("slow");
            $("div#fullList").hide("slow");
            $("div#stat").show();
            $("#event_id").val(id);
        },
        complete: function (){
            $("div#stat").hide();

        },
        success: function(msg){
            $("div#more").html(msg);
            $("div#more").show("slow");
            $("div#mailform").show();
        },
        error: function(){
        //alert("error ");
        }
    });

}
function fullList()
{
    $("div#fullList").show("slow");
    //$("div#fullList").slideDown("slow");
    $("div#more").hide("slow");
    $("#choose_event_id").hide();
}
var error = 0;
var error_lang = 0;
function checkEmpty(id)
{

    if($("#"+id).val().length == 0)
    {
        $("#"+id).addClass("error");
        error = error + 1;
    }else{
        var template = /^[A-Za-z0-9@\.\,\-\+\_\'\"\&\/\(\) ](([_\.\-]?[a-zA-Z0-9@\.\,\-\+\_\'\"\&\/\(\) ]+)*)+$/;
        //var template = /^[^А-Яа-я]+$/;
        //var template = /^[^A-Za-z0-9]/;

        var str = $("#"+id).val();
        if (template.test(str))
        {
            $("#"+id).removeClass();
        }else{
            $("#"+id).addClass("error");
            error = error + 1;
            error_lang = error_lang+1;
        }
    }
}



function checkKppInn(id,num)
{
    if($("#"+id).val().length != num)
    {
        $("#"+id).addClass("error");
        error = error + 1;
    }
}


//document.getElementById("email_pre").onkeypress = function (e) {
//  if(!e) e=window.event;
//  alert('test');
//
//  key = e.keycode ? e.keycode : e.which;
//  if(key==13) e.returnValue=false;
//}


function doSomething(event) {
    event = event || window.event;
    key = event.which || event.keyCode;
    if (key == 13) return false;
}








HotKeyHandler.keys = {};
HotKeyHandler.convertIEKey={
    "1":65,
    "2":66,
    "4":68,
    "12":76,
    "16":80,
    "19":83,
    "20":84,
    "21":85,
    "26":90
};
function HotKeyHandler(ev) {
    var evt, key;
    if(!(evt=window.event? window.event: ev)) return;
    key = evt.keyCode? evt.keyCode: evt.charCode;
    key=HotKeyHandler.convertIEKey[String(key)]? HotKeyHandler.convertIEKey[String(key)]: key;
    if (evt.ctrlKey||key==27) {
        key=evt.shiftKey? String.fromCharCode(key).toUpperCase(): String.fromCharCode(key).toLowerCase();
        if(typeof(HotKeyHandler.keys[key]) == "function"){
            HotKeyHandler.keys[key](evt);
            evt.cancelBubble = true;
            evt.returnValue = false;
            if(evt.preventDefault) evt.preventDefault();
            if(evt.stopPropagation) evt.stopPropagation();
            return false;
        }
    }
    return true;
}

HotKeyHandler.windowInit=function() {
    if(document.addEventListener && (getOperaVersion()>6||getOperaVersion()==0)) {
        document.addEventListener("keypress", HotKeyHandler, false);
    } else {
        document.attachEvent("onkeydown", HotKeyHandler);
    }
}

function getOperaVersion() {
    var opver=navigator.userAgent.match(/Opera\s*([0-9.]+)/i);
    return (opver&&opver.length>1)? parseFloat(opver[1]): 0;
}

HotKeyHandler.keys = {
    "v":function(){
        alert("Вставка информации из буфера обмена запрещена");
    }
};
//HotKeyHandler.windowInit();






window.onload = function() {
    document.getElementById('email_pre').onkeypress = doSomething;
    //var inputi = document.getElementById('myform').getElementsByTagName('INPUT');
    $(":input").keypress(HotKeyHandler.windowInit());
    //$(":input").attr("onbeforepaste", "return false");
    $(":input").attr("oncontextmenu", "return false");
	
	
//	$(selectors[i]).attr("oncontextmenu", "return
//false");

//   for(var i = 0; i < inputi.length; i++) {
//       inputi[i].onkeypress = function() {HotKeyHandler.windowInit()}
//   }
}





function check()
{
    checkEmpty('Name');
    checkEmpty('Surname');
    if($("#event_id").val().length == 0)
    {
        $("#choose_event_id").show();
        error = error + 1;
    }else{
        $("#choose_event_id").hide();
    }
    checkEmpty('Organisation');
    checkEmpty('Position');
    checkEmpty('Address');
    checkEmpty('Telephone');
    checkEmpty('Fax');
    checkEmpty('ZIP');
    checkEmpty('City');
    checkEmpty('Adress');
    checkEmpty('Email');
    check_email('Email');
    if(!$("input[@name=translate]:checked").val() && $("input#hiddentrans").val()!='No')
    {
        $("p.lalala").css("color", "Red");
        if(error==0) {
            alert("Please choose do you need translation");
        }
        error = 1;
    }
    if(error_lang!=0)
        alert("Fill the form in English. \nLegal character: \. \, \- \+ \_ \' \" \& \\ \/ \( \)");
    if(error == 0)
        $("#myform").submit();
    error = 0;
    error_lang = 0;
}




function checkspbf()
{
    checkEmpty('fillingup_name');
    checkEmpty('fillingup_phone');
    checkEmpty('fillingup_email');
    check_email('fillingup_email');
    checkEmpty('companyname');
    checkEmpty('address');
    checkEmpty('phone');
    checkEmpty('fax');
    checkEmpty('first_name');
    checkEmpty('first_position');
    checkEmpty('first_email');
    check_email('first_email');
    if(error_lang!=0)
        alert("Fill the form in English. \nLegal character: \. \, \- \+ \_ \' \" \& \\ \/ \( \)");
    if(error == 0)
        $("#spbform").submit();
    error = 0;
    error_lang = 0;
}


function check_email(emaila)
{
    var template = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/;
    email = $("#"+emaila).val();
    if (template.test(email)) {
        return true;
    }else{
        $("#"+emaila).addClass("error");
        error = error + 1;
    }
}



function getTable(email)
{
	
    //	alert($('input[name=compstatus]:checked').val())
    //	alert($("input[@name=compstatus]:checked").val())
    //	exit();

    $.ajax({
        url: "/application/views/aebrus/files/registrationlist/registrationlistsystem/ajax2.php",
        type: "POST",
        dataType: "html",
        //		data: "id="+$("input#email_pre").val()+"&ide="+$("input#event_id").val(),
        data: "id="+$("input#email_pre").val()+"&ide="+$("input#event_id").val()+"&compstat="+$("input[@name=compstatus]:checked").val(),
        beforeSend: function (){

        //$("div#fullList").hide("slow");
        //$("div#stat").show();
        //$("#event_id").val(id);
        },
        complete: function (){
            $("div#mailform").hide("slow");
        //			$("div#mainform").show("slow");

        },
        success: function(msg){
            $("div#mainform").html(msg);
            $("div#mainform").show("slow");

        },
        error: function(){
        //alert("error ");
        }
    });

}



function check2()
{
    checkEmpty('id_commeet');
    checkEmpty('id_company');
    checkEmpty('fio');
    checkEmpty('phone');
    checkEmpty('email');
    check_email('email');
    if(error_lang!=0)
        alert("Fill the form in English. \nLegal character: \. \, \- \+ \_ \' \" \& \\ \/ \( \)");
    if(error == 0)
        $("#commeetreg").submit();
    error = 0;
    error_lang = 0;
}


function check3()
{

    checkEmpty('choosestatus');
    checkEmpty('email');
    check_email('email');
    checkEmpty('name');
    checkEmpty('surname');
    $val=$('#choosestatus').val();
	
    if ($val=='AMC company') {
        checkEmpty('company');
    } else if($val=='Media') {
        checkEmpty('medianame');
        checkEmpty('telnumber');
    //		checkEmpty('journalistid');
    }
		
		
    if(error == 0)
        $("#annualpressconference").submit();
    error = 0;
    error_lang = 0;
}





function check4()
{

//    checkEmpty('choosestatus');
    checkEmpty('email');
    check_email('email');
    checkEmpty('name');
    checkEmpty('surname');
//    $val=$('#choosestatus').val();

        checkEmpty('medianame');
        checkEmpty('telnumber');



    if(error == 0)
        $("#regpress").submit();
    error = 0;
    error_lang = 0;
}









$(function() {
    $('#id_commeet').change(function() {
        $idcomm=$(this).val();
        //		alert($idcomm);
        $.ajax({
            type: "POST",
            url: "/application/views/aebrus/files/commeet_reg/commeet_regsystem/ajax.php?action=companylist&idcomm="+$idcomm,
            success: function(html){
                if (html!='') {
                    //					alert(html);
                    html=html.split("__");
                    $("#id_company").html(html[0]);
                    $('#emcoord').show();
                    $(".koordemail").html(html[1]);
                    $(".koordemail").attr('href',html[1]);
                }
            }
        });
    });
	
    $('#choosestatus').change(function() {
        $val=$(this).val();
        if ($val=='CV company') {
            $('.mediablock').hide();
            $('.amcblock').show();
        } else if($val=='Media') {
            $('.mediablock').show();
            $('.amcblock').hide();
        } else{
            $('.mediablock').hide();
            $('.amcblock').hide();
        }
		
    });
})



