
var attributes = new Array();

var criterias = new Array();




function get_xmlhttprequest()
{
	var xmlHttp;
	
	try
	{
		xmlHttp=new XMLHttpRequest();
        return xmlHttp;
	}
	
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			return xmlHttp;
		}
		
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			}
			
			catch (e)
			{
				alert("Przeglądarka nie wspiera AJAX!");
				return false;
			}
		}
	
	}
	
}


function add_attribiute(attribute)
{
	is_in = 0;
	
	for(i=0; i < attributes.length; i++ )
	{
		if( attributes[i] == attribute )
		{
			attributes[i] = 0;
			
			is_in++;
		}
		
	}
	
	if(is_in == 0)
	{
		attributes[attributes.length] = attribute;
	}
}


function set_attribute(parent,lang, attribute)
{
	a_class = document.getElementById('Attr_'+attribute).className;
	
	
	if( a_class == 'normal')
	{
		document.getElementById('Attr_'+attribute).className = 'act';
		
		
	}
	
	else
	{
		document.getElementById('Attr_'+attribute).className = 'normal';
	}
	
	add_attribiute(attribute);
	
	
	var params = 'parent='+parent+'&lang='+lang+'&attributes='+attributes;
	
	var xHR = get_xmlhttprequest();
	
    xHR.onreadystatechange = function() 
    {
		
		if(xHR.readyState == 4 && xHR.status == 200) 
		{
			c_txt = xHR.responseText;
			
			document.getElementById('ProductsList').innerHTML = c_txt;
			
		}
		
		
	 }
    
    xHR.open('POST', pr_url, true);
	xHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xHR.setRequestHeader("Content-length", params.length);
	xHR.setRequestHeader("Connection", "close");
    xHR.send(params);

	
	return false;


}

function step_2()
{
	s_email = document.getElementById('UEmail').value;
	
	
		document.getElementById('NMsg').style.display='none';
	
	
	if( !email_validate(s_email) )
	{
		document.getElementById('WEmail').style.display='block';
	}
	
	else
	{
		document.getElementById('Step_1').style.display='none';
		document.getElementById('Step_2').style.display='block';
	}
}

function set_sex(sex)
{
	document.getElementById('S1').style.backgroundPosition='left top';
	document.getElementById('S2').style.backgroundPosition='left top';
	
	document.getElementById('S'+sex).style.backgroundPosition='bottom';
	document.getElementById('Sex').value=sex;
	
}

function check_form(myform)
{
	s_email = myform.email.value;
	
	document.getElementById('Validate').style.display='none';
	
	
	if(myform.sex.value == 0 || myform.city.value == '' || myform.city.value == city)
	{
		document.getElementById('Validate').style.display='block';
		
		document.getElementById('Validate').innerHTML=req;
		
		return false;
	}
		
	
	if( !email_validate(s_email) )
	{
		document.getElementById('WEmail').style.display='block';
		
		return false;
	}
	
	
	
	
	return true;
}


function email_validate(src) 
{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
}


function set_criteria(c_id, lang, phrase, type)
{
	a_class = document.getElementById('Attr_'+c_id).className;
	
	
	
	if( a_class == 'normal')
	{
		document.getElementById('Attr_'+c_id).className = 'act';
		
		
	}
	
	else
	{
		document.getElementById('Attr_'+c_id).className = 'normal';
	}
	
	add_criteria(type);
	
	params2 = 'lang='+lang+'&phrase='+phrase+'&criterias='+criterias;
	
   var xHR = get_xmlhttprequest();
	
    xHR.onreadystatechange = function() 
    {
		
		if(xHR.readyState == 4 && xHR.status == 200) 
		{
			c_txt = xHR.responseText;
			
			document.getElementById('NList').innerHTML = c_txt;
			
		}
		
		
	 }
    
    xHR.open('POST', se_url, true);
	xHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xHR.setRequestHeader("Content-length", params2.length);
	xHR.setRequestHeader("Connection", "close");
    xHR.send(params2);

	
	return false;
}

function add_criteria(attribute)
{
	is_in = 0;
	
	for(i=0; i < criterias.length; i++ )
	{
		if( criterias[i] == attribute )
		{
			criterias[i] = '';
			
			is_in++;
		}
		
	}
	
	if(is_in == 0)
	{
		criterias[criterias.length] = attribute;
	}
}



