/*======================================================================*\
|| #################################################################### ||
|| # vBGamEz 4.5.6
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2008-2009 GiveMeABreak. All Rights Reserved.            ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBGAMEZ IS NOT FREE SOFTWARE ------------------ # ||
|| # http://vbgamez.cyber-worlds.cn | http://cyber-worlds.cn          # ||
|| #################################################################### ||
\*======================================================================*/

function vbgamez_collapse_codes(url, scroll)
{
  if(fetch_object('codes').style.display == 'none')
   {
        fetch_object('codes').style.display = '';
        if(scroll)
        {
                     window.location.href = url + '#codes';
        }

   }else{ 

        fetch_object('codes').style.display = 'none';
   }
}

function vbgamez_quickedit_Init(commentid)
{
    if(fetch_object('comment_edit_restore_' + commentid).innerHTML == "")
    {
         fetch_object('comment_edit_restore_' + commentid).innerHTML = fetch_object('comment_edit_' + commentid).innerHTML;
         vbg_set_cursor('wait');
         vbg_show_progress(commentid);  

    }else{
         window.location.href = vbg_scriptname + '?do=editcomment&id=' + commentid;
    }
 
    var sUrl = vbg_scriptname;
    var postData = 'do=editcomment&ajax=1&securitytoken=' + SECURITYTOKEN + '&id=' + commentid;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
            fetch_object('comment_edit_' + commentid).innerHTML = o.responseText;

            vbg_hide_progress(commentid);
            vbg_set_cursor();
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}

function vbgamez_quickedit_restore(commentid)
{

  fetch_object('comment_edit_' + commentid).innerHTML = fetch_object('comment_edit_restore_' + commentid).innerHTML;
  fetch_object('comment_edit_restore_' + commentid).innerHTML = '';
}

function vbgamez_quickedit_save(commentid)
{
    vbg_set_cursor('wait');
    vbg_show_progress(commentid);

    var text = fetch_object('text_edit_' + commentid).value;

    var sUrl = vbg_scriptname;
    var postData = 'do=doeditcomment&sbutton=1&message=' + encodeURIComponent(text)  + '&ajax=1&securitytoken=' + SECURITYTOKEN + '&id=' + commentid;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
           if(o.responseText == 'saved')
            {
              fetch_object('comment_edit_' + commentid).innerHTML = PHP.htmlspecialchars(text);
            }else{
              alert(o.responseText);
            }
            vbg_hide_progress(commentid);
            fetch_object('comment_edit_restore_' + commentid).innerHTML = '';
            vbg_set_cursor();
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}

function vbg_show_progress(element_id)
{

  fetch_object('vbg_progress_' + element_id).style.display = '';
}

function vbg_hide_progress(element_id)
{

  fetch_object('vbg_progress_' + element_id).style.display = 'none';
}


function vbg_fetch_rating(serverid)
{

    var sUrl = vbg_scriptname;
    var postData = 'do=updrating&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
           fetch_object('rating_' + serverid).innerHTML = o.responseText;
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}



function vbg_rate(serverid, type)
{

    var sUrl = vbg_scriptname;

    if(type == 'plus')
    {
         var postData = 'do=ratingplus&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN + '&fromajax=1';
    }else{
         var postData = 'do=ratingminus&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN + '&fromajax=1';
    }

    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
           if(o.responseText == 'verify')
           {
                   vbg_show_verify_form(serverid, type);
           }else if(o.responseText == ""){

               vbg_fetch_rating(serverid);

           }else if(o.responseText != "" && o.responseText != 'verify')
           {
               alert(o.responseText);
           }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}


function fetch_steam(game)
{
    fetch_object('steam_div').innerHTML = '';
    fetch_object('steam_blockrow').style.display = 'none';

    var sUrl = vbg_scriptname;
    var postData = 'do=showsteam&game=' + game + '&securitytoken=' + SECURITYTOKEN;

    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
           if(o.responseText != "")
           {
               fetch_object('steam_div').innerHTML = o.responseText;
               fetch_object('steam_blockrow').style.display = '';
           }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}

function vbg_whoplaying(serverid)
{
        window.open(vbg_scriptname + '?do=whoplaying&serverid=' + serverid, 'vbg_whoplaying_' + serverid,'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=520');
}

function vbg_viewinfo(serverid)
{
        window.open(vbg_scriptname + '?do=viewinfo&id=' + serverid, 'vbg_viewinfo_' + serverid,'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=520');
}

function vbg_detalis(serverid)
{
        window.open(vbg_scriptname + '?do=viewdetalis&id=' + serverid, 'vbg_viewdetalis_' + serverid,'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=600,height=500');
}

function vbg_imwindow(icq)
{
        window.open('http://www.icq.com/people/webmsg.php?to=' + icq, 'vbg_imwindow_' + icq,'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=520');
}

function vbg_detalisbanned(serverid)
{
        window.open(vbg_scriptname + '?do=viewbanned&id=' + serverid, 'vbg_detalisbanned_' + serverid,'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=520');
}

function vbg_PostComment(serverid)
{
    var text = PHP.trim(fetch_object('new_comment').value);

    if(text == '') { return false; }

    vbg_set_cursor('wait');
    vbg_show_progress('new_comment');

    var newcomment_content = fetch_object('last_comment').innerHTML;
    var counter = fetch_object('vbg_counter').innerHTML;

    var sUrl = vbg_scriptname;
    var postData = 'do=doaddcomment&sbutton=1&id=' + serverid + '&ajax=1&message=' + encodeURIComponent(text) + '&securitytoken=' + SECURITYTOKEN;

    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
           if(o.responseText != "")
           {
               vbg_hide_progress('new_comment');
               if(o.responseText != 'error')
               {
                  fetch_object('new_comment').value = '';
                  fetch_object('last_comment').innerHTML = newcomment_content + o.responseText;

                  if(vbg_comments_moderation == 0)
                  {
                           fetch_object('vbg_counter').innerHTML = parseFloat(counter) + 1;
                           fetch_object('vbg_commentstats').style.display = '';
                  }

                  fetch_object('vbg_actions').style.display = '';
                 vbg_set_cursor();
               }
           }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}

function vbg_fetch_additional_game_type(gametype)
{
    fetch_steam(gametype);
    fetch_object('search_additional').innerHTML = '';

    if(gametype == 'bf1942' || gametype == 'farcry' || gametype == 'halflife' || gametype == 'halflifewon' || gametype == 'source')
    {
         // good
    }else{
        return false; 
    }
   
    vbg_show_progress('search'); 
 
    var sUrl = vbg_scriptname;
    var postData = 'do=fetch_type&ajax=1&securitytoken=' + SECURITYTOKEN + '&type=' + gametype;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
            if(o.responseText != "")
            {
                 fetch_object('search_additional').innerHTML = o.responseText;
            }
            vbg_hide_progress('search');
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}

function vbg_upload_map(serverid, gametype, game, mapname)
{
    var sUrl = vbg_scriptname;
    var postData = 'do=uploadmap&ajax=1&securitytoken=' + SECURITYTOKEN + '&id=' + serverid + '&type=' + gametype + '&game=' + game + '&mapname=' + mapname;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
            if(o.responseText != "")
            {
                        fetch_object('vbgamez_ajax_content_div').innerHTML = o.responseText;

                        fetch_object('vbg_uploadbutton').onclick = function(e) { vbg_do_upload_map(serverid, gametype, game, mapname); }

                        fetch_object('vbg_closeuploadbutton').onclick = function(e) { vbg_closeupload_map(); }

            }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}


function vbg_do_upload_map(serverid, gametype, game, mapname)
{
    var sUrl = vbg_scriptname;
    var filename = fetch_object('vbg_filename').value;

    var postData = 'do=douploadmap&ajax=1&securitytoken=' + SECURITYTOKEN + '&id=' + serverid + '&type=' + gametype + '&game=' + game + '&filename=' + filename + '&mapname=' + mapname;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
            if(o.responseText != "")
            {
                       if(o.responseText == 'OK')
                       {
                            document.forms.vbg_uploadfile.submit();
                       }else{
                            alert(o.responseText);
                       }
            }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function vbg_closeupload_map()
{ 
    fetch_object('vbgamez_ajax_content_div').innerHTML = '';
}

function vbg_update_server(serverid, isvb3)
{
    fetch_object('vbg_updater').style.display = '';
    var sUrl = vbg_scriptname;
    var postData = 'do=updateserver&id=' + serverid + '&ajax=1&securitytoken=' + SECURITYTOKEN;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
               fetch_object('vbg_serverinfo').innerHTML = o.responseText;

               if(isvb3)
               {
                           fetch_object('vbg_updater').style.display = 'none';
               }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function vbg_show_verify_form(serverid, type)
{
    var sUrl = vbg_scriptname;

    if(type == 'plus')
    {
         var postData = 'do=ratingplus&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN;
    }else{
         var postData = 'do=ratingminus&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN;
    }

    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
               fetch_object('vbgamez_ajax_content_div').innerHTML = o.responseText;
               fetch_object('vbg_verifybutton').onclick = function(e) { vbg_do_verify(serverid, type); }

               fetch_object('vbg_closeverifybutton').onclick = function(e) { vbg_closeverify(); }

        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function vbg_closeverify()
{ 
    fetch_object('vbgamez_ajax_content_div').innerHTML = '';
}

function vbg_do_verify(serverid, type)
{
    var sUrl = vbg_scriptname;

    var captcha_text = fetch_object('imageregt').value;

    var captcha_hash = fetch_object('hash').value;

    if(type == 'plus')
    {
         var postData = 'do=ratingplus&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN + '&fromverify=1&ajax=1&humanverify[input]=' + captcha_text + '&humanverify[hash]=' + captcha_hash;
    }else{
         var postData = 'do=ratingminus&serverid=' + serverid + '&securitytoken=' + SECURITYTOKEN + '&fromverify=1&ajax=1&humanverify[input]=' + captcha_text + '&humanverify[hash]=' + captcha_hash;
    }

    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
               if(o.responseText == 'error')
               {
                      alert(vbphrase['vbg_humanverify_error']);
               }else{

                      fetch_object('vbgamez_ajax_content_div').innerHTML = '';
                      vbg_fetch_rating(serverid);
               }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function vbg_switch_tab(type)
{ 
    if(top_rating)
    {
          fetch_object('tab_rating').setAttribute("class", "");
          fetch_object('rating').style.display = 'none';
    }

    if(top_visiting)
    {
          fetch_object('tab_visits').setAttribute("class", "");
          fetch_object('visits').style.display = 'none';
    }

    if(top_views)
    {
          fetch_object('tab_views').setAttribute("class", "");
          fetch_object('views').style.display = 'none';
    }

    if(top_comments)
    {
          fetch_object('tab_comments').setAttribute("class", "");
          fetch_object('comments').style.display = 'none';
    }

    if(top_maps)
    {
          fetch_object('tab_maps').setAttribute("class", "");
          fetch_object('maps').style.display = 'none';
    }

    if(detalis_main)
    {
          fetch_object('tab_content_container').setAttribute("class", "");
          fetch_object('content_container').style.display = 'none';
    }

    if(detalis_codes)
    {
          fetch_object('tab_codes').setAttribute("class", "");
          fetch_object('codes').style.display = 'none';
    }

    if(detalis_graphics)
    {
          fetch_object('tab_graphics').setAttribute("class", "");
          fetch_object('graphics').style.display = 'none';
    }

    fetch_object(type).style.display = '';
    fetch_object('tab_' + type).setAttribute("class", "selected");
}


function vbg_hightlight(thisinfo, id)
{
       if(thisinfo.checked == true)
       {
                 fetch_object('comment_message_' + id).setAttribute("class", "highlight");
       }else{
                 fetch_object('comment_message_' + id).removeAttribute("class", "highlight");
       }
       vbg_inlinemod_count();
}

function vbg_select_all_checkbox(type, is_vb3)
{

var count = 0;
var inputs = document.getElementsByTagName('input');

   for (var i = 0; i < inputs.length; i++)
    {
      if(type == 'selectall')
      {
        if (inputs[i].type == 'checkbox' && inputs[i].name == 'commentsarray[]')
        {
           if(inputs[i].checked == false)
            { 
               document.getElementById(inputs[i].id).checked = true;
               vbg_hightlight(inputs[i], inputs[i].value);
            }
        }
      }else if(type == 'unselectall')
      {
        if (inputs[i].type == 'checkbox' && inputs[i].name == 'commentsarray[]')
        {
           if(inputs[i].checked == true)
            { 
               document.getElementById(inputs[i].id).checked = false;
               vbg_hightlight(inputs[i], inputs[i].value);
            }
        }
      }else if(type == 'invertselected')
      {
        if (inputs[i].type == 'checkbox' && inputs[i].name == 'commentsarray[]')
        {
           if(inputs[i].checked == true)
            { 

               document.getElementById(inputs[i].id).checked = false;
               vbg_hightlight(inputs[i], inputs[i].value);
            }else{

               document.getElementById(inputs[i].id).checked = true;
               vbg_hightlight(inputs[i], inputs[i].value);
            }
        }
      }
    }
 
  if(is_vb3)
  {
           vbmenu_hide('imod');
  }else{
           YAHOO.vBulletin.vBPopupMenu.close_all('view-server-popups');
  }
}

function vbg_inlinemod_count()
{

var count = 0;
var inputs = document.getElementsByTagName('input');

   for (var i = 0; i < inputs.length; i++)
    {
        if (inputs[i].type == 'checkbox' && inputs[i].name == 'commentsarray[]')
        {
           if(inputs[i].checked == true)
            { 
               count++;
            }
        }
    }

 fetch_object('vbg_moderation_count').innerHTML = count;
}

function vbg_set_cursor(type)
{
     if(!type)
     {
             var type = 'auto';
     }
     
     document.body.style.cursor = type;
}

function vbg_load_servername()
{
    var ip = fetch_object('address').value;
    var port = fetch_object('port').value;
    var type = fetch_object('game').value;

    if(ip == "" || port == "" || type == "")
    {
            return false;
    }

    vbg_show_progress('add');

    var sUrl = vbg_scriptname;
    var postData = 'do=fetch_servername&ip=' + ip + '&port=' + port + '&type=' + type + '&securitytoken=' + SECURITYTOKEN;
    var handleSuccess = function(o)
    {
        if(o.responseText !== undefined)
        {
            if(o.responseText != "")
            {
                        fetch_object('name').value = o.responseText;
                        vbg_hide_progress('add');
            }
        }
    }
    var handleFailure = function(o)
    {
        if(o.responseText !== undefined)
        {
            alert(o.responseText);
        }
    }
    var callback =
    {
        success: handleSuccess,
        failure: handleFailure,
        timeout: vB_Default_Timeout
    };
    YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function vbg_switch_tab_vb3(type)
{ 
    if(top_rating)
    {
          fetch_object('tab_rating').setAttribute("class", "tborder thead");
          fetch_object('rating').style.display = 'none';
    }

    if(top_visiting)
    {
          fetch_object('tab_visits').setAttribute("class", "tborder thead");
          fetch_object('visits').style.display = 'none';
    }

    if(top_views)
    {
          fetch_object('tab_views').setAttribute("class", "tborder thead");
          fetch_object('views').style.display = 'none';
    }

    if(top_comments)
    {
          fetch_object('tab_comments').setAttribute("class", "tborder thead");
          fetch_object('comments').style.display = 'none';
    }

    if(top_maps)
    {
          fetch_object('tab_maps').setAttribute("class", "tborder thead");
          fetch_object('maps').style.display = 'none';
    }

    if(detalis_main)
    {
          fetch_object('tab_content_container').setAttribute("class", "tborder thead");
          fetch_object('content_container').style.display = 'none';
    }

    if(detalis_codes)
    {
          fetch_object('tab_codes').setAttribute("class", "tborder thead");
          fetch_object('codes').style.display = 'none';
    }

    if(detalis_graphics)
    {
          fetch_object('tab_graphics').setAttribute("class", "tborder thead");
          fetch_object('graphics').style.display = 'none';
    }

    fetch_object(type).style.display = '';
    fetch_object('tab_' + type).setAttribute("class", "tborder tcat");
}

function fetch_blockrow(val, isvb3)
{
       // быдло table-row нельзя скрыть спаном/дивом >:(

      if(val == 'wow' || val == 'la2' || val == 'aion')
      {

             if(!isvb3)
             {
                      fetch_object('vbg_blockrow').style.display = 'none';
                      fetch_object('vbg_blockrow_db').style.display = '';
             }else{
                      fetch_object('div_address').style.display = 'none';
                      fetch_object('div_port').style.display = 'none';
                      fetch_object('div_name').style.display = 'none';

                      fetch_object('div_db_address').style.display = '';
                      fetch_object('div_db_user').style.display = '';
                      fetch_object('div_db_password').style.display = '';
             }

             var ppos = document.location.hash.indexOf('#');
             var type = (ppos == -1) ? false : document.location.hash.substr(ppos+1);

             if(!type)
             {
                        document.location.href = document.location.href + '#' + val;
             }
      }else{

             if(!isvb3)
             {
                      fetch_object('vbg_blockrow').style.display = '';
                      fetch_object('vbg_blockrow_db').style.display = 'none';
             }else{
                      fetch_object('div_address').style.display = '';
                      fetch_object('div_port').style.display = '';
                      fetch_object('div_name').style.display = '';

                      fetch_object('div_db_address').style.display = 'none';
                      fetch_object('div_db_user').style.display = 'none';
                      fetch_object('div_db_password').style.display = 'none';
             }
      }
}

function blockrow_onload(isvb3)
{
  var ppos = document.location.hash.indexOf('#');
  var type = (ppos == -1) ? false : document.location.hash.substr(ppos+1);
  if(type)
  {
            fetch_blockrow(type, isvb3);

            fetch_object('game').value = type;
  }
}

function vBG_Hide_Overlay()
{	
	document.getElementById("preview_div").style.display = "none";
	document.onmousemove = '';
	document.getElementById("preview_div").style.left = "-500px";
	clearTimeout(timer);
}

function vBG_Show_Overlay(imagename)
{
        if(!fetch_object('preview_div'))
        {
                var newNode = document.createElement('div');
                newNode.setAttribute('id', 'preview_div');
                newNode.setAttribute('style', 'display: none; position: absolute;z-index:110;');
                document.body.appendChild(newNode);
        }

        if(!(typeof window['vbg_show_overlay'] == 'function'))
        {
                     vBG_loadScript('clientscript/vbulletin_ajax_vbgamez_overlay.js', function()
                     {
                              vBG_loadScript('clientscript/vbulletin_ajax_vbgamez_overlay.js', function() { });
                     });
        }

	timer = setTimeout("vbg_show_overlay('" + imagename + "');", 20);

        return false;
}

function vBG_loadScript(url, callback)
{
        var script = document.createElement("script");
        script.type = "text/javascript";
        if (script.readyState)
        {
            script.onreadystatechange = function()
            {
                if (script.readyState == "loaded" || script.readyState == "complete")
                {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        }else{
            script.onload = function() {
                callback();
            };
        }
        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
}