var VideoFenster = null;
var vaktiv = null;
var tmpstr="";

function speichern()
{
  tmpstr=document.getElementById("tmpyoutube").value;

  if(tmpstr.search(/youtube/) != -1)
  {
    document.getElementById("linkidx").value=0;
    readYouTubeLink();
  }
  else if(tmpstr.search(/clipfish/) != -1)
  {
    document.getElementById("linkidx").value=1;
    readClipFishLink();
  }
  else if(tmpstr.search(/myvideo/) != -1)
  {
    document.getElementById("linkidx").value=2;
    readMyVideoLink();
  }
  else if(tmpstr.search(/dailymotion/) != -1)
  {
    document.getElementById("linkidx").value=3;
    readDailyMotionLink();
  }
  else
  {
    alert(fehler2);
  }
  nvabbrechen();
}

function readYouTubeLink()
{
  var tstart = 0;
  document.getElementById("linktype").value="youtube";

  if(((tmpstr.search(/object/) != -1)||(tmpstr.search(/watch/) != -1)) && (tmpstr.search(/youtube.com/) != -1))
  {
    tstart= (tmpstr.search(/object/) != -1)?(tmpstr.indexOf('/v/')+3):(tmpstr.indexOf('=')+1);
    document.getElementById("ytlink").value=tmpstr.slice(tstart,tstart+11);
    document.getElementById("aktion").value=1;
//    sendrequest(window.location.href + "&show_only=newVideo&title="+htmlentities(document.getElementById("vtitle").value)+"&linkidx="+document.getElementById("linkidx").value+"&ytlink="+document.getElementById("ytlink").value+"&linktype="+document.getElementById("linktype").value+"&description="+htmlentities(document.getElementById("vdescription").value));
    sendrequest(window.location.href + "&show_only=newVideo&title="+$F("vtitle")+"&linkidx="+$F("linkidx")+"&ytlink="+$F("ytlink")+"&linktype="+$F("linktype")+"&description="+$F("vdescription"));
  }
  else
    abrsp(tmpstr);
}

function readClipFishLink()
{
  var tstart = 0;
  document.getElementById("linktype").value="clipfish";

  if(((tmpstr.search(/object/) != -1)||(tmpstr.search(/player.php/) != -1)) && (tmpstr.search(/clipfish/) != -1))
  {
    tstart= tmpstr.indexOf('videoid=')+8;
    document.getElementById("ytlink").value=tmpstr.slice(tstart,tstart+20);
    document.getElementById("aktion").value=1;
//    sendrequest(window.location.href + "&show_only=newVideo&title="+htmlentities(document.getElementById("vtitle").value)+"&linkidx="+document.getElementById("linkidx").value+"&ytlink="+document.getElementById("ytlink").value+"&linktype="+document.getElementById("linktype").value+"&description="+htmlentities(document.getElementById("vdescription").value));
	sendrequest(window.location.href + "&show_only=newVideo&title="+$F("vtitle")+"&linkidx="+$F("linkidx")+"&ytlink="+$F("ytlink")+"&linktype="+$F("linktype")+"&description="+$F("vdescription"));
  }
  else
    abrsp(tmpstr);
}

function readMyVideoLink()
{
  var tstart = 0;
  document.getElementById("linktype").value="myvideo";

  if(((tmpstr.search(/object/) != -1)||(tmpstr.search(/watch/) != -1)) && (tmpstr.search(/myvideo/) != -1))
  {
    tstart= (tmpstr.search(/object/) != -1)?(tmpstr.indexOf('/movie/')+7):(tmpstr.indexOf('/watch/')+7);
    document.getElementById("ytlink").value=tmpstr.slice(tstart,tstart+7);
    document.getElementById("aktion").value=1;
//    sendrequest(window.location.href + "&show_only=newVideo&title="+htmlentities(document.getElementById("vtitle").value)+"&linkidx="+document.getElementById("linkidx").value+"&ytlink="+document.getElementById("ytlink").value+"&linktype="+document.getElementById("linktype").value+"&description="+htmlentities(document.getElementById("vdescription").value));
	sendrequest(window.location.href + "&show_only=newVideo&title="+$F("vtitle")+"&linkidx="+$F("linkidx")+"&ytlink="+$F("ytlink")+"&linktype="+$F("linktype")+"&description="+$F("vdescription"));
  }
  else
    abrsp(tmpstr);
}

function readDailyMotionLink()
{
  var tstart = 0;
  document.getElementById("linktype").value="dailymotion";

  if(((tmpstr.search(/object/) != -1)||(tmpstr.search(/video/) != -1)) && (tmpstr.search(/dailymotion/) != -1))
  {
    tstart= (tmpstr.search(/object/) != -1)?(tmpstr.indexOf('/swf/')+5):(tmpstr.indexOf('/video/')+7);
    $("ytlink").value=tmpstr.slice(tstart,tstart+6);
    $("aktion").value=1;
//    sendrequest(window.location.href + "&show_only=newVideo&title="+htmlentities(document.getElementById("vtitle").value)+"&linkidx="+document.getElementById("linkidx").value+"&ytlink="+document.getElementById("ytlink").value+"&linktype="+document.getElementById("linktype").value+"&description="+htmlentities(document.getElementById("vdescription").value));
	sendrequest(window.location.href + "&show_only=newVideo&title="+$F("vtitle")+"&linkidx="+$F("linkidx")+"&ytlink="+$F("ytlink")+"&linktype="+$F("linktype")+"&description="+$F("vdescription"));
  }
  else
    abrsp(tmpstr);
}

function setType(idx)
{
  $("linkidx").value=idx;
}

function openVideoPortal(idx,link)
{
  var ltype = new Array("youtube","clipfish","myvideo","dailymotion");
  $("linktype").value=ltype[idx];

  VideoFenster = window.open(link,"videofenster","width="+screen.availWidth+", height="+screen.availHeight+" top=0, left=0, location=yes, menubar=yes, scrollbars=yes");
  VideoFenster.focus();
}

function changeVideo(vid,lt)
{
  var ltype = new Array("width=441, height=371","width=485, height=405","width=440, height=385","width=436, height=360");

  VideoFenster = window.open(site_url+"playVideo.php?vid="+vid, "playvideo", "left=300,top=100,"+ltype[lt]+",status=no,location=no,resizable=no");
  VideoFenster.focus();
}

function changeVideoadd(vz,title,id)
{
  addViews(id,1);
  $("myptitle").innerHTML='&nbsp;'+title;
  $("myplay").innerHTML='<object width="425" height="355" standby="Video wird geladen"><param name="movie" value="http://www.youtube.com/v/'+vz+'&rel=1"></param><param name="wmode" value="transparent"></param><embed id="eplay" src="http://www.youtube.com/v/'+vz+'&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
  $("myplaydiv").style.display="inline";
}

function changeViewVideo(vz,title)
{
   $("myptitle").innerHTML='&nbsp;'+title;
   $("myplay").innerHTML='<object width="350" height="294" standby="Video wird geladen"><param name="movie" value="http://www.youtube.com/v/'+vz+'&rel=1"></param><param name="wmode" value="transparent"></param><embed id="eplay" src="http://www.youtube.com/v/'+vz+'&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="350" height="294"></embed></object>';
}

function closeplayer()
{
  $("myptitle").innerHTML='&nbsp;';
  $("myplay").innerHTML='&nbsp;';
  $("myplaydiv").style.display="none";
}

function abrsp(tmpstr)
{
  if(tmpstr.length == 0)
  {
    alert(fehler2);
  }
  else
  {
    alert(fehler1);
  }
}

