





function send1(){
document.getElementById("buttons_send").style.display='none';
document.getElementById("inquiry_send").style.display='inline';
}

function close_send1(){
document.getElementById("buttons_send").style.display='inline';
document.getElementById("inquiry_send").style.display='none';
}

function send2(){
document.getElementById("buttons_send").style.display='none';
document.getElementById("friend_send").style.display='inline';
}

function close_send2(){
document.getElementById("buttons_send").style.display='inline';
document.getElementById("friend_send").style.display='none';
}


function ptype1(){
document.getElementById("btn_order1").style.display='inline';
document.getElementById("btn_order2").style.display='none';
}


function ptype2(){
document.getElementById("btn_order1").style.display='none';
document.getElementById("btn_order2").style.display='inline';

}


function opengallery(imageis){

var open="gallery.php?img="+imageis;
var heightis=screen.height-60;
window.open(open,'ga','scrollbars=1,width=696,height='+heightis+',screenX=0,screenY=0,top=0,left=0');

}

function writeopinion(diris){

var open="writeopinion.php?dir="+diris;
var heightis=screen.height-60;
window.open(open,'gaga','scrollbars=1,width=696,height='+heightis+',screenX=0,screenY=0,top=0,left=0');

}

function sendafriend(diris){

var open="sendafriend.php?dir="+diris;
var heightis=screen.height-60;
window.open(open,'gago','scrollbars=1,width=696,height='+heightis+',screenX=0,screenY=0,top=0,left=0');

}

function opencatalog(imageis){

var open="imgcatalog.php?img="+imageis;

window.open(open,'gal','scrollbars=0,width=640,height=480,screenX=0,screenY=0,top=0,left=0');

}



function getSelectedRadio(buttonGroup) {
   
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return true;
         }
      }
   } else {
      if (buttonGroup.checked) { return true; } 
   }

   return false;
} 


function check_form1(){
			df=document.order;


if(!getSelectedRadio(df.ptype)){
alert("Моля изберете метод на плащане");
df.ptype[0].focus();
return false;
}

			
if (!df.agreement.checked){
alert("Моля отбележете прочетохте/съгласни ли сте с \"Правилата и условията на този онлайн магазин\"?");
df.agreement.focus();
return false;
}
		
			if (df.client_name.value.length==0){
				alert('Моля попълнете поле \"Име, Презиме, Фамилия\"');
				df.client_name.focus();
				return false;
			}

               
			
			if (df.client_place.value.length==0){
				alert('Моля попълнете поле \"Населено място (град,село)\"');
				df.client_place.focus();
				return false;
			}
			
			if (df.client_address.value.length==0){
				alert('Моля попълнете поле \"Точен адрес за доставка (жк,бул.,ул.,№,бл.,ет.,ап.)\"');
				df.client_address.focus();
				return false;
			}
			if (df.client_phone.value.length==0){
				alert('Моля попълнете поле \"Телефон за връзка (по възможност мобилен)\"');
				df.client_phone.focus();
				return false;
			}

			
			if (df.client_email.value.length==0){
				alert('Моля попълнете поле \"E-mail\"');
				df.client_email.focus();
				return false;
			}
			var filter=/^.+@.+\..{2,3}$/
  			if (df.client_email.value.length>0 && !filter.test(df.client_email.value)) {
				alert('Моля попълнете валиден \"E-mail\"');
				df.client_email.select();
				return false;
			}


return true;

	}	









function check_number(poleto,the_product,the_dir){
// only allow numbers to be entered
var checkOK = "0123456789";
var count_e=eval("document.basket."+poleto);
var checkStr = count_e.value;
var allValid = true;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid||checkStr==0)
{
//alert("Please enter only digit characters in the \"numbers\" field.");
//theForm.numbers.focus();
return (false);
}
else{
var gobasket="basket.php?action=addtobasket&product_add="+the_product+"&dir="+the_dir+"&product_count="+checkStr;
window.location.href=gobasket;
}


}



function check_number_order(poleto,the_product){
// only allow numbers to be entered
var checkOK = "0123456789";
var count_e=eval("document.order."+poleto);
var checkStr = count_e.value;
var allValid = true;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid||checkStr==0)
{
//alert("Please enter only digit characters in the \"numbers\" field.");
//theForm.numbers.focus();
return (false);
}
else{
var gobasket="order.php?action=addtobasket&product_add="+the_product+"&product_count="+checkStr;
window.location.href=gobasket;
}


}




function plus(){

document.getElementById("count_product").innerHTML='Имате <b> '+count_p+' </b> продукта в кошницата';
document.getElementById("totalprice_products").innerHTML='Текущата Ви сметка е <b> '+total_pr.toFixed(2)+' </b> лв.';

}


function addtobasket(name,value){
document.cookie=name+"="+value;



alert("Този продукт беше добавен във Вашата кошница!");
plus2(value);
}





function change_count_product(name,price){

var form_basket=document.basket;

var price_is="price_"+name;
var count_this="count_"+name;
var count_e=eval("form_basket."+count_this);
var all_price=(price*count_e.value).toFixed(2);

document.getElementById(price_is).innerHTML=all_price;



name1="count_products";
value1=parseFloat(count_p)+parseFloat(count_e.value);
document.cookie=name1+"="+value1;
if(count_p==1){
document.getElementById("count_product").innerHTML='Имате <b> '+value1+' </b> продукт в кошницата';
}
else{
document.getElementById("count_product").innerHTML='Имате <b> '+value1+' </b> продукта в кошницата';
}



total_pr=parseFloat(total_pr)+parseFloat(all_price);
document.getElementById("totalprice_products").innerHTML='Текущата Ви сметка е <b> '+total_pr.toFixed(2)+' </b> лв.';
name2="totalprice_products";
value2=total_pr;
document.cookie=name2+"="+value2;





}







function plus2(price){

count_p++;
name1="count_products";
value1=count_p;
document.cookie=name1+"="+value1;
if(count_p==1){
document.getElementById("count_product").innerHTML='Имате <b> '+count_p+' </b> продукт в кошницата';
}
else{
document.getElementById("count_product").innerHTML='Имате <b> '+count_p+' </b> продукта в кошницата';
}


total_pr=parseFloat(total_pr)+parseFloat(price);
document.getElementById("totalprice_products").innerHTML='Текущата Ви сметка е <b> '+total_pr.toFixed(2)+' </b> лв.';
name2="totalprice_products";
value2=total_pr;
document.cookie=name2+"="+value2;
}



function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}





function addtobasketdetails(name,value){
document.cookie=name+"="+value;


window.opener.location.href=window.opener.location.href;
}


function deletebasket(name,price) { 

var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
value="";
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();



count_p--;
name1="count_products";
value1=count_p;
document.cookie=name1+"="+value1;
if(count_p==1){
document.getElementById("count_product").innerHTML='Имате <b> '+count_p+' </b> продукт в кошницата';
}
else{
document.getElementById("count_product").innerHTML='Имате <b> '+count_p+' </b> продукта в кошницата';
}


total_pr=parseFloat(total_pr)-parseFloat(price);
document.getElementById("totalprice_products").innerHTML='Текущата Ви сметка е <b> '+total_pr.toFixed(2)+' </b> лв.';
name2="totalprice_products";
value2=total_pr;
document.cookie=name2+"="+value2;



window.location.href='basket.php';





}



function deletebasketsend(name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
value="";
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
}

function submitorder(){
document.orderok.submit();
}

function deleteorder(name,value) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
value="";
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
window.location.href=window.location.href;
}




function fulldetails(table,rowid){

var open="fulldetails.php?tableid="+table+"&rowid="+rowid;

window.open(open,'fulldetails','width=600,height=400,scrollbars=1,screenX=200,screenY=150,top=150,left=200');

}


function forget(){



window.open('forget.php','forget','width=400,height=200,scrollbars=0,screenX=200,screenY=150,top=150,left=200');

}


function viewbasket(){
window.open('basket.php','basket','width=600,height=400,scrollbars=1,screenX=200,screenY=150,top=150,left=200');
}


function check_search(){
df=document.search;

			if (df.search.value.length==0||df.search.value.length<2){
				alert("Please enter word of phrase !");
				df.search.focus();
				return false;
			}

}

function order(name,value){

document.cookie=name+"="+value;
alert('If you a new customer please create an account with us or if you already have one please sign in');
}

function addtobasketorder(name,value){
document.cookie=name+"="+value;


window.location.href='order.php';
}