// 2010 なで学 core
//window.console = window.console || { assert:function(){ }, log:function(){} };
//
// 
var NDG_CORE = {
	Version: '20100112.006',
	
	timer : null,
	
	initialize : function(){
		this.menu_slide.initialize();
		this.help_slide.initialize();
		this.side_menu.initialize();
		this.start_timer();
		
		this.preload();
		//console.log();
/*
		var src = 'http://widgets.twimg.com/j/2/widget.js';
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = src;
		document.body.appendChild(script);
*/
	},
	
	start_timer : function (){
		clearInterval(NDG_CORE.timer);
		NDG_CORE.timer = setInterval('NDG_CORE.action()',20);
	},
	
	action : function (){
		NDG_CORE.menu_slide.paint();
		NDG_CORE.help_slide.paint();
		NDG_CORE.float_area.paint();
		NDG_CORE.trial.check();
		NDG_CORE.inquiry.check();
		NDG_CORE.request.check();
		NDG_CORE.visitor.check();
	},
	
	menu_slide : {
		area : null,
		target : null,
		height : 0,
		next : null,
		initialize : function(){
			this.area = document.getElementById('submenu');
			
			var btn = document.getElementById('gm_about');
			try {
				btn.addEventListener('click', function(){NDG_CORE.menu_slide.click('list_about');},false);
			}catch(e){
				btn.attachEvent('onclick', function(){NDG_CORE.menu_slide.click('list_about');});
			}
			
			var btn = document.getElementById('gm_event');
			try {
				btn.addEventListener('click', function(){NDG_CORE.menu_slide.click('list_event');},false);
			}catch(e){
				btn.attachEvent('onclick', function(){NDG_CORE.menu_slide.click('list_event');});
			}
			
			var btn = document.getElementById('gm_support');
			try {
				btn.addEventListener('click', function(){NDG_CORE.menu_slide.click('list_support');},false);
			}catch(e){
				btn.attachEvent('onclick', function(){NDG_CORE.menu_slide.click('list_support');});
			}
			
			var btn = document.getElementById('gm_dlife');
			try {
				btn.addEventListener('click', function(){NDG_CORE.menu_slide.click('list_dlife');},false);
			}catch(e){
				btn.attachEvent('onclick', function(){NDG_CORE.menu_slide.click('list_dlife');});
			}
		},
		
		click : function(name){
			var obj = NDG_CORE.menu_slide;
			obj.next = document.getElementById(name);
			if(obj.target == null) obj.target = obj.next;
			
			NDG_CORE.start_timer();
		},
		
		paint : function(){
			var obj = NDG_CORE.menu_slide;
			
			if(obj.target == null) return;
			
			
			if(obj.height <= 0){
				obj.target.style.display = 'none';
				obj.target = obj.next;
				obj.target.style.display = 'block';
			}
			
			obj.area.style.height = obj.height + 'px';
			
			
			var targetheight = obj.target==obj.next ? obj.target.offsetHeight : 0;
			var diff = (targetheight - obj.height) * 0.3;
			diff = diff <= 0 ? Math.floor(diff) : Math.ceil(diff);
			
			obj.height = obj.height + diff;
			
			//console.log(obj.target.offsetHeight + '/' + obj.height);
		}
	},
	
	help_slide : {
		target : 'help',
		button : 'helpbtn',
		area : '',
		height : 150,
		postion : 150,
		toggle : false,
		
		initialize : function(){
			this.area = document.getElementById(this.target);
			var btn = document.getElementById(this.button); 
			try {
				btn.addEventListener('click', function(){NDG_CORE.help_slide.click();},false);
			}catch(e){
				btn.attachEvent('onclick', function(){NDG_CORE.help_slide.click();});
			}
		},
		
		click : function(){
			NDG_CORE.help_slide.toggle = NDG_CORE.help_slide.toggle ? false : true;
			//console.log(NDG_CORE.help_slide.toggle);
			NDG_CORE.start_timer();
		},
		
		paint : function(){
			var diff = ((NDG_CORE.help_slide.toggle ? 0 : NDG_CORE.help_slide.height) - NDG_CORE.help_slide.postion) / 4;
			NDG_CORE.help_slide.postion += NDG_CORE.help_slide.toggle ? Math.floor(diff) : Math.ceil(diff);
			if(NDG_CORE.help_slide.postion > NDG_CORE.help_slide.height) NDG_CORE.help_slide.postion = NDG_CORE.help_slide.height;
			if(NDG_CORE.help_slide.postion < 0) NDG_CORE.help_slide.postion = 0;
			NDG_CORE.help_slide.area.style.marginTop = '-' + NDG_CORE.help_slide.postion + 'px';
		}
	},
	
	
	side_menu : {
		target : 'side_menu',
		url : '/side_menu.php',
		initialize : function(){
			NDG_CORE.Ajax.request(
				NDG_CORE.side_menu.url,
				function(responseText){
					var area = document.getElementById(NDG_CORE.side_menu.target); 
					if(area) area.innerHTML = responseText;




				}
			);
		}
	},
	
	
	float_area : {
		toggle : false,
		area_div : null,
		area_bg : null,
		opacity : 0,
		top : -900,
		displayed : false,
		url : '',
		
		initialize : function(){
		},
		
		click : function(){
			var obj = NDG_CORE.float_area;
			obj.toggle = obj.toggle ? false : true;
			obj.displayed = true;
			
			if (typeof document.documentElement.style.maxHeight == "undefined") {
				location.href = "#";
			}
		},
		
		paint : function(){
			var obj = NDG_CORE.float_area;
			
			if(! obj.displayed) return;
			
			if(! obj.area_bg){
				obj.area_bg = document.createElement('div');
				document.body.appendChild(obj.area_bg);
			}
			
			if(! obj.area_div){
				obj.area_div = document.createElement('div');
				document.body.appendChild(obj.area_div);
				
				NDG_CORE.Ajax.request(
					NDG_CORE.float_area.url,
					function(responseText){
						NDG_CORE.float_area.area_div.innerHTML = responseText;
						var cancel = document.getElementById('btncancel');
						if(cancel){
							try {
								cancel.addEventListener('click', function(){NDG_CORE.float_area.click();},false);
							}catch(e){
								cancel.attachEvent('onclick', function(){NDG_CORE.float_area.click();});
							}
						}
					}
				);
			}
			
			var style_div = obj.get_style('div');
			var style_bg  = obj.get_style('background');
			
			if(NDG_CORE.Browser.MSIE){
				obj.area_div.style.cssText = style_div;
				obj.area_bg.style.cssText = style_bg;
			}else{
				obj.area_div.setAttribute("style",style_div);
				obj.area_bg.setAttribute("style",style_bg);
			}
			
			if(obj.toggle){
				obj.opacity = obj.opacity + 5;
				obj.top = obj.top + 70;
			}else{
				obj.opacity = obj.opacity - 5;
				obj.top = obj.top - 90;
			}
			
			if(obj.opacity < 0) obj.opacity = 0;
			if(obj.opacity > 60) obj.opacity = 60;
			
			if(obj.top < -900) obj.top = -900;
			if(obj.top > ((NDG_CORE.env('win_height') - obj.area_div.offsetHeight) / 3)) obj.top = ((NDG_CORE.env('win_height') - obj.area_div.offsetHeight) / 3);
			
			if(obj.opacity <= 0 && obj.top <= -900){
				obj.displayed = false;
				document.body.removeChild(obj.area_div);
				document.body.removeChild(obj.area_bg);
				obj.area_div = null;
				obj.area_bg = null;
			}
		},
		
		get_style : function(index){
			var obj = NDG_CORE.float_area;
			var result = '';
			
			switch(index){
			case 'div':
//				result += 'position:absolute;';
				result += 'position:fixed;_position:absolute;';
				result += 'z-index:10000;';
				if(obj.area_div) result += 'top:'+ obj.top +'px;left:'+ ((NDG_CORE.env('win_width') - obj.area_div.offsetWidth) / 2) + 'px;';
//				result += 'background-color:#FFF;';
				break;
				
			case 'background':
//				result += 'position:absolute;';
				result += 'position:fixed; _position:absolute;';
				result += 'z-index:9999;';
				result += 'background-color:#000;';
				result += 'top:0;left:0;';
				result += 'width:100%;height:100%;';
				result += 'filter: alpha(opacity='+ obj.opacity +');';
				result += '-moz-opacity:'+(obj.opacity/100)+';';
				result += 'opacity:'+(obj.opacity/100)+';';
				break;
			}

			return result;
		}
		
	},
	
	trial : {
		target : 'js_trial_form',
		syntax : false,
		initialized : false,
		query : '',
		sending : false,
		
		check : function(){
			var obj = NDG_CORE.trial;
			var check_value, target;
			
			target = document.getElementById(obj.target);
			if(! target) return false;
			
			
			var result = true;
			var query = '';
			
			// check name
			target = document.getElementById('js_trial_name');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&na=' + encodeURIComponent(check_value);
			
			// check yomi
			target = document.getElementById('js_trial_yomi');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&yo=' + encodeURIComponent(check_value);
			
			// check tel
			target = document.getElementById('js_trial_tel');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&tl=' + encodeURIComponent(check_value);
			
			// check email
			target = document.getElementById('js_trial_email');
			if(! target) return false;
			check_value = target.value;
			if(! check_value.match(/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i)) result = false; 
			query = query + '&em=' + encodeURIComponent(check_value);
			
			if(result){
				// get js_trial_pref
				target = document.getElementById('js_trial_pref');
				if(! target) return false;
				query = query + '&pr=' + encodeURIComponent(target.value);
				
				// get js_trial_pref
				target = document.getElementById('js_trial_year');
				if(! target) return false;
				query = query + '&ye=' + encodeURIComponent(target.value);
				
				// get js_trial_id
				target = document.getElementById('js_trial_id');
				if(! target) return false;
				query = query + '&id=' + encodeURIComponent(target.value);
				
				// get js_trial_briefing
				target = document.getElementById('js_trial_briefing');
				if(! target) return false;
				if(target.checked) query = query + '&pm=' + encodeURIComponent('enable');
				
				// get js_trial_briefing
				target = document.getElementById('click_questions');
				if(! target) return false;
				if(target.checked){
					query = query + '&qs=' + encodeURIComponent('enable');
					target = document.getElementById('js_trial_q_1');
					if(target) if(target.checked) query = query + '&q1=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_2');
					if(target) if(target.checked) query = query + '&q2=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_3');
					if(target) if(target.checked) query = query + '&q3=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_4');
					if(target) if(target.checked) query = query + '&q4=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_5');
					if(target) if(target.checked) query = query + '&q5=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_6');
					if(target) if(target.checked) query = query + '&q6=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_6');
					if(target) if(target.checked) query = query + '&q7=' + encodeURIComponent('enable');
					
					target = document.getElementById('js_trial_q_comment');
					if(target) query = query + '&qc=' + encodeURIComponent(target.value);
				}
				
				
				obj.query = query;
			}
			
			obj.syntax = result;
			
			if(obj.syntax){
				target = document.getElementById('js_trial_submit_on');
				if(target) target.style.display = 'block';
				
				target = document.getElementById('js_trial_submit_off');
				if(target) target.style.display = 'none';
				
				if(! obj.initialized){
					target = document.getElementById('js_trial_submit_on');
					try {
						target.addEventListener('click', function(){NDG_CORE.trial.send();},false);
					}catch(e){
						target.attachEvent('onclick', function(){NDG_CORE.trial.send();});
					}
					obj.initialized = true;
				}
				
			}else{
				target = document.getElementById('js_trial_submit_on');
				if(target) target.style.display = 'none';
				
				target = document.getElementById('js_trial_submit_off');
				if(target) target.style.display = 'block';
			}
		},
		
		send : function(){
			var obj = NDG_CORE.trial;
			obj.check();
			if(! obj.syntax) return false;
			if(obj.sending) return true;
			
			obj.initialized = false;
			var target;
			target = document.getElementById(obj.target);
			if(target) target.style.display = 'none';
			
			target = document.getElementById('js_sending');
			if(target) target.style.display = 'block';
			
			
			obj.sending = true;
			NDG_CORE.Ajax.request(
				'/contact/receive_trial.php?' + obj.query,
				function(responseText){
					NDG_CORE.trial.sending = false;
					NDG_CORE.float_area.area_div.innerHTML = responseText;
					var cancel = document.getElementById('btncancel');
					if(cancel){
						try {
							cancel.addEventListener('click', function(){NDG_CORE.float_area.click();},false);
						}catch(e){
							cancel.attachEvent('onclick', function(){NDG_CORE.float_area.click();});
						}
					}
				}
			);
			
		}
	},
	
	inquiry : {
		target : 'js_inquiry_form',
		syntax : false,
		initialized : false,
		query : '',
		
		check : function(){
			var obj = NDG_CORE.inquiry;
			var check_value, target;
			
			target = document.getElementById(obj.target);
			if(! target) return false;
			
			var result = true;
			var query = '';
			
			// check name
			target = document.getElementById('js_inquiry_name');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&na=' + encodeURIComponent(check_value);
			
			// check yomi
			target = document.getElementById('js_inquiry_yomi');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&yo=' + encodeURIComponent(check_value);
			
			// check tel
			target = document.getElementById('js_inquiry_tel');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&tl=' + encodeURIComponent(check_value);
			
			// check email
			target = document.getElementById('js_inquiry_email');
			if(! target) return false;
			check_value = target.value;
			if(! check_value.match(/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i)) result = false; 
			query = query + '&em=' + encodeURIComponent(check_value);
			
			// check comment
			target = document.getElementById('js_inquiry_comment');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&qn=' + encodeURIComponent(check_value);
			
			if(result){
				query = query + '&qu=' + encodeURIComponent(document.URL);
				obj.query = query;
			}
			
			obj.syntax = result;
			
			if(obj.syntax){
				target = document.getElementById('js_inquiry_submit_on');
				if(target) target.style.display = 'block';
				
				target = document.getElementById('js_inquiry_submit_off');
				if(target) target.style.display = 'none';
				
				if(! obj.initialized){
					target = document.getElementById('js_inquiry_submit_on');
					try {
						target.addEventListener('click', function(){NDG_CORE.inquiry.send();},false);
					}catch(e){
						target.attachEvent('onclick', function(){NDG_CORE.inquiry.send();});
					}
					obj.initialized = true;
				}
				
			}else{
				target = document.getElementById('js_inquiry_submit_on');
				if(target) target.style.display = 'none';
				
				target = document.getElementById('js_inquiry_submit_off');
				if(target) target.style.display = 'block';
			}
		},
		
		send : function(){
			var obj = NDG_CORE.inquiry;
			obj.check();
			if(! obj.syntax) return false;
			obj.initialized = false;
			
			var target;
			target = document.getElementById(obj.target);
			if(target) target.style.display = 'none';
			
			target = document.getElementById('js_sending');
			if(target) target.style.display = 'block';
			
			NDG_CORE.Ajax.request(
				'/contact/receive_inquiry.php?' + obj.query,
				function(responseText){
					NDG_CORE.float_area.area_div.innerHTML = responseText;
					var cancel = document.getElementById('btncancel');
					if(cancel){
						try {
							cancel.addEventListener('click', function(){NDG_CORE.float_area.click();},false);
						}catch(e){
							cancel.attachEvent('onclick', function(){NDG_CORE.float_area.click();});
						}
					}
				}
			);
			
		}
	},
	
	request : {
		target : 'js_request_form',
		syntax : false,
		initialized : false,
		query : '',
		
		check : function(){
			var obj = NDG_CORE.request;
			var check_value, target;
			
			target = document.getElementById(obj.target);
			if(! target) return false;
			
			var result = true;
			var query = '';
			
			// check name
			target = document.getElementById('js_request_name');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&na=' + encodeURIComponent(check_value);
			
			// check yomi
			target = document.getElementById('js_request_yomi');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&yo=' + encodeURIComponent(check_value);
			
			// check tel
			target = document.getElementById('js_request_tel');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&tl=' + encodeURIComponent(check_value);
			
			// check email
			target = document.getElementById('js_request_email');
			if(! target) return false;
			check_value = target.value;
			if(! check_value.match(/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i)) result = false; 
			query = query + '&em=' + encodeURIComponent(check_value);
			
			// check zip
			target = document.getElementById('js_request_zip');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&zp=' + encodeURIComponent(check_value);
			
			// check address
			target = document.getElementById('js_request_address');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&ad=' + encodeURIComponent(check_value);
			
			
			// check questions A
			var questions_value = '体験入学・学校見学について' + "\n";
			var chk_questions = false;
			// check - q1 
			target = document.getElementById('js_qa_1');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q2
			target = document.getElementById('js_qa_2');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q3
			target = document.getElementById('js_qa_3');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q4
			target = document.getElementById('js_qa_4');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q5
			target = document.getElementById('js_qa_5');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			
			if(chk_questions != true) result = false;
			
			
			// check questions B
			questions_value += '学校について知りたい事はありますか？' + "\n";
			var chk_questions = false;
			// check - q1 
			target = document.getElementById('js_qb_1');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q2
			target = document.getElementById('js_qb_2');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q3
			target = document.getElementById('js_qb_3');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q4
			target = document.getElementById('js_qb_4');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q5
			target = document.getElementById('js_qb_5');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q6
			target = document.getElementById('js_qb_6');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q7
			target = document.getElementById('js_qb_7');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q8
			target = document.getElementById('js_qb_8');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			// check - q9
			target = document.getElementById('js_qb_9');
			if(! target) return false;
			if(target.checked){
				chk_questions = true;
				questions_value += '・'+target.value + "\n";
			}
			
			if(chk_questions != true) result = false;
			
			query = query + '&qq=' + encodeURIComponent(questions_value);
			
			
			// if(questions_value != '') console.log(questions_value);
			
			
			if(result){
				target = document.getElementById('js_request_pref');
				if(! target) return false;
				query = query + '&pr=' + encodeURIComponent(target.value);
				
				target = document.getElementById('js_request_year');
				if(! target) return false;
				query = query + '&yr=' + encodeURIComponent(target.value);
				
				target = document.getElementById('js_request_interests');
				if(! target) return false;
				query = query + '&in=' + encodeURIComponent(target.value);
				
				target = document.getElementById('js_request_mailmagazine');
				if(target) if(target.checked) query = query + '&mm=' + encodeURIComponent('enable');
				
				obj.query = query;
			}
			
			obj.syntax = result;
			
			if(obj.syntax){
				target = document.getElementById('js_request_submit_on');
				if(target) target.style.display = 'block';
				
				target = document.getElementById('js_request_submit_off');
				if(target) target.style.display = 'none';
				
				if(! obj.initialized){
					target = document.getElementById('js_request_submit_on');
					try {
						target.addEventListener('click', function(){NDG_CORE.request.send();},false);
					}catch(e){
						target.attachEvent('onclick', function(){NDG_CORE.request.send();});
					}
					obj.initialized = true;
				}
				
			
			}else{
				target = document.getElementById('js_request_submit_on');
				if(target) target.style.display = 'none';
				
				target = document.getElementById('js_request_submit_off');
				if(target) target.style.display = 'block';
			}
		},
		
		send : function(){
			var obj = NDG_CORE.request;
			obj.check();
			if(! obj.syntax) return false;
			obj.initialized = false;
			
			var target;
			target = document.getElementById(obj.target);
			if(target) target.style.display = 'none';
			
			target = document.getElementById('js_sending');
			if(target) target.style.display = 'block';
			
			// encodeURIComponent();
			
			NDG_CORE.Ajax.request(
				'/contact/receive_request.php?' + obj.query,
				function(responseText){
					NDG_CORE.float_area.area_div.innerHTML = responseText;
					var cancel = document.getElementById('btncancel');
					if(cancel){
						try {
							cancel.addEventListener('click', function(){NDG_CORE.float_area.click();},false);
						}catch(e){
							cancel.attachEvent('onclick', function(){NDG_CORE.float_area.click();});
						}
					}
				}
			);
			
		}
	},
	
	visitor : {
		target : 'js_visitor_form',
		syntax : false,
		initialized : false,
		query : '',
		
		check : function(){
			var obj = NDG_CORE.visitor;
			var check_value, target;
			
			target = document.getElementById(obj.target);
			if(! target) return false;
			
			var result = true;
			var query = '';
			
			// check name
			target = document.getElementById('js_visitor_name');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&na=' + encodeURIComponent(check_value);
			
			// check yomi
			target = document.getElementById('js_visitor_yomi');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&yo=' + encodeURIComponent(check_value);
			
			// check tel
			target = document.getElementById('js_visitor_tel');
			if(! target) return false;
			check_value = target.value;
			if(check_value == '') result = false; 
			query = query + '&tl=' + encodeURIComponent(check_value);
			
			// check email
			target = document.getElementById('js_visitor_email');
			if(! target) return false;
			check_value = target.value;
			if(! check_value.match(/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i)) result = false; 
			query = query + '&em=' + encodeURIComponent(check_value);
			
			
			if(result){
				target = document.getElementById('js_visitor_date');
				if(! target) return false;
				query = query + '&td=' + encodeURIComponent(target.value);
				
				target = document.getElementById('js_visitor_time');
				if(! target) return false;
				query = query + '&tt=' + encodeURIComponent(target.value);
				
				target = document.getElementById('js_visitor_hour');
				if(! target) return false;
				query = query + '&th=' + encodeURIComponent(target.value);
				
				target = document.getElementById('js_visitor_mailmagazine');
				if(target) if(target.checked) query = query + '&mm=' + encodeURIComponent('enable');
				
				obj.query = query;
			}
			
			obj.syntax = result;
			
			if(obj.syntax){
				target = document.getElementById('js_visitor_submit_on');
				if(target) target.style.display = 'block';
				
				target = document.getElementById('js_visitor_submit_off');
				if(target) target.style.display = 'none';
				
				if(! obj.initialized){
					target = document.getElementById('js_visitor_submit_on');
					try {
						target.addEventListener('click', function(){NDG_CORE.visitor.send();},false);
					}catch(e){
						target.attachEvent('onclick', function(){NDG_CORE.visitor.send();});
					}
					obj.initialized = true;
				}
				
			
			}else{
				target = document.getElementById('js_visitor_submit_on');
				if(target) target.style.display = 'none';
				
				target = document.getElementById('js_visitor_submit_off');
				if(target) target.style.display = 'block';
			}
		},
		
		send : function(){
			var obj = NDG_CORE.visitor;
			obj.check();
			if(! obj.syntax) return false;
			obj.initialized = false;
			
			var target;
			target = document.getElementById(obj.target);
			if(target) target.style.display = 'none';
			
			target = document.getElementById('js_sending');
			if(target) target.style.display = 'block';
			
			// encodeURIComponent();
			
			NDG_CORE.Ajax.request(
				'/contact/receive_visitor.php?' + obj.query,
				function(responseText){
					NDG_CORE.float_area.area_div.innerHTML = responseText;
					var cancel = document.getElementById('btncancel');
					if(cancel){
						try {
							cancel.addEventListener('click', function(){NDG_CORE.float_area.click();},false);
						}catch(e){
							cancel.attachEvent('onclick', function(){NDG_CORE.float_area.click();});
						}
					}
				}
			);
			
		}
	},
	
	env : function (index){
		var obj = NDG_CORE;
		var result = null;
		switch(index){
		case 'win_height': result = obj.Browser.MSIE ? document.documentElement.clientHeight : window.outerHeight; break;
		case 'win_width':  result = obj.Browser.MSIE ? document.documentElement.clientWidth : window.outerWidth; break;
		}
		return result;
	},
	
	Ajax : {
		status : false,
		busy : false,
		
		request : function(aUrl, aFunc){
			NDG_CORE.Ajax.busy = true;
			httpObj = NDG_CORE.Ajax.createXMLHttpRequest();
			if( httpObj ){
				httpObj.open("GET","http://"+document.domain+aUrl,true);
				httpObj.onreadystatechange = function(){
					switch(httpObj.readyState){
					case 1: break;
					case 2: break;
					case 3: break;
					case 4:
						if(httpObj.status == 200){
							aFunc(httpObj.responseText);
						}
						NDG_CORE.Ajax.busy = false;
						break;
					}
			    };
				httpObj.send(null);
			}
			return true;
		},
		
		createXMLHttpRequest : function(){
			var ajax = false;
			if(window.XMLHttpRequest){
				ajax = new XMLHttpRequest();
			}else if(window.ActiveXObject){
				try{
					ajax = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e){
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			return ajax;
		}
	},
	
	preload : function(){
		var target = new Array("/images/quickform_body.png","/images/quickform_foot.png");
		var preload = new Array();
		for(i=0; i<target.length; i++){
			preload[i] = new Image();
			preload[i].src = target[i];
		}
	},
	
	debug : function(str){
		var target = document.getElementById('debug_area');
		if(target) target.innerHTML += '<br />' + str;
		console.log(str);
	},
	
	Browser: {
		MSIE: !!(window.attachEvent && !window.opera),
		Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
		AppleWebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
		Opera: !!(window.opera)
	}
};

try {
	window.addEventListener('load', function(){NDG_CORE.initialize();}, false);
}catch(e){
	window.attachEvent('onload', function(){NDG_CORE.initialize();});
}



// UI functions
function ndg_inquiry(){
	NDG_CORE.float_area.url = '/contact/quickform_inquiry.php';
	NDG_CORE.float_area.click();
}

function ndg_request(){
	NDG_CORE.float_area.url = '/contact/quickform_request.php';
	NDG_CORE.float_area.click();
}

function ndg_visitor(){
	NDG_CORE.float_area.url = '/contact/quickform_visitor.php';
	NDG_CORE.float_area.click();
}

function ndg_trial(index){
	NDG_CORE.float_area.url = '/contact/quickform_trial.php?trialid=' + index;
	NDG_CORE.float_area.click();
}

function ndg_display_switch(name, value){
	var obj = document.getElementById(name);
	if(obj) obj.style.display = value ? 'block' : 'none';
}
