﻿function CreateDiv(id, html, width, height, left, top, display, parentDiv) 
{
   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);
   
   if (width) {
       newdiv.style.width = 300;
   }
   
   if (height) {
       newdiv.style.height = 300;
   }
   
   if ((left || top) || (left && top)) {
       newdiv.style.position = "absolute";
       
       if (left) {
           newdiv.style.left = left;
       }
       
       if (top) {
           newdiv.style.top = top;
       }
   }
   
   if (display) {
       newdiv.style.display = display;
   }
   
   if (html) {
       newdiv.innerHTML = html;
   } else {
       newdiv.innerHTML = "";
   }
   
   if( parentDiv )
   {
    parentDivElement = document.getElementById(parentDiv);
    if(parentDivElement != null && parentDivElement != 'undefined')
    {
        parentDivElement.appendChild(newdiv);
    }
   }
   else
   {
    document.body.appendChild(newdiv);
   }

} 

function GetElementByID(ElementID) {
    var Element = document.getElementById(ElementID);

    if (!Element) {
        Element = null;
    }

    return Element;
}

function DivSetVisibility(DivID, IsVisible) {
    var DivElement = GetElementByID(DivID);

    if (DivElement != null) {
        if (IsVisible == true) {
            DivElement.style.display = 'block';
        }
        else {
            DivElement.style.display = 'none';
        }
    }
}

function DivDisplay(DivID) {
    var DivElement = GetElementByID(DivID);

    //unhides hidden elements
    if (DivElement != null) {
        if (DivElement.style.display == 'block') {
            //do nothing
        }
        else {
            DivElement.style.display = 'block';
        }
    }
}

function DivSetContent(DivID, Content, Class) {
    var DivElement = GetElementByID(DivID);

    if (DivElement != null) {
        DivElement.innerHTML = Content;
        DivElement.className = Class;
    }
}

function DivShow(DivID, Content, Class) {
    DivDisplay(DivID);
    DivSetContent(DivID, Content, Class);
}

function SetElementCSSClass(ElementID, CSSClass) {
    Element = GetElementByID(ElementID);
    
    if (Element != null) 
    {
        Element.className = CSSClass;
        //Element.id = CSSClass;
    }
}

function SetActiveTab(TabID) {
   
    SetElementCSSClass("ctl00_main_top_navigation_main_tab_link_home", "");
    SetElementCSSClass("ctl00_main_top_navigation_main_tab_link_phone", "");
    SetElementCSSClass("ctl00_main_top_navigation_main_tab_link_pc", "");
    SetElementCSSClass("ctl00_main_top_navigation_main_tab_link_music", "");
    
    SetElementCSSClass(TabID, "ON");
}

function show_message(title, message)
{    
    $('#Alert').html(message);
    tb_show(title, '#TB_inline?iframe=true&height=100&width=200&modal=true&inlineId=AlertContent', false);    
    
    return false;
}

function show_html(title, html_path)
{    
    $('#Alert').html(html_path);        
    tb_show(title, '<a href="'+ html_path + '"?height=220&width=400" class="thickbox" title="' + title + '">No-scroll content</a>');        
    return false;
}

function LoginCheck(eMail, Password)
{
    if (eMail.value == '' && Password.value == '') {
        return show_message('Login failed', 'Login failed. Please try again!');
    }
    else {
        return true;
    }
}

update_header_phone_finished = function() {
    FormElement = document.getElementById("ctl00_main_top_navigation_main_tab_link_phone");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_phone_phone_page.aspx', '', 'right_column_content');
            return false; 
        }
    }

    FormElement = document.getElementById("ctl00_ContentPlaceHolderContent_left_column_promo_phone");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_phone_phone_page.aspx', '', 'right_column_content');
            return false;
        }
    }
}

update_header_pc_finished = function() {
    FormElement = document.getElementById("ctl00_main_top_navigation_main_tab_link_pc");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_computer_file_view.aspx', '', 'right_column_content');
            return false; 
        }
    }

    FormElement = document.getElementById("ctl00_ContentPlaceHolderContent_left_column_promo_pc");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_computer_file_view.aspx', '', 'right_column_content');
            return false;
        }
    }
}

update_header_pc_now_has_unlimited = function() {
    FormElement = document.getElementById("ctl00_main_top_navigation_main_tab_link_pc");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_computer.aspx', '', 'right_column_content');
            return false; 
        }
    }

    FormElement = document.getElementById("ctl00_ContentPlaceHolderContent_left_column_promo_pc");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_computer.aspx', '', 'right_column_content');
            return false;
        }
    }    
}

update_header_music_finished = function(small_player_loaded) {
    FormElement = document.getElementById("ctl00_main_top_navigation_main_tab_link_music");

    if (FormElement != null) {
        FormElement.onclick = function() {
            AjaxPOST('my_music_music_page.aspx', '', '');
            return false;
        }
    }

    FormElement = document.getElementById("ctl00_ContentPlaceHolderContent_left_column_promo_music");

    if (FormElement != null) {
        if (small_player_loaded) {
            FormElement.onclick = null;
        }
        else {
            FormElement.onclick = function() {
                AjaxPOST('my_music_music_page.aspx', '', '');
                return false;
            }
        }
    }
}

update_edited_phone_info = function(phone_name, phone_number) {
    FormElement = parent.document.getElementById("phone_name");

    if (FormElement != null) {
        FormElement.innerHTML = phone_name;
    }

    FormElement = parent.document.getElementById("phone_number");

    if (FormElement != null) {
        FormElement.innerHTML = phone_number;
    }
}

update_edited_pc_info = function(pc_name) {
    FormElement = parent.document.getElementById("device_name");

    if (FormElement != null) {
        FormElement.innerHTML = pc_name;
    }
}

update_logged_in_user = function(email) {
    FormElement = document.getElementById("ctl00_main_top_navigation_logged_in_user");

    if (FormElement != null) {
        FormElement.innerHTML = email;
    }
}

clear_text_after_timeout = function(ElementID, TimeOut) {
    setTimeout("clear_element_text('" + ElementID + "');", TimeOut);
}

clear_element_text = function(ElementID) {
    FormElement = document.getElementById(ElementID);

    if (FormElement != null) {
        FormElement.innerHTML = "";
    }
}
