

function list_page_submit(page)
{
	document.submit_form.page.value=page;
	document.submit_form.submit();
}


function GetHeight(ID,NAME)
{
	if (document.height){
		alert("a"+parent.frames[NAME].document.height);
		document.getElementById(ID).style.height = parent.frames[NAME].document.height +20 +"px" ;
	}else{
		alert(document.getElementById(ID).style.width);
		alert("b"+parent.frames[NAME].document.body.scrollWidth);
		document.getElementById(ID).style.height = parent.frames[NAME].document.body.scrollHeight +20 +"px";
		document.getElementById(ID).style.width  = parent.frames[NAME].document.body.scrollWidth +20 +"px";
	}
}


function submitDetailSearch(type)
{
	var sel = $('#mode'+type).val();

	$('#mode').val(sel);
	$('#search').submit();

}

function affiliate_link(a){
	window.open("affiliate-link.php?sid="+a,"","width=500,height=580");
}
function affiliate_link2(){
	window.open("affiliate-link2.php","","width=500,height=380");
}

function alert_kiyaku(){
	alert( "会員規約に同意していただけない場合、会員登録することはできません。" );
}


//メールマガジン　
//フォーム送信
function submit_mailmaga(op)
{
	var send = 0;
	if( op == "add" ){
		if(mailchk(document.mailmaga_form.email.value) == false){
			alert("メールアドレスを正しく入力してください。");
		}else{
			send = 1;
		}
	}else if( op == "edit" ){
		if(mailchk(document.mailmaga_form.email_old.value) == false) {
			alert("登録しているメールアドレスを正しく入力してください。");
		}else{
			var mail = document.mailmaga_form.email_new.value;
			if( mail != "" && mailchk(mail) == false) {
				alert("変更後のメールアドレスを正しく入力してください。");
			} else {
				send = 1;
			}
		}
	}else if( op == "delete" ){
		if (mailchk(document.mailmaga_form.email_stop.value) == false) {
			alert("メールアドレスを正しく入力してください。");
		} else {
			send = 1;
		}
	}
	
	if( send ){
		document.mailmaga_form.op.value = op;
		document.mailmaga_form.submit();
	}
}

//アフィリエイト　------------------------------------------------------
function affiliate_reset() {
	document.affiliate.reset();
}

function affiliate_check() {
	var err_msg="";

	if (document.affiliate.name.value.length < 2) {
		err_msg += "・お名前\n";
	}
	if (document.affiliate.kana.value.length < 2) {
		err_msg += "・ふりがな\n";
	}
	if (document.affiliate.birthday_year.value == "----") {
		err_msg += "・生年月日(西暦)\n";
	}
	if (document.affiliate.birthday_month.value == "--") {
		err_msg += "・生年月日(月)\n";
	}
	if (document.affiliate.birthday_day.value == "--") {
		err_msg += "・生年月日(日)\n";
	}
	if (document.affiliate.post.value.length < 8) {
		err_msg += "・郵便番号\n";
	}
	if (document.affiliate.pref.value == "") {
		err_msg += "・都道府県\n";
	}
	if (document.affiliate.city.value == "") {
		err_msg += "・市区郡\n";
	}
	if (document.affiliate.town.value == "") {
		err_msg += "・町村字\n";
	}
	if (document.affiliate.street.value == "") {
		err_msg += "・番地\n";
	}
	if (document.affiliate.phone.value == "") {
		err_msg += "・電話番号\n";
	}
	if(mailchk(document.affiliate.email.value) == false) {
		err_msg += "・メールアドレス\n";
	}
	if (document.affiliate.homepage.value == "") {
		err_msg += "・ホームページアドレス\n";
	}
	if (err_msg.length > 0) {
		alert("以下の項目を正しく入力して下さい。\n\n" + err_msg);
	} else {
		document.affiliate.op.value = "check";
		document.affiliate.submit();
	}
}




var gCnt=0;
var gNum=32;

$(document).ready(function(){
	var a = $('#brand').get();
	if( a.length > 0 ){
//		alert(a);
		
		
		get_brand_list(32,0);
		
	}

});
var TimerID;
function get_brand_list(num,cnt)
{
	if(TimerID) {
		clearTimeout(TimerID);
	}
//	var gid = $("#search input[name='gid']").val();
	var gid = $("input[name='gid']").val();
//	alert(gid);

	$.ajax({
	  url: "ajax_brand_list.php",
	  cache: false,
      type: "POST",
      data: "gid="+gid+"&cnt="+cnt+"&num="+num,
	  success:callback_func,
	  async: true
	 });

}

function callback_func(datas)
{
	if( datas != "" && datas != "NG" ){
//alert(datas);
		var gid = $("input[name='gid']").val();

		var arr = datas.split("\n");
		var _num = arr[0];
		var i;
		
		var html;
		for(i=0 ; i<_num ; i++){
			var arr2 = arr[i+1].split("<|>");
			
			if( (i)%4 == 0 ){
				html = "<ul>";
			}
			html += "<li><p><label>";
			html += "<input type='checkbox' value='"+arr2[1]+"' name='b[]' />";
			html += "<a href='list.php?gid="+gid+"&type=brand&b="+arr2[0]+"' class='wordBreak' title='"+arr2[2]+"'>"+arr2[2]+"</a>";
		   	html += "</label></p></li>";
			if( (i+1)%4 == 0 ){
				html += "</ul>";

				var n = $("#brand_div ul").length;
				if( n > 0 ){
					$("#brand_div ul:eq("+(n-1)+")").after(html);
				}else{
					$("#brand_div").append(html);
				}
			}
		}
		if( (_num%4) != 0 ){
			html += "</ul>";
			var n = $("#brand_div ul").length;
			if( n > 0 ){
				$("#brand_div ul:eq("+(n-1)+")").after(html);
			}else{
				$("#brand_div").append(html);
			}
		}
		if( _num >= gNum ){
			gCnt++;
			get_brand_list(32,gCnt);
//			get_brand_list(30,cnt+1);
//			TimerID = setTimeout(get_brand_list(30,cnt+1), 1000);
		}
	}
}

//--------------------------------------------------------------------------------------------------------------
//メールフォーマットチェック（Ａ－ｃｕｔｅより抜粋）
function mailchk(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray == null) {
		alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat) == null) {
		alert("The username doesn't seem to be valid.")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray != null) {
		// this is an IP address
		for (var i=1; i<=4; i++) {
			if (IPArray[i] > 255) {
				alert("Destination IP address is invalid!")
				return false
			}
		}
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray == null) {
		alert("The domain name doesn't seem to be valid.")
		return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 4)) {
	   alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	if (len<2) {
		var errStr="This address is missing a hostname!"
		alert(errStr)
		return false
	}
	return true;
}

