window.onload = initialization; 
window.onresize = setScreenClass;

function initialization() {
	tabActive = getElement('tab1');
	displayed = getElement('about_block');
}


function getElement(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all(id);
	}
}

function showInfo(sourceTab, infoContainer) {
	if (sourceTab != tabActive) {
		changingCurrent = getElement(infoContainer);
		tabActive.className = tabActive.className.replace(/block2/g, 'head10');
		sourceTab.className = 'block2';		
		tabActive = sourceTab;
		changingCurrent.style.display = 'block';
		displayed.style.display = 'none';
		displayed = changingCurrent;
	}
}

	/**
	* @desc Install main variables
	*/
	var new_window;
	var allow_flash = false;
	
	// Clear func
	function onclearform(frm) {
		for (var i = 0; i < frm.length; i++)
		if (/^(text|pass)/.test(frm.elements[i].type))
		frm.elements[i].value = '';
		else if (/^(radio|checkbox)/.test(frm.elements[i].type))
		frm.elements[i].checked = false;
		else if (/^select/.test(frm.elements[i].type))
		frm.elements[i].options.selectedIndex = (/one$/.test(frm.elements[i].type) ? 0 : -1);
	}
	
	//  Vote func
	function write_quest(str) {
		for (var i = 0; i < str.length; i++)
		if (!isNaN(parseInt(str.elements[i].value)))
		if (str.elements[i].checked) {
			str.submit();
			return;
		}
		alert('Пожалуйста, выбирите один из предложенных вариантов дл\я голосовани\я!');
	}
	
	function onindicatetext(str) {
		str.value = str.value.replace(/^(\s+)/gi, '');
		str.value = str.value.replace(/(\s+)$/gi, '');
		if (str.value.length > 0)
		return true;
	
		//if(str==null) return;
		str.select();
		str.focus();
		return false;
	}
	
	function submitform(url)
	{
	   document.form_with_navigation.action = url;
	   document.form_with_navigation.submit();
	}		
	
	function onindicateexists(str, tmp) {
		for (var i = 0; i < tmp.length; i++)
		if (str == tmp[i])
		return true;
		return false;
	}
	
	function onindicatemail(str) {
		var tmp  = '';
		var lg   = true;
		var arr0 = new Array(45, 46, 95);
	
		var arr1 = str.value.match(/\b(\w((\w|\.|-)*\w)?@\w((\w|\.|-)*\w)?(\.[a-z]{2,3}))\b/gi);
		if (arr1 != null)
		for (var i = 0; (i < arr1.length && lg); i++) {
			tmp+= (tmp.length > 0 ? String.fromCharCode(59, 32) : '') + arr1[i];
			for (var j = 0; j < arr0.length; j++)
			if (arr1[i].indexOf(String.fromCharCode(arr0[j], arr0[j])) > -1) {
				lg = false; break; }
		}
	
	
		if (!lg || (str.value.length > 0 && tmp.length == 0))
		return false;
	
		str.value = tmp;
		return true;
	}
	
	function onindicatehref(str)
	{
		var tmp_href=str.value;
	
		var arr1 = tmp_href.match(/^(http:\/\/)([_a-z\d\-]+(\.[_a-z\d\-]+)+)((\/[ _a-z\d\-\\\.]+)+)*/gi);
		if(arr1!=null) return true
		else return false
	}
	
	function onsubmitform2(frm) {
		if(frm.city.value==0)
		{
		 alert("Укажите город");
		 return false;
		}
	}	
	
	function onformsform(frm,page) {
		var page_mas=eval(page+"_arr");

		for (var i = 0; i < frm.length; i++)
		{
			if (/^(text|password)/i.test(frm.elements[i].type))
			{
				if (!onindicatetext(frm.elements[i]))
				{
					if (onindicateexists(frm.elements[i].name, page_mas)) {
						onformsmess(frm.elements[i].name);
						return;
					}
				}
				else if (/mail$/.test(frm.elements[i].name))
				{
					if (!onindicatemail(frm.elements[i])) {
						onformsmess(frm.elements[i].name);
						return;
					}
				}
				else if(/href$/.test(frm.elements[i].name))
				{
					if (!onindicatehref(frm.elements[i])) {
						onformsmess(frm.elements[i].name);
						return;
					}
				}
			}
			else if(/category/.test(frm.elements[i].name))
			{
				if(frm.elements[i].options[frm.elements[i].selectedIndex].value==0)
				{
					onformsmess(frm.elements[i].name);
					return;
				}
			}
		}
	
		frm.submit();
	}
	
	function onformsmess(str) {
		var tmp = eval(str);
		alert(tmp.length > 0 ? tmp : mess);
	}
	
	function filt(frm, name, val) 
	{
		for (var i = 0; i < frm.length; i++)
		 if(frm.elements[i].name == name)
		 {
		  frm.elements[i].value=val;
		  frm.submit();
		 }
	}	
	
	function setcookie(name, value) 
	{
    	name  = trimfield(name);
   		value = trimfield(value);
    	if (value.length > 0)
        	document.cookie = name + '=' + value + '; path=/;';
    	else 
     	{
        	var todaydate = new Date();
        	todaydate.setDate(todaydate.getDate() - 1);

        	document.cookie = name + '=' + value + '; expires=' + todaydate.toGMTString() + '; path=/;';
     	}
	}	

	function trimfield(str) 
	{
	    while (str.length > 0 && (str.charCodeAt(0) == 32 || str.charCodeAt(0) == 13 || str.charCodeAt(0) == 10))
	        str = str.substr(1);
	    while (str.length > 0 && (str.charCodeAt(str.length - 1) == 32 || str.charCodeAt(str.length - 1) == 13 || str.charCodeAt(str.length - 1) == 10))
	        str = str.substr(0, str.length - 1);
	
	    return str.replace(/(  *)/g, ' ');
	}	
	
	function show(id)
	{
		var el=document.getElementById(id);
		
		if (el.style.display=='none')
			el.style.display='block';
		else
			el.style.display='none';
	}	
	
	function openWindow(url, w, h) {
		var options = "width=" + w + ",height=" + h + ",";
		options += "scrollbars=yes,status=no,";
		options += "menubar=no,toolbar=no,position=center,location=no,directories=no";
		var newWindow = window.open(url, 'newWind', options);
		newWindow.focus();
	}
	
	
	function disableSearchSelect() {
	    select = document.getElementById('search_select');
	    select.disabled = true;
	}
	
	function enableSearchSelect() {
	    select = document.getElementById('search_select');
	    select.disabled = false;
	}	
	
	
	function window_available()
	{
		if (!new_window) return false
		else if (new_window.closed) return false
		else return true
	}
	
	function resize_image(path)
	{
		var img_loaded=new Image();
		img_loaded.src=path;
		new_window.window.resizeTo(img_loaded.width,img_loaded.height);
	}
	
	function display_image(path,title)
	{
		var img=new Image();
		img.src=path;
		img_width=img.width;
		img_height=img.height;
	
		add_param="menubar=no,toolbar=no,location=no,directories=no,width="+img_width+",height="+img_height;
	
		(window_available())? new_window.close(): new_window=false;
	
		new_window = window.open("","",add_param);
		new_window.document.writeln('<html>');
		new_window.document.writeln('<head>');
		new_window.document.writeln('<title>'+title);
		new_window.document.writeln('<\/title>');
		new_window.document.writeln('<\/head>');
		new_window.document.writeln('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
		new_window.document.writeln("<img src='"+img.src+"'>");
		new_window.document.writeln('<\/body>');
		new_window.document.writeln('<\/html>');
		var img_loaded=new Image();
		img_loaded.src=path;
		new_window.window.resizeTo(img_loaded.width,img_loaded.height);
		new_window.document.close();
	}
	
	function write_image(i, t)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width='+Math.floor(screen.width/2)+',height='+Math.floor(screen.height/2);
		 var wind = window.open(SITE_URL + 'image.php?act='+i+'&title='+t,'OrattaImage',par);
		wind.focus();
	}
	
	function send_pass(i)
	{
		var par='location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=450,height=140';
		var wind=window.open(SITE_URL+LANG_URL+'user/forgot','Blank',par);
		wind.focus();
	}
	
	function del_item(id)
	{
		var f = document.getElementById('form');	
		f.action.value="del";
		f.item_to_edit.value=id;
		f.submit(); 
	}
	
	function message(i, id)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=600,height=570';
		var wind=window.open(SITE_URL+LANG_URL+'message/'+i+'/'+id,'Blank',par);
		wind.focus();
	}	
	
	function write_product(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=350,height=250';
		var wind=window.open(SITE_URL+LANG_URL+'product/detail/'+i,'Blank',par);
		wind.focus();
	}
	
	function write_form(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=500,height=500';
		var wind=window.open(SITE_URL+LANG_URL+'forms/'+i,'Blank',par);
		wind.focus();
	}
	
	function write_table(i)
	{
		var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=500,height=300';
		var wind=window.open(SITE_URL+LANG_URL+'table/'+i,'Blank',par);
		wind.focus();
	}
	
	/**
	 * Check allow flash
	 */
	var plugVersion = 6;
	var n = navigator; 
	
	if (n.plugins && n.plugins.length > 0)
	{
		var np = n.plugins;
		for (i in np)
		if (np[i].description && np[i].description.match(/Shockwave[\s]+Flash[\s]+([0-9\.]+)/ig))
		{
			if (parseInt(RegExp.$1) > plugVersion)
			{
				allow_flash = true;
				break;
			}
		}
	}
	else if (n.userAgent && /MSIE/ig.test(n.userAgent) && /Win/ig.test(n.appVersion))
	{
		document.write('<SCRIPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('allow_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & plugVersion)))\n');
		document.write('</SCRIPT\> \n');
	}
	
	/**
	 * Check allow flash
	 * 
	 * @author X-MAN <Admin@relax-info.com>
	 * @return bool
	 */
	function check_allow_flash()
	{	
		return (allow_flash)? 1 : 0;
	}
	
    function updatelist(event)
    { 
		alert(event.charCode);
    }	
    
	function _(e) {
	    return document.getElementById(e) ? document.getElementById(e) : false;
	}    
    
	fsize.counter = 0;
	fsize.classNames = new Array('12', '14');
	
	function fsize($)
	{
		 _('content').style.fontSize = (function(){
			return function ()
			{
				if ($ == "+")
				{
					fsize.counter++
					if ( fsize.counter < fsize.classNames.length)
					{
						_("plus").src = "http://interref.biz/images/font_up_off.gif";
						_("minus").src = "http://interref.biz/images/font_down.gif";
						return fsize.classNames[fsize.counter]
					}
					else
					{
						fsize.counter = fsize.classNames.length - 1;
						return fsize.classNames[fsize.counter]
					}
				}
				
				if ($ == "-")
				{
					fsize.counter--
					if ( fsize.counter > 0 )
					{
						return fsize.classNames[fsize.counter]
					}
					else
					{
						_("plus").src = "http://interref.biz/images/font_up.gif";
						_("minus").src = "http://interref.biz/images/font_down_off.gif";
						fsize.counter = 0;
						return fsize.classNames[fsize.counter]
					}
				}
			}();
		})() + "px";
	}     
