function jump( url )
{
    if ( url != '' )
        document.location.href = url;
}

function rating( imageid, rate, staffid, lngCode )
{
    var url = '/' + lngCode + '/ajax';
    var param = {
    imageid : imageid,
    rate : rate,
    staffid : staffid
    };
    var elem = 'c' + imageid;
    var gri = new Ajax.Updater( {
        success : elem
    }, url, {
    method : 'post',
    parameters : param
    } );
}

function addStaffCommentary( imageid, scomment, lngCode )
{
    var url = '/' + lngCode + '/ajax';
    var param = {
    imageid : imageid,
    scomment : scomment
    };
    var elem = 'sc' + imageid;
    var gri = new Ajax.Updater( {
        success : elem
    }, url, {
    method : 'post',
    parameters : param
    } );
}

function compare_two_field( firstid, secondid, messid )
{
    var pattern = /.*/i;
    var password = $( firstid ).value;
    $( messid ).innerHTML = '';
    if ( pattern.test( password ) === true ) {
        if ( $( firstid ).value != '' && ( secondid ).value != '' ) {
            if ( $( secondid ).value != $( firstid ).value ) {
                $( firstid ).style.backgroundColor = '#ffcccc';
                $( secondid ).style.backgroundColor = '#ffcccc';
            } else {
                $( firstid ).style.backgroundColor = '#ccffcc';
                $( secondid ).style.backgroundColor = '#ccffcc';
            }
        }
    } else {
        $( firstid ).style.backgroundColor = '#ffcccc';
        $( messid ).innerHTML = '<span style="color:#aa0000;">wrong password</span>';
    }
}

function compareFields( masterField, slaveField )
{
    var pattern = /.+/i;
    var denyColor = '#ffcccc';
    var approvedColor = '#ccffcc';
    if ( pattern.test( $( masterField ).value ) === true ) {
        if ( $( slaveField ).value != $( masterField ).value ) {
            $( masterField ).style.backgroundColor = denyColor;
            $( slaveField ).style.backgroundColor = denyColor;
        } else {
            $( masterField ).style.backgroundColor = approvedColor;
            $( slaveField ).style.backgroundColor = approvedColor;
        }
    } else {
        $( masterField ).style.backgroundColor = denyColor;
    }
}

function check_email( email )
{
    var pattern = /^[\w-\.]+@(\w|-){2,}\.[a-zA-Z]{2,4}$/i;
    if ( pattern.test( email ) === true ) {
        $( 'emmessage' ).innerHTML = '';
        $( 'emailreg' ).style.backgroundColor = '#ffffff';
        var url = '/modules/imthumb.php';
        var param = {
            checkemail : email
        };
        var elem = 'emmessage';
        var gri = new Ajax.Updater( {
            success : elem
        }, url, {
        method : 'post',
        parameters : param
        } );
    } else {
        $( 'emmessage' ).innerHTML = '<span style="color:#aa0000;">error of typing e-mail</span>';
        $( 'emailreg' ).style.backgroundColor = '#ffcccc';
    }
}

function check_registration_form()
{
    if ( $( 'country' ).value != 0 && $( 'emailreg' ).value != '' && $( 'passwreg' ).value != '' && $( 'confirmreg' ).value != '' && $( 'passwreg' ).value == $( 'confirmreg' ).value ) {
        var empattern = /^[\w-\.]+@(\w|-){2,}\.[a-zA-Z]{2,4}$/i;
        var pwpattern = /.*/i;
        if ( empattern.test( $( 'emailreg' ).value ) === true && pwpattern
                .test( $( 'passwreg' ).value ) === true ) {
            if ( $( 'agreereg' ).checked == true )
                $( 'btnSubmitReg' ).disabled = 0;
            else
                $( 'btnSubmitReg' ).disabled = 1;
        }
    } else {
        $( 'btnSubmitReg' ).disabled = 1;
    }
}

function checkEmail( fieldId )
{
    var pattern = /^[\w-\.]+@(\w|-){2,}\.[a-zA-Z]{2,4}$/i;
    var denyColor = '#ffcccc';
    var approvedColor = '#ccffcc';
    if ( pattern.test( $( fieldId ).value ) === true ) {
        $( fieldId ).style.backgroundColor = approvedColor;
    } else {
        $( fieldId ).style.backgroundColor = denyColor;
    }
}

function switchDisplayStyle( id )
{
    if ( $( id ).style.display == 'none' ) {
        $( id ).style.display = 'block';
    } else {
        $( id ).style.display = 'none';
    }
}

function clearButton( fieldId, buttonId )
{
    if ( $( fieldId ).value == '' ) {
        $( buttonId ).disabled = true;
    } else {
        $( buttonId ).disabled = false;
    }
}

function showUserImages( userId, placeId, lngCode )
{
    // var url = '/jscripts/ajax_handler.php';
    var url = '/' + lngCode + '/ajax';
    var param = {
        ratingId : userId
    };
    var elem = placeId;
    var gri = new Ajax.Updater( {
        success : elem
    }, url, {
    method : 'post',
    parameters : param
    } );
    var floatWindow = $( placeId );
    floatWindow.style.right = '50px';
    floatWindow.style.bottom = '50px';
    floatWindow.style.top = '50px';
    floatWindow.style.left = '50px';
    floatWindow.style.overflow = 'auto';
    floatWindow.style.position = 'fixed';
    floatWindow.style.display = 'block';
}

function showMailForm( email, userId, placeId, lngCode )
{
    var floatWindow = $( 'userEmailPopup' );
    var textarea = $( 'emailMessage' );
    var userName = $( 'userName' );
    var cancelButton = $( 'cancelEmailButton' );
    var sendButton = $( 'sendEmailButton' );
    textarea.addClassName( 'emailPopupInside' );
    var windowContent = floatWindow.innerHTML;
    userName.innerHTML = '&laquo;' + email + '&raquo;';
    $( 'userEmailPopup' ).show();
    cancelButton.onclick = function()
    {
        floatWindow.hide();
        floatWindow.innerHTML = windowContent;
    };
    sendButton.onclick = function()
    {
        if ( textarea.value != '' ) {
            var url = '/' + lngCode + '/ajax';
            var param = {
            userid : userId,
            message : textarea.value
            };
            var elem = $( 'mailAlert' );
            var gri = new Ajax.Updater( {
                success : elem
            }, url, {
            method : 'post',
            parameters : param,
            insertion : Insertion.Bottom
            } );
            sendButton.disabled = 'disabled';
        }
    };

    var mouseOut = $( 'userEmailPopup' )
            .observe( 'mouseout', function( event, element )
            {
                $( 'userEmailPopup' ).setOpacity( 0.3 );
            } );
    var mouseOver = $( 'userEmailPopup' )
            .observe( 'mouseover', function( event, element )
            {
                $( 'userEmailPopup' ).setOpacity( 1 );
            } );
}

function closePopupWindow( id )
{
    $( id ).hide();
    $( id ).innerHTML = '';
}

function popupHelper( constantName, lngCode )
{
    var helper = $( 'popupHelper' );
    var pointer = Event.pointer( event );
    var startX = pointer.x;
    var startY = pointer.y;
    helper.addClassName( 'popupHelper' );
    helper.style.top = startY + 10 + 'px';
    helper.style.left = startX - 230 + 'px';
    /* helper.innerText = helper.getAttribute( 'style' ); */
    var url = '/' + lngCode + '/ajax';
    var param = {
        constantName : constantName
    };
    var elem = helper;
    var gri = new Ajax.Updater( {
        success : elem
    }, url, {
    method : 'post',
    parameters : param
    } );
    helper.setOpacity( 0.8 );
    helper.show();
}

function popupHelperClose()
{
    $( 'popupHelper' ).style.top = '0px';
    $( 'popupHelper' ).style.right = '0px';
    $( 'popupHelper' ).hide();
}

/**
 * Асинхронное изменение квот пользователя. Использует quotaResponse() (см.
 * ниже)
 * 
 * @param int
 *            requestId
 * @param str
 *            obj
 * @param str
 *            lngCode
 */
function changeQuota( requestId, obj, lngCode )
{
    var url = '/' + lngCode + '/ajax';
    var param = {
    obj : obj,
    requestId : requestId
    };
    var ar = new Ajax.Request( url, {
    method : 'post',
    parameters : param,
    onComplete : quotaResponse
    } );
}
/**
 * Используется в changeQuota() для обработки возвращаемых значений.<br />
 * Входной формат данных:<br />
 * <i>(str)</i><b>elementID:</b><i>(int)</i><b>elementIndex:</b><i>(str)</i><b>emptySign:</b><i>(mix)</i><b>renewValue</b>
 * @param request
 * @returns void
 */
function quotaResponse( request )
{
    var response = request.responseText.toString();
    var arr = response.split( ':' );
    if ( arr[3] != 'drop' ) {
        if ( arr[3] != -1 ) {
            $( arr[0] + 'Now' + arr[1] ).innerHTML = arr[3];
        }
        $( arr[0] + arr[1] ).innerHTML = arr[2];
    } else {
        $( 'requestSet' + arr[1] ).hide();
    }
}

/*
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 */

