﻿String.prototype.trim =function(){return this.replace(/(^\s+)|(\s+$)/g,"");}
String.prototype.ltrim=function(){return this.replace(/^\s+/,"");}
String.prototype.rtrim=function(){return this.replace(/\s+$/g,"");}

function setHome(obj)
{
   var url="http://"+document.location.host+"/";
   obj.style.behavior="url(#default#homepage)";
   obj.setHomePage(url);
}

function addToFav(name)
{
    url="http://"+document.location.host+"/";
    window.external.AddFavorite(url,name);
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function isEmail(str)
{
    return /^[\w-]+@[\w-]+(\.[a-z]{2,3}){1,2}$/i.test(str);
}
function isTel(str)
{
    return /^(\d{2,6}-){0,2}\d{4,16}$/.test(str);
}

function GetTimeKey() {
    var d = new Date();
    return d.getHours() + "_" + d.getMinutes() + "_" + d.getSeconds();
}

function cgVercode(o) {
    var key = GetTimeKey();
    o.src=o.src.replace(/(\?t=)[\d\.\_]+$/,'$1'+key);
}

function doSel(name,act)
{
    if (!arguments[1]){act = name;name = 'ids';}
    var o = document.getElementsByName(name);
    if (o.length <1) return;
    var f;
    switch(act)
    {
        case "all":
            f = function(c){c.checked = true;}
            break;
        case "other":
            f = function(c){c.checked = (c.checked)?false:true;}
            break;
        case "none":
            f = function(c){c.checked = false;}
            break;
        default:
            return;
    }
    for (var i=0;i<o.length;i++) f(o[i]);
}

function GetIptPreFix(name) {
    var n = name.lastIndexOf('$');
    if (n == -1) name = '';
    else name = name.substr(0, n + 1);
    return name;
}

function getFlash(src,w,h,alpha,vars)
{
    var tmp = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="{$w}" height="{$h}"><param name="movie" value="{$src}" /><param name="quality" value="high" />{$attach1}<embed src="{$src}" quality="high" {$attach2}  pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="{$w}" height="{$h}"></embed></object>';
    tmp = tmp.replace(/\{\$src\}/g,src).replace(/\{\$w\}/g,w).replace(/\{\$h\}/g,h);
    var attach = '',attach2 = '';
    if (alpha == true){
        attach += '<param name="wmode" value="transparent" />';
        attach2+= ' wmode="transparent" ';
    }
    if (vars && vars != ''){
        attach += '<param name="FlashVars" value="'+vars+'" />';
        attach2+= ' FlashVars="'+vars+'" ';
    }
    tmp = tmp.replace('{$attach1}',attach).replace('{$attach2}',attach2);
    document.writeln(tmp);
}
//2009-9 Alle
function getFlv2(src,w,h,auto,title)
{
    var cfg = {player:'swf/vcastr22.swf',w:520,h:400};
    var para = {vcastr_file:'',LogoUrl:'swf/logo.png',IsAutoPlay:0,vcastr_title:''};
    para.vcastr_file = src;
    if (w) cfg.w = isNaN(w) || w == 0 ? cfg.w : w;
    if (h) cfg.h = isNaN(h) || h == 0 ? cfg.h : h;
    if (typeof auto != 'undefined') para.IsAutoPlay = (auto == 1) ? 1 : 0;
    if (title) para.vcastr_title = title;
    var tmp = '<object type="application/x-shockwave-flash" data="@player@" width="@w@" height="@h@"><param name="movie" value="@player@"/><param name="allowFullScreen" value="true" /><param name="FlashVars" value="@para@"/></object>'
    for(var o in cfg){tmp = tmp.replace(eval('/@'+ o+'@/g'),cfg[o]);}
    var p = '';
    for(var o in para)
    {
        if (para[o] == '') continue;
        p += o + '='+para[o]+'&';
    }
    if (p != '') p = p.slice(0,-1);
    tmp = tmp.replace('@para@',p);
    return tmp;
}
function getFlv(src,w,h,auto,title,time)
{
    var cfg = {player:'swf/vcastr3.swf',w:520,h:400,title:'',src:'',auto:true,logo:'swf/logo.png',time:''};
    cfg.src = src;
    if (w) cfg.w = isNaN(w) || w == 0 ? cfg.w : w;
    if (h) cfg.h = isNaN(h) || h == 0 ? cfg.h : h;
    if (typeof auto != 'undefined') cfg.auto = (auto == 1) ? true : false;
    if (title) cfg.title = title;
	if (time)  cfg.time = time;
    var tmp = '<object type="application/x-shockwave-flash" data="@player@" width="@w@" height="@h@"><param name="movie" value="@player@"/><param name="allowFullScreen" value="true" /><param name="FlashVars" value="xml=<vcastr><channel><item><source>@src@</source><duration>@time@</duration><title>@title@</title></item></channel><config><isAutoPlay>@auto@</isAutoPlay><isShowAbout>false</isShowAbout></config><plugIns><logoPlugIn><url>logoPlugIn.swf</url><logoText></logoText><logoTextAlpha>0.75</logoTextAlpha><logoTextFontSize>24</logoTextFontSize><logoTextColor>0xffffff</logoTextColor><textMargin>20 20 auto auto</textMargin><logoClipUrl>@logo@</logoClipUrl><logoClipAlpha>1</logoClipAlpha><clipMargin>12 auto auto 12</clipMargin></logoPlugIn></plugIns></vcastr>"/></object>';
    for(var o in cfg){tmp = tmp.replace(eval('/@'+ o+'@/g'),cfg[o]);}
    return tmp;
}

function fixFlv(id)
{
    var o = document.getElementById(id);
    if (!o || o.innerHTML.indexOf('[/flv]') == -1) return;
    var reg = new RegExp('\\[flv(\\s+var=(\\{[^}]+\\}))?\\]([^\\[]+)\\[\\/flv\\]','ig');
    var m = reg.exec(o.innerHTML);
    var p;
    var tmp = o.innerHTML;
    while(m){
        if (m[2] != ''){
            try{eval('p='+m[2]);}
            catch(err){break;}
           tmp = tmp.replace(m[0],getFlv(m[3],isNaN(p.w)?0:p.w,isNaN(p.h)?0:p.h,isNaN(p.auto)?0:p.auto,p.title?p.title:'',p.time?p.time:''));
        }
        else{
            tmp = tmp.replace(m[0],getFlv(m[3]));    
        }
        m = reg.exec(o.innerHTML);
    }
    o.innerHTML = tmp;
}
function cleanFlv(id)
{
    var o = document.getElementById(id);
    if (!o) return;
	if (o.innerHTML.indexOf('[/flv]') == -1) return;
    var reg = new RegExp('\\[flv(\\s+var=(\\{[^}]+\\}))?\\]([^\\[]+)\\[\\/flv\\]','ig');
    o.innerHTML = o.innerHTML.replace(reg,'');
}