var popy;
function PopW(theURL,winName,features)
{
	if(!window.focus)
		return true;

	if(popy!=null)
	{
		if(!popy.closed)
			popy.window.close();
    }
	popy = window.open(theURL,winName,features);
	popy.focus();

    return false;
}
//==============================================================================
var popy1;
function PopW1(theURL,winName,features)
{
	if(!window.focus)
		return true;

	if(popy1!=null)
	{
		if(!popy1.closed)
			popy1.window.close();
    }
	popy1 = window.open(theURL,winName,features);
	popy1.focus();

    return false;
}
//==============================================================================
function HelpOpenNewWin(url,table_name,object_id,field_name,pdf_flag)//for solution pdf,product pdf,user_solution pdf
{
	var theURL   = url;
	var winName  = 'new_win';
	var features = 'width=750,height=550,status=no,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes';

	PopW(theURL,winName,features);
	
	SendDataForStatistic(table_name,object_id,field_name,pdf_flag);
}
//==============================================================================
function HelpOpenNewWinMaterial(url)//not used
{
	var theURL   = url;
	var winName  = 'new_win_mat';
	var features = 'width=750,height=550,status=no,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes';

	PopW(theURL,winName,features);
}
//==============================================================================
function HelpOpenNewWinProductPicture(url, my_width, my_height, table_name, object_id, field_name)
{
	var theURL   = url;
	var winName  = 'product_picture';
	var features = 'width='+my_width+',height='+my_height+',status=no,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes';

	PopW(theURL,winName,features);
	
	SendDataForStatistic(table_name,object_id,field_name);
}
//==============================================================================
function HelpOpenNewWinSolutionPicture(url, my_width, my_height, table_name, object_id, field_name)
{
	var theURL   = url;
	var winName  = 'solution_picture';
	var features = 'width='+my_width+',height='+my_height+',status=no,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes';

	PopW(theURL,winName,features);
	SendDataForStatistic(table_name,object_id,field_name);
}
//==============================================================================
function Operation(page, val)//used for tree_oper
{
		location = page+"?tree_oper="+val;
	   	//checkForm = document.form1;
	   	//checkForm.tree_oper.value = val;
		//checkForm.submit();
}
//==============================================================================
function OperationWizard(val, my_file)
{
	switch(val)
	{
		case 1: //admin part
		    HelpOpenNewWin(my_file);
		break;
		
		case 2: //logout
		    location = my_file;
		break;
	}
}
//==============================================================================
//==============================================================================
function OperationUser(val)
{
	checkForm = document.user_form;
	checkForm.operation_user.value = val;
	checkForm.submit();
}
//==============================================================================
//==============================================================================
function HelpOpenNewWinDoc(url, table_name, object_id, field_name)//for product_pdf
{
	var theURL   = url;
	var winName  = 'web_mat';
	var features = '';

	PopW1(theURL,winName,features);
	
	SendDataForStatistic(table_name,object_id,field_name);
}
//==============================================================================
function MenuOperation(action,val)
{
	checkForm = document.form1;
	checkForm.action = action;
	checkForm.tree_oper.value = val;
	checkForm.submit();
}
//==============================================================================
function SendDataForStatistic(table_name,object_id,field_name,pdf_flag)
{
	if(top.for_statistic != null)
	{
		var current_location = top.for_statistic.location;
		
		top.for_statistic.location = current_location+"&table_name="+table_name+"&object_id="+object_id+"&field_name="+field_name+"&pdf_flag="+pdf_flag;
	}
}
//==============================================================================
function ChangeLocation(my_url)
{
	location = my_url;
}
//==============================================================================
function ChangeBackgroundImage(id, img_src)
{
	if(document.getElementById(id) != null)
	{
		document.getElementById(id).style.backgroundImage = "url("+img_src+")";
		document.getElementById(id).style.backgroundRepeat = "no-repeat";
		document.getElementById(id).style.cursor = "pointer";
		document.getElementById(id).style.cursor = "hand";
	}
}
//==============================================================================
function ChangeBackgroundColor(id, my_color1, my_color2, my_color3)
{
	var part_id = '';
	var my_arr  = id.split("-");
	if(my_arr.length == 2)
	{
		part_id = my_arr[0];
	}

	if(document.getElementById(part_id+'-1') != null)
	{
		document.getElementById(part_id+'-1').style.backgroundColor = my_color1;
		document.getElementById(part_id+'-1').style.cursor = "pointer";
		document.getElementById(part_id+'-1').style.cursor = "hand";
	}
	
	if(document.getElementById(part_id+'-2') != null)
	{
		document.getElementById(part_id+'-2').style.backgroundColor = my_color2;
		document.getElementById(part_id+'-2').style.cursor = "pointer";
		document.getElementById(part_id+'-2').style.cursor = "hand";
	}
	
	if(document.getElementById(part_id+'-3') != null)
	{
		document.getElementById(part_id+'-3').style.backgroundColor = my_color3;
		document.getElementById(part_id+'-3').style.cursor = "pointer";
		document.getElementById(part_id+'-3').style.cursor = "hand";
	}

}
//==============================================================================
function SwapImageSrc(img_name, img_src)
{
	var my_id = img_name+'_1';
	
	if(document.images[img_name] != null)
	{
		document.images[img_name].src=img_src;
	}
	
	if(document.getElementById(my_id) != null)
	{
		if(document.getElementById(my_id).style.visibility == 'hidden')
			document.getElementById(my_id).style.visibility = 'visible';
		else
			document.getElementById(my_id).style.visibility = 'hidden';
	}
	
	/*if(document.images[img_name] != null)
	{
		document.images[img_name].src=img_src;
	}*/
	
}
//==============================================================================
function HideContent(my_id)
{
	if(document.getElementById(my_id) != null)
	{
		document.getElementById(my_id).style.visibility = 'hidden';
	}
}
//==============================================================================
var img_scroller;
var scroller_direction;
function img_scroll(activate, direction)
{
    scroll_speed = 4; // speed of scroller

    scroller_direction = direction;
    div_scroll = document.getElementById('scroller');

    if(activate)
    {
    	if (direction)
    	{
    		div_scroll.scrollTop += scroll_speed;
    	}
        else
        {
        	div_scroll.scrollTop -= scroll_speed;
        }

        img_scroller = setTimeout("img_scroll(1, scroller_direction)", 1);
    }
    else clearTimeout(img_scroller);
}
//==============================================================================
var img_scroller_gallery;
var scroller_direction_gallery;
function img_scroll_gallery(activate, direction, my_id)
{
    scroll_speed_gallery = 2; // speed of scroller
	my_new_id = my_id;
    scroller_direction_gallery = direction;
    div_scroll_gallery = document.getElementById('scroller_gallery'+my_new_id);

    if(activate)
    {
    	if (direction)
    	{
    		div_scroll_gallery.scrollLeft += scroll_speed_gallery;
    	}
        else
        {
        	div_scroll_gallery.scrollLeft -= scroll_speed_gallery;
        }

        img_scroller_gallery = setTimeout("img_scroll_gallery(1, scroller_direction_gallery, my_new_id)", 1);
    }
    else clearTimeout(img_scroller_gallery);
}
//==============================================================================
function DesideViewOrNotScroll()
{
	if(document.getElementById('scroller') == null)
	{
		return;
	}
	
	scroll_speed = 2; // speed of scroller
    div_scroll   = document.getElementById('scroller');
    
    div_scroll.scrollTop += scroll_speed;

	if(div_scroll.scrollTop > 0)
	{
		div_scroll.scrollTop = 0;
	}
	else
	{
		if(document.getElementById('img_up') != null)
			document.getElementById('img_up').style.visibility = 'hidden';
			
		if(document.getElementById('img_down') != null)
			document.getElementById('img_down').style.visibility = 'hidden';
	}
}
//==============================================================================
function SS_swapImgRestore() { //v3.0
    var i,x,a=document.SS_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
        x.src=x.oSrc;
}

function SS_findObj(n, d) { //v4.01
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);}
    if(!(x=d[n])&&d.all)
        x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++)
        x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++)
        x=SS_findObj(n,d.layers[i].document);
    if(!x && d.getElementById)
        x=d.getElementById(n);
    return x;
}

function SS_swapImage() { //v3.0
    var i,j=0,x,a=SS_swapImage.arguments;
    document.SS_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=SS_findObj(a[i]))!=null) {
            document.SS_sr[j++]=x;
            if(!x.oSrc) x.oSrc=x.src;
            x.src=a[i+2];
        }
}

function SS_preloadImages() { //v3.0
    var d=document;
    if(d.images){ if(!d.SS_p)
        d.SS_p=new Array();
    var i,j=d.SS_p.length,a=SS_preloadImages.arguments;
    for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0) {
            d.SS_p[j]=new Image; //alert(a[i]);
            d.SS_p[j++].src=a[i];}}
}

// onMouseOut="SS_swapImgRestore()"
// onMouseOver="SS_swapImage('Image14','','../images/AboutERCDown.jpg',1)"
//==============================================================================
//==============================================================================
function GetXmlHttpObject(handler)
{
      var xmlHttp = null;
      if (window.XMLHttpRequest) 
      { // Mozilla, Safari,...
         xmlHttp = new XMLHttpRequest();
         if (xmlHttp.overrideMimeType) 
         {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            xmlHttp.overrideMimeType('text/html');
         }
      } 
      else if (window.ActiveXObject) 
      { // IE
         try 
         {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
         } 
         catch (e) 
         {
            try 
            {
               xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
            	
            }
         }
      }
      if (xmlHttp == null) 
      {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      return xmlHttp;
}
/*==============================================================================*/
var div_id_topical_img = 0;

function stateChangedProduct()
{
	var my_id = ReturnCharCode('products');
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if(document.getElementById("result"+my_id) != null)
		{
			document.getElementById("result"+my_id).innerHTML = xmlHttp.responseText;
			//content_plan.insertAdjacentHTML("afterBegin", xmlHttp.responseText);
		}
	}
}
/*==============================================================================*/
function stateChangedPictureTopical()
{
	var my_id = div_id_topical_img;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if(document.getElementById("ti_"+my_id) != null)
		{
			document.getElementById("ti_"+my_id).innerHTML = xmlHttp.responseText;
		}
	}
}
/*==============================================================================*/
/*==============================================================================*/
function GetResultPictureTopical(picture_id, div_id)
{
	div_id_topical_img = div_id;
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url = 'objects/topical_ajax_inc.php?picture_id='+picture_id+'&sid='+Math.random();;
	
	xmlHttp.onreadystatechange = stateChangedPictureTopical;
	xmlHttp.open('GET', url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(null);
}
//==============================================================================
function ReturnCharCode(my_string)
{
	var my_num = 0;
	var my_arr = my_string.split("");
	
	for(var i = 0 in my_arr)
	{
		my_num = my_num + my_string.charCodeAt(i);
	}
	
	return my_num;
}
//==============================================================================
function CreateIntro()
{
	var str = '';
	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="840" height="495" id="intro" align="middle">';
	str += '<param name="allowScriptAccess" value="sameDomain" />';
	str += '<param name="movie" value="intro.swf" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="bgcolor" value="#f0d3a6" />';
	str += '<embed src="intro.swf" quality="high" bgcolor="#f0d3a6" width="840" height="495" name="intro" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str += '</object>';

	document.write(str);
}
//==============================================================================
