﻿/* BEGIN: General Functions */

// Used to open a popup page
function popup(pageURL,x,y)
{
    var newwin = window.open( pageURL, "_blank", "toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,top=0,left=0,width=" + x + ",height=" + y + ",resizable=yes" );
}

// Used to refresh the opener page
function refreshOpenerPage()
{
    window.opener.location.href = window.opener.location.href;
}

// Used to trim whitespace characters
function TrimWhiteSpace(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

/* END: General Functions */

/* BEGIN: Validation Functions */

// AddNewsComment.aspx
function AddNewsComment_ValidateBody(source, arguments)
{
    if (TrimWhiteSpace(document.forms[0].elements['ctl00_PupupContent_Body'].value).length < 3 || TrimWhiteSpace(document.forms[0].elements['ctl00_PupupContent_Body'].value).length > 1000)
    {
        source.innerText = 'Yorum metni için en az 3, en fazla 1000 karakter kullanabilirsiniz. Siz ' + TrimWhiteSpace(document.forms[0].elements['ctl00_PupupContent_Body'].value).length + ' karakter kullandınız.';
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;    
    }
}

// Administration/FaqDetails.aspx
function Administration_FaqDetails_ValidateBody(source, arguments)
{
    if (TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Description'].value).length < 1 || TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Description'].value).length > 500)
    {
        source.innerText = 'Açıklama için en az 1, en fazla 500 karakter kullanabilirsiniz. Siz ' + TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Description'].value).length + ' karakter kullandınız.';
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;    
    }
}

// AddNewsComment.aspx
function Administration_NewsCommentDetails_ValidateBody(source, arguments)
{
    if (TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Body'].value).length < 3 || TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Body'].value).length > 1000)
    {
        source.innerText = 'Yorum metni için en az 3, en fazla 1000 karakter kullanabilirsiniz. Siz ' + TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Body'].value).length + ' karakter kullandınız.';
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;    
    }
}

// Administration/ProductDetails.aspx
function Administration_ProductDetails_ValidateSummary(source, arguments)
{
    if (TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Summary'].value).length > 250)
    {
        source.innerText = 'Ürün özet açıklaması için en fazla 250 karakter kullanabilirsiniz. Siz ' + TrimWhiteSpace(document.forms[0].elements['ctl00_maincontent_Summary'].value).length + ' karakter kullandınız.';
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;    
    }
}

/* END: Validation Functions */

/* BEGIN: AJAX Functions */
function Administration_Top10GameList_GetAutoComplete(textBox, selectBox)
{
    if (textBox.value.length > 2)
    {
        var platform = document.forms[0].elements['ctl00_maincontent_PlatformId'];
        // Clear the select box
        selectBox.options.length = 0;
        selectBox.options[0] = new Option('Sonuçlar alınıyor', '');
        
        var response = Top10GameList.GetSuggestedGameNames(platform[platform.selectedIndex].value, textBox.value);

        if (response.error == null)
        {
            if (response.value != null)
            {
                // Clear the select box
                selectBox.options.length = 0;
                selectBox.options[0] = new Option('Lütfen bir oyun seçiniz', '');
                var i = 0;
                for (i = 0; i < response.value.length; i++)
                {
                    selectBox.options[i + 1] = new Option(response.value[i], response.value[i]);
                }
            }
            else
            {
                selectBox.options.length = 0;
                selectBox.options[0] = new Option('Sonuç bulunamadı', '');
            }
        }
        else
        {
            selectBox.options.length = 0;
            selectBox.options[0] = new Option('Sunucuda hata oluştu', '');
        }
    }
}

function Administration_Top10GameList_SetTextBoxValue(textBox, selectBox)
{
    textBox.value = selectBox.options[selectBox.selectedIndex].value;
}

function Administration_PhotoGalleryDetails_GetAutoComplete(textBox, selectBox)
{
    if (textBox.value.length > 2)
    {
        var platform = document.forms[0].elements['ctl00_maincontent_PlatformId'];
        // Clear the select box
        selectBox.options.length = 0;
        selectBox.options[0] = new Option('Sonuçlar alınıyor', '');
        
        var response = PhotoGalleryDetails.GetSuggestedGameNames(platform[platform.selectedIndex].value, textBox.value);

        if (response.error == null)
        {
            if (response.value != null)
            {
                // Clear the select box
                selectBox.options.length = 0;
                selectBox.options[0] = new Option('Lütfen bir oyun seçiniz', '');
                var i = 0;
                for (i = 0; i < response.value.length; i++)
                {
                    selectBox.options[i + 1] = new Option(response.value[i], response.value[i]);
                }
            }
            else
            {
                selectBox.options.length = 0;
                selectBox.options[0] = new Option('Sonuç bulunamadı', '');
            }
        }
        else
        {
            selectBox.options.length = 0;
            selectBox.options[0] = new Option('Sunucuda hata oluştu', '');
        }
    }
}

function Administration_PhotoGalleryDetails_SetTextBoxValue(textBox, selectBox)
{
    textBox.value = selectBox.options[selectBox.selectedIndex].value;
}

function Administration_ProductCategoryList_GetRecommendedProductCategoryName(id, parentId, productCategoryName)
{
    if (TrimWhiteSpace(productCategoryName).length == 0)
    {
        document.forms[0].elements['ctl00_maincontent_Name'].focus();
    }
    else
    {
        Administration_ProductCategoryList.RecommendFriendlyUrl(id, parentId, productCategoryName, Administration_ProductCategoryList_RecommendFriendlyUrl_CallBack);
    }
}

function Administration_ProductCategoryList_RecommendFriendlyUrl_CallBack(response)
{
    if (response.error == null)
    {
        document.forms[0].elements['ctl00_maincontent_FriendlyUrl'].value = response.value;
    }
}

function Administration_ProductDetails_GetRecommendedProductName(id, productName)
{
    if (TrimWhiteSpace(productName).length == 0)
    {
        document.forms[0].elements['ctl00_maincontent_Name'].focus();
    }
    else
    {
        Administration_ProductDetails.RecommendFriendlyUrl(id, productName, Administration_ProductDetails_RecommendFriendlyUrl_CallBack);
    }
}

function Administration_ProductDetails_RecommendFriendlyUrl_CallBack(response)
{
    if (response.error == null)
    {
        document.forms[0].elements['ctl00_maincontent_FriendlyUrl'].value = response.value;
    }
}

function ProductDetails_SelectImage(imageUrl)
{
    ctl00_ContentPlaceHolder1_ProductDetailsBox1_AjaxProductImage.Callback(imageUrl);     
}
/* END: AJAX Functions */

/* BEGIN: ComponentArt Functions */
function Administration_ProductCategoryList_treeContextMenu(treeNode, e)
{
    if (treeNode.ID != '0' && treeNode.ID != '-1')
    {
        ctl00_maincontent_ProductCategoryTreeContextMenu.ShowContextMenu(e, treeNode.ID);
    } 
}
/* END: ComponentArt Functions */
