function GetInputValue(url,containerid,obj)
{
    //alert(url+document.getElementsByName("captchainput")[0].value+containerid);
    ajaxpage(url+document.getElementsByName("captchainput")[0].value, containerid);  
}
function CheckBoxsetChecked(obj)
{
	var check = document.getElementsByName("chekboxcart");
	for (var i=0; i<check.length; i++)
	{check[i].checked = true;}	     
}
function CheckBoxsetUnChecked(obj) 
{
	var check = document.getElementsByName("chekboxcart");
	for (var i=0; i<check.length; i++)
	{check[i].checked = false;}
}
function CheckBoxSetDel(url,containerid,obj)
{
	var check = document.getElementsByName("chekboxcart");
	var querystring='';
	for (var i=0; i<check.length; i++)
	{if (check[i].checked==true){querystring=querystring+check[i].value+',';}}
	if (querystring!=='') {querystring='?ids='+encodeURIComponent(querystring=querystring.slice(0, querystring.length-1))}
    ajaxpage(url+querystring+'&korzinaidsoper=-1', containerid);
}
function karzinaappend(url,containerid,obj)
{
var radios = document.getElementsByTagName('input');
var iscolor=0;
var iscolor_checked=0;
var urladd='';
for (var i = 0; i < radios.length; i++) {
    if (radios[i].type === 'radio' && radios[i].name === 'radioName') {
        //
        if (radios[i].checked){iscolor_checked = 1;urladd='&tovaricolorvalue='+radios[i].value;}
        iscolor = 1;      
        }
    }	
    if (iscolor==0) {ajaxpage(url, containerid);} else {if (iscolor_checked==0){alert ('Не выбран цвет приобретаемого телефона!');} else {ajaxpage(url+urladd, containerid);};}
}
function CheckAdress(url,containerid,obj)
{
	if (document.getElementById("korzina_fio").value=='')
    {
        alert('Не указаны Фамилия, Имя, Отчество');
        document.getElementById("korzina_fio").focus();
            
    } else
    {
        if (document.getElementById("korzina_adress_index").value=='')
        {
            alert('Не указан почтовый индекс');
            document.getElementById("korzina_adress_index").focus();
            
        } else
        {
            if (document.getElementById("korzina_region").value==0 && !(document.getElementById("korzina_adress_city").value=='Москва' || document.getElementById("korzina_adress_city").value=='Санкт-Петербург'))
            {
                alert('Не указан регион');
                document.getElementById("korzina_region").focus();
            
            } else
            {
                if (document.getElementById("korzina_adress_city").value=='')
                {
                    alert('Не указан город');
                    document.getElementById("korzina_adress_city").focus();
            
                } else
                {
                if (document.getElementById("korzina_adress_city").value=='Санкт-Петербург' || document.getElementById("korzina_adress_city").value=='Москва') {document.getElementById("korzina_region").value==0}     
                    if (document.getElementById("korzina_adress_st").value=='')
                    {
                        alert('Не указана улица');
                        document.getElementById("korzina_adress_st").focus();
            
                    } else
                    {
                        if (document.getElementById("korzina_adress_dom").value=='')
                        {
                            alert('Не указан дом');
                            document.getElementById("korzina_adress_dom").focus();
            
                        } else
                        {
                            if (document.getElementById("korzina_email").value=='')
                            {
                                alert('Не указан E-mail');
                                document.getElementById("korzina_email").focus();
            
                            } else
                            {
                                var phone=document.getElementById("korzina_mphone").value
                                if (phone=='' || phone.length > 12 || phone.length < 11 )
                                {
                                    alert('Не указан, или не коректно указан контактный телефон');
                                    document.getElementById("korzina_mphone").focus();
            
                                } else
                                {
querystring='&korzina_fio='+encodeURIComponent(document.getElementById("korzina_fio").value);
querystring=querystring+'&korzina_adress_index='+encodeURIComponent(document.getElementById("korzina_adress_index").value);
querystring=querystring+'&korzina_region='+encodeURIComponent(document.getElementById("korzina_region").value);
querystring=querystring+'&korzina_adress_city='+encodeURIComponent(document.getElementById("korzina_adress_city").value);
querystring=querystring+'&korzina_adress_st='+encodeURIComponent(document.getElementById("korzina_adress_st").value);
querystring=querystring+'&korzina_adress_dom='+encodeURIComponent(document.getElementById("korzina_adress_dom").value);
querystring=querystring+'&korzina_adress_kv='+encodeURIComponent(document.getElementById("korzina_adress_kv").value);
querystring=querystring+'&korzina_adress_kom='+encodeURIComponent(document.getElementById("korzina_adress_kom").value);
querystring=querystring+'&korzina_email='+encodeURIComponent(document.getElementById("korzina_email").value);
querystring=querystring+'&korzina_mphone='+encodeURIComponent(document.getElementById("korzina_mphone").value);
querystring=querystring+'&korzina_adress_rayon='+encodeURIComponent(document.getElementById("korzina_adress_rayon").value);
ajaxpage('loading.php','what_get_shipp');
ajaxpage(url+querystring, containerid);                    
                                }   
                            }
                        }                
                    }
                } 
            }
        }    
    }

}

function gotofinal(url,containerid,obj)
{
var radios = document.getElementsByTagName('input');
var iscolor_checked=0;
var urladd='';
for (var i = 0; i < radios.length; i++) {
    if (radios[i].type === 'radio' && radios[i].name === 'radioNamePay') {
        //
        if (radios[i].checked){iscolor_checked = 1;urladd='&paying_id='+encodeURIComponent(radios[i].value);}    
        }
    }	
    if (iscolor_checked==0){alert ('Не выбран метод оплаты!');} else {ajaxpage(url+urladd, containerid);}
}

function gotopay(url,containerid,obj)
{
var radios = document.getElementsByTagName('input');
var iscolor_checked=0;
var urladd='';
for (var i = 0; i < radios.length; i++) {
    if (radios[i].type === 'radio' && radios[i].name === 'radioNameShipp') {
        //
        if (radios[i].checked){iscolor_checked = 1;urladd='&shipping_id='+radios[i].value;}    
        }
    }	
    if (iscolor_checked==0){alert ('Не выбрана служба доставки!');} else {ajaxpage(url+urladd, containerid);}
}

function OpenImagePopup(imgPath, title, alt) {
    var win = window.open('','preview',
    'width=50,height=50,left=0,top=0,screenX=0,screenY=0,resizable=1,scrollbar=0,status=0');
    
    var winDoc = win.document;
    if (title == undefined) title = 'My Image, Click to Close';
    if (alt   == undefined) alt   = 'My Image, Click to Close';
    var content = '<html><head><title>' + title + '</title>' +
    			  '<style>body{overflow: hidden;margin:0;}img{border:0;}</style>' +
    			  '</head><body><a href="javascript:self.close()">' +
    			  '<img alt="' + alt + '" id="image" src="imgshow.php?imgfilename=' + imgPath + '" /></a></body></html>'
    win.document.write(content);
    
    winDoc.body.onload = function() {
    	var obj = winDoc.getElementById('image');
    	var w = obj.width, h = obj.height;
    	var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
    	
    	var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
    	var top =  (self.opera ? iHeight : screen.availHeight)/2 - h/2;
    	win.resizeTo(w+10, h+100);
    	win.moveTo(left, 0);
    }
    
    win.onload = winDoc.body.onload; // special for Mozilla
    
    // !!! Very important statement: popup onload won't execute without it!
    win.document.close();
    win.focus();
} 
