function slistInit(){

	var fName = 'catList.xml?(new Date()).getTime()';

	httpObj = createXMLHttpRequest(catListInitData);

	if (httpObj){

		httpObj.open("GET",fName,true);

		httpObj.send(null);

		}

}

function catListInitData(){

	if ((httpObj.readyState == 4) && (httpObj.status == 200)){

		xmlData = httpObj.responseXML;

		pCatListTags = xmlData.getElementsByTagName("parentCat");

		pcatLen = pCatListTags.length;

		CatListValue = "";

		CatListValue += '<select id="subCat" onchange="loadLinkCode();" name="subCat">';

		CatListValue += '<option value="0" selected="selected">選択してください</option>';

		for(l=0; l<pcatLen; l++){

			pCatnum = pCatListTags[l].getAttribute("num");

			pCatname = pCatListTags[l].getAttribute("name");

			

			spnum = document.regForm.parentCat.value;



			catListTags = pCatListTags[l].getElementsByTagName("category");

			userLen = catListTags.length;

			

			if(pCatnum == spnum){

				for(i=0; i<userLen; i++){

					num = catListTags[i].getAttribute("number");

					cname = catListTags[i].getAttribute("catName");

					CatListValue +='<option value="' + num + '">'+cname+'</option>';

				}

			}

			

		}

		CatListValue += '</select>';

		document.getElementById('subCatList').innerHTML = CatListValue;

	}else{

	}

}



function loadLinkCode(){

	var fName = 'catList.xml?(new Date()).getTime()';

	httpObj = createXMLHttpRequest(displayData);

	if (httpObj){

		httpObj.open("GET",fName,true);

		httpObj.send(null);

		}

}

function displayData(){

	if ((httpObj.readyState == 4) && (httpObj.status == 200)){

		xmlData = httpObj.responseXML;

		pCatListTags = xmlData.getElementsByTagName("parentCat");

		pcatLen = pCatListTags.length;

		resultText = "";

		for(l=0; l<pcatLen; l++){

			pCatnum = pCatListTags[l].getAttribute("num");

			pCatname = pCatListTags[l].getAttribute("name");

			dLinkName = pCatListTags[l].getAttribute("defaultName");

			dLinkUrl = pCatListTags[l].getAttribute("defaultUrl");

			spnum = document.regForm.parentCat.value;



			catListTags = pCatListTags[l].getElementsByTagName("category");

			userLen = catListTags.length;

			

			if(pCatnum == spnum){

				for(i=0; i<userLen; i++){

					num = catListTags[i].getAttribute("number");

					cname = catListTags[i].getAttribute("catName");

					lname = catListTags[i].getAttribute("linkName");

					lurl = catListTags[i].getAttribute("linkUrl");

					if(lname==""){

						lname = dLinkName;

						lurl = dLinkUrl;

					}

					snum = document.regForm.subCat.value;

						if(num == snum){

						//	resultText = '<a href="' +  lurl + '">' + lname + '</a>';

							resultText = '<a href="http://www.sougolinker.com">相互リンク</a><a href="' +  lurl + '">' + lname + '</a>';

							document.getElementById('linkUrl').innerHTML = '<div class="linkedUrl" id="linkedUrl'+snum+'"></div><input type=\"hidden\" name=\"linkedUrl\" id=\"linkedUrl\" value=\"\" /><span id=\"linkedUrl_mm\"></span>';

							document.regForm.checkUrl.value = lurl;



							new Ajax.InPlaceEditor( 'linkedUrl'+snum, 'lib/php/check.php?lurl='+lurl, {size:60,onComplete:function(transport, element) {new Effect.Highlight(element, {startcolor: this.options.highlightcolor});

																																									 document.regForm.linkedUrl.value = element.innerHTML;

																																									 formCheck('lurl');

																																									 }} );

					}else{

					}

				}

			}

		}

		document.regForm.linkCode.value = resultText;

		new Effect.Highlight('linkedUrl'+snum, {keepBackgroundImage:true});

	}else{

		document.regForm.linkCode.value = "Loading...";

	}

}

