var img = document.getElementsByTagName("img");
var div = document.getElementsByTagName("div");
var form = document.getElementsByTagName("form");
var a = document.getElementsByTagName("a");
var input = document.getElementsByTagName("input");
var txt = document.getElementsByTagName("textarea");
var selects = document.getElementsByTagName("select");

function ovr() {
	for(i = 0; i < img.length; i++) {
		img[i].onmouseover = function() {
			if(this.className == "ovr") {
				this.src = this.src.replace(".gif" , "_ovr.gif");
				this.src = this.src.replace(".jpg" , "_ovr.jpg");
				this.src = this.src.replace(".png" , "_ovr.png");
			}
		}
		img[i].onmouseout = function() {
			if(this.className == "ovr") {
				this.src = this.src.replace("_ovr.gif" , ".gif");
				this.src = this.src.replace("_ovr.jpg" , ".jpg");
				this.src = this.src.replace("_ovr.png" , ".png");
			}
		}
	}
}

function uranai() {
	if(div["uranai"].style.display == "none") {
		div["uranai"].style.display = "block";
	} else if(div["uranai"].style.display == "block") {
		div["uranai"].style.display = "none";
	}
}

function cards(id1 , id2 , id3 , id4 , id5 , id6) {
		img[id1].src = "/common/images/card2/select.gif";
		
		img[id2].style.visibility = "hidden";
		img[id3].style.visibility = "hidden";
		img[id4].style.visibility = "hidden";
		img[id5].style.visibility = "hidden";
		img[id6].style.visibility = "hidden";
}
//印刷
function PrintPage(){
	if(document.getElementById || document.layers){
		window.print();		//印刷をします
	}
}

function clears(formName) {
	reset();
}

//問合せチェック
function toi() {
	if(!input["name"].value) {
		alert("お名前を入力してください");
		return false;
	}
	if(!input["kana"].value) {
		alert("フリガナを入力してください");
		return false;
	} else {
		if(!input["kana"].value.match(/^[\u30A0-\u30FF]+$/)) {
			alert("フリガナは全角カナで入力してください");
			return false;
		}
	}
	if(!input["email"].value) {
		alert("メールアドレスを入力してください");
		return false;
	} else {
		if(!input["email"].value.match(/^\S+@\S+\.\S+$/)) {
			alert("メールアドレスの形式が正しくありません");
			return false;
		}
	}
	if(!txt["msg"].value) {
		alert("内容を入力してください");
		return false;
	}
}



//会員登録チェック
function joinMember() {
	
	if(!input["email"].value) {
		alert("メールアドレスを入力してください");
		return false;
	} else {
		if(!input["email"].value.match(/^\S+@\S+\.\S+$/)) {
			alert("メールアドレスの形式が正しくありません");
			return false;
		}
	}
	
	if(!input["emailcheck"].value) {
		alert("確認用に再度メールアドレスを入力してください");
		return false;
	} else {
		if(input["emailcheck"].value != input["email"].value) {
			alert("メールアドレスが一致しません");
			return false;
		}
	}
	
	
	if(!input["pwd"].value) {
		alert("パスワードを入力してください");
		return false;
	} else {
		var str = input["pwd"].value;
		if(str.length < 4) {
			alert("パスワードは4文字以上で入力してください");
			return false;
		}
		if(str.length > 10) {
			alert("パスワードは10文字以内で入力してください");
			return false;
		} 
		if(str.match(/^[0-9]+$/) || str.match(/^[a-zA-z¥s]+$/)) {
			alert("パスワードは半角英字と半角数字を混ぜてください");
			return false;
		}
	}
	
	if(!selects["sex"].value || selects["sex"].value == "選択してください" || selects["sex"].value == "") {
		alert("性別を選択してください");
		return false;
	}
	
	if(!input["y"].value) {
		alert("生まれた年を西暦で入力してください");
		return false;
	}
	if(!input["y"].value.match(/^[0-9]+$/)) {
		alert("入力データが正しくありません");
		return false;
	}
	if(!input["m"].value) {
		alert("生まれた月を入力してください");
		return false;
	}
	if(!input["m"].value.match(/^[0-9]+$/)) {
		alert("入力データが正しくありません");
		return false;
	}
	if(!input["d"].value) {
		alert("生まれた日を入力してください");
		return false;
	}
	if(!input["d"].value.match(/^[0-9]+$/)) {
		alert("入力データが正しくありません");
		return false;
	}
}

//広告申込（input）
function onB() {
	for(i = 0; i < input.length; i++) {
		input[i].onFocus = function() {
			this.style.backgroundColor = "#ffffff";
		}
		input[i].onBlur = function() {
			this.style.backgroundColor = "#f0f0f0";
		}
	}
	for(s = 0; s < selects.length; s++) {
		selects[s].onFocus = function() {
			this.style.backgroundColor = "#ffffff";
		}
		selects[s].onBlur = function() {
			this.style.backgroundColor = "#f0f0f0";
		}
	}
	for(t = 0; t < txt.length; t++) {
		txt[t].onFocus = function() {
			this.style.backgroundColor = "#ffffff";
		}
		txt[t].onBlur = function() {
			this.style.backgroundColor = "#f0f0f0";
		}
	}
}
//広告申込（金額計算）
function publicPrice(type) {
	if(type == "A") {
		if(selects["terms"].value == 1) {
			input["price"].value = 120000;
		}
		else if(selects["terms"].value == 2) {
			input["price"].value = 235000;
		}
		else if(selects["terms"].value == 3) {
			input["price"].value = 350000;
		}
	}
	else if(type == "B") {
		if(selects["terms"].value == 1) {
			input["price"].value = 98000;
		}
		else if(selects["terms"].value == 2) {
			input["price"].value = 195000;
		}
		else if(selects["terms"].value == 3) {
			input["price"].value = 290000;
		}
	}
	else if(type == "C") {
		if(selects["terms"].value == 1) {
			input["price"].value = 68000;
		}
		else if(selects["terms"].value == 2) {
			input["price"].value = 135000;
		}
		else if(selects["terms"].value == 3) {
			input["price"].value = 202000;
		}
	}
	else if(type == "D") {
		if(selects["terms"].value == 1) {
			input["price"].value = 50000;
		}
		else if(selects["terms"].value == 2) {
			input["price"].value = 99000;
		}
		else if(selects["terms"].value == 3) {
			input["price"].value = 148000;
		}
	}
}
//広告申込（入力チェック）
function public() {
	if(!input["name"].value) {
		alert("お名前を入力してください");
		return false;
	}
	if(!input["kana"].value) {
		alert("フリガナを入力してください");
		return false;
	} else {
		if(!input["kana"].value.match(/^[\u30A0-\u30FF]+$/)) {
			alert("フリガナは全角カナで入力してください");
			return false;
		}
	}
	
	if(!input["cName"].value) {
		alert("会社名を入力してください");
		return false;
	}
	if(!input["cKana"].value) {
		alert("会社名のフリガナを入力してください");
		return false;
	} else {
		if(!input["cKana"].value.match(/^[\u30A0-\u30FF]+$/)) {
			alert("フリガナは全角カナで入力してください");
			return false;
		}
	}
	
	if(!input["email"].value) {
		alert("メールアドレスを入力してください");
		return false;
	} else {
		if(!input["email"].value.match(/^\S+@\S+\.\S+$/)) {
			alert("メールアドレスの形式が正しくありません");
			return false;
		}
	}
	
	if(!input["stay"].value) {
		alert("会社の所在地を入力してください");
		return false;
	}
	if(!input["tel"].value) {
		alert("連絡先（電話番号）を入力してください");
		return false;
	}
	
	if(!selects["terms"].value) {
		alert("掲載期間を選択してください");
		return false;
	}
	
	if(!input["sitename"].value) {
		alert("サイト名を入力してください");
		return false;
	}
	if(input["siteUrl"].value) {
		if(input["siteUrl"].value == "http://") {
			alert("サイトURLを入力してください");
			return false;
		}
	}
	if(!input["category"].value) {
		alert("サイトのカテゴリーを入力してください");
		return false;
	}
	
	if(!txt["site"].value) {
		alert("サイト内容を入力してください");
		return false;
	}
}

function pp() {
	if(input["price"]) {
		input["price"].onclick = function() {
			alert("書き換えは出来ません");
			input["price"].blur();
		}
		input["price"].onselectstart = function() {
			alert("書き換えは出来ません");
			input["price"].blur();
		}
		input["price"].onkeydown = function() {
			alert("書き換えは出来ません");
			input["price"].blur();
		}
	}
}
window.onload = function() {
	ovr();
	onB();
	pp();
}