
/*
 Basic operation
---------------------------------------------------------------------- */
window.onload = function() {
	var objForm;
	var i;


	//Delete focus for anchor
	objForm = document.getElementsByTagName('a');
	for (i=0 ; i<objForm.length ; i++) objForm[i].onfocus = function() {this.blur();}


	//Delete focus
	//Text all select
	objForm = document.getElementsByTagName('input');
	for (i=0 ; i<objForm.length ; i++) {
		switch (objForm[i].type) {
			case 'text':     objForm[i].onfocus = function() {this.select();};break;
			case 'password': objForm[i].onfocus = function() {this.select();};break;
			case 'checkbox': objForm[i].onfocus = function() {this.blur();};break;
			case 'radio':    objForm[i].onfocus = function() {this.blur();};break;
			case 'button':   objForm[i].onfocus = function() {this.blur();};break;
			case 'submit':   objForm[i].onfocus = function() {this.blur();};break;
			case 'reset':    objForm[i].onfocus = function() {this.blur();};break;
			default: break;
		}
	}
	objForm = document.getElementsByTagName('textarea');
	for (i=0 ; i<objForm.length ; i++) {
		objForm[i].onfocus = function() {this.select();};
	}


	//Open recruit
	objForm = document.getElementsByTagName('a');
	for (i=0 ; i<objForm.length ; i++) {
		if (objForm[i].id.match('recruit')) objForm[i].onclick = function() {show_window('recruit.php?page_id=1', 'recruit', 770, 580)}
	}


	//Open girl data
	objForm = document.getElementsByTagName('a');
	for (i=0 ; i<objForm.length ; i++) {
		if (objForm[i].id.match('show_')) objForm[i].onclick = function() {show_window('girl.php?girl_id=' + Number(this.id.replace(/show_/, '')), 'girl_view', 620, 760)}
	}


	//Change image
	objForm = document.getElementsByTagName('img');
	for (i=0 ; i<objForm.length ; i++) {
		if (objForm[i].id.match('sub_image_')) {
			objForm[i].onmouseover = function() {
				//Image tag
				document.main_image.src   = this.src;
				document.main_image.title = this.title;
			}
		}
	}


	//First set image
	objForm = document.getElementsByTagName('img');
	for (i=0 ; i<objForm.length ; i++) {
		if (objForm[i].id.match('sub_image_')) {
			//Image tag
			document.main_image.src   = objForm[i].src;
			document.main_image.title = objForm[i].title;

			break;
		}
	}
}


/*
 Open window
---------------------------------------------------------------------- */
function show_window(url, name, width, height) {
	//Get center point
	var x = (screen.width  - width)  / 2;
	var y = (screen.height - height) / 2;

	//Open
	window.open(url, name, 'width=' + width + ', height=' + height + ', left=' + x + ', top=' + y + ', scrollbars=yes', 'replace=false')
}


/*
 Iframe auto resize
---------------------------------------------------------------------- */
function resize_iframe(tgt_id) {
	var obj_iframe  = [tgt_id];
	var iframehide = "yes";

	//
	function resize_caller() {
		for (i = 0; i < obj_iframe.length; i++) {
			if (document.getElementById) {
				resize_iframe(obj_iframe[i]);
			}

			if ((document.all || document.getElementById) && iframehide=="no") {
				var tempobj=document.all? document.all[obj_iframe[i]] : document.getElementById(obj_iframe[i]);
				tempobj.style.display="block";
			}
		}
	}

	//
	function resize_iframe(frameid) {
		var currentfr=document.getElementById(frameid);

		if (currentfr && !window.opera) {
			currentfr.style.display="block";

			if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {
				currentfr.height = currentfr.contentDocument.body.offsetHeight; 
			} else if (currentfr.Document && currentfr.Document.body.scrollHeight) {
				currentfr.height = currentfr.Document.body.scrollHeight;
			}

			if (currentfr.addEventListener) {
				currentfr.addEventListener("load", readjust_iframe, false);
			} else if (currentfr.attachEvent) {
				currentfr.attachEvent("onload", readjust_iframe);
			}
		}
	}

	//
	function readjust_iframe(loadevt) {
		var crossevt=(window.event)? event : loadevt;
		var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;

		if (iframeroot) {
			resize_iframe(iframeroot.id);
		}
	}

	//
	function loadinto_iframe(iframeid, url) {
		if (document.getElementById) {
			document.getElementById(iframeid).src=url;
		}
	}

	//
	if (window.addEventListener) {
		window.addEventListener("load", resize_caller, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", resize_caller);
	} else {
		window.onload=resize_caller;
	}
}
