// Positic Software http://www.positic.ru

var pos_steklopaket = [
		"24 мм",	//0
		"32 мм",	//1
		"40 мм",	//2
		"48 мм"	//3
	];

var pos_win = [
	
		{profile:2,
		 name:'Euro-Design',
		 img:'/images/stories/profiles/rehau/rehau-euro-design-small.gif',
		 ref:'/rehau/euro-design.html',
		 addToCart:'/order.html?addprofile=80',
		 camera:3,
		 paket:1
		},		
		{profile:2,
		 name:'Basic-Design',
		 img:'/images/stories/profiles/rehau/rehau-basic-design-small.gif',
		 ref:'/rehau/basic-design.html',
		 addToCart:'/order.html?addprofile=81',
		 camera:3,
		 paket:1
		},		
		{profile:2,
		 name:'Thermo-Design',
		 img:'/images/stories/profiles/rehau/rehau-thermo-design-small.gif',
		 ref:'/rehau/thermo-design.html',
		 addToCart:'/order.html?addprofile=82',
		 camera:3,
		 paket:1
		},		
		{profile:2,
		 name:'Sib-Design',
		 img:'/images/stories/profiles/rehau/rehau-sib-design-small.gif',
		 ref:'/rehau/sib-design.html',
		 addToCart:'/order.html?addprofile=83',
		 camera:3,
		 paket:2
		},			
		{profile:2,
		 name:'Brillant-Design',
		 img:'/images/stories/profiles/rehau/rehau-brilliant-design-small.gif',
		 ref:'/rehau/brillant-design.html',
		 addToCart:'/order.html?addprofile=84',
		 camera:5,
		 paket:1
		},
		
		
		{profile:1,
		 name:'Softline',
		 img:'/images/stories/profiles/veka/veka-softline-small.gif',
		 ref:'/veka/softline.html',
		 addToCart:'/order.html?addprofile=75',
		 camera:3,
		 paket:1
		},
		{profile:1,
		 name:'Topline',
		 img:'/images/stories/profiles/veka/veka-topline-small.gif',
		 ref:'/veka/topline.html',
		 addToCart:'/order.html?addprofile=76', 
		 camera:3,
		 paket:1
		},
		{profile:1,
		 name:'Topline Plus',
		 img:'/images/stories/profiles/veka/veka-topline-plus-small.gif',
		 ref:'/veka/topline-plus.html',
		 addToCart:'/order.html?addprofile=77',
		 camera:3,
		 paket:1
		},
		{profile:1,
		 name:'Euroline',
		 img:'/images/stories/profiles/veka/veka-euroline-small.gif',
		 ref:'/veka/euroline.html',
		 addToCart:'/order.html?addprofile=78', 
		 camera:3,
		 paket:1
		},
		{profile:1,
		 name:'Sunline',
		 img:'/images/stories/profiles/veka/veka-sunline-small.gif',
		 ref:'/veka/sunline.html',
		 addToCart:'/order.html?addprofile=79',	 
		 camera:1,
		 paket:1
		},

		
		
		{profile:3,
		 name:'Favorit',
		 img:'/images/stories/profiles/thyssen/thyssen-favorit-small.gif',
		 ref:'/thyssen/favorit.html',
		 addToCart:'/order.html?addprofile=85',
		 camera:5,
		 paket:1
		},
		{profile:3,
		 name:'Bautec',
		 img:'/images/stories/profiles/thyssen/thyssen-bautec-small.gif',
		 ref:'/thyssen/bautec.html',
		 addToCart:'/order.html?addprofile=86',
		 camera:3,
		 paket:1
		},
		
		
		{profile:4,
		 name:'Design-3D',
		 img:'/images/stories/profiles/salamander/salamander-design-3d-small.gif',
		 ref:'/salamander/salamander-design-3d.html',
		 addToCart:'/order.html?addprofile=87',
		 camera:5,
		 paket:3
		},
		{profile:4,
		 name:'Streamline',
		 img:'/images/stories/profiles/salamander/salamander-streamline-small.gif',
		 ref:'/salamander/salamander-streamline.html',
		 addToCart:'/order.html?addprofile=88',
		 camera:5,
		 paket:3
		}		
				
	];

var pos_profiles = [
		{id:1,
		 name:"VEKA",
		 img:"/templates/okno777/images/veka-logo.gif",
		 ref:"/veka.html"
		},
		{id:2,
		 name:"REHAU",
		 img:"/templates/okno777/images/rehau-logo.gif",
		 ref:"/rehau.html"
		},
		{id:3,
		 name:"THYSSEN",
		 img:"/templates/okno777/images/thyssen-logo.gif",
		 ref:"/thyssen.html"
		},
		{id:4,
		 name:"SALAMANDER",
		 img:"/templates/okno777/images/salamander-logo.gif",
		 ref:"/salamander.html"
		}
	];


	
function pos_writePlace(){
	document.write('<div id="pos-fastselect"><div id="pos-header"></div><div id="pos-view"></div></div>');
	pos_repaintHeader();
	
	var lastVals = readCookie('pos-sel-c');
	if(lastVals){
		var mlastVals = lastVals.split('|');
		document.getElementById("pos-sel-profile").value = mlastVals[0];
		document.getElementById("pos-sel-camera").value = mlastVals[1];
		document.getElementById("pos-sel-paket").value = mlastVals[2];
	}
	pos_repaintTable();	
}

function onSelChange(){
	pos_repaintTable();
}

function pos_repaintTable(){
	var place = document.getElementById("pos-view");
	
	t = '<TABLE id="pos-sel-lines" cellspacing="0" cellpadding="0" border="1">';
	
	t += '<TR><TH colspan=3>Профиль</TH><TH title="Количество воздушных камер в конструкции профиля">Камер</TH><TH title="Максимальная ширина заполнения (стеклопакета)">Заполнение (max)</TH><TH>Действия</TH></TR>';
	
	var v_profile = parseInt(document.getElementById("pos-sel-profile").value);
	var v_camera  = parseInt(document.getElementById("pos-sel-camera").value);	
	var v_paket   = parseInt(document.getElementById("pos-sel-paket").value);

	if(v_profile==0&&v_camera==0&&v_paket==0){
	  eraseCookie('pos-sel-c');
	}else{
	  createCookie('pos-sel-c', v_profile+'|'+v_camera+'|'+v_paket, 7);
	}  
	var cntr = 0, lastProf = null;
	for(var i=0;i<pos_win.length;i++){
		if(!(v_profile == 0 || pos_win[i].profile == v_profile)) continue;
		if(!(v_camera == 0  || pos_win[i].camera  == v_camera)) continue;
		if(!(v_paket == 0 || v_paket == 1 || v_paket-1 <= pos_win[i].paket )) continue;		
		var currProfile = pos_profiles[pos_win[i].profile-1];
		t += '<TR class="pos-sel-line">';

		  //if(lastProf!=pos_win[i].profile){
			  t += '<TD class="pos-sel-it">';
			    t += '<A href="'+currProfile.ref+'"><IMG border="0" width="30" height="30" SRC="'+currProfile.img+'"></A>';
			  t += '</TD>';	
		  //}
		  t += '<TD class="pos-sel-it">';
		    t += '<A href="'+pos_win[i].ref+'"><IMG border="0" width="30" height="30" SRC="'+pos_win[i].img+'"></A>';
		  t += '</TD>';		  
		
		  t += '<TD class="pos-sel-it">';
		    t += '<A href="'+pos_win[i].ref+'">'+currProfile.name +" "+ pos_win[i].name+'</A>';
		  t += '</TD>';
		  
		  t += '<TD class="pos-sel-it pos-sel-it-v">';
		    t += pos_win[i].camera;
		  t += '</TD>';				  

		  t += '<TD class="pos-sel-it pos-sel-it-v">';
		    t += pos_steklopaket[pos_win[i].paket];
		  t += '</TD>';

		  if(currProfile.id == 4){
		  t += '<TD class="pos-sel-it pos-sel-it-v">';
		    t += '<A title="Переход в калькулятор, где можно рассчитать стоимость окна различной конфигурации из этого профиля." href="'+pos_win[i].addToCart+'">Рассчитать стоимость</A>';
		  t += '</TD>';
		  }
		  
		t += '</TR>';
		cntr ++;
	}	
	t += '</TABLE>';

	if(cntr==0){
		place.innerHTML = '<div id="pos-no">Нет профилей удовлетворяющих выбранным условиям</div>';
		return;
	}	
	place.innerHTML = t;	
}

function pos_repaintHeader(){
	var place = document.getElementById("pos-header");
	
	var t = "";
	
	t += '<TABLE id="pos-tab-header"><TR>';
	
	t += '<TD>Профиль:<br><SELECT id="pos-sel-profile" onchange="onSelChange()">';
	t += '<OPTION value="0">--- Любой ---</OPTION>';
	for(var i=0;i<pos_profiles.length;i++){
		var sel = pos_profiles[i].sel?'selected="selected"':'';
		t += '<OPTION '+sel+' value="'+pos_profiles[i].id+'">'+pos_profiles[i].name+'</OPTION>';
	}
	t += '</SELECT></TD>';

	t += '<TD>Кол-во камер:<br><SELECT id="pos-sel-camera" onchange="onSelChange()">';
	t += '<OPTION value="0">--- Любое ---</OPTION>';
	t += '<OPTION value="3">3</OPTION>';
	//t += '<OPTION value="4">4</OPTION>';
	t += '<OPTION value="5">5</OPTION>';			
	t += '</SELECT></TD>';	

	t += '<TD>Ширина заполнения:<br><SELECT id="pos-sel-paket" onchange="onSelChange()">';
	t += '<OPTION value="0">--- Любая ---</OPTION>';
	for(var i=0;i<pos_steklopaket.length;i++){
		t += '<OPTION value="'+(i+1)+'">'+pos_steklopaket[i]+'</OPTION>';
	}
	t += '</SELECT></TD>';		
	
	t += '</TR></TABLE>';
	
	place.innerHTML = t;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}




function pos_listConfigs(idProfile){
	document.write('---');
}
