// JavaScript Document
function ajax_request()
{
    if (window.XMLHttpRequest) 
	{
        return new window.XMLHttpRequest;
    }
    else 
	{
        try 
		{
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) 
		{
            return null;

        }
    }
}
function getIEVersion()
{
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{
 		var ieversion=new Number(RegExp.$1) 
 		return ieversion;
	}
	else return false;	
}
function gotoUrl(url)
{
	document.location=url;	
}
function setCookie(c_name,c_value)
{
	document.cookie=c_name+"="+c_value+";";
}
function getCookie(c_name)
{
	if (document.cookie.length>0)
  	{
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1)
    	{
    	c_start=c_start + c_name.length+1;
    	c_end=document.cookie.indexOf(";",c_start);
    		if (c_end==-1) c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	}
  	}
	return "";
}
function getVal(id)
{	
	if(document.getElementById(id))	return document.getElementById(id).value;
	else return -1;
}
function getObj(id)
{
		return document.getElementById(id);
}
function checkEmail(mail) 
{
	var email = mail;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) 
	{
		return false;
	}
	else return true;
}
function CheckAll(id) 
{
	var rows = document.getElementsByTagName('input');
	var checkbox;
	for ( var i = 0; i < rows.length; i++ ) 
	{
		checkbox = rows[i];
		if ( checkbox && checkbox.type == 'checkbox' && checkbox.id==id) 
		{
			checkbox.checked = !checkbox.checked;
		}
	}
	return true;
}
function CheckAll2(id) 
{
	var rows = document.getElementsByTagName('input');
	var checkbox;
	for ( var i = 0; i < rows.length; i++ ) 
	{
		checkbox = rows[i];
		if ( checkbox && checkbox.type == 'checkbox' && ((checkbox.id).indexOf(id)>-1)) 
		{
			checkbox.checked = !checkbox.checked;
		}
	}
	return true;
}
function getNameFromId(id,name) 
{
	var rows = document.getElementsByTagName('input');
	var checkbox;
	for ( var i = 0; i < rows.length; i++ ) 
	{
		checkbox = rows[i];
		if ( checkbox && checkbox.type == 'checkbox' && checkbox.id==id) 
		{
			if(checkbox.name==name) return checkbox;
		}
	}
	return false;
}
function isChecked(id) 
{
	var rows = document.getElementsByTagName('input');
	var checkbox;
	for ( var i = 0; i < rows.length; i++ ) 
	{
		checkbox = rows[i];
		if ( checkbox && checkbox.type == 'checkbox' && checkbox.checked) 
		{
			return true;
		}
	}
	return false;
}
function ShowHide(id) 
{
	var rows = document.getElementsByTagName('tr');
	for ( var i = 0; i < rows.length; i++ ) 
	{
		tr = rows[i];
		if ( tr && tr.id==id)  
		{
			if(tr.style.display=='none') tr.style.display='table-row';
			else tr.style.display='none';
		}
	}
	return true;
}
function PopupWindow(url,width,height)
{
	 var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	var myBars = 'directories=no,location=yes,menubar=no,status=no,titlebar=no,toolbar=no'; 
	var myOptions = 'scrollbars=yes,width='+width+',height='+height+',resizeable=yes,left=' + left + ',top=' + top + 'screenX=' + left + ',screenY=' + top; 
	var myFeatures = myBars + ',' + myOptions; 
	var wnd = open(url,'',myFeatures); 
}

function EffectWindow(url)
{
	window.onload = Shadowbox.init;	
}

function PrintWindow(id,width,height)
{
	var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no'; 
	var myOptions = 'scrollbars=yes,width='+width+',height='+height+',resizeable=yes'; 
	var myFeatures = myBars + ',' + myOptions; 
	var wnd = open('','',myFeatures);
	wnd.document.write('<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html;  charset=utf-8" />\n<title>საბეჭდი ვერსია</title>\n</head>\n<body>\n');
	
	wnd.document.write(document.getElementById(id).innerHTML);
	
	wnd.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">\n<tr>\n<td align="right" valign="middle">\n<label>\n<img style="cursor:pointer" src="images/print_32.png"  hspace="5" title="ბეჭდვა"  onclick="window.print();"/>\n</label>\n</td>\n</tr>\n</table>\n</body>\n</html>');
}
function SendToFriendWindow(id,width,height)
{
	var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no'; 
	var myOptions = 'scrollbars=yes,width='+width+',height='+height+',resizeable=yes'; 
	var myFeatures = myBars + ',' + myOptions; 
	var wnd = open('','',myFeatures);	
	wnd.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>გაუგზავნე მეგობარს</title><style type="text/css">body,td,th {font-size: 12px; color: #000000;}</style></head><body><form name="form1" method="post" action="modules/sendtofriend/index.php">  მეგობრის ელ. ფოსტა<br><label><input type="text" name="toemail" id="toemail"></label><br>კომენტარი<br><label><textarea name="comment" id="comment" cols="35" rows="5"></textarea></label><br><br><label><input type="submit" name="button" id="button" value="გაგზავნა"></label><label><input type="reset" name="button2" id="button2" value="ფორმის გასუფთავება"><input type="hidden" name="message" id="message" value=""></label></form></body></html>');
	wnd.document.getElementById("message").value=document.getElementById(id).innerHTML;
}
function show_player(filename)
{
	var width=300;
	var height=220;
	document.write("<embed name='player' type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' width='"+width+"' height='"+height+"' showcontrols='true' autostart='false' src='"+filename+"'></embed>");
}
function show_player2(filename)
{
	var width=540;
	var height=380;
	document.write("<embed name='player' type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' width='"+width+"' height='"+height+"' showcontrols='true' autostart='false' src='"+filename+"'></embed>");
}
function playerWindow(filename)
{
	var width=300;
	var height=220;
	
	var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no'; 
	var myOptions = 'scrollbars=yes,width=819,height=610,resizeable=yes'; 
	var myFeatures = myBars + ',' + myOptions; 
	var wnd = open('','',myFeatures);
	wnd.document.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>ვიდეო რგოლი</title><style type='text/css'><!-- body,td,th {	font-size: 12px;} body { background-color: #000000; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } --></style></head><body><embed name='player' type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' width='800' height='600' showcontrols='true' autostart='true' src='"+filename+"'></embed></body></html>");
}
function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(window.location.href);
}
function FuncGetEventInfo(url,containerId)
{
	var xmlRequest=ajax_request();
	xmlRequest.open('GET',url,true);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlRequest.onreadystatechange=function()
	{
		if (this.readyState == 4 && this.status == 200)
		{
			var obj=getObj(containerId);
			if(xmlRequest.responseText) 
			{
				titleAnimationStart();
				if(obj) obj.innerHTML=xmlRequest.responseText;
			}
			else titleAnimationStop();
		}
	}
	xmlRequest.send();
}
function getEventInfo(url,containerId)
{
	setInterval("FuncGetEventInfo('"+url+"','"+containerId+"')",5*1000);	
}
function updateObjectStatus()
{
	var xmlRequest=ajax_request();
	xmlRequest.open('GET',SITE_URL+'callback.php?cmd=updateObjectStatus',true);
	xmlRequest.send();
}
function MessageBox(w,h,path)
{
	var xmlRequest=ajax_request();
	xmlRequest.open('GET',path,true);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlRequest.onreadystatechange=function()
	{
		if (this.readyState == 4 && this.status == 200)
		{
			REDIPS.dialog.show(w, h, xmlRequest.responseText);return false;	
		}
	}
	xmlRequest.send();
}
function ListBoxClear(id)
{
	var liste = document.getElementById(id);
    var howMany = liste.options.length;         
	liste.options.length = 1;
	liste.selectedIndex = 0;  
} 
function LoadListbox(url,target)
{
	var xmlRequest=ajax_request();
	var optn='';
	xmlRequest.open('GET',url,true);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	
	xmlRequest.onreadystatechange=function()
	{
		if (this.readyState == 4 && this.status == 200)
		{
			var optionList=xmlRequest.responseText.split("\n");
			var regex = /<.*[^>] value='(.*[^'])'.*>(.*)<.*>/i;
			ListBoxClear(target);
			for(i=0;i<optionList.length;i++)
			{
				try
				{
					var matches = regex.exec(optionList[i]);
					
					optn = document.createElement('option');
					optn.text = matches[2];
					optn.value= parseInt(matches[1]);
					if(optionList[i].indexOf('selected')!=-1) optn.selected=true;
					getObj(target).options.add(optn);
				}
				catch(e){}
			}
		}
	}
	xmlRequest.send();
}
function getSize(fileid)
{
	var myFSO = new ActiveXObject("Scripting.FileSystemObject");
	var filepath = document.getElementById(fileid).value;
	var thefile = myFSO.getFile(filepath);
	var size = thefile.size;
	return size
}
var titleAnimationStatus=false;
var titleAnimationInterval;
function titleAnimation()
{
	if(document.title=="Videoclass.ge") document.title="**************************";
	else document.title="Videoclass.ge";
}
function titleAnimationStart()
{
	if(!titleAnimationStatus) 
	{
		titleAnimationInterval=setInterval("titleAnimation();",400);
		//PlaySound();
	}
	titleAnimationStatus=true;
}
function titleAnimationStop()
{
	titleAnimationStatus=false;
	clearInterval(titleAnimationInterval);
	document.title="Videoclass.ge";
}
function PlaySound() 
{ 
	var _sndObj="soundMSG";
	var sndFile="images/msg.wav";
	var i, method = "", sndObj = eval(_sndObj);
	
	if (sndObj != null) 
	{
		if (navigator.appName == 'Netscape') method = "play";
		else 
		{
			if (window.MM_WMP == null) 
			{
				window.MM_WMP = false;
				for(i in sndObj) if (i == "ActiveMovie") 
				{
					window.MM_WMP = true; break;
				}
			}
			if (window.MM_WMP) method = "play";
			else if (sndObj.FileName) method = "run";
		} 
	}
	if (method) eval(_sndObj+"."+method+"()");
	else window.location = sndFile;
}
function addtoFavorites(t,obj_id)
{
	var xmlRequest=ajax_request();
	xmlRequest.open('GET',SITE_URL+"callback.php?cmd=setfavorites&id="+obj_id,true);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlRequest.send();
	t.style.display="none";
	document.getElementById("fav_"+obj_id).style.display="block";
}
function removeFavorites(obj_id)
{
	var xmlRequest=ajax_request();
	xmlRequest.open('GET',SITE_URL+"callback.php?cmd=removefavorites&id="+obj_id,true);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlRequest.send();
	document.getElementById("fav_"+obj_id).style.display="none";
}
function addToFavorites2() 
{
	
	var title=document.title;
	var url=document.location.href;
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if(is_chrome)
	{
				var a=window,b=document,c=encodeURIComponent,d=a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&title="+c(b.title),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300);
	}
	else if (window.sidebar) 
	{
			window.sidebar.addPanel(title, url,"");
			return false;
	} 
	else if( window.external ) 
	{
			window.external.AddFavorite( url, title); 
			return false;
	}
	else if(window.opera && window.print) 
	{
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
			return false;
	}
}
function setHomePage(oLink)
{
	oLink.style.behavior='url(#default#homepage)';
	oLink.setHomePage(document.location.href);
	return false;
}
var popupInterval;
function popupMenu()
{
	var menu=document.getElementById("popupMenuDiv");
	if(menu.style.display=="none") menu.style.display="block";
	else menu.style.display="none";	
}
function popupOpen()
{
	popupInterval=setTimeout(popupMenu,100);
}
function popupClearinterval()
{
	clearInterval(popupInterval);
}
var popupInterval2;
function popupMenu2()
{
	var menu=document.getElementById("popupMenuDiv2");
	if(menu.style.display=="none") menu.style.display="block";
	else menu.style.display="none";	
}
function popupOpen2()
{
	popupInterval2=setTimeout(popupMenu2,100);
}
function popupClearinterval2()
{
	clearInterval(popupInterval2);
}
function getOffset(obj) 
{
    var pos = {'x':0,'y':0};
    if(obj.offsetParent) {
        while(1) {
          pos.x += obj.offsetLeft;
          pos.y += obj.offsetTop;
          if(!obj.offsetParent) {
            break;
          }
          obj = obj.offsetParent;
        }
    } else if(obj.x) {
        pos.x += obj.x;
        pos.y += obj.y;
    }
    return pos;
}
function WIShow(obj,full_transparent)
{
	var xmlRequest=ajax_request();
	var o=getObj("transText");
	var t=getObj("transText_cont");
	var pos=getOffset(obj);
	t.innerHTML=obj.alt;
	if(full_transparent) o.className="transText_free";
	else o.className="transText";
	scrollL=obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.scrollLeft;
	o.style.left=(pos.x-scrollL)+"px";
	o.style.top=pos.y+"px";
	o.style.display="block";
	o.onclick=function()
	{
		xmlRequest.open('GET',SITE_URL+"callback.php?cmd=fixwebsitevisit&id="+obj.id,true);
		xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
		xmlRequest.send();
		window.open(obj.title);	
	}
}
function WIHide(h)
{
	var o=getObj("transText");
	o.style.display="none";
}
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function resizeFB()
{
	var FBbox=document.getElementById("FBbox");
	var FBbg=document.getElementById("FBbg");
	var ht=120;
	var wd=300;
	var p='px';
	var tp=((pageHeight()-ht)/2)-12;
	var lt=((pageWidth()-wd)/2)-12;
	
	FBbox.style.top=(tp<0?0:tp)+p;
	FBbox.style.left=(lt<0?0:lt)+p;
	FBbg.style.left="0px";
	FBbg.style.top="0px";
	
	FBbg.style.width=posTop()+pageWidth()+p;
	FBbg.style.height=posLeft()+pageHeight()+p;		
}
function _showFB()
{
	var xmlRequest=ajax_request();
	xmlRequest.open('GET',SITE_URL+"?stop_timer",true);
	xmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlRequest.send();
	var FBbox=document.getElementById("FBbox");
	var FBbg=document.getElementById("FBbg");
	var ht=120;
	var wd=300;
	var p='px';
	var tp=((pageHeight()-ht)/2)-12;
	var lt=((pageWidth()-wd)/2)-12;
	
	FBbox.style.top=(tp<0?0:tp)+p;
	FBbox.style.left=(lt<0?0:lt)+p;
	FBbg.style.left="0px";
	FBbg.style.top="0px";
	
	FBbg.style.width=posTop()+pageWidth()+p;
	FBbg.style.height=posLeft()+pageHeight()+p;
	FBbg.style.display="block";
	FBbox.style.display="block";
	window.onresize=resizeFB;
}
function showFB(timer)
{
	var timer2=parseInt(30-timer);
	if(timer>=0 && timer2!=-1) setTimeout("_showFB();",timer2*1000);
}
function closeFB()
{
	var FBbox=document.getElementById("FBbox");	
	var FBbg=document.getElementById("FBbg");
	FBbox.style.display="none";
	FBbg.style.display="none";
}
function showAFAT(caption,text,pos,show)
{
	if(!show) return;
	var AFAT=document.getElementById("AFAT");
	var AFAT_content=document.getElementById("AFAT_content");
	var AFAT_title=document.getElementById("AFAT_title");
	var AFAT_titleAD=document.getElementById("AFAT_titleAD");
	var AFAT_caption=document.getElementById("AFAT_caption");
	var AFAT_ID=document.getElementById(text);
	
	AFAT_title.style.display="none";
	AFAT_titleAD.style.display="table";
	AFAT_caption.innerHTML=caption;
	
	AFAT_content.innerHTML=AFAT_ID.innerHTML;	
	AFAT.style.display="block";
}
function hideAFAT()
{
	var AFAT=document.getElementById("AFAT");
	var AFAT_content=document.getElementById("AFAT_content");
	var AFAT_title=document.getElementById("AFAT_title");
	var AFAT_titleAD=document.getElementById("AFAT_titleAD");
	var AFAT_caption=document.getElementById("AFAT_caption");
	
	AFAT_title.style.display="table";
	AFAT_titleAD.style.display="none";
	AFAT_caption.innerHTML="";
	AFAT_content.innerHTML="";	
	AFAT.style.display="none";
}
