var providers=[
{name:'OpenID', url:'', img:'/skins/default/images/icons/openid/openid32.png', openid2:false},
{name:'Яндекс', url:'http://openid.yandex.ru/', img:'/skins/default/images/icons/openid/yandex32.png', openid2:true},
{name:"Google", url:'https://www.google.com/accounts/o8/id', img:'/skins/default/images/icons/openid/google32.png', openid2:true},
{name:"Rambler", url:'http://rambler.ru/', img:'/skins/default/images/icons/openid/rambler32.png', openid2:true},
{name:"Blogger", url:'http://{username}.blogspot.com/', img:'/skins/default/images/icons/openid/blogger32.png', openid2:false},
{name:"Livejournal", url:'http://{username}.livejournal.com/', img:'/skins/default/images/icons/openid/livejournal32.png', openid2:false}
/*{name:"Twitter", url:'http://rambler.ru/{username}', img:'/skins/default/images/icons/openid/twitter32.png', openid2:false},
{name:"Вконтакте", url:'http://vkontakteid.ru', img:'/skins/default/images/icons/openid/twitter32.png', openid2:true},
{name:"Mail.ru", url:'http://{username}.id.mail.ru', img:'/skins/default/images/icons/openid/twitter32.png', openid2:false},
{name:"Facebook", url:'http://www.facebook.com/{username}', img:'/skins/default/images/icons/openid/twitter32.png', openid2:false},
{name:"Twitter", url:'https://{username}.myopenid.com', img:'/skins/default/images/icons/openid/twitter32.png', openid2:false},
{name:"WordPress", url:'http://{username}.wordpress.com', img:'/skins/default/images/icons/openid/twitter32.png', openid2:false}*/
];

var username='имя';

function openIdSelector(elmnt)
{
	list=createList(elmnt);
	elmnt.parentNode.appendChild(list);
}

function createList(elmnt)
{
	var i=0;
	div=document.createElement('div');
	div.className='oid_list';
	for(i=0;i<providers.length;i++)
	{
		item=providers[i];
		img=document.createElement('img');
		img.src=item.img;
		img.alt=item.name;
		img.title=item.name;
		img.addEventListener('click', function(iurl, el){return function () {setOidValue(iurl, el);	}}(item.url, elmnt), false);
		div.appendChild(img);
	}
	return div;
}

function setOidValue(value, elmnt)
{
	value=value.replace(/\{username\}/, '{'+username+'}');
	elmnt.value=value;
	if (begin = value.indexOf('{'))
	{
		var end = value.indexOf('}')+1;
		createSelection(begin, end, elmnt);
	}
}

function createSelection(start, end, field)
{

    if ( field.createTextRange )
	{
        var newend = end - start;
        var selRange = field.createTextRange();
        selRange.collapse(true);
        selRange.moveStart("character", start);
        selRange.moveEnd("character", newend);
        selRange.select();
    } 
    else if( field.setSelectionRange )
	{
        field.setSelectionRange(start, end);
    } 

    field.focus();
}

function setSelectors()
{
	var i=0;
	inputs=document.getElementsByTagName('input');
	for (i=0; i<inputs.length;i++)
	{
		if (inputs[i].className=='openid_input') openIdSelector(inputs[i]);
	}
}

var oldOnLoad = window.onload;
window.onload = function(evt) {
    try {
	setSelectors();
    } finally {
	return oldOnLoad && oldOnLoad(evt);
    }
};