function add(add_id,href)
{
	if (q=prompt('Введіть назву.',''))
	{
		window.location=href+'/add/'+add_id+'/'+q;
	}
}

function edit(name_tree,edit_id,href)
{
	if (q=prompt('Введіть нову назву.',name_tree))
	{
		window.location=href+'/edit/'+edit_id+'/'+q;
	}
}

function del(del_id,href)
{
	if (confirm("Ви дійсно хочете видалити цю позицію?"))
	{
		window.location=href+'/del/'+del_id;		
	}
}

function red(href)
{
		window.location=href+'';
}



function charge()
{
  actshop = new Image();
  actshop.src = "image/allshops-but.gif";
  onshop = new Image();
  onshop.src = "image/allshops-but-on.gif";
}
charge();


function show_hide(id)
{
		if (document.getElementById(id).style.display == 'none')
		{
			document.getElementById(id).style.display='';
		}
		else
		{
			document.getElementById(id).style.display='none';
		}
}

function confirm_to(href)
{
	if (confirm('Вы действительно хотите удалить?'))
	{
		window.location=href;		
	}
}


function loadDateOfBirth(mode) {    
    var day = document.getElementById("dayOfBirth");
    var month = document.getElementById("monthOfBirth");
    var year = document.getElementById("yearOfBirth");
    var dateOfBirth = document.getElementById("dateOfBirth");    
    
    // Get Current Year
    var time = new Date();
    var currYear = time.getFullYear();
    var thisYear = time.getFullYear()+5;
    
    
    var daysInMonth=0;
    var totalMonths=12;
    var totalYears=10;
    
    // Prepare Year Dropdown
    year.options.length=totalYears+1;
    year.options[0].value=-1;
    year.options[0].text="Год";
    for (var i=1; i<=totalYears; i++,thisYear--) {
        year.options[i].value=thisYear;
        year.options[i].text=thisYear;
    }
    
    // Prepare Month Dropdown
    month.options.length=13;
    month.options[0].value=-1;
    month.options[0].text="Месяц";
    month.options[1].value=1;
    month.options[1].text="Январь";
    month.options[2].value=2;
    month.options[2].text="Февраль";
    month.options[3].value=3;
    month.options[3].text="Март";
    month.options[4].value=4;
    month.options[4].text="Апрель";
    month.options[5].value=5;
    month.options[5].text="Май";
    month.options[6].value=6;
    month.options[6].text="Июнь";
    month.options[7].value=7;
    month.options[7].text="Июль";
    month.options[8].value=8;
    month.options[8].text="Август";
    month.options[9].value=9;
    month.options[9].text="Сентябрь";
    month.options[10].value=10;
    month.options[10].text="Октябрь";
    month.options[11].value=11;
    month.options[11].text="Ноябрь";
    month.options[12].value=12;
    month.options[12].text="Декабрь";
    
    var od = 0;
    var om = 0;
    var oy = 0;
    if (mode == 1 && dateOfBirth) {
        // We need to parse dateOfBirth and reset value for
        // day, month, year select list
        var dob = dateOfBirth.value;
        var dobLen = dob.length;
        if (dobLen>0) {
            var dateOfBirthArr=dob.split("/");  
            om=dateOfBirthArr[0];
            od=dateOfBirthArr[1];
            oy=dateOfBirthArr[2];          
            oy = (currYear - oy) + 1;           
            month.options.selectedIndex=om;
            year.options.selectedIndex=oy;          
        }
    }
        
    var monthValue = month.value;
    if (year.value > 0 && monthValue > 0) {
        if (monthValue==2) {
            if (year.value % 4 != 0) {
                daysInMonth=28;
            } else if  (year.value % 400 == 0) {
                daysInMonth=29;
            } else if (year.value % 100 == 0) {
                daysInMonth=28;
            } else {
                daysInMonth=29;
            }        
        } else if (monthValue==1 || monthValue==3 || monthValue==5 || 
                   monthValue==7 || monthValue==8 || monthValue==10 || monthValue==12) {
            daysInMonth=31;
        } else {
            daysInMonth=30;
        }
    }                
    day.options.length=daysInMonth+1;
    day.options[0].value=-1;
    day.options[0].text="День";
    for (var i=1; i<=daysInMonth; i++) {
        day.options[i].value=i;
        day.options[i].text=i;
    }    
    
    if (mode == 1 && od > 0) {
        day.options.selectedIndex=od;
    }
    
    // Prepare dateOfBirth
    if (year.value > 0 || month.value > 0 || day.value > 0) {        
        dateOfBirth.value = month.value + "/" + day.value + "/" + year.value;        
    } else {
        dateOfBirth.value="";
    }
}



function check_email(e) {
			ret = false;
			inp = document.getElementById(e);
			e = inp.value;
			if (e != '')
			{
				ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
				for(i=0; i < e.length; i++){
					if(ok.indexOf(e.charAt(i))<0){
						ret = true;
					}
				}
				if (ret == true)
				{
					alert('Вы ввели недопустимый email');
						inp.focus();
						inp.select();
				}
			}
}
			
			
function check_site(s) {
			ret = false;
			inp = document.getElementById(s);
			s = inp.value;
			if (s != '')
			{
				ok = "1234567890qwertyuiopasdfghjklzxcvbnm.-_QWERTYUIOPASDFGHJKLZXCVBNM";

				for(i=0; i < s.length; i++){
					if(ok.indexOf(s.charAt(i))<0){
						ret = true;
					}
				}
				if (ret == true)
				{
					alert('Вы ввели недопустимый сайт');
						inp.focus();
						inp.select();
				}
			}
}



function img_set(id,img,idcur)
{
	document.getElementById(id).src = img;
	
	document.getElementById('aimg1').bgColor = '#FFFAEE';
	document.getElementById('aimg2').bgColor = '#FFFAEE';
	document.getElementById('aimg3').bgColor = '#FFFAEE';
	document.getElementById('aimg4').bgColor = '#FFFAEE';
	document.getElementById('aimg5').bgColor = '#FFFAEE';
	document.getElementById('aimg6').bgColor = '#FFFAEE';
	document.getElementById('aimg7').bgColor = '#FFFAEE';
	document.getElementById('aimg8').bgColor = '#FFFAEE';
	
	document.getElementById(idcur).bgColor = '#FF7905';
}


function maxlength(max,text)
{
	count = text.value.length;
	if (count > max)
	{
		alert('Количество символов больше '+max);
	}
}


function set_inp(id,set)
{
	document.getElementById(id).value = set;
	alert('Установлено!');
}



function show_hide_map(id)
{
		document.getElementById('1stage').style.display = 'none'
		document.getElementById('2stage').style.display = 'none'
		document.getElementById('3stage').style.display = 'none'
	
		if (document.getElementById(id).style.display == 'none')
		{
			document.getElementById(id).style.display='';
		}
		else
		{
			document.getElementById(id).style.display='none';
		}
}


function popup(mylink, windowname)
{
	window.open(mylink, windowname, 'width=800,height=600,scrollbars=yes');
}
