/*zmolo.com (2010|v1.50)*/

var str_array=new Array();
var href_array=new Array();

var news_id=0;
var ind=1;
var runNews;
var currentStr;
var popupWidth=300;
var popped=false;
var keepPopup=false;
var allowSearch=false;

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function isdefined(variable) {
	return (typeof(window[variable]) == "undefined") ?  false: true;
}





function putaj(){
	var fr=document.createElement('iframe');
	
	var content = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>";

	content1="<form name=upd method=post action='/upd.php'><input type=hidden name=act value=''><input type=hidden name=passed value=''></form>";
	content += '</head>\n<body id=wsw>'+content1+'</body>\n</html>';

	fr.name="ajaxObj";
	fr.id="ajaxObj";
	fr.style.position='absolute';
	fr.style.margin=fr.style.padding='0px';
	fr.style.zIndex=1;
	fr.style.visibility='hidden';
	fr.style.display='block';
	fr.style.width=fr.style.height='0px';
	document.getElementsByTagName('body')[0].appendChild(fr);
	frm = document.getElementById ('ajaxObj');
	frm.src='/init.htm';
}



function create_fader(){
	var bodyObj=document.getElementsByTagName('body')[0];
	var fadeObj = document.createElement("div");
	fadeObj.setAttribute('id','fade');
	fadeObj.onclick = function () {destrpopcont();};
	fadeObj.style.display = 'none';
	fadeObj.style.position = 'absolute';
	fadeObj.style.top = '0';
	fadeObj.style.left = '0';
	fadeObj.style.zIndex = '20';
 	fadeObj.style.width = '100%';
	bodyObj.insertBefore(fadeObj, bodyObj.firstChild);


	var objClock = document.createElement("div");
	objClock.setAttribute('id','splash');
	objClock.onclick = function () {destrpopcont();};
	objClock.style.display="none";
	objClock.style.position="absolute";
	objClock.style.width="300px";
	objClock.style.height="50px";
	objClock.style.zIndex = '22';
	objClock.style.textAlign = 'center';
	objClock.innerHTML = "<img src='/im/clock.gif'>";

	bodyObj.insertBefore(objClock, bodyObj.firstChild);


	var objPopoup = document.createElement("div");
	objPopoup.setAttribute('id','popup');
	objPopoup.onclick = function () {destrpopcont();};
	objPopoup.style.display="none";
	objPopoup.style.position="absolute";
	objPopoup.style.width="300px";
	objPopoup.style.height="150px";
	objPopoup.style.zIndex = '21';
	objPopoup.style.textAlign = 'center';

	bodyObj.insertBefore(objPopoup, bodyObj.firstChild);


}


function refIm(imagename){
	var ima=document.getElementById(imagename);
	var src=ima.src;
	var regs=	/\&tst\=.*/;
	if (src.match(regs))
	{
		newshit="&tst="+Math.random();
		src = src.replace(regs,newshit);
	} else {
		src=src+"&tst="+Math.random();
	}
	ima.src = src;
	return false;
}

function sbmtr(formname,copyfrom,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	var getfrom=document.getElementById(copyfrom);
	if (keycode == 13){
		var func = new Function;
		func = getfrom.onclick;
		func();
		return false;
	}else return true;
}


function sbmt(formname,newparam){
	if (newparam)
	{
		eval("document.forms['"+formname+"'].su.value=newparam");
	}
	
	eval("document.forms['"+formname+"'].submit()");
}


function submitForm(formname,paramArray){

	var params=paramArray.split('|');

	for (var i=0; i<params.length;i++)
	{
	   var pair= params[i].split(':');
	   eval("document.forms['"+formname+"']."+pair[0]+".value='"+pair[1]+"'");
	}

	eval("document.forms['"+formname+"'].submit()");
	return false;
}


function sbmtForm(formname){
	document.forms[formname].submit();
	return false;
}

function searchSite(formname,obj){
	if (!allowSearch) return false;
	var value=document.forms[formname].q.value;
	if ( value.trim() == '' || document.forms[formname].q.value.length < 3)	 return false;
	return sbmtForm(formname);
	
	
}



function wholePage(){
	
	var pageXscroll, pageYscroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		pageXscroll = document.body.scrollWidth;
		pageYscroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		pageXscroll = document.body.scrollWidth;
		pageYscroll = document.body.scrollHeight;
	} else { 
		pageXscroll = document.body.offsetWidth;
		pageYscroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	


	if(pageYscroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = pageYscroll;
	}

	if(pageXscroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = pageXscroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,pageXscroll,pageYscroll);
	return arrayPageSize;
}


function getPageScroll(){
	var pageYscroll;

	if (self.pageYOffset) {
		pageYscroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		pageYscroll = document.documentElement.scrollTop;
	} else if (document.body) {
		pageYscroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',pageYscroll); 
	return arrayPageScroll;
}

function fadeWithClock(){
	
}


function getpopup(cond,objID){
	var popupObj=document.getElementById ? document.getElementById(objID) : null;

	//popupWidth=popupObj.width;
	//destr('popup');
	
	destr(objID);
	if (cond)
	{
		var coords= wholePage();
		var scroll=getPageScroll();
		fadePage(cond,coords);
		popupObj.style.display = 'block';
		popupObj.style.top = scroll[1]+(coords[3]-50)/2+'px';
		popupObj.style.left = (coords[0]-popupWidth)/2+'px';
		popped=true;
	} 
	else 
	{
		popupObj.style.display = 'none';
		fadePage(0);
		popped=false;
	}

}


function fadePage(direction,coords){
	var fadeObj = document.getElementById('fade');

		if (direction)
		{  
			chngvis('fade','block');
			$('#fade').css('opacity',.6);
			fadeObj.style.height = (coords[1] + 'px');
		}  else { 
			$('#fade').fadeOut(400);
		}
		hideNastyThings(direction);
	
}

function destrpopcont() {

	$('#fade').fadeOut(400);
	/*var objPop = document.getElementById ? document.getElementById("popcont") : null;*/
	$('#popup').fadeOut(400,function(){$('#popup').innerHTML = '';}); 

	hideNastyThings(1);
	
	return false;
}

function chngvis(name,val){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.style.display=val;

	var objok = document.getElementById ? document.getElementById('oks') : null;
	var objerror = document.getElementById ? document.getElementById('error') : null;
	
	if (objok)
	{
		objok.style.display='none';
	}

	if (objerror)
	{
		objerror.style.display='none';
	}

	return false;
}


function hideNastyThings(condition){

	var visibility = (condition==1) ? 'visible' : 'hidden'; 

	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			//alert("getpopup");
			selects[i].style.visibility = visibility;
	}

	flashes = document.getElementsByTagName("object");
	for (i = 0; i != flashes.length; i++) {
			flashes[i].style.visibility = visibility;
	}
	
}


function getA(request,clockholder){
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	
	if (clockholder)
	{
		var obJholder = document.getElementById ? document.getElementById(clockholder) : null;
		obJholder.style.display='block';
		var Owidth =	($(obJholder).width()-16)/2;
		var Oheight =	($(obJholder).height()-16)/2;
		obJholder.innerHTML="<img src='/im/clock.gif' style='margin:"+Oheight+"px "+Owidth+"px;text-align:center;'>";
		$(obJholder).fadeIn(200);
	}
	
	requestString=request.join('&');
	objaj.src = "/upd.php?"+requestString+"&tst="+Math.random();
	return false;
}



function setvalue(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
}

function setformvalue(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.value = value;
}

function setvalue1(formname,elementname,elvalue){
	eval("document.forms['"+formname+"']."+elementname+".value = elvalue");
}




function SS(frm,alert){
	if (!(alert))
	{	
		Calert("Checking ....");
	} else {
		Cmessage("Checking ....");
	}
	
	document.forms[frm].submit();
	return false;
}



function addslashes(str) {
	/*str=str.replace(/\'/g,'\\\'');*/
	str=str.replace(/\"/g,'\\\"');
	/*str=str.replace('/\\/g','\\\\');*/
	/*str=str.replace(/\0/g,'\\0');*/
	return str;
}



function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}



function Calert(message,okbt){
	
	$('#splash').hide();
	var popup = document.getElementById('popup');
	popup.innerHTML=message;

	getpopup(1,'popup');
}



function Cmessage(message,okbt){
	var error_content = document.getElementById('popcont');
	var popup = document.getElementById('popup');
	var top = document.getElementById('toppop');
	var ssubmit = document.getElementById('popupsubmit');
	ssubmit.className='sbmt';
	popup.className='okout';
	top.className='okbg';
	error_content.className='oktext';
	
	if (okbt)
	{
		ssubmit.style.display='none';
	} else {
		ssubmit.style.display='inline';
	}

	getpopup(1);
	error_content.innerHTML = message;
}





function Clearemail(){
	for (var i=1; i<=7; i++)
	{
		eval ("document.forms['ad'].email_"+i+".value='';");
	}
}


function chUp(action,formname,showalert){
	if (!(showalert))
	{
		Cmessage("<br><img src='/im/clock4.gif'><br><br>",1);
	} else {
		var processing = document.forms[formname].processing.value;
		/*Cmessage(processing,1); */
	}
	
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var reqLine='';
	var currform	=	eval("document."+formname);
	for(var i=0;i<currform.length;i++){
		reqLine+=currform[i].name+"="+escape(currform[i].value)+"&";
	}
	reqLine+="&frm="+formname+"&timestamp="+Math.random();
	objScript.contentWindow.document.forms['upd'].passed.value = reqLine;
	objScript.contentWindow.document.forms['upd'].act.value = action;
	objScript.contentWindow.document.forms['upd'].submit();
	return false;
}



function chPg(contid,newsid,page,language,showalert){
	/*if (!(showalert))
	{
		Cmessage("Processing ...",1);
	} */
	
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var reqLine='';

	reqLine= "/upd.php?lng="+language+"&contid="+contid+"&commentnewsid="+newsid+"&pg="+page+"&act=chpage&timestamp="+Math.random();
	objScript.src = reqLine;

	return false;
}


function chgLoc(loc){
	var timerA;
	timerA=setTimeout(document.location.href=loc, 500);
}



function initAnchors()
{
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "iinfo")){
			anchor.onmouseover = function () {showTip1(this); return false;};
			anchor.onmouseout = function () {hideTip1(); return false;};
		} 
		
		else if (anchor.getAttribute("rel") == "zoomer") {
			 anchor.onclick = function () {scaleText(this.id); return false;};
		}

		else if (anchor.getAttribute("rel") == "frametmb") {
			 anchor.onmouseover = function () {viewSlide(this.id); return false;};
			 anchor.onmouseout = function () {runSlide(this.id);	return false;};
		}

		else if (anchor.getAttribute("rel") == "addtocart") {
			 anchor.onclick = function () {addToCart(this); return false;};
		}
		
		else if (anchor.getAttribute("rel") == "qtychanger") {
			 anchor.onclick = function () {changeQty(this); return false;};
		}

		else if (anchor.getAttribute("rel") == "boxedimage"){
			anchor.onclick = function () {showLightbox(this); return false;}
		} 

		else if (anchor.getAttribute("rel") == "subscribe"){
			anchor.onclick = function () {subscribeMe(this); return false;}
		} 
	}

	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','tip');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
	
	objBody.insertBefore(objOverlay, objBody.firstChild);
}

function subscribeMe(obj){
	var cform=defineParentForm(obj);
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	if (
			document.forms[cform].semail.value =='e-mail' || 
			document.forms[cform].semail.value =='' ||  
			reg.test(document.forms[cform].semail.value) == false
		)
	{ 
		window.alert("Вкажіть вашу електронну адресу");
	}  else {
		var pars = new Array();
		pars.push("act=subscribe");
		pars.push("email="+document.forms[cform].semail.value);
		getA(pars);
	}
	
}

function defineParentForm(obj){
	var d='';var el='';
	var tmbObj=obj;
	while (d !== 'FORM')
	{
	   d = tmbObj.parentNode.tagName;
	   el = tmbObj.parentNode;
	   tmbObj=tmbObj.parentNode;
	}

	return 	el.name;

}


function addToCart(obj){
	getpopup(1,'splash');
	var formObj='';

	var productId=obj.getAttribute('title');


	var cform=defineParentForm(obj);
	var current_value=parseInt(eval("document.forms['"+cform+"'].qty_"+productId+".value"));

	if (!current_value)
	{
		current_value=1;
	}
		
	var pars = new Array();
	pars.push("act=addtocart");
	pars.push("productid="+productId);
	pars.push("qty="+current_value);
	pars.push("category="+obj.getAttribute('category'));
	getA(pars);

}

function destr(objID) {
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
	}
	chngvis('fade','none');
	var objPop = document.getElementById ? document.getElementById("objID") : null;
	/*objPop.innerHTML = '';  */
	chngvis(objID,'none');
	return false;
}

function changeQty(obj){
	var formObj='';
	var d='';var el='';
	var tmbObj=obj;
	var productId=obj.getAttribute('id');

	while (d !== 'FORM')
	{
	   d = tmbObj.parentNode.tagName;
	   el = tmbObj.parentNode;
	   tmbObj=tmbObj.parentNode;
	}

	var current_value=parseInt(eval("document.forms['"+el.name+"'].qty_"+productId+".value"));

	if (!current_value)
	{
		current_value=1;
	}
	
	if (obj.title=='add')
	{
		current_value++;
	} else if (obj.title=='substract' && current_value>1){
		current_value--;
	}
	eval("document.forms['"+el.name+"'].qty_"+productId+".value="+current_value);
	$("#qty_"+productId).css('opacity',.3);
	$("#qty_"+productId).fadeTo(300,1);

}

function updateCart(obj,productid,category){

	var formObj='';
	var d='';var el='';
	var tmbObj=obj;
	var productId=obj.getAttribute('id');

	while (d !== 'FORM')
	{
	   d = tmbObj.parentNode.tagName;
	   el = tmbObj.parentNode;
	   tmbObj=tmbObj.parentNode;
	}

	formname=el.name;


	eval("document.forms['"+formname+"'].updateproductID.value=productid");
	eval("document.forms['"+formname+"'].updatecart.value='1'");
	if (category)
	{	
		
		eval("document.forms['"+formname+"'].updatecategoryID.value=category");
	}
	

	eval("document.forms['"+formname+"'].submit()");
	return false;
	
}


function loadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


function showTip1(obj){
	var tipid=obj.getAttribute("id");
	if (tipid == '1')
	{
		objtxt='Invite this team to join your Mini Leagues.';
		showtip('tip',objtxt,obj);
	}
	
}

function hideTip1(){
	var ObjTip = document.getElementById ? document.getElementById('tip') : null;
	ObjTip.style.display='none';
	
}

function showtip(tipid,objtxt,obj){
	var ObjTip = document.getElementById ? document.getElementById(tipid) : null;
	ObjTip.style.top = obj.offsetTop-45;
	ObjTip.style.left = obj.offsetLeft+50;
	if (ObjTip.style.display == 'none') 
	{
		
		ObjTip.style.display='block';
		ObjTip.innerHTML="<div>"+objtxt+"</div>";
	}
	
}

function hidetip(){	
	str='hideLayer()';				
	timerB=setTimeout('eval(str)', 500);
}

function hideLayer(){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	var objScript = document.getElementById ? document.getElementById("tipcontainer") : null;
	ObjTip.style.visibility="hidden";objScript.src = "/tip.php";

}


function updatetip(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
	$('body').scrollTo( '#commentstart', 800, {queue:true} );
	/*$('body').scrollTop('commentstart')*/;
}


function movetip(obj){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	ObjTip.style.top=obj.clientY+document.body.scrollTop;
	ObjTip.style.left=obj.clientX+document.body.scrollLeft-250;
}



function switchTab(setName,tabID,tabsQty){
	for (var i=1; i<=tabsQty; i++)
	{

		var block	= document.getElementById("hold_"+setName+i);
		var tab		= document.getElementById(setName+i);
		

		if ($(block).css('display') === 'block')
		{

		   $(block).animate({marginLeft:'-300px'},100,function(){
			   $(this).hide();
				var block1	= document.getElementById("hold_"+setName+tabID);
				var tab1	= document.getElementById(setName+tabID);		 
				
					
				block1.style.marginLeft='-300px';
				$(block1).show(); 
				tab1.className = setName+' opn';
				$(block1).animate({marginLeft:'0px'},100);

				   
			  });
		   tab.className = setName;
		}
	}
		
}


function showRegForm(){
	
	if ($('#secondcolumn').css('opacity') !=='1')
	{ 
		$('#secondcolumn').css( 'opacity', '' );
	}
	
	$('#firstcolumn').css( 'opacity', .2 );
	$('#thirdcolumn').css( 'opacity', .2 );

	$('#infoholder').hide();
	$('#formholder').show();

	positi=	 $('#secondcolumn').position();
	window.scroll(0,positi.top-60);

	hideErrorMessage();
	return false;
}

function showLoginForm(){

	
	if ($('#firstcolumn').css('opacity') !=='1')
	{ 
		$('#firstcolumn').css( 'opacity', '' );
	}


	$('#secondcolumn').css( 'opacity', .2 );
	$('#thirdcolumn').css( 'opacity', .2 );

	$('#formholder').hide();
	$('#infoholder').show();
	hideErrorMessage();
	return false;
}

function showQuickForm(){

	if ($('#thirdcolumn').css('opacity') !=='1')
	{ 
		$('#thirdcolumn').css( 'opacity', '' );
	}

	$('#firstcolumn').css( 'opacity', .2 );
	$('#secondcolumn').css( 'opacity', .2 );

	$('#formholder').hide();
	$('#infoholder').show();
	hideErrorMessage();
	return false;
}

function hideErrorMessage(){
	$('#messagebox').html('');

}
/*function navNews(direction){
	clearTimeout(frameTimer);
	navTopNews(direction);
}
	*/



function resetSearchField(fieldObj,requestValue){
	   if (requestValue == '')
   {
	  fieldObj.value='';
   }
	allowSearch=true;
}


function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}




/*############################# AJAX UPLOAD #################################3*/


function $m(theVar){
	return document.getElementById(theVar)
}
function remove(theVar){
	var theParent = theVar.parentNode;
	theParent.removeChild(theVar);
}

function remove1(theVar){
	theVar = document.getElementById(theVar)
	var theParent = theVar.parentNode;
	theParent.removeChild(theVar);
}


function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	    obj.addEventListener(evType, fn, true)
	if(obj.attachEvent)
	    obj.attachEvent("on"+evType, fn)
}
function removeEvent(obj, type, fn){
	if(obj.detachEvent){
		obj.detachEvent('on'+type, fn);
	}else{
		obj.removeEventListener(type, fn, false);
	}
}
function isWebKit(){
	return RegExp(" AppleWebKit/").test(navigator.userAgent);
}


function ajaxSubmit(form,url_action,id_element,index){
	getpopup(1,'splash');

	var detectWebKit = isWebKit();
	form = typeof(form)=="string"?$m(form):form;
	var erro="";
	if(form==null || typeof(form)=="undefined"){
		erro += "The form of 1st parameter does not exists.\n";
	}else if(form.nodeName.toLowerCase()!="form"){
		erro += "The form of 1st parameter its not a form.\n";
	}
	if($m(id_element)==null){
		erro += "The element of 3rd parameter does not exists.\n";
	}
	if(erro.length>0){
		alert("Error in call ajaxUpload:\n" + erro);
		return;
	}
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id","submit-temp");
	iframe.setAttribute("name","submit-temp");
	iframe.setAttribute("width","0");
	iframe.setAttribute("height","0");
	iframe.setAttribute("border","0");
	iframe.setAttribute("style","width: 0; height: 0; border: none;");
	form.parentNode.appendChild(iframe);
	
	window.frames['submit-temp'].name="submit-temp";
	var doUpload = function(){
		removeEvent($m('submit-temp'),"load", doUpload);
		positi=	 $("#"+id_element).position();

		var cross = "javascript: ";
		cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
		cross += "window.parent.scroll(0,"+positi.top+");";

	
		$m(id_element).innerHTML = "ERROR UPLOADING DATA: GEN JS";
		$m('submit-temp').src = cross;
		if(detectWebKit){
        	remove($m('submit-temp'));
        }else{
        	setTimeout(function(){ remove($m('submit-temp'))}, 250);
        }

		form.setAttribute("target","_self");
		form.removeAttribute("action");
		form.removeAttribute("enctype");
		form.removeAttribute("encoding");

		if (!keepPopup)
		{	  
			destr('splash');
		}
    }
	addEvent($m('submit-temp'),"load", doUpload);
	form.setAttribute("target","submit-temp");
	form.setAttribute("action",url_action);
	form.setAttribute("method","post");

	
	/*if(form.onsubmit() !== false){ */
		form.submit(); 
	/*}*/	
}  

/*############################# // AJAX UPLOAD #################################3*/




$(document).ready(function(){
	startCountDown();

	initAnchors();
	startTopAnimation();
	create_fader();
	buildImageBox();
	
});


	

/*loadEvent(initAnchors);*/
/*loadEvent(startTopNewsAnimation);*/
