﻿/**
 * $Id: forms.js 1321 2007-10-26 13:40:00Z alex $
 *
 * @copyright Copyright (c) 2007, Effective Solution Band Ltd, All rights reserved.
 * @url http://www.esb.com.ua
*/

function _$(id){
    return document.getElementById(id);
}

/* Job */

var g_count_photo = 1;
function formJobAddPhoto(){
    if(g_count_photo<5){
        g_count_photo += 1;
        var div = document.createElement('div');
        div.innerHTML = '<div class="fieldname_nr">' + 
                    _$('photo_text').innerHTML + ' ' + g_count_photo + 
                    ' </div><div class="fieldinput"><input name="photo[]" type="file" /></div>';
                    
        _$('photo_add').parentNode.appendChild(div);
    }
}

function formValidateJob(result_validate){
    if(!result_validate){
        return false;
    }
    if(_$('mobphone').value.length==0 && _$('domphone').value.length==0 && _$('workphone').value.length==0){
        alert(localization.web_form_validate_job_need_phone);
        return false;
    }
    var t = document.getElementsByTagName('input');
    var count = 0;
    for(var i=0; i<t.length; i++){
        if(t[i].name == 'job_position[]' && t[i].checked == true){
            count += 1;
        }
    }
    if(count == 0){
        alert(localization.web_form_validate_job_set_position);
        return false;
    }

    return true;
}

/* Casting */

var g_count_casting_photo = 2;
function formCastingAddPhoto(){
    if(g_count_casting_photo<5){
        g_count_casting_photo += 1;
        var div = document.createElement('div');
        div.innerHTML = '<div class="fieldname_nr">' + 
                    _$('photo_text').innerHTML + ' ' + g_count_casting_photo + 
                    ' </div><div class="fieldinput"><input name="photo[]" type="file" /></div>';
        _$('photo_add').parentNode.appendChild(div);
    }
}

var g_count_casting_video = 1;
function formCastingAddVideo(){
    if(g_count_casting_video <5){
        g_count_casting_video += 1;
        var div = document.createElement('div');
        div.innerHTML = '<div class="fieldname_nr">' + 
                    _$('video_text').innerHTML + ' ' + g_count_casting_video + 
                    ' </div><div class="fieldinput"><input name="video[]" type="file" /></div>';                    
        _$('video_add').parentNode.appendChild(div);
    }
}
var g_count_casting_audio = 1;
function formCastingAddAudio(){
    if(g_count_casting_audio<5){
        g_count_casting_audio += 1;
        var div = document.createElement('div');
        div.innerHTML = '<div class="fieldname_nr">' + 
                    _$('audio_text').innerHTML + ' ' + g_count_casting_audio + 
                    ' </div><div class="fieldinput"><input name="audio[]" type="file" /></div>';                    
        _$('audio_add').parentNode.appendChild(div);
    }
}


function formValidateCasting(result_validate){
    if(!result_validate){
        return false;
    }
    if(_$('mobphone').value.length==0 && _$('domphone').value.length==0 && _$('workphone').value.length==0){
        alert(localization.web_form_validate_job_need_phone);
        return false;
    }
    // Check Photo
    var sExt1 = checkExtension(_$('photo1').value, ['jpg','jpeg']);
    var sExt2 = checkExtension(_$('photo2').value, ['jpg','jpeg']);
    if(sExt1 != true || sExt2 != true){
        alert(localization.web_form_casting_need_more_photo);
        return false;
    }
    return true;
}


function checkExtension(path, arr_ext){
    var sExt = path.substring(path.lastIndexOf('.') + 1);
    var sExtension = new String(sExt);
    sExtension = sExtension.toLowerCase();
    var result = false;
    for(var i=0;i<arr_ext.length;i++){
        result = result || (sExtension == arr_ext[i]);
    }
    if(!result){
        return sExtension;
    }
    return result;
}

function reloadCaptcha(){
    _$('imgCaptha').src = g_base_url + 'captcha.php?' + Math.round(Math.random(0)*1000)+1;
}

