var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_nav45up = (is_nav && (is_minor >= 4.5));
    var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav5 = (is_nav && (is_major == 5));
    var is_nav5up = (is_nav && (is_major >= 5));
    var is_nav7down = false;
    var is_nav7 = false;
    var is_nav6 = false;
    var is_nav6_0 = false;
    var is_mozilla = false;
    var netscapeVerRegex = new RegExp();
    if(is_nav4up)
    {
    	is_nav7down = true;
    	netscapeVerRegex.compile("([.])*netscape([^/])*/", "gi");
    	var info = netscapeVerRegex.exec(agt);
    	if(info != null)
    	{
	    	var nav_major = parseInt(agt.substr(netscapeVerRegex.lastIndex));
	    	var nav_minor = parseFloat(agt.substr(netscapeVerRegex.lastIndex));
	    	is_nav7down = nav_major < 7;
	    	is_nav7 = nav_major == 7;
	    	is_nav6 = nav_major == 6;
	    	is_nav6_0 = nav_minor == 6.0;
	    }
	  	else if(is_nav5up)
	  	{
	  		is_mozilla = true;
	  		is_nav7down = false;
	  	}
    }

    var is_ie   = (agt.indexOf("msie") != -1);
    var is_ie3  = (is_ie && (is_major < 4));
    var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
    var is_ie4up  = (is_ie  && (is_major >= 4));
    var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
    var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0")!=-1) );

    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_webtv = (agt.indexOf("webtv") != -1);

   



var isNetscape=((navigator.userAgent.toLowerCase().indexOf('mozilla')!=-1)&&
         (navigator.userAgent.toLowerCase().indexOf('spoofer')==-1)&&
         (navigator.userAgent.toLowerCase().indexOf('compatible')==-1));


function showElement(element_id) {
   if (document.layers){
     eval("document."+element_id).visibility="visible";
   }
   if (document.all){
       eval("document.all."+element_id).style.visibility="visible";
   }
   if (isNetscape && document.getElementById &&
         document.getElementById(element_id) &&
         document.getElementById(element_id).style){
         
             document.getElementById(element_id).style.visibility="visible";
   }
}

function hideElement(element_id) {

   if (document.layers){
     eval("document."+element_id).visibility="hidden";
   }
   if (document.all){
       eval("document.all."+element_id).style.visibility="hidden";
   }
   if (isNetscape && document.getElementById &&
         document.getElementById(element_id) &&
         document.getElementById(element_id).style){
         
              document.getElementById(element_id).style.visibility="hidden";
   }
}


function showHelpWindow(page){
	var	wnd=null;
	var	w = 600;
	var	h = 700;
	wnd=window.open('','Help',
	'scrollbars=1,toolbar=0,location=0,menubar=0,dirctories=0,status=0,resizable=1'+
	',top=50,left=50'+
	',width=' + w +
	',height=' + h +
	''
	);
	wnd.location.href = page;
	wnd.focus(1);
}

var digits="0123456789";
var phone="+ 0123456789-/()";
var letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"абвгдежзийклмнопрстуфхцчшщъьщюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ'";
var punctuation="!?()-/,.\"\';:";
var other="@#&*%$";
function isInvalidValue(value,pattern){
	ferror=false;
    for (i=0;i<value.length;i++){
        if (pattern.indexOf(value.charAt(i))==-1){
             ferror=true;
             break;
        }
    }

	return ferror;
}

function isInt(value){
    return !isInvalidValue(value,digits);
}

function isPhone(value){
    return !isInvalidValue(value,phone);
}

function isName(value){
    return !isInvalidValue(value,letters+" ");
}
function isString(value){
    return !isInvalidValue(value,letters+" "+digits+punctuation+other);
}
function empty(field,fieldName){
        alert("Попълването на полето '"+fieldName+"' е задължително!\n Моля попълнете това поле!");
        field.focus();
		field.select();
		return true;
}
function invValue(field,fieldName){
        alert("Полето '"+fieldName+"' съдържа невалидна стойност!\n Моля коригирайте стойността в това поле!");
        field.focus();
		field.select();
		return true;
}

function getRadioValue(radio){
	for (i=0;i<radio.length;i++){
	    if (radio[i].checked){
	        return radio[i].value;	
	    }
	}
}

var isSelected=false;

function selected(){
    isSelected=true;
}
function deselected(){
    isSelected=false;
}

function changeQuantity(id,newQuantity) {
	f = document.orderForm;
	errorFounded = false;
	for (i=0;i<newQuantity.length;i++){
	    if (digits.indexOf(newQuantity.substr(i,1))==-1){
			errorFounded=true;
            alert("Моля, въведете стойност между 1 и 99.");
            return false;
		}
	}
	document.location = 'set.php?id='+id+'&qty='+newQuantity;	
}

function keyPress(id,keyCode,value) {

	if ((keyCode>=48)&(keyCode<=57)){
	    if (isSelected){
	         changeQuantity(id,""+digits.charAt(keyCode-48));
	    }
	    else {
	        changeQuantity(id,value+""+digits.charAt(keyCode-48));
	    }
	}
	
}