/******************************************\
      insects upload javascript file
\******************************************/
// global
var d = document;

// открыть окно с формой закачки
function openList(theURL,winName,features) {
        var ScreenWidth=window.screen.width;
        var ScreenHeight=window.screen.height;
        placementx=(ScreenWidth/2)-(240);
        placementy=(ScreenHeight/2)-(200);
        window.open(theURL,winName,features+",left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy);
        return false;
}

// проверка формы на заполнение при нажатии кнопы отправки
function check(){
        if (d.upload.user_name.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
                notice('укажите имя / fill the name field', 'ff0000');
                d.upload.user_name.focus();
                return false;
        }
        if (d.upload.user_mail.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
                notice('укажите электропочту / fill the e-mail field', 'ff0000');
                d.upload.user_mail.focus();
                return false;
        }
        if (d.upload.user_site.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
                notice('укажите сайт / fill the link field', 'ff0000');
                d.upload.user_site.focus();
                return false;
        }
        if (d.upload.img.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
                notice('добавьте файл / add file', 'ff0000');
                d.upload.img.focus();
                return false;
        }
}

// отображение картинки при выборе файла: onchange -- action
function set_pic(){
        var patch = d.upload.img.value;
        var regex = /.*\.(jpg|jpeg)$/i; // .jpg .jpeg, .JpEg and etc.
        if (regex.test(patch)){
                d.getElementById('pic').src = patch;
                d.upload.send.disabled = false;
        }else{
                d.getElementById('pic').src = 'i/empty.gif';
                notice('Только JPEG', 'ff0000');
                d.upload.send.disabled = true;
        }
        return true;
}

// первоначальный фокус
function fstart(){
        d.upload.user_name.focus();
}

// вывод сообщения в id="notice"
function notice(text, color){
        d.getElementById('notice').style.color = '#'+color;
        d.getElementById('notice').innerHTML = ''+text;
}