var http_request = false;
var searchArray = new Array ( );
var searchPage = 1;
var content_id="content";
var products="";
var fnr="";
var pnr="";
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = GetResponse;
http_request.open('POST', url, true);
//http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader('Content-Type','text/xml;charset=utf-8')
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}
function GetResponse() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			result = http_request.responseText;
			if (result!=false) {
				//alert(result);
				if(content_id=="products_list,header_main_container"){
					var res=result.split("#");
					var div=content_id.split(",");
					fnr=res[0];
					pnr=res[1];
					document.getElementById("description").innerHTML=res[2];
					document.getElementById(div[1]).innerHTML=res[3];
					document.getElementById(div[0]).innerHTML=res[4];
				}else {
					document.getElementById(content_id).innerHTML=result;
				}
			}
		} else {
			alert('There was a problem with the request.');
		}
	}
}
function GetAgentData(type,agent,txtdata) {
	content_id=type;
	var poststr = encodeURI(txtdata);//utf8encode(txtdata);
	makePOSTRequest(agent, poststr);
}
function getMaterial(type,id) {
	var url = "/mxl-fashion/luhtawww.nsf/getMaterial?OpenAgent";
	if (type=="1") {
		if(id!="") {
			var tmp=document.getElementById(id);
			var search;
			if (tmp.checked){
				search=tmp.value;
			} else {
				search='';
			}		
			if(id.length>0){
				GetAgentData("material_content",url,search);
			}
			unCheckMaterials(id);
		}
	}
	if (type=="2") {
		var tmp=document.getElementById('material_1');
		if (!tmp.checked) {
			var tmp2=tmp.previousSibling;
			tmp.checked=true;
			tmp2.className='jsCheckbox jsmaterial_1 A';
		}
		if(id.length>0){
			GetAgentData("material_content",url,id);
		}
	}
}
function unCheckMaterials(id) {
	var size=parseInt(document.getElementById('materials').value);
	var tmp;
	for (i=1;i<=size;i++) {
		tmp=document.getElementById('material_' + i.toString());
		var tmp2=tmp.previousSibling;
		if (tmp.checked && tmp.id!=id) {
			tmp.checked=false;
			tmp2.className='jsCheckbox jsmaterial_'  + i.toString();
		}
	}
}
function uncheckAllProducts() {
	var cats=parseInt(document.getElementById('cats').value);
	var tmp;
	for (i=1;i<=cats;i++) {
		var temp=document.getElementById('nr' + i.toString());
		if(temp!=null){
		nr=parseInt(document.getElementById('nr' + i.toString()).value);
		for (j=1;j<=nr;j++) {
			var t=document.getElementById(i.toString() + "_" + j.toString());
			t.checked=false;
			var t2=t.previousSibling;
			t2.className='jsCheckbox js' + i.toString() + ' _'  + j.toString();
		}
		}
	}
	for(k=1;k<=4;k++){
		var t3=document.getElementById("panel" + k.toString());
		if (t3!=null){
		t3.className="";
		}
	}
}
function newssearch(year,month){
	var url = "/mxl-fashion/luhtawww.nsf/newssearch?OpenAgent";
	GetAgentData('news_list',url,'year=' + year + '&month='+month);
}
function materialsearch(){
	var url = "/mxl-fashion/luhtawww.nsf/materialsearch?OpenAgent";
	var searchtext=document.getElementById('searchproduct').value;
	GetAgentData('material_content',url,searchtext);
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
// if cookie exists
if (offset != -1) { 
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function trim(arr2){
var arr1=new Array();
for(j=0;j<arr2.length;j++)
if(arr2[j]!="")
arr1[arr1.length]=arr2[j];
arr2.length=arr1.length;
for(j=0;j<arr1.length;j++)
arr2[j]=arr1[j];
return arr2;
}

function set_cookie(myName,myValue) {
  if (testSessionCookie()) {
    writeSessionCookie (myName, myValue);
  }
  else
    alert ("Sorry - session cookies are currently disabled."); 
}
function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}
function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}
function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}
function getChoice1() {
var country=document.getElementById("getStoreForm").Country;
for (var i = 0; i < country.length; i++) {
if (country.options[i].selected == true) {
return country.options[i].text
}
}
return null;
}
function getChoice2() {
var line=document.getElementById("getStoreForm").Line;
for (var i = 0; i < line.length; i++) {
if (line.options[i].selected == true) {
return line.options[i].text
}
}
return null;
}
function getStore()
{
 var c=getChoice1();
 if (c!="--"){
  var l=getChoice2();
  if (l!="--"){
  var lan=document.getElementById("getStoreForm").Lan.value;
var lan2="";
if(lan=="" || lan=="FI"){
lan2="";
}else {
lan2=lan+"_";
lan2=lan2.toLowerCase();
}
  var url="/mxl-fashion/luhtawww.nsf/pages/" + lan2 +"stores.html?OpenDocument&";
  window.location=url + "country=" + c + "&store=" + l;
  }
 }
}

