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 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;
}
/*==============================================================================*/
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 stateChangedSolution()
{
	var my_id = ReturnCharCode('solutions');
	
	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 GetResultProduct(val)
{
	var char_code = ReturnCharCode('products');
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url        = 'objects/products_ajax_inc.php?tree_oper='+val+'&page_char_code='+char_code+'&sid='+Math.random();;
	//var parameters = 'posted_object='+(my_data);
	//url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange = stateChangedProduct;
	xmlHttp.open('GET', url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-unlencoded");
	xmlHttp.send(null);
}
/*==============================================================================*/
function GetResultSolution(val)
{
	var char_code = ReturnCharCode('solutions');
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}
	
	var url        = 'objects/solutions_ajax_inc.php?tree_oper='+val+'&page_char_code='+char_code+'&sid='+Math.random();;
	//var parameters = 'posted_object='+(my_data);
	//url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange = stateChangedSolution;
	xmlHttp.open('GET', url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-unlencoded");
	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;
}
//==============================================================================

