﻿/*
 * JS Common Function
 * 2009.06.09 KiHyunKim
 */

f_addEvent( window, "onload", removeAtagFocus, false );

function removeAtagFocus(){
	var objs = document.getElementsByTagName("A");
	for (var i=0; i<objs.length; i++) 
		objs[i].onfocus = onFocusAtag;
}
function onFocusAtag() {
	this.blur();
}

// Form Input Guide
var InputGuide = new Object();
InputGuide.addFormGuide = function( form ){
	var objs = form.getElementsByTagName('INPUT');
	for (var i=0; i<objs.length; i++) {
		if ((objs[i].type=='text') && (objs[i].title.length>0)) this.addInputGuide( objs[i] );
	}
}
InputGuide.addInputGuide = function( obj ) {
	obj.onfocus = this.onInputGuideFocus;
	obj.onblur	= this.onInputGuideBlur;
	this.onInputGuideBlur.bind( obj )();
}
InputGuide.onInputGuideFocus = function() {
	if (this.value==this.title) {
		this.style.color = "#000000";
		this.value = "";
	}
	return true;
}
InputGuide.onInputGuideBlur = function() {
	if ((this.value.trim().length==0) || (this.value==this.title)) {
		this.style.color = "#999999";
		this.value = this.title;
	}
	return true;
}

// Movie Window
function openServiceMovie(title) {
	//top.window.open( "/service/popup_movie.asp?service="+encodeURIComponent(title), "PopupMovie", "width=193,height=129,resizable=0,scrollbars=0,menubar=0,location=0,status=0,directories=0,toolbar=0" );
}
function f_adjustPopupSize(width,height) {
	top.resizeBy(width-top.LPlib.browserSize().width, 0);
	top.resizeBy(0, height-top.LPlib.browserSize().height);
}

// Flash Embed
function f_writeFlashTags(id,src,width,height,wmode,bgcolor,flashvars) {
	var requiredMajorVersion = 9;
	var requiredMinorVersion = 0;
	var requiredRevision = 124;
	var hasProductInstall = DetectFlashVer(6, 0, 65);
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if ( hasProductInstall && !hasRequestedVersion ) {
		var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
		var MMredirectURL = window.location;
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		var MMdoctitle = document.title;
		AC_FL_RunContent(
			"src", "/images/swf/playerProductInstall",
			"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
			"width", width,
			"height", height,
			"align", "middle",
			"id", id,
			"quality", "high",
			"bgcolor", bgcolor,
			"wmode", wmode,
			"name", id,
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	} else if (hasRequestedVersion) {
		AC_FL_RunContent(
		"src", src,
		"flashvars", flashvars,
		"width", width,
		"height", height,
		"align", "middle",
		"id", id,
		"quality", "high",
		"bgcolor", bgcolor,
		"wmode", wmode,
		"name", id,
		"allowScriptAccess","sameDomain",
		"type", "application/x-shockwave-flash",
		"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	} else {
		var alternateContent = 'このサイトをご覧になるには<a href="http://www.adobe.com/go/getflash/" target="_blank">FlashPlayer</a>が必要です。';
		document.write(alternateContent);
	}
}

//Check Form
function onKeyDownCheckNumber(e) {
	var obj		= ( (window.event) ? window.event.srcElement : e.target );
	var code	= ( (window.event) ? event.keyCode : e.which );
	var shift	= ( (window.event) ? event.shiftKey : e.shiftKey );
	var ctrl	= ( (window.event) ? event.ctrlKey : e.ctrlKey );
	var alt		= ( (window.event) ? event.altKey : e.altKey );
	if (
		((alt == true) && (code >= 37 && code <= 40)) ||
		((ctrl == true && (code == 78 || code == 82)) || (code >= 112 && code <= 123)) ||
		((!alt) && (!ctrl) && code!=8 && code!=9 && code!=46 && (code<35 || code>40) && (code<48 || code>57) && (code<96 || code>105)) ||
		((shift==true) && (code<35 || code>40))
		) {
		//alert(alt.toString() + ctrl.toString() + shift.toString() + code.toString());
		if (window.event) { try { event.keyCode = 0; event.cancelBubble = true; event.returnValue = false; }catch(e){} }
		return false;
		
	}
	return true;
}

function onKeyDownCheckEmail(e) {
	var obj		= ( (window.event) ? window.event.srcElement : e.target );
	var code	= ( (window.event) ? event.keyCode : e.which );
	var shift	= ( (window.event) ? event.shiftKey : e.shiftKey );
	var ctrl	= ( (window.event) ? event.ctrlKey : e.ctrlKey );
	var alt		= ( (window.event) ? event.altKey : e.altKey );
	if (
		((alt == true) && (code >= 37 && code <= 40)) ||
		((ctrl == true && (code == 78 || code == 82)) || (code >= 112 && code <= 123)) ||
		((!alt) && (!ctrl) && code!=8 && code!=9 && code!=46 && (code<35 || code>40) && (code<48 || code>57) && (code<96 || code>105) && (code<65 || code>90) && code!=189 && code!=109 && code!=190 && code!=110 ) ||
		((shift==true) && (code<35 || code>40) && code!=50 && code!=109 && code!=189)
		) {
		//alert(alt.toString() + ctrl.toString() + shift.toString() + code.toString());
		if (window.event) { try { event.keyCode = 0; event.cancelBubble = true; event.returnValue = false; }catch(e){} }
		return false;
		
	}
	return true;
}

function onKeyDownCheckTelephone(e) {
	var obj		= ( (window.event) ? window.event.srcElement : e.target );
	var code	= ( (window.event) ? event.keyCode : e.which );
	var shift	= ( (window.event) ? event.shiftKey : e.shiftKey );
	var ctrl	= ( (window.event) ? event.ctrlKey : e.ctrlKey );
	var alt		= ( (window.event) ? event.altKey : e.altKey );
	if (
		((alt == true) && (code >= 37 && code <= 40)) ||
		((ctrl == true && (code == 78 || code == 82)) || (code >= 112 && code <= 123)) ||
		((!alt) && (!ctrl) && code!=8 && code!=9 && code!=46 && (code<35 || code>40) && (code<48 || code>57) && (code<96 || code>105) && code!=189 && code!=109 ) ||
		((shift==true) && (code<35 || code>40) && code!=48 && code!=57)
		) {
		//alert(alt.toString() + ctrl.toString() + shift.toString() + code.toString());
		if (window.event) { try { event.keyCode = 0; event.cancelBubble = true; event.returnValue = false; }catch(e){} }
		return false;
		
	}
	return true;
}

function f_checkKanjiHiraKana(str) {
	for (var i=0; i<str.length; i++) if ((!str.isHiraKana(i)) && (!str.isKanji(i))) return false;
	return true;
}

function alertInputFailure(obj, msg) {
	var errorBox = document.getElementById("error_msg");
	if (errorBox) {
		errorBox.innerHTML = msg;
		errorBox.style.display = "block";
	}
	if (!obj.type) {
		if ( obj[0] && ((obj[0].type=='radio')||(obj[0].type=='checkbox')) ) {
			obj[0].focus();
			return false;
		}
	}
	obj.focus();
	return false;
}

function hideInputFailure() {
	var errorBox = document.getElementById("error_msg");
	if (errorBox) {
		errorBox.innerHTML = "";
		errorBox.style.display = "none";
	}
	return false;
}