var x=0;
var n=1;
var o=0;

jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery('#aaa').hide();
	jQuery('#bbb').hide();
	jQuery('#field_child').hide();	
	//jQuery('#eee').hide();	
	jQuery('#add').hide();	
});
function choose_type(type){
	jQuery.noConflict();
	if(type=='checkbox'||type=='radio'||type=='select'||type=='sel_set'){
		jQuery('#aaa').show();
		jQuery('#bbb').show();
		jQuery('#field_child').show();		
		//jQuery('#eee').hide();
		jQuery('#add').show();		
	}
	else if(type=="tyc"){
		jQuery('#aaa').hide();
		jQuery('#bbb').hide();
		jQuery('#field_child').hide();		
		//jQuery('#eee').hide();
		jQuery('#add').hide();		
	}
	else if(type=="sel_set"){
		jQuery('#aaa').show();
		jQuery('#bbb').show();
		jQuery('#field_child').show();		
		//jQuery('#eee').show();
		jQuery('#add').show();		
	}
	else{
		jQuery('#aaa').show();
		jQuery('#bbb').show();
		jQuery('#field_child').hide();		
		//jQuery('#eee').hide();
		jQuery('#add').show();
	}
}
function click_field(type){

	jQuery.noConflict();
	if(type=='checkbox'||type=='radio'||type=='select'||type=='sel_set'){
		jQuery('#aaa').show();
		jQuery('#bbb').show();
		jQuery('#field_child').show();		
		//jQuery('#eee').hide();
		click_field_child(type,null);
	}	
	else if(type=="text"){
		alert("テキストタイプは使用できません");
		return;
	}
	else if(type=="textarea"){
		alert("テキストエリアフィールドタイプは使用できません");
		return;
	}
	else if(type=="file"){
		alert("ファイルタイプは使用できません");
		return;
	}
	else if(type=="password"){
		alert("パスワードタイプは使用できません");
		return;
	}
	else if(type=="address"){
		alert("住所タイプは使用できません");
		return;
	}
	else if(type=="email"){
		alert("Eメールタイプは使用できません");
		return;
	}
	else if(type=="coment"){
		alert("コメントタイプは使用できません");
		return;
	}
	
	else if(type=="tyc"){
		alert("フィールドタイプ選択ください");
		jQuery('#aaa').show();
		jQuery('#bbb').show();
		jQuery('#label_child').hide();		
		//jQuery('#eee').hide();
		return;
	}
	else{
		jQuery('#aaa').show();
		jQuery('#bbb').show();
		jQuery('#label_child').hide();	
		//jQuery('#eee').hide();
	}
}
function click_field_child(){
	jQuery.noConflict();
	jQuery('#field_child').append('<div id="id1'+x+'">要素名：<input type="text"  name="child[]" value="" /><a href="javascript:deleteRow1('+x+');">削除</a></div>');
	//jQuery('#eee').hide();
	x++;
}
/*
function addseisei(type){
	
	jQuery.noConflict();
//	jQuery('#ddd').append('<div id="id2'+n+'"><a href="javascript:click_field_child2('+n+');">要素名生成</a>....<a href="javascript:deleteRow2('+n+');">削除</a></div>');
	n++;
}

function click_field_child2(index){
	jQuery.noConflict();
	jQuery("#id2"+index).append('<div id="id3'+o+'">要素名：<input type="text"  name="child[]" value="" /><a href="javascript:deleteRow3('+o+');">削除</a></div>');
//	jQuery('#eee').show();
	o++;
}
*/
function deleteRow1(index)
  {
   var row = jQuery("#id1"+index);
   row.fadeOut("slow", function()
    {
     row.remove();
    });
  }
function deleteRow2(index)
{
 var row = jQuery("#id2"+index);
 row.fadeOut("slow", function()
  {
   row.remove();
  });
}

function deleteRow3(index)
{
 var row = jQuery("#id3"+index);
 row.fadeOut("slow", function()
  {
   row.remove();
  });
}


function changeorder(id,ptype){
	document.admf.fieldid.value=id;
	move(ptype);
}
function changeorderchild(id,cid,ptype){
	document.admf.fieldid.value=id;
	document.admf.fieldcid.value=cid;
	move(ptype);
}

function delfield(id){

	document.admf.fieldid.value=id;
	move('del');
}
function delfieldc(id,cid){

	document.admf.fieldid.value=id;
	document.admf.fieldcid.value=cid;
	move('del');
}
function delfieldc2(id,cid,cid2){
	
	document.admf.fieldid.value=id;
	document.admf.fieldcid.value=cid;
	document.admf.fieldcid2.value=cid2;
	move('del2');
	
}
function addfieldc(id){
	document.admf.fieldid.value=id;
	move('add_field_child');
}


function echeck(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	if(str.indexOf(at,(lat+1))!=-1){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	if(str.indexOf(dot,(lat+2))==-1){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	if(str.indexOf(" ")!=-1){
		alert("Eメールのフォーマットが正しくありません。");
		return false;
	}
	return true;				
}