// JavaScript Document
function getrandom(min_random, max_random)
{
	max_random++;

	var range = max_random - min_random;
	var n = Math.floor(Math.random()*range) + min_random;

	return n;
}


function ltrim( source )
{
	var index = 0;
	while( source.charAt(index) == " " ) index++;
	return source.substr(index);
}

function rtrim( source )
{
	var index = source.length - 1;
	while( source.charAt(index) == " " ) index--;
	return source.substring(0, index + 1);
}

function trim( source )
{
	return ltrim(rtrim(source));
}

function ZoomSmallImage(image_id)
{
	//document.getElementById('big_image').src = cfgRootPath + 'templates/' + cfgTemplateName + '/images/loading.gif';
	document.getElementById('big_image').src = cfgRootPath + 'templates/' + cfgTemplateName + '/images/1x1.gif';
	document.getElementById('big_image').src = cfgRootPath + 'includes/showimage.php?type=products&id=' + document.getElementById('small_image_' + image_id).value + '&w=316&h=316&wm=0';
}

function ZoomImage( img_type, img_file, width, height, description )
{
	var img_src;
	img_src = cfgRootPath + 'includes/showimage.php?type=' + img_type + '&id=' + img_file; // + '&w=' + width + '&h=' + height;

	nw = window.open('', 'ZoomImage', 'toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0,width=' + (width + 20) + ',height=' + (height + 50) + ',top='+eval(screen.height/2-(height+50)/2)+',left='+eval(screen.width/2-(width+20)/2));
	nw.focus();
	nw.document.write('<html>');
	nw.document.write('<head>');
	nw.document.write('<title>21plus.co.il</title>');
	nw.document.write('<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">');
	nw.document.write('</head>');
	nw.document.write('<body style="margin:0px 0px 0px 0px; padding:0px 0px 0px 0px;">');
	nw.document.write('<style type="text/css"> ');
	nw.document.write('body { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background-color: #ffffff; } ');
	nw.document.write('body, div, td { font-family: "Lucida Grande", "Trebuchet MS", "Bitstream Vera Sans", Verdana, Helvetica, sans-serif; font-size: 15px; color: #000000; font-weight: bold; } ');
	nw.document.write('a { font-size: 13px; color: #0055CC; font-weight: normal; text-decoration:underline; } ');
	nw.document.write('a:hover { font-size: 13px; color: #CC0000; font-weight: normal; text-decoration:underline; } ');
	nw.document.write('</style>');
	nw.document.write('<br />');
	nw.document.write('<div align="center">');
	nw.document.write('<img src="' + img_src + '" border="0" onClick="window.close();" alt="Закрыть окно" title="Закрыть окно" style="cursor:pointer;" onload="window.stop();">');
	nw.document.write('<br />');
	nw.document.write('<a href="" onClick="window.close();">Закрыть окно</a>');
	nw.document.write('</div>');
	//nw.document.write('<div align="left">');
	//nw.document.write(description);
	//nw.document.write('</div>');
	nw.document.write('</body>');
	nw.document.write('</html>');
	if( navigator.appName.substring(0,8) == "Netscape" )
	{
		//nw.location = '#';
	}
	nw.focus();
	return false;
}

// Ajax
function PHPtoDIV(div_id, php_str)
{
	var AddScr = document.createElement('script');
	found = 0;
	i = 0;
	while(ch = php_str.substr(i,1))
	{
		if ( ch == '?' )
		{
			found = 1;
			break;
		}
		i++;
	}

	if ( found == 1)
	{
		str = '&';
	}
	else
	{
		str = '?';
	}

	AddScr.src = php_str + str + 'div_id=' + div_id;

	document.body.appendChild(AddScr);
	return false;
}

function TopProductSelect(product_id)
{
	alert(product_id);
}

//=======================================================
// BEGIN - Strip
//=======================================================
var StripTimer_1 = null;
var StripTimer_2 = null;
var strip_scrolling_dir_1 = 'r';
var strip_scrolling_dir_2 = 'l';


function StopStripScrolling(n)
{
	eval("clearTimeout(StripTimer_"+n+")");
}

function StartStripScrolling(dir,n)
{
	if ( dir == 'r' )
	{
		eval("strip_scrolling_dir_"+n+" = 'r'");
	}
	else if ( dir == 'l' )
	{
		eval("strip_scrolling_dir_"+n+" = 'l'");;
	}

	if ( eval("strip_scrolling_dir_" +n+"== 'r'") )
	{
		StripScrolling_Right(n);
	}
	else
	{
		StripScrolling_Left(n);
	}
}

function StripScrolling_Left(n)
{
	var strip = document.getElementById('div_strip_'+n);

	strip.scrollLeft = strip.scrollLeft + 1;

	if ( strip.scrollLeft >= (eval("strip_width_"+n)))
	{
		//alert(strip.scrollLeft);
		strip.scrollLeft = 0;
	}

	var str ="StripTimer_"+n;
	var str2= 'setTimeout("StripScrolling_Left('+n+')", 10)';
	eval(str+" = "+str2);
}


function StripScrolling_Right(n)
{
	var strip = document.getElementById('div_strip_'+n);

	strip.scrollLeft = strip.scrollLeft - 1;

	if ( strip.scrollLeft <= 0 )
	{
		strip.scrollLeft = eval("strip_width_"+n);
	}

	var str ="StripTimer_"+n;
	var str2= 'setTimeout("StripScrolling_Right('+n+')", 10)';
	eval(str+" = "+str2);

}
//=======================================================
// END - Strip
//=======================================================

//=======================================================
// BEGIN - SmallStrip
//=======================================================
var SmallStripTimer_1 = null;
var SmallStripTimer_2 = null;

var smallstrip_scrolling_dir_1 = 'r';
var smallstrip_scrolling_dir_2 = 'l';


function StopSmallStripScrolling(n)
{
	eval("clearTimeout(SmallStripTimer_"+n+")");
}

function StartSmallStripScrolling(dir,n)
{
	if ( dir == 'r' )
	{
		eval("smallstrip_scrolling_dir_"+n+" = 'r'");
	}
	else if ( dir == 'l' )
	{
		eval("smallstrip_scrolling_dir_"+n+" = 'l'");
	}

	if ( eval("smallstrip_scrolling_dir_" +n+" == 'r'"))
	{
		SmallStripScrolling_Right(n);
	}
	else
	{
		SmallStripScrolling_Left(n);
	}
}

function SmallStripScrolling_Left(n)
{
	var smallstrip = document.getElementById('div_smallstrip_'+n);

	smallstrip.scrollLeft = smallstrip.scrollLeft + 1;

	if ( smallstrip.scrollLeft >= eval("smallstrip_width_"+n) + 1 )
	{
		smallstrip.scrollLeft = 0;
	}

	var str ="SmallStripTimer_"+n;
	var str2= 'setTimeout("SmallStripScrolling_Left('+n+')", 25)';
	eval(str+" = "+str2);
}


function SmallStripScrolling_Right(n)
{
	var smallstrip = document.getElementById('div_smallstrip_'+n);

	smallstrip.scrollLeft = smallstrip.scrollLeft - 1;

	if ( smallstrip.scrollLeft <= 0 )
	{
		smallstrip.scrollLeft = eval("smallstrip_width_"+n);
	}
	var str ="SmallStripTimer_"+n;
	var str2= 'setTimeout("SmallStripScrolling_Right('+n+')", 25)';
	eval(str+" = "+str2);
}
//=======================================================
// END - SmallStrip
//=======================================================


//=======================================================
// BEGIN - GetCalendar
//=======================================================

function GetCalendar(direct)
	{
	if(direct<0)
		var str  = "dec";
	else
		var str  = "inc";
	PHPtoDIV('calendar_div', cfgRootPath + 'includes/_getcalendar.php?inc_month='+str);
	//PHPtoDIV('calendar_div', cfgRootPath + 'admin/includes/_pages_edit.php');
	}

//=======================================================
// BEGIN - GetCalendar
//=======================================================

function GoToPage(n, razdel)
{

	var group = document.getElementById('group_name').value;

	document.location.href = cfgRootPath +cfgLANG+'/'+razdel+'/' + group + '/page_' + n;
}

function GotoUrl(url)
	{
	document.location.href = url;
	event.cancelBubble=true;
	}


function Check_Date_RegExp(str_ch)
	{
		str = str_ch;
		reg = new RegExp("([0-9]{2})\\.([0-9]{2})\\.[0-9]{4}","i");
		result = reg.exec(str);
		if(result==null || result[1]>31)
			return false;
		if(result==null || result[2]>12)
			return false
	return true;
	}

function News_Filter()
	{
		el = document.getElementById('filter_date_1');
		if(Check_Date_RegExp(el.value)==false)
			{
			alert("Wrong Date, enter format: xx.xx.xxxx");
			el.focus();
			el.value = "";
			return false;
			}
		el = document.getElementById('filter_date_2');
		if(Check_Date_RegExp(el.value)==false)
			{
			alert("Wrong Date, enter format: xx.xx.xxxx");
			el.focus();
			el.value = "";
			return false;
			}
	document.getElementById('filter_date_form').submit();
	}

function Show_Submenu(menu_id, show)
	{
	var str ='sub_'+ menu_id;
	el = document.getElementById(str);
	//el.style.margin-top = "-2px";
	if(show==1)
		el.style.display="block";
	else
		el.style.display="none";
	}

