/**
 * Predefined standart function "alert" with JS
 * This function use two the new parameters.
 * [e] -> event object
 * [arr] -> array with action declarations for comand buttons.
 *
 * @version 0.1
 * @athor Evgeni Baldzisky
 */
Svincs.include('draging');
window.alertNum = 0;
window.alert = function ($messege,rule){
	window.alertNum++;
	
	var template = '';
		template += '<table id="popup" style="border-collapse: collapse;">';
		template += '	<tr>';
		template += '		<td class="pop1" height="20" width="20"></td>';
		template += '		<td class="pop2" height="20"></td>';
		template += '		<td class="pop3" height="20" width="20"></td>';
		template += '	</tr>';
		template += '	<tr>';
		template += '		<td class="pop4"></td>';
		template += '		<td class="pop5">';
		template += '			<div class="popup_content_fixer"></div>';
		template += '			<div class="popup_button_bar">';
		template += '				<input type="button" class="popup_btn_ok" value="X" id="popup_btn_ok'+window.alertNum+'"/>';
		template += '			</div>';
		template += '			<div class="popup_content">' + $messege + '</div>';
		template += '		</td>';
		template += '		<td class="pop6"></td>';
		template += '	</tr>';
		template += '	<tr>';
		template += '		<td class="pop7"></td>';
		template += '		<td class="pop8" height="20"></td>';
		template += '		<td class="pop9"></td>';
		template += '	</tr>';
		template += '</table>';

	var pop = new Svincs.Window.Popup();
		pop.HTML(template,rule);

		var yes_btn = document.getElementById('popup_btn_ok'+window.alertNum);
		if(yes_btn){
			yes_btn.onclick = function(){
				if(typeof rule == 'function') rule();
				if(typeof rule == 'object' && typeof rule.exec == 'function'){
					rule.exec();
				}
				pop.remove();
			}
			yes_btn.focus();
		}

    	if(typeof rule == 'object' && rule.nodrag){
			return pop;
		}

    	pop.div.onmouseover = function (){
    		Svincs.Draging.Event(this,function (p,t,o){
				if(t == 'Y'){
					pop.div.style.top = p+'px';
					if(pop.iframe) pop.iframe.style.top = p+'px';
				}
				if(t == 'X'){
					pop.div.style.left = p+'px';
					if(pop.iframe) pop.iframe.style.left = p+'px';
				}
    		});
    	}

	return pop;
}

function changeStatusFlashObjects(flash_col,status){
	for(var i=0;i<flash_col.length;i++){
		flash_col.item(i).style.display = status;
	}
}

window.bg_global = function (){
	var width = Svincs.Info.winInfo('scrollWidth') - 20;// + Svincs.Info.winInfo('scrollWidth');
	var height = Svincs.Info.winInfo('scrollHeight');// + Svincs.Info.winInfo('scrollHeight');

	return window.alert('<div class="global_bg" style="width:'+width+'px;height:'+height+'px"></div>',{nodrag:1,_default:1});
}

window.specialAlert = function (msg,rule){

	var flash_col = document.getElementsByTagName('object');
		changeStatusFlashObjects(flash_col,'none');

	if(rule.bg){
		var bg = rule.bg;
	}else{
		var bg = window.bg_global();
	}
	if(Svincs.Info.ie && !Svincs.Info.ie7){
		bg.div.style.top = bg.iframe.style.top = '0px';
	}
	if(typeof rule == 'object'){
		rule.exec = function(){
			changeStatusFlashObjects(flash_col,'block');
			bg.remove();
		};
	}else if(typeof rule == 'function'){
		var f = rule;
		rule = {
			exec : function(){
				changeStatusFlashObjects(flash_col,'block');
				bg.remove();
				f();
			}
		}
	}else{
		rule = {
			exec : function(){
				changeStatusFlashObjects(flash_col,'block');
				bg.remove();
			}
		}
	}
	return window.alert(msg,rule);
}

window.confirmNum = 0;
window.confirm = function ($messege,rule){
	window.confirmNum++;

	var template = '';
		template += '<table id="popup" style="border-collapse: collapse;">';
		template += '	<tr>';
		template += '		<td class="pop1" height="20" width="20"></td>';
		template += '		<td class="pop2" height="20"></td>';
		template += '		<td class="pop3" height="20" width="20"></td>';
		template += '	</tr>';
		template += '	<tr>';
		template += '		<td class="pop4"></td>';
		template += '		<td class="pop5">';
		template += '			<div class="popup_content_fixer"></div>';
		template += '			<div class="popup_content">' + $messege + '</div>';
		template += '			<div class="_popup_button_bar">';
		template += '				<input type="button" class="popup_btn_ok" value="" id="popup_btn_ok'+window.confirmNum+'"/>';
		template += '				<input type="button" class="popup_btn_no" value="" id="popup_btn_no'+window.confirmNum+'"/>';
		template += '			</div>';
		template += '		</td>';
		template += '		<td class="pop6"></td>';
		template += '	</tr>';
		template += '	<tr>';
		template += '		<td class="pop7"></td>';
		template += '		<td class="pop8" height="20"></td>';
		template += '		<td class="pop9"></td>';
		template += '	</tr>';
		template += '</table>';

	var pop = new Svincs.Window.Popup();
		pop.HTML(template);

		var yes_btn = document.getElementById('popup_btn_ok'+window.confirmNum);
		if(yes_btn){
			yes_btn.onclick = function(){
				if(typeof rule == 'function') rule();
				if(typeof rule == 'object' && typeof rule.exec == 'function'){
					rule.exec();
				}
				pop.remove();
			}
			yes_btn.focus();
		}
		var no_btn = document.getElementById('popup_btn_no'+window.confirmNum);
		if(no_btn){
			no_btn.onclick = function(){
				pop.remove();
			}
		}

    	pop.div.title = '';
    	pop.div.onclick = function (){return false;}

    	if(typeof rule == 'object' && rule.nodrag){
			return pop;
		}

    	pop.div.onmouseover = function (){
    		Svincs.Draging.Event(this,function (p,t,o){
					if(t == 'Y'){
						pop.div.style.top = p+'px';
						if(pop.iframe) pop.iframe.style.top = p+'px';
					}
					if(t == 'X'){
						pop.div.style.left = p+'px';
						if(pop.iframe) pop.iframe.style.left = p+'px';
					}
    			}
    		);
    	}

	return pop;
}