function $(id){
	return document.getElementById(id);
}
function $$(container,tag){
	return container.getElementsByTagName(tag);
}

/*
*	draws alert and confirm dialogues and adds specified text
*	function call: 
		alertbox('<message>','<type [alert],[confirm]>','<btn1 text>','<btn2 text>')
*/
var cnt=interval=0;
var blinking=false;
var actionBlock,alertContainer;
var confirmation=0;

/* function message(targ){
	var UPLOAD='<p><strong>Only images allowed.</strong></p><p>The file should be of type jpg, jpeg, gif, bmp or, png.</p>'
	
	
	targ=eval(targ.toUpperCase());
	return targ;
}
 */
function releaseBlock(){
	$('container').removeChild(actionBlock);
	$('container').removeChild(alertContainer);
}

function signal(){	
 	function blink(){
		if(cnt%2==0){
			$('current_alert').style.visibility='hidden';
			cnt++;
		}
		else{
			$('current_alert').style.visibility='visible';
			cnt++;
		}
		if(cnt>=4){
			clearInterval(interval);
			interval=0;
			cnt=0;
		}
	}
if(interval)
	clearInterval(interval);
interval=setInterval(blink,50);
}

//function alertbox(event,type,btn1,btn2){
function alertbox(message,type,btn1,btn2){
// replace ascii newline with html line break
//message=message.replace(/\n/g,"<br />");
/* ** block other actions ** */
	actionBlock=document.createElement('div');
	actionBlock.style.width='100%';
	actionBlock.style.height='1400px';
	actionBlock.style.top='0';
	actionBlock.style.left='0';
	actionBlock.style.position='absolute';
	actionBlock.style.zIndex='2';
	actionBlock.style.background='#fff';
	value=5;
	actionBlock.style.opacity = value/10;
	actionBlock.style.filter = 'alpha(opacity=' + value*10 + ')';

	actionBlock.onclick=signal;
	$('container').appendChild(actionBlock);
/* ** ******************* ** */
	alertContainer=document.createElement('div');
	var alertText=document.createElement('div');
	
	alertContainer.id='current_alert';
	alertText.id='alert_message';

 	alertText.innerHTML=message;
	alertContainer.style.zIndex='3000';
	alertContainer.appendChild(alertText);
 	
	if(type=='alert'){
		var button=document.createElement('a');
		button.className='submit_btn';
		button.id='button';
		button.innerHTML=btn1;
		alertContainer.appendChild(button);
		button.style.left='50%';
		button.style.marginLeft='-36px';
		button.onmouseup=releaseBlock;
	}
	else{
		var buttonLeft=document.createElement('a');
		var buttonRight=document.createElement('a');
		buttonLeft.className=buttonRight.className='submit_btn';
		buttonLeft.id='button_left';
		buttonRight.id='button_right';
		buttonLeft.style.left='25%';
		buttonRight.style.left='75%';
		buttonLeft.style.marginLeft=buttonRight.style.marginLeft='-36px';
		buttonLeft.innerHTML=btn1;
		buttonRight.innerHTML=btn2;
		alertContainer.appendChild(buttonLeft);
		alertContainer.appendChild(buttonRight);
 		buttonLeft.onmouseup=function(){
			confirmation++;
			releaseBlock();
			confirmCounter(confirmation);
			
 		}
		buttonRight.onmouseup=function(){
			confirmation;
			decline(confirmation);
			releaseBlock();
			// goto some page
		}
 	
	}
	$('container').appendChild(alertContainer);
}
