var server='';
var BaseH=272;


function resizer() {
	
	}
	
function upload() {
		 var v=document.getElementById('loading');
		 if (v) v.style.visibility='visible';
		 v=document.getElementById('upok');
		 if (v) v.style.visibility='hidden';
		 v=document.getElementById('upfi');
		 if (v) v.style.visibility='hidden';
		 v=document.getElementById('upst');
		 if (v) v.style.visibility='hidden';
		 v=document.getElementById('sotto');
		 if (v) v.style.visibility='hidden';
		 }
	
var cpa=0;
function recapt() {
		 var v=document.getElementById('capt');
		 if (v) v.src='captcha.php?'+(cpa++)+Math.random();
		 }

function playerror(img,error) {
		 	var o=document.body.clientWidth;
						

	var htm='<div class="errore"><img src="'+img+'" width=425 height=344 alt="">';
	htm+='<br>'+error+'</div>';
	document.write(htm);
		 
		}
		 
function playvideo(url,auto,prev,vid) {

	if (prev) url+='&image='+prev; 

	var FO = {	
		movie:"/flvplayer.swf",
		width:"425",
		height:"331",
		majorversion:"7",
		build:"0",
		bgcolor:"0xc0c0c0",
		flashvars:"file="+url+"&showdigits=true&showfsbutton=true&repeat=false&fsreturnpage="+encodeURIComponent("/"+vid)+"&fullscreenpage=fs%2ephp%3f"+vid+"&logo=VIDEOLOB%2egif" 
		}
		;
		
	if (auto) FO.flashvars+="&autostart=true"; else FO.flashvars+="&autostart=false"; 

		 	
		
	UFO.create(	FO, "player1");
	
	}
	
	
function RemoveComment(idx) {
		 var o = new Object;
		 o.cmd='rcom';
		 o.id = comment[idx].i;
		 o.idx=idx;
		 AJAXService('/ajax.php',o,RemoveCommentOk);
		 }
		 
function RemoveCommentOk(j) {

		 	comment[j.idx].t ='<p align="center"><span style="font-family:verdana; font-size:9pt; color:#000; background-color: #f00; border: #c00 1px solid;">&nbsp;Comment Removed&nbsp;</span></p>';
			comment[j.idx].i=0;
			opencomment(-1);
			opencomment(j.idx);
		 	
		 }
		 
function EmbedThis() {
  var bu = document.getElementById('EmButton');
  if (bu) bu.style.visibility='hidden';
  var o = new Object();
  
  o.cmd='emb';
  o.id=parseInt(videoid);
  AJAXService('/ajax.php',o, function (js) {
    if (!js.emb) return;
    var bu = document.getElementById('EmArea');
    if (bu) {
      bu.style.visibility='visible';
      bu.style.height='16px';
      bu = document.getElementById('EmText');
      bu.value = js.emb;
      bu.focus();
      bu.select();
      }
    }
  )
;}

function Select(id) {
  var v =document.getElementById(id);
  if (v) {
    v.focus();
    v.select();
    }
  }
		 
function opencomment(num) {
	var v,ax,xtra;
	for (ax=0;ax<30;ax++) {
		v=document.getElementById('cmt'+ax);
		if (!v) break;
		
		if (lastcomm==num) {
		   v.style.visibility='hidden';
		   v.style.height='1px';		   
		   } else {
		   if (num==ax) {
		   	  			v.style.visibility='visible';
						v.style.height='100px';
						v.style.overflow='auto';
						if (comment[num].i) xtra='<br><button class="inp" onclick="RemoveComment(' + num + ')">Remove</button>'; else xtra='';
						v.innerHTML=comment[num].t + '<p align="right">'  + comment[num].u + xtra +'</p>';
						} else {
		   	  			v.style.visibility='hidden';
						v.style.overflow='hidden';
						v.style.height='1px';
						v.innerHTML='<img src="T.gif" alt="" width=1 height=1>';
						}
		   }
		
		}
	if (lastcomm==num) lastcomm=-1; else lastcomm=num;
    }
		
function removevideo(id,pg) {
  if (!pg) pg=''; else pg='&url='+encodeURIComponent(pg); 
	if (confirm("Are you sure to remove the video?")) location.href="myshell.php?id="+id+"&act=1"+pg;
	}
		
function Postcomment() {
  var o = new Object;
  var v = document.getElementById('cmid');
  o.videoid = v.value;
  
  v=document.getElementById('cmtit');
  o.title=v.value;
  
  v=document.getElementById('cmtext');
  o.body=v.value;
  
  AJAXService('/addcomm2.php',o, function (json) {
      if (json.ok) {
        var v = document.getElementById('commentbox');
        v.style.height='32px';
        v.style.textAlign='center';
        v.innerHTML = 'Comment added';
        //if (document.URL) top.location.href=document.URL;
        }
    }
    )
    ;
  
  }
		
function Star(ax) {
  ax++;
  var o = new Object;
	o.id=videoid;
	o.rate = ax;
	AJAXService('/rater.php',o, RateDone);
  }
		
function RateDone (json) {
    var v = document.getElementById('stars');
    if (v) {
          v.style.color='#f00';
          v.innerHTML=json.html;
          }
          
    var x = document.getElementById('ratetd');
    if (x) {
					x.style.border='#ccc 1px solid';
					x.style.textAlign='center';
					x.innerHTML=json.html;
					}
    }
		
function rateajax(videoid) {
		 var o = new Object;
		 o.id=videoid;
		 var v = document.getElementById('rater');
		 o.rate = v.value;
		 AJAXService('/rater.php',o, RateDone);
		 }
		
function ShowComment() {
  var v = document.getElementById('pcomment');
  if (v) {
    v.style.height='1px';
    v.style.visibility='hidden';
    }
    
  v = document.getElementById('commentbox');
  if (v) {
    v.style.height='180px';
    v.style.visibility='visible';
    }
  }
		
function editvideo(id) {top.location.href="/edit.php?id="+id; }

function flagvideo(id) {top.location.href="/flag.php?id="+id; }

function sharevideo(id) {top.location.href="/share.php?id="+id; }	
			 			 		 
function playvideofs(url,auto,prev,vid) {

	if (prev) url+='&image='+prev; 

	var FO = {	
		movie:"/flvplayer.swf",
		width:"400",
		height:"300",
		majorversion:"7",
		build:"0",
		bgcolor:"0xc0c0c0",
		flashvars:"file="+url+"&showdigits=true&showfsbutton=true&repeat=false&fsreturnpage="+encodeURIComponent("/"+vid)+"&fullscreenpage="+encodeURIComponent("/"+vid)+"&logo=VIDEOLOB%2egif&link=%2f" +vid
		}
		;
		
	if (auto) FO.flashvars+="&autostart=true"; else FO.flashvars+="&autostart=false"; 

	var w=320;
	var h=240;

	h = document.body.clientHeight-20;
	w = Math.ceil(h * (4/3));
	
	if (w>document.body.clientWidth) {
		w=document.body.clientWidth-20;
		h=Math.ceil(w / (4/3)); 
		}
			
	FO.width=w;
	FO.height=h+16;
	
	UFO.create(	FO, "player1");
	
	}

function prevideo(num) {
	var i = document.getElementById('prev' + num );
	
	}	

	
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function ToHex(v) {
		 var s = v.toString(16);
		 if (v<16) s='0'+s;
		 return s.substr(0,2);		 
		 }

function Escape(st) {
	var string = ''+st+'';
	if (st==null) return '';
	
    return string.replace(/[\x00-\x1F'\\]/g, function (x) {
          if (x == "'" || x == "\\") return "\\" + x;
          return "\\x" + ToHex(String.charCodeAt(x, 0));
        })
  }
    function JSON(o) {
			
			if (o instanceof Array)  return JSONARRAY(o);
			if (o instanceof Object) return JSONOBJECT(o);
			
			return '"'+Escape(o)+'"';
			
			}
	
	function JSONARRAY (o) {
			 var str='[';
			 var le=o.length;
			 var ax;
			 var f;
			 	 for (ax=0;ax<le;ax++) {
				 	 f=0; 
					 if (o[ax] instanceof Array) {f=1; str+=JSONARRAY(o[ax]);}
					 if (f==0) if (o[ax] instanceof Object) {f=1; str+=JSONOBJECT(o[ax]);}
					 if (f==0) str+='"'+Escape(o[ax])+'"';
					 str+=',';					 
				 	 }
					 
			 if (str!='[') str=str.substr(0,str.length-1);
			 return str+']';
			 }
			 
	function JSONOBJECT (o) {
			 var str='{';
			 var f;
			 var i;
			 	 
				 for (i in o) {
				 	 str+='"'+Escape(i)+'":';
					 f=0;
					 if (o[i] instanceof Array) {f=1; str+=JSONARRAY(o[i]);}
					 if (f==0) if (o[i] instanceof Object) {f=1; str+=JSONOBJECT(o[i]);}
					 if (f==0) str+='"'+Escape(o[i])+'"';
					 str+=',';
				 	 }
					 
			 if (str!='{') str=str.substr(0,str.length-1);
			 return str+'}';
			 }
function AJAXService(file,object,callback,mega) {
		 var req='?';
		 var o;
		 var post;
		 var t;
		 
		 if (mega) {
		 	post='';
			for (o in object) {
				t = new Object();
				t[o]=object[o];
				post+=JSON(t)+'\n';
				}
		 	} else post = JSON(object);
			
		 if (file.charAt(0)!='/') file=server+file;
	 
		 try { HTTP.abort(); } catch(e) { ; }
		 HTTP = new getHTTPObject();
		 
		 HTTP.open('POST',file,true);
		 HTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	 	 HTTP.setRequestHeader("Content-length", post.length);	
		 HTTP.onreadystatechange= function () {
								 if (HTTP.readyState == 4) {
  								 	if (HTTP.status!=200) {
	   								   alert('Server status error:\n'+HTTP.statusText);
									   } else {
									   	  try {
  	   								   	   post=eval('(' + HTTP.responseText + ')');
										    } catch(err) { 
											o=document.getElementById('message');
										   if (o) o.innerHTML=HTTP.responseText;
										   
										  	alert('Data Error\n'+HTTP.responseText);
											return;//
											}
									   if (post.info) alert(post.info);
									   if (post.err) {
									   	  alert(post.err);
										  return;s
									   	  }
									   if (callback) callback(post);		   
									   } //200
  								 } //4
											  
		 			} //fun_fun
		 HTTP.send(post);
		 } //ajax
	
function StartPrev(vid,id) {
  var img = document.getElementById('PREV' + id);
  if (!img) return;
  //if (img.flag) return;
  img.src = '/vi/'+vid+'.gif';
  img.style.width='110px';
  img.style.height='80px';
  }	

function StopPrev(vid,id) {
  var img = document.getElementById('PREV' + id);
  if (!img) return;
  //if (!img.flag) return;
  img.src = '/vi/'+vid+'.jpg';
  img.style.width='110px';
  img.style.height='80px';
  
  }
	
function SetPrev(px) {
  var vp = document.getElementById('videoprev');
  var ax;
  var v;
  if (!vp) alert('vp'); else vp.value=px;
  for (ax=1;ax<5;ax++) {
    v=document.getElementById('tblprev' + ax);
    if (v) {
      if (ax == px) v.style.borderColor='#fff'; else v.style.borderColor='#000';
      }
    }
  }
	
var previews;
var lastcomm=-1;
var comment;
 
