// alert by tlissak
// last mod 19/12/2007
// v 0.3

///////////////////////////////////////
//
//		DONT USE CSS BODY HEIGHT 100 %
//		WITH MASK
//		Mask height PROBLEM
//
//////////////////////////////////////
var HIDE_LIST = true
var HIDE_BUTTON = true
var MASK_OPACITY = true

window.alert = alert ;
alert.prototype.box ;
alert.prototype.textbox ;
alert.prototype.timeout ;
alert.prototype.mask ;
alert.prototype.text  ;
alert.prototype.init  ;
alert.prototype.image ; 
alert.prototype.show  ;

alert.prototype.boxhtml ;
alert.prototype.isStart ;
alert.prototype.close ;
alert.prototype.ok ;

alert.prototype.hide_btn  ;
alert.prototype.hide_list ;
alert.prototype.mask_opac ;

alert.text = "" ;
alert.title = "&nbsp;" ; //' <div id="alert_header"></div>'
alert.ok	= " Fermer "

alert.boxhtml  = '<div id="alert_mask">&nbsp;</div>'
alert.boxhtml  += '<span id="alert_box">'
alert.boxhtml  += '		<div id="alert_top" onmousedown="move.mousedown(event,this.parentNode.id)">'+alert.title+'</div>'
alert.boxhtml  += '		<div id="alert_middle">'
alert.boxhtml  += '			<div id="alert_image" ></div><div id="alert_textbox"></div>'
alert.boxhtml  += '		</div>'
alert.boxhtml  += '		<div id="alert_bottom" align="center"><input type="button" value="'+alert.ok+'" " id="alert_button" onclick="alert.close()" /></div>'
alert.boxhtml  += '</span>'


document.write(alert.boxhtml)
document.write('<link rel="stylesheet" type="text/css" href="Css/Alert.css">')

function alert(p,type,hide_btn,hide_list,mask_opac){ 

	p = hide_list ? "<li style='list-style:none'>"+  p + "</li>" : "<li>"+  p + "</li>"
	
	//alert.hide_list  = hide_list
	alert.hide_btn = hide_btn
	alert.mask_opac = mask_opac
	
	if (alert.isStart){
		alert.show(  alert.textbox.innerHTML + p, type) ;
	}else{
		alert.init()
		alert.isStart = true
		alert.show(p , type)
	}
}
alert.close = function(){
	alert.mask.style.display='none'
	alert.box.style.display='none'
	alert.isStart = false
}

function htmlEncode(s) {
	    var str = new String(s);
        //str = str.replace(/&/g, "&amp;");
        //str = str.replace(/</g, "&lt;");
        //str = str.replace(/>/g, "&gt;");
        //str = str.replace(/"/g, "&quot;");
		
        return str;
}



alert.init = function(){
	alert.box = document.getElementById("alert_box") ;
	
	if (!alert.box){
		clearTimeout(alert.timeout) ;
		alert.text += p + alert.text;
		alert.timeout = setTimeout("alert(alert.text)",100) ;
		return ;
	}
	alert.image = document.getElementById("alert_image") ;
	alert.mask = document.getElementById("alert_mask") ;
	alert.textbox = document.getElementById("alert_textbox") ;
}




function docDimensions() {
			var myWidth = 0, myHeight = 0;
			myHeight = document.documentElement && document.all ? document.body.scrollHeight  : document.documentElement.offsetHeight
			
			var intH,intW
            var scrollOfssetTop,scrollOfssetLeft
			try{
				intH = window.outerHeight ? window.outerHeight : 640;
            	intW = window.outerWidth ? window.outerWidth : 780;
			
				intH = (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : intH ;
				intW = (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth  : intW ;
				
				scrollOfssetTop = (document.documentElement && document.documentElement.scrollTop) ?  document.documentElement.scrollTop : document.body.scrollTop;
				scrollOfssetLeft =  (document.documentElement && document.documentElement.scrollLeft) ?  document.documentElement.scrollLeft : document.body.scrollLeft;
			}catch(e){		}
			return { x: parseInt(myWidth), y: parseInt(myHeight),client_y: parseInt(intH + scrollOfssetTop),client_x:parseInt(intW + scrollOfssetLeft) };
			
		
}


alert.show = function(text,type){
	
	alert.mask.className = alert.mask_opac ? "opacity_7"	: ""
	
	document.getElementById("alert_button").style.visibility = alert.hide_btn ? "hidden" : "visible"
	
	//console.log(alert.hide_btn)
	
	var doc_h,doc_w,at_t,at_l
	
	try {
		doc_h  = docDimensions().client_y
		doc_w  = docDimensions().client_x
		at_t	=  ((doc_h / 2 )- 50)
		at_l	=((doc_w / 2) - 200)
	}catch(e){}
	
	doc_h = docDimensions().y

	
		alert.mask.style.height = doc_h+ "px"
		alert.mask.style.display='block'
		
		clearTimeout(alert.timeout) ;
		
		alert.box.style.display = "block" ;
		

		alert.box.style.top = at_t + "px" ; 
		alert.box.style.left = at_l + "px" ; 
		
		text = String(text).replace(/\n/ig,"")
		
		if (String(type).toLowerCase()=="error"){
			alert.image.className =  "ERROR"
		}else if(String(type).toLowerCase()=="constraction"){
			alert.image.className =  "CONSTRACTION"			
		}else if(String(type).toLowerCase()=="none"){
			alert.image.style.display = "none"	
		}else{
			alert.image.className = "OK"
		}
		
		alert.textbox.innerHTML = text ;
		try{//IE cant move focus on visability hidden
			$("alert_button").focus()
		}catch(e){}
	//alert.timeout = setTimeout("alert.close();",4500) ;
}








//move v0.6


var move={
	mousedown:function(e,elm_id){
		this.elm = document.getElementById(elm_id)
		this.elm.style.position = "absolute"
		this.process 	= true
		this.old_y_pos  = parseInt(this.elm.style.top) ? parseInt(this.elm.style.top) : this.findObjPos(this.elm).y
		this.old_x_pos	= parseInt(this.elm.style.left) ? parseInt(this.elm.style.left) : this.findObjPos(this.elm).x
		this.old_csr_x  = this.cursorPosition(e).x - this.old_x_pos
		this.old_csr_y	= this.cursorPosition(e).y - this.old_y_pos
		document.body.onselectstart=function(){return false}//ie
		document.body.onmousedown=function(){return false}//mozilla}
		document.onmousemove= move.mousemove
		}
		,mouseup:function(){
			//mask.hide()
			move.process=false
			document.onmouseup = null
			document.onmousemove = null
			document.body.onselectstart=function(){return true}//ie
			document.body.onmousedown=function(){return true}//mozilla
		}
		,mousemove:function(e){
			//mask.show(5)
			if(move.process){
				move.elm.style.left = move.cursorPosition(e).x - move.old_csr_x +"px"
				move.elm.style.top  = move.cursorPosition(e).y - move.old_csr_y +"px"
				document.onmouseup= move.mouseup
			}
		
		}
		,cursorPosition:function(ev){
			ev = ev || window.event;
			if(ev.pageX || ev.pageY){			return {x:ev.pageX, y:ev.pageY};		}
			return {
				x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
				y:ev.clientY + document.body.scrollTop  - document.body.clientTop
			}
		}
		,findObjPos:function(obj) {
		if (obj){
			var curleft = 0 ;var curtop = 0;
			if (obj.offsetParent) {
				curleft = obj.offsetLeft
				curtop = obj.offsetTop
				while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft
					curtop += obj.offsetTop
				}
			}
			return {x:curleft,y:curtop};
		}
	}
}

function alert_const(){
	alert("bienvenue sur les site darkdildo.fr","constraction",HIDE_BUTTON,HIDE_LIST)
	alert("&nbsp;","constraction",HIDE_BUTTON,HIDE_LIST)
	alert("Ce site est en construction.","constraction",HIDE_BUTTON,HIDE_LIST)
	alert("&nbsp;","constraction",HIDE_BUTTON,HIDE_LIST)
	alert("OUVERTURE PROCHAINE","error",HIDE_BUTTON,HIDE_LIST,MASK_OPACITY)	
	//window.setTimeout('alert.close()',100)
}

var HIDE_LIST 		= true
var HIDE_BUTTON 	= true
var MASK_OPACITY 	= true


window.onload =  function(){
	//alert_const()
	
}
