/* Flash Contents Express ------------------------------- */

function topSWF(PATH,YOKO,TATE) {
	TAG_object = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + YOKO + '" height="' + TATE + '" />'
	TAG_file = '<param name="movie" value="' + PATH + '" />'
	TAG_embed = '<embed src="' + PATH + '" quality="high" width="' + YOKO + '" height="' + TATE + '" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_jp"></embed>'

	document.write(TAG_object);
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write(TAG_file);
	document.write('<param name="quality" value="high" />');
	document.write(TAG_embed);
	document.write('</object>');
}


/* Close Window ----------------------------------------- */

function killwin() {
	window.close();
}


/* Login Select ----------------------------------------- */

function chkradio(flag) {
	if(flag == 0) {
		document.getElementById('login-mypage').style.display = 'block';
		document.getElementById('login-shift').style.display = 'none';
	} else {
		document.getElementById('login-mypage').style.display = 'none';
		document.getElementById('login-shift').style.display = 'block';
	}
}


/* Login Text ------------------------------------------- */

var DEFAULT_PASSWORD = 'パスワード';
var INPUT_TYPE_PASSWORD = 'password';
var INPUT_TYPE_TEXT = 'text';
var TEXT_FOCUS_COLOR = '#000';
var TEXT_BLUR_COLOR = '#999';

function myIDf(obj) {
	if(obj.value==obj.defaultValue) {
		obj.value="";
		obj.style.color=TEXT_FOCUS_COLOR;
	}
}

function myIDb(obj) {
	if(obj.value=="") {
		obj.value=obj.defaultValue;
		obj.style.color=TEXT_BLUR_COLOR;
	}
}

function myPWf(obj) {
	if(obj.value==DEFAULT_PASSWORD) {
		changePWElement(obj, INPUT_TYPE_PASSWORD, "", TEXT_FOCUS_COLOR, true);
	}
}

function myPWb(obj) {
	if(obj.value=="") {
		changePWElement(obj, INPUT_TYPE_TEXT, DEFAULT_PASSWORD, TEXT_BLUR_COLOR, false);
	}
}

function doMyPageLogin(formObject) {
	doLogin('mypageLoginForm', 'myID', 'myPW');
}


function sfIDf(obj) {
	if(obj.value==obj.defaultValue) {
		obj.value="";
		obj.style.color=TEXT_FOCUS_COLOR;
	}
}

function sfIDb(obj) {
	if(obj.value=="") {
		obj.value=obj.defaultValue;
		obj.style.color=TEXT_BLUR_COLOR;
	}
}

function sfPWf(obj) {
	if(obj.value==DEFAULT_PASSWORD) {
		changePWElement(obj, INPUT_TYPE_PASSWORD, "", TEXT_FOCUS_COLOR, true);
	}
}

function sfPWb(obj) {
	if(obj.value=="") {
		changePWElement(obj, INPUT_TYPE_TEXT, DEFAULT_PASSWORD, TEXT_BLUR_COLOR, false);
	}
}

function doWebShiftLogin(formObject) {
	doLogin('webShiftLoginForm', 'sfID', 'sfPW');
}

function changePWElement(element, type, value, color, isFocus){

	try {
		if(isFocus){
			element.value = value;
			element.setAttribute("type", type);
		}else{
			element.setAttribute("type", type);
			element.value = value;
		}
		element.style.color = color;

	} catch (e) {
		var newElement = null;
		try {
			newElement = document.createElement("<input type='" + type + "' name='" +  element.getAttribute('name') +"'>");
		} catch (e2) {
		}

		if(newElement == null){
			newElement = document.createElement("input");
			newElement.setAttribute("name", element.getAttribute('name'));
		}

	        var test = newElement.getAttribute("type");	
		if(test == null){
			newElement.setAttribute("type", type);
		}
		newElement.setAttribute("id", element.getAttribute('id'));
		newElement.setAttribute("maxlength", element.getAttribute('maxlength'));
		newElement.setAttribute("onfocus", element.getAttribute('onfocus'));
		newElement.setAttribute("onblur", element.getAttribute('onblur'));
		newElement.className = element.className;
		newElement.value = value;
		element.style.color = color;

		element.parentNode.replaceChild(newElement, element);

		if(isFocus){
			newElement.focus();
			newElement.focus();
		}else{
			newElement.blur();
		}
	}
}

function doLogin(form, id, pw){

	var idElement = document.getElementById(id);
	var pwElement = document.getElementById(pw);
	var formElement = document.getElementById(form);
	var path = formElement.getAttribute('action');

	if(idElement.value != idElement.defaultValue && pwElement.value != DEFAULT_PASSWORD) {
		formElement.action = 'https://' + location.host + path;
		formElement.submit();
		formElement.action = path;
	}
}
