function new_window(url, win_name){
	win_name=window.open(url,'win_name','toolbar=no,scrollbars=yes,resizable=yes,width=450,height=260,status=no,left=100,top=100,screenX=100,screenY=100,status=no')
	win_name.focus()
}

function pic_win(url,wintitle){
	picwin=window.open('http://knigi.biz/image.php?pic='+url+'&name='+wintitle,'picwin','toolbar=no,scrollbars=no,width=620,height=485,left=100,top=100,screenX=100,screenY=100,status=no');
	picwin.focus();
}

function converter_popup(){
	win_name=window.open("html/windconverter.html",win_name,'toolbar=no,scrollbars=yes,resizable=yes,width=250,height=200,status=no,left=0,top=0,screenX=0,screenY=0')
	win_name.focus()
}

function print_window(url){
	printwin=window.open(url,'printwin','toolbar=no,scrollbars=yes,width=800,height=480')
	printwin.focus()
}

function print_page(){
	window.print();
//	window.close();
}

function window_resize(pic){
	x=document.images.pic.width + 10
	y=document.images.pic.height + 5
	window.width=x
	window.height=y
}

function hilite(elementname,color){
	if (document.all){
		document.all[elementname].bgColor=color;
	}
	else{
		document.getElementById(elementname).bgColor=color;
	}
}

function wishToReceive(){
var f_obj=document.regForm;
if(f_obj.wish_f.checked==true){
	sel_flg=true;
	document.getElementById("cat_box").style.color="#000";
	document.getElementById("cat_box2").style.color="#000";
	f_obj.choose_section[0].checked=true;
}else{
	sel_flg=false;
	document.getElementById("cat_box").style.color="#666";
	document.getElementById("cat_box2").style.color="#666";
	f_obj.choose_section[0].checked=false;
	f_obj.choose_section[1].checked=false;
	}
}

function clear_cat(){
var f_obj=document.regForm;
document.getElementById("cat_box2").length=1
document.getElementById("cat_box2").options[0]=null
}

function add_all_cat(){
var f_obj=document.regForm;
clear_cat();
if(sel_flg)for(q=0;q<=f_obj.list.length-1;q++){
	document.getElementById("cat_box2").options[q]=new Option();
	document.getElementById("cat_box2").options[q].value=document.getElementById("cat_box").options[q].value;
	document.getElementById("cat_box2").options[q].text=document.getElementById("cat_box").options[q].text;
	document.getElementById("cat_box2").options[q].selected=true;
	}
}

function add_cat(){
var f_obj=document.regForm;		
var len=document.getElementById("cat_box2").length
for(i=0;i<=document.getElementById("cat_box").length-1;i++){
	if(document.getElementById("cat_box").options[i].selected&&sel_flg){
		var flag=true;
		if(len>0)for(t=0;t<=len-1;t++)if(document.getElementById("cat_box").options[i].value==document.getElementById("cat_box2").options[t].value)flag=false;
		if(flag){
		document.getElementById("cat_box2").options[len]=new Option();
		document.getElementById("cat_box2").options[len].value=document.getElementById("cat_box").options[i].value;
		document.getElementById("cat_box2").options[len].text=document.getElementById("cat_box").options[i].text;
		document.getElementById("cat_box2").options[len].selected=true;
		len++;
		}
	}
	if(document.getElementById("cat_box").options[i].selected)document.getElementById("cat_box").options[i].selected=false;
}
}

function rmv_cat(){
	var f_obj=document.regForm;		
		for(i=document.getElementById("cat_box2").length-1;i>=0;i--)if(document.getElementById("cat_box2").options[i].selected){document.getElementById("cat_box2").options[i]=null;}
		if(!f_obj.choose_section[1].checked)f_obj.choose_section[1].checked=true;
}

function sel_country(val){
if(val!="BG"){
	document.getElementById("town_bg").style.display = 'none';
	document.getElementById("town").style.display = 'inline';
}else{
	document.getElementById("town_bg").style.display = 'inline';
	document.getElementById("town").style.display = 'none';
	}
}

function showPane(paneId, activeTab) {

 	if(paneId=='pane1'){
	      document.getElementById("pane1").style.display = "block";
	      document.getElementById("tab1").style.backgroundColor = "#cccccc";
	      document.getElementById("pane2").style.display = "none";
	      document.getElementById("tab2").style.backgroundColor = "transparent";
	}else{
	      document.getElementById("pane2").style.display = "block";
	      document.getElementById("tab2").style.backgroundColor = "#cccccc";
	      document.getElementById("pane1").style.display = "none";
	      document.getElementById("tab1").style.backgroundColor = "transparent";
	}

}

function rateOver(rating) {
	var rateImage = document.getElementById('ratingstars');
	//for(prop in rateImage) if(!confirm(prop + ' = ' + rateImage[prop])) break;
	if(rateImage){
		rateImage.src = design + rating + '-stars.gif';
	}
}

function rateOut() {
	var rateImage = document.getElementById('ratingstars');
	if(rateImage){
		rateImage.src = design + userRating + '-stars.gif';
	}
}

function rankProduct(productid, rating) {
   ajax.getData('ajax.php?act=rateProduct&productid=' + productid + '&rating=' + rating,function(xmlhttp) {
       if ( xmlhttp.readyState == 4 ) {
         if (xmlhttp.status == 200) {
               var results = xmlhttp.responseText.split(';');
               //alert(xmlhttp.responseText);
               var rank = results[0];
               var votes = results[1];
               userRating = rank;
			   rateOut();
               document.getElementById("ratingstars").src = design + Math.round(parseFloat(rank)) + '-stars.gif';
               document.getElementById("votes").innerHTML = votes;
         }
      }
   });
}

function total(id){
	if (document.all){
		document.all['all_suma'].firstChild.nodeValue=id.toFixed(2) + 'лв.';
	}
	else{
		document.getElementById('all_suma').firstChild.nodeValue=id.toFixed(2)+ 'лв.';
	}
}
function total_get(){
	if (document.all){
		rez=document.all['all_suma'].firstChild.nodeValue;
	}
	else{
		rez=document.getElementById('all_suma').firstChild.nodeValue;
	}
	return rez;
}
function uncheck_post(){
		var all=parseFloat(total_get());
		total(all);
}

function change_post(){
	if(document.sales.delivery[0].checked){
		var all=parseFloat(document.sales.sum_all_price.value);
		var box1=parseFloat(document.sales.post_dost.value);
		var box2=parseFloat(document.sales.post_prepor.value);
		document.sales.payment[3].checked=false;
		document.sales.delivery[1].checked=false;
		total(all+box1+box2);
	}
	else{
	    var all=parseFloat(document.sales.sum_all_price.value);
		total(all);
	}
}

function change_post_suma(button_name){
	if(button_name=='post_dost'){
		if(document.sales.post_dost.checked){
			var box=parseFloat(document.sales.post_dost.value);
			var all=parseFloat(document.sales.sum_all_price.value);
//			document.sales.all_suma.value=all+box;
			total(all+box);
		}else{
//			document.sales.post_dost.checked=false;
			var all=parseFloat(document.sales.sum_all_price.value);
			// document.sales.all_suma.value=all;
			total(all);
//			document.sales.post_prepor.checked=false;
//			document.sales.post_platej.checked=false;
		}
	}
	if(button_name=='post_prepor'){
		if(document.sales.post_prepor.checked){
			var box=parseFloat(document.sales.post_prepor.value);
			var all=parseFloat(total_get());
//			document.sales.all_suma.value=all+box;
			total(all+box);
		}else{
			document.sales.post_prepor.checked=false;
			var box=parseFloat(document.sales.post_prepor.value);
			var all=parseFloat(total_get());
//			var all=parseFloat(document.sales.all_suma.value);
//			document.sales.all_suma.value=all-box;
			total(all-box);
		}
	}
}
function change_postplatej(){
	if(document.sales.post_platej.checked){
		
		document.sales.post_dost.checked=false;
		document.sales.post_prepor.checked=false;

		var all=parseFloat(document.sales.sum_all_price.value);
			total(all);
		document.sales.speedy_dost.checked=false;
		document.sales.speedy_dost.disabled=true;

	}
	else{
		document.sales.speedy_dost.checked=false;
		document.sales.speedy_dost.disabled=true;
		document.sales.post_dost.checked=true;
		document.sales.post_prepor.checked=true;
		var all=parseFloat(document.sales.sum_all_price.value);
		var box1=parseFloat(document.sales.post_dost.value);
		var box2=parseFloat(document.sales.post_prepor.value);
		total(all+box1+box2);
	}
}
function check_speedy(){
//		document.sales.speedy.checked=true;
		document.getElementById('delivery_speedy').checked=true;
		var all=parseFloat(document.sales.sum_all_price.value);
		var box=parseFloat(document.sales.speedy_dost.value);
		total(all+box);
		document.sales.payment[2].checked=true;
}
function change_speedy(){
	if(document.getElementById('delivery_speedy').checked){
		var all=parseFloat(document.sales.sum_all_price.value);
		var box=parseFloat(document.sales.speedy_dost.value);
		total(all+box);
		document.sales.payment[2].checked=true;
	}else{
	    var all=parseFloat(document.sales.sum_all_price.value);
		document.sales.payment.checked=false;
		total(all);
	}
}
function change_speedy_suma(button_name){
	if(button_name=='speedy_dost'){
		if(document.sales.speedy_dost.checked){
			var box=parseFloat(document.sales.speedy_dost.value);
			var all=parseFloat(document.sales.sum_all_price.value);
			total(all+box);
		}else{
			document.sales.speedy_dost.checked=false;
			var all=parseFloat(document.sales.sum_all_price.value);
			total(all);
		}
	}
}


