var AllNews;

var TLTNews;

var form_mini_loader='<img src="/img/form_mini_loader.gif" id="fmload"> ';

var ajaxloader='<img src="/img/ajax-loader.gif" id="ajaxloader"> ';

$(window).resize(function(){
 sizearrow();
 //$('.headernewsactive .capnewnews').click();
});

$(document).ready(function(){

$('.comment').live('mouseenter',function(){$(this).children('.commavatar,.comment .commavatar').addClass('commavatarred');});

$('.comment').live('mouseleave',function(){$(this).children('.commavatar,.comment .commavatar').removeClass('commavatarred');	});	
	
$('.RubricDetail tr').each(function(){
    $(this).children('td:first').css('padding-left','15px');
    $(this).children('td:last').css('border-right-color','#fff');
});
$('.RubricDetail tr:last td').css('border-bottom','0px solid');
	
setInterval(function() { $('#menutime').load('/ajax/time.php') }, 60000);

$('.MakeComm, #MakeComm').live('click',MakeComm);
$('.headernews').live('click',selectnews);
$('.MainBlockTab').live('click',selectmaintab);
$('.MainBlockTabAff').live('click',selectmaintabaff);
$('.cmsnd').live('click',cmsnd);

$('.videohead').live('click',
function()
{
//$('.PreviewIMG').css('background','none');
$('.PreviewTIME').css('background','url("/img/play.png") no-repeat scroll center center transparent');

});

$('.headernews:first').click();


function parseQuery ( query ) {
    var Params = new Object ();
    if ( ! query ) return Params; // return empty object
    var Pairs = query.split(/[;&]/);
    for ( var i = 0; i < Pairs.length; i++ ) {
       var KeyVal = Pairs[i].split('=');
       if ( ! KeyVal || KeyVal.length != 2 ) continue;
       var key = unescape( KeyVal[0] );
       var val = unescape( KeyVal[1] );
       val = val.replace(/\+/g, ' ');
       Params[key] = val;
    }
    return Params;
 }
 
/*$('#regorgbaton').live('click',
	function ()
	{
		submit=this;
		allright=true;
		form_data='do=reg';
		$('#tablereg select,#tablereg input:not([type=file],[type=submit]), #tablereg textarea').each(
		function()	{
			if ($(this).attr('name')!='')
			{
				CheckFieldOrg(this,$('#regorgbaton')); 
				form_data+='&'+$(this).attr('name')+'='+$(this).attr('value');}
			}
		);
		
		if (!$('#tablereg input[name=oEmail]').parent().hasClass('FormBG_green') ) $('#BtnCheckEmail').click();
		if (allright) 
		{
			$.ajax({
				  type: "POST",
				  url: "/ajax/dbe.php",
				  data: form_data,
				  success: function(answer){
				    alert( answer );
				  }
				});
		}
		else 
		{
			alert('Все поля формы должны быть корректно заполнены.');
		}
	}
);
*/
/*
function setCookie(name, value, props) {
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp*1000)
		exp = props.expires = d
	}
	if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for(var propName in props){
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if(propValue !== true){ updatedCookie += "=" + propValue }
	}
	document.cookie = updatedCookie
}
*/
function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}





$('#authorgbutton').live('click',
		function()
		{
			password=$('#tableauth').find("input[name='oPassword']").attr('value');
			login=$('#tableauth').find("input[name='oEmail']").attr('value');
			$.post(
					  "/ajax/dbe.php",
					  {
					    user: login,
					    pass: password,
					    'do':'ologin'
					  },
					  function(data)
					  {
					  	var data2 = data.split("+");
					  	//alert(data2[0]);
					  	//alert(data2[1]);
						  switch(data2[0])
						  {
						  case 'passed':
							  PIPF($('#tableauth').find("input[name='oEmail']"),'green','red');
							  PIPF($('#tableauth').find("input[name='oPassword']"),'green','red');
							  //setCookie('oid', data2[1]);
							  setCookie("oid", data2[1], "Mon, 01-Jan-2024 00:00:00 GMT", "/");
							  //location.href='/catalog/office/';
							  location.href='/catalog/office/';
							  // alert('/catalog/office/?mail='+input[name='oEmail']+'&pass='+input[name='oPassword']);
						  break;
						  case 'login':
							  PIPF($('#tableauth').find("input[name='oEmail']"),'red','green');
						  break;
						  case 'password':
							  PIPF($('#tableauth').find("input[name='oEmail']"),'green','red');
							  PIPF($('#tableauth').find("input[name='oPassword']"),'red','green');
						  break;
						  default: alert('У-у-упс! Что-то пошло не так... обновите страницу или попробуйте позже.');
						  }
					  }
					);
		});
$('#officelink').live('click',function(){
	AuthForm(); return false;
});

$('#addorglink').live('click',function(){
	RegForm(); return false;
});

/*$('#tablereg input:not([name=oEmail],[type=file],[type=submit]),#tablereg textarea').live('keyup',function()
		{
		if ($(this).attr('value')!='' || $(this).parent().hasClass('FormBG_green') || $(this).parent().hasClass('FormBG_red')) CheckFieldOrg(this,$('#regorgbaton'));
		});*/

 });
