alertbox_bg_left = new Image();
alertbox_bg_left.src = 'images/error/alert_corner_left.png';
alertbox_bg_center = new Image();
alertbox_bg_center.src = 'images/error/alert_loop.jpg';
alertbox_bg_right = new Image();
alertbox_bg_right.src = 'images/error/alert_corner_right.png';

alertbox_btn_bg_left = new Image();
alertbox_btn_bg_left = 'images/error/button_left.png';
alertbox_btn_bg_center = new Image();
alertbox_btn_bg_center = 'images/error/button_loop.jpg';
alertbox_btn_bg_right = new Image();
alertbox_btn_bg_right = 'images/error/button_right.png';

alertbox_btn_bg_left_on = new Image();
alertbox_btn_bg_left_on = 'images/error/button_left.png';
alertbox_btn_bg_center_on = new Image();
alertbox_btn_bg_center_on = 'images/error/button_loop.jpg';
alertbox_btn_bg_right_on = new Image();
alertbox_btn_bg_right_on = 'images/error/button_right.png';

function alertBox(alert_title,alert_text,alert_confirm){

	/* create */
	var the_bgbox = document.createElement('div');
	the_bgbox.id = 'alert_bgbox';

	var the_box = document.createElement('div');
	the_box.id = 'alert_box';
	var the_box_left = document.createElement('div');
	the_box_left.id = 'alert_box_left';
	var the_box_center = document.createElement('div');
	the_box_center.id = 'alert_box_center';
	var the_box_right = document.createElement('div');
	the_box_right.id = 'alert_box_right';

	the_box.appendChild(the_box_left);
	the_box.appendChild(the_box_center);
	the_box.appendChild(the_box_right);

	var the_title = document.createElement('div');
	the_title.id = 'alert_box_title';
	the_box_center.appendChild(the_title);

	var the_text = document.createElement('div');
	the_text.id = 'alert_box_text';
	the_box_center.appendChild(the_text);

	var the_submit = document.createElement('div');
	the_submit.id = 'alert_box_submit';
	the_box_center.appendChild(the_submit);

	var the_anchor = document.createElement('a');
	the_submit.appendChild(the_anchor);

	var the_submit_left = document.createElement('div');
	the_submit_left.id = 'alert_box_submit_left';
	the_anchor.appendChild(the_submit_left);
	var the_submit_center = document.createElement('div');
	the_submit_center.id = 'alert_box_submit_center';
	the_anchor.appendChild(the_submit_center);

	var the_submit_contain = document.createElement('div');
	the_submit_contain.id = 'alert_box_submit_contain';
	the_submit_center.appendChild(the_submit_contain);

	var the_submit_center_text = document.createElement('div');
	the_submit_center_text.id = 'alert_box_submit_center_text';
	the_submit_center_text.innerHTML = alert_confirm;
	the_submit_contain.appendChild(the_submit_center_text);

	var the_submit_center_shadow = document.createElement('div');
	the_submit_center_shadow.id = 'alert_box_submit_center_shadow';
	the_submit_center_shadow.innerHTML = alert_confirm;
	the_submit_contain.appendChild(the_submit_center_shadow);


	var the_submit_right = document.createElement('div');
	the_submit_right.id = 'alert_box_submit_right';
	the_anchor.appendChild(the_submit_right);

	var the_body = document.getElementsByTagName('body')[0];
	the_body.appendChild(the_bgbox);
	the_body.appendChild(the_box);

	/* end of create*/
	the_title.innerHTML = "<div class='alertbox_shadow'>" + alert_title +
							"<div class='alertbox_title'>" + alert_title +
						"</div></div>";
	alert_text = alert_text;
	the_text.innerHTML = alert_text;

	the_bgbox.style.visibility = 'visible';
	the_box.style.visibility = 'visible';

	the_bgbox.style.display = 'block';
	the_box.style.display = 'block';

	the_box_left.style.backgroundRepeat= 'no-repeat';
	the_box_left.style.backgroundImage='url('+alertbox_bg_left.src+')';
	the_box_center.style.backgroundRepeat= 'repeat';
	the_box_center.style.backgroundImage='url('+alertbox_bg_center.src+')';
	the_box_right.style.backgroundRepeat= 'no-repeat';
	the_box_right.style.backgroundImage='url('+alertbox_bg_right.src+')';

	the_submit_left.style.backgroundRepeat= 'no-repeat';
	the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left+')';
	the_submit_center.style.backgroundRepeat= 'repeat';
	the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center+')';
	the_submit_right.style.backgroundRepeat= 'no-repeat';
	the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right+')';

	
	the_anchor.onmouseover = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_submit_left.style.backgroundPosition='0px -26px';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_submit_center.style.backgroundPosition='0px -26px';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_submit_right.style.backgroundPosition='0px -26px';
	}
	the_anchor.onmouseout = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left+')';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center+')';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right+')';
	}
	
	the_anchor.onmousedown = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_submit_left.style.backgroundPosition='0px -52px';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_submit_center.style.backgroundPosition='0px -52px';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_submit_right.style.backgroundPosition='0px -52px';
	}
	the_anchor.onmouseup = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_submit_left.style.backgroundPosition='0px -26px';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_submit_center.style.backgroundPosition='0px -26px';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_submit_right.style.backgroundPosition='0px -26px';
	}
	

	the_submit_center_text.style.width = the_submit_center_text.offsetWidth + 20 + 'px';
	the_submit_center_shadow.style.width = the_submit_center_text.style.width;
	the_submit_contain.style.width = the_submit_center_text.style.width;

	the_box_center.style.width = (alert_text.length <100)?'300px':((alert_text.length / 50 * 120) + 'px');
	the_box_center.style.width = (parseInt(the_box_center.style.width) < (parseInt(the_submit_center_text.offsetWidth) + 32))?(parseInt(the_submit_center_text.offsetWidth) + 32 + 'px'):(parseInt(the_box_center.style.width)+'px');
	the_box.style.width = (parseInt(the_box_center.style.width) + 26) + 'px';

	the_bgbox.style.height = document.body.offsetHeight + 'px';
	the_box.style.top = ((document.documentElement.scrollTop || document.body.scrollTop) + ((document.documentElement.clientHeight)/5)) + 'px';
	the_box.style.left = parseInt((the_bgbox.offsetWidth-the_box.offsetWidth)/2)+'px';
	var press = true;
	the_anchor.focus();
	the_anchor.onclick = function(){formGo(true);};
	document.onkeypress = EnterPressed;
}

function okCancelBox(alert_title, alert_text,alert_ok, alert_cancel, callBack, value){

	/* create */
	var the_bgbox = document.createElement('div');
	the_bgbox.id = 'alert_bgbox';

	var the_box = document.createElement('div');
	the_box.id = 'alert_box';
	var the_box_left = document.createElement('div');
	the_box_left.id = 'alert_box_left';
	var the_box_center = document.createElement('div');
	the_box_center.id = 'alert_box_center';
	var the_box_right = document.createElement('div');
	the_box_right.id = 'alert_box_right';

	the_box.appendChild(the_box_left);
	the_box.appendChild(the_box_center);
	the_box.appendChild(the_box_right);

	var the_title = document.createElement('div');
	the_title.id = 'alert_box_title';
	the_box_center.appendChild(the_title);

	var the_text = document.createElement('div');
	the_text.id = 'alert_box_text';
	the_box_center.appendChild(the_text);

	var the_submit = document.createElement('div');
	the_submit.id = 'alert_box_submit';
	the_box_center.appendChild(the_submit);

	var the_anchor = document.createElement('a');
	the_submit.appendChild(the_anchor);

	var the_submit_left = document.createElement('div');
	the_submit_left.id = 'alert_box_submit_left';
	the_anchor.appendChild(the_submit_left);
	var the_submit_center = document.createElement('div');
	the_submit_center.id = 'alert_box_submit_center';
	//confirm button
	//the_submit_center.innerHTML = alert_ok;
	the_anchor.appendChild(the_submit_center);

	var the_submit_contain = document.createElement('div');
	the_submit_contain.id = 'alert_box_submit_contain';
	the_submit_center.appendChild(the_submit_contain);

	var the_submit_right = document.createElement('div');
	the_submit_right.id = 'alert_box_submit_right';
	the_anchor.appendChild(the_submit_right);

	var the_submit_center_text = document.createElement('div');
	the_submit_center_text.id = 'alert_box_submit_center_text';
	the_submit_center_text.innerHTML = alert_ok;
	the_submit_contain.appendChild(the_submit_center_text);

	var the_submit_center_shadow = document.createElement('div');
	the_submit_center_shadow.id = 'alert_box_submit_center_shadow';
	the_submit_center_shadow.innerHTML = alert_ok;
	the_submit_contain.appendChild(the_submit_center_shadow);

	var the_cancel = document.createElement('div');
	the_cancel.id = 'alert_box_cancel';
	the_box_center.appendChild(the_cancel);

	var the_anchor2 = document.createElement('a');
	the_cancel.appendChild(the_anchor2);

	var the_cancel_left = document.createElement('div');
	the_cancel_left.id = 'alert_box_cancel_left';
	the_anchor2.appendChild(the_cancel_left);
	var the_cancel_center = document.createElement('div');
	the_cancel_center.id = 'alert_box_cancel_center';
	the_anchor2.appendChild(the_cancel_center);

	var the_cancel_contain = document.createElement('div');
	the_cancel_contain.id = 'alert_box_cancel_contain';
	the_cancel_center.appendChild(the_cancel_contain);

	var the_cancel_right = document.createElement('div');
	the_cancel_right.id = 'alert_box_cancel_right';
	the_anchor2.appendChild(the_cancel_right);

	var the_cancel_center_text = document.createElement('div');
	the_cancel_center_text.id = 'alert_box_cancel_center_text';
	the_cancel_center_text.innerHTML = alert_cancel;
	the_cancel_contain.appendChild(the_cancel_center_text);

	var the_cancel_center_shadow = document.createElement('div');
	the_cancel_center_shadow.id = 'alert_box_cancel_center_shadow';
	the_cancel_center_shadow.innerHTML = alert_cancel;
	the_cancel_contain.appendChild(the_cancel_center_shadow);

	var the_body = document.getElementsByTagName('body')[0];
	the_body.appendChild(the_bgbox);
	the_body.appendChild(the_box);
	/* end of create*/
	the_title.innerHTML = "<div class='alertbox_shadow'>" + alert_title +
							"<div class='alertbox_title'>" + alert_title +
						"</div></div>";
	alert_text = alert_text;
	the_text.innerHTML = alert_text;

	the_bgbox.style.visibility = 'visible';
	the_box.style.visibility = 'visible';

	the_bgbox.style.display = 'block';
	the_box.style.display = 'block';

	the_box_left.style.backgroundRepeat= 'no-repeat';
	the_box_left.style.backgroundImage='url('+alertbox_bg_left.src+')';
	the_box_center.style.backgroundRepeat= 'repeat';
	the_box_center.style.backgroundImage='url('+alertbox_bg_center.src+')';
	the_box_right.style.backgroundRepeat= 'no-repeat';
	the_box_right.style.backgroundImage='url('+alertbox_bg_right.src+')';

	the_submit_left.style.backgroundRepeat= 'no-repeat';
	the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left+')';
	the_submit_center.style.backgroundRepeat= 'repeat';
	the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center+')';
	the_submit_right.style.backgroundRepeat= 'no-repeat';
	the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right+')';

	
	the_anchor.onmouseover = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_submit_left.style.backgroundPosition='0px -26px';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_submit_center.style.backgroundPosition='0px -26px';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_submit_right.style.backgroundPosition='0px -26px';
	}
	the_anchor.onmouseout = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left+')';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center+')';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right+')';
	}
	
	the_anchor.onmousedown = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_submit_left.style.backgroundPosition='0px -52px';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_submit_center.style.backgroundPosition='0px -52px';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_submit_right.style.backgroundPosition='0px -52px';
	}
	the_anchor.onmouseup = function(){
		the_submit_left.style.backgroundRepeat= 'no-repeat';
		the_submit_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_submit_left.style.backgroundPosition='0px -26px';
		the_submit_center.style.backgroundRepeat= 'repeat';
		the_submit_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_submit_center.style.backgroundPosition='0px -26px';
		the_submit_right.style.backgroundRepeat= 'no-repeat';
		the_submit_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_submit_right.style.backgroundPosition='0px -26px';
	}

	the_cancel_left.style.backgroundRepeat= 'no-repeat';
	the_cancel_left.style.backgroundImage='url('+alertbox_btn_bg_left+')';
	the_cancel_center.style.backgroundRepeat= 'repeat';
	the_cancel_center.style.backgroundImage='url('+alertbox_btn_bg_center+')';
	the_cancel_right.style.backgroundRepeat= 'no-repeat';
	the_cancel_right.style.backgroundImage='url('+alertbox_btn_bg_right+')';

	
	the_anchor2.onmouseover = function(){
		the_cancel_left.style.backgroundRepeat= 'no-repeat';
		the_cancel_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_cancel_left.style.backgroundPosition='0px -26px';
		the_cancel_center.style.backgroundRepeat= 'repeat';
		the_cancel_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_cancel_center.style.backgroundPosition='0px -26px';
		the_cancel_right.style.backgroundRepeat= 'no-repeat';
		the_cancel_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_cancel_right.style.backgroundPosition='0px -26px';
	}
	the_anchor2.onmouseout = function(){
		the_cancel_left.style.backgroundRepeat= 'no-repeat';
		the_cancel_left.style.backgroundImage='url('+alertbox_btn_bg_left+')';
		the_cancel_center.style.backgroundRepeat= 'repeat';
		the_cancel_center.style.backgroundImage='url('+alertbox_btn_bg_center+')';
		the_cancel_right.style.backgroundRepeat= 'no-repeat';
		the_cancel_right.style.backgroundImage='url('+alertbox_btn_bg_right+')';
	}
	
	the_anchor2.onmousedown = function(){
		the_cancel_left.style.backgroundRepeat= 'no-repeat';
		the_cancel_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_cancel_left.style.backgroundPosition='0px -52px';
		the_cancel_center.style.backgroundRepeat= 'repeat';
		the_cancel_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_cancel_center.style.backgroundPosition='0px -52px';
		the_cancel_right.style.backgroundRepeat= 'no-repeat';
		the_cancel_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_cancel_right.style.backgroundPosition='0px -52px';
	}
	the_anchor2.onmouseup = function(){
		the_cancel_left.style.backgroundRepeat= 'no-repeat';
		the_cancel_left.style.backgroundImage='url('+alertbox_btn_bg_left_on+')';
		the_cancel_left.style.backgroundPosition='0px -26px';
		the_cancel_center.style.backgroundRepeat= 'repeat';
		the_cancel_center.style.backgroundImage='url('+alertbox_btn_bg_center_on+')';
		the_cancel_center.style.backgroundPosition='0px -26px';
		the_cancel_right.style.backgroundRepeat= 'no-repeat';
		the_cancel_right.style.backgroundImage='url('+alertbox_btn_bg_right_on+')';
		the_cancel_right.style.backgroundPosition='0px -26px';
	}

	the_submit_center_text.style.width = the_submit_center_text.offsetWidth + 20 + 'px';
	the_submit_center_shadow.style.width = the_submit_center_text.style.width;
	the_submit_contain.style.width = the_submit_center_text.style.width;

	the_cancel_center_text.style.width = the_cancel_center_text.offsetWidth + 20 + 'px';
	the_cancel_center_shadow.style.width = the_cancel_center_text.style.width;
	the_cancel_contain.style.width = the_cancel_center_text.style.width;

	the_box_center.style.width = (alert_text.length <100)?'300px':((alert_text.length / 50 * 120) + 'px');
	the_box_center.style.width = (parseInt(the_box_center.style.width) < (the_submit_center_text.offsetWidth + the_cancel_center_text.offsetWidth + 67))?(parseInt(the_submit_center_text.offsetWidth) + parseInt(the_cancel_center_text.offsetWidth) + 28 + 'px'):(parseInt(the_box_center.style.width)+'px');
	the_box.style.width = (parseInt(the_box_center.style.width) + 26) + 'px';

	the_bgbox.style.height = document.body.offsetHeight + 'px';
	the_box.style.top = ((document.documentElement.scrollTop || document.body.scrollTop) + ((document.documentElement.clientHeight)/5)) + 'px';
	the_box.style.left = parseInt((the_bgbox.offsetWidth-the_box.offsetWidth)/2)+'px';

	var the_submit_btn = document.getElementById('alert_box_submit');
	var the_cancel_btn = document.getElementById('alert_box_cancel');
	the_anchor.onclick = function(){ callBackGo(true, callBack, value);};
	the_anchor2.onclick = function(){ callBackGo(false, callBack, value);};
	document.onkeypress = function(e){
		var characterCode;
		var evt = e || window.event;
		if(evt && evt.which){           // NN4 specific code
		characterCode = evt.which
		}
		else {
		characterCode = evt.keyCode // IE specific code
		}

		if (characterCode == 13 || characterCode == 32){
		  return callBackGo(true, callBack, value);
		}else{
		  return callBackGo(false, callBack, value);
		}
	};
}

function formGo(ans){
	var the_bgbox = document.getElementById('alert_bgbox');
	var the_box = document.getElementById('alert_box');
	var the_body = document.getElementsByTagName('body')[0];
	the_body.removeChild(the_bgbox);
	the_body.removeChild(the_box);
	document.onkeypress = '';
	return ans;
}

function callBackGo(ans, callBack, value){
	var the_bgbox = document.getElementById('alert_bgbox');
	var the_box = document.getElementById('alert_box');
	var the_title = document.getElementById('alert_box_title');
	var the_text = document.getElementById('alert_box_text');
	var the_body = document.getElementsByTagName('body')[0];
	the_body.removeChild(the_bgbox);
	the_body.removeChild(the_box);
	callBack(ans, value);
	return false;
}

function EnterPressed(e) {
// Code adapted from Jennifer Madden
// http://jennifermadden.com/162/examples/stringEnterKeyDetector.html
  var characterCode;
  var evt = e || window.event;
  if(evt && evt.which){           // NN4 specific code
    characterCode = evt.which
  }
  else {
    characterCode = evt.keyCode // IE specific code
  }

  if (characterCode == 13 || characterCode == 32){
	  return formGo(true);
  }else{
	  return false;
  }
}