function check_word_count(myform){
  var wc = myform.note.value;
  
  if(wc.length>1500){
  	alert("メモ帳は1500文字以上保存できません。");
  	return false;
  }
}

function moveGroup(gid)
{ 
  document.form2.mode.value = "move";
  document.form2.group_id.value = gid;
  document.form2.submit();
}

function add_favorite(id){
        var xmlhttp = getXmlhttp();
        var url = "";

        url = "/app/contact/index.php?mode=add&req=xmlhttp&favorite=1&contact_id="+id;
        xmlhttp.open('GET', url, true);
        xmlhttp.onreadystatechange = function(){
          if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
             res = xmlhttp.responseText;
             res = res.replace(/^\s+|\s+$/g,"");
             if(res == "added"){
               alert("お気に入りに追加しました。");
               xmlHttpGet('/app/search.php?favorite=1&limit=20&tpl=favorite&get_hits=0', 'onlineArea');
             }else if(res == "duplicate"){
               alert("既に登録されています。");
             }else if(res == "false"){
               alert("既に追加されています。");
             }else if(res == "limit"){
               alert("登録制限を越えました。お気に入りリストをご確認下さい。");
             }else{
               alert("追加できませんでした。");
             }
          }
        }

        xmlhttp.send(null);
}


function add_contact(id){
	var xmlhttp = getXmlhttp();
	var url = "";
	
	url = "/app/contact/index.php?mode=add&req=xmlhttp&contact_id="+id;
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
			res = xmlhttp.responseText;
	                res = res.replace(/^\s+|\s+$/g,"");		
			if(res == "added")
				//alert("メモ帳リストに追加しました。");
                                openContact(id);
			else if(res == "false")
				alert("既に追加されています。");
			else if(res == "limit")
				alert("登録制限を越えました。お気に入りリストをご確認下さい。");
			else
				alert("追加できませんでした。");
		}
	}
	
	xmlhttp.send(null);
}

function add_contact_by_names(names){
	var xmlhttp = getXmlhttp();
	var url = "";
	
	url = "/app/contact/index.php?mode=add_by_names&req=xmlhttp&list="+names;
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
			res = xmlhttp.responseText;
			
			if(res == "error")
				alert("既に追加されています。");
			else
				alert(res);
		}
	}
	
	xmlhttp.send(null);
}

function remove_favorite(dataform) {
   var myList = new Array();
  // var list = dataform.contact_list;
   var list =  document.getElementsByName('contact_list[]');
   var str = "";
   var j = 0;
   for (i=0; i<list.length; i++){
     if (list[i].checked==true && list[i].value.length > 0)
     {
        myList[j] = list[i].value;
        j++;
     }
   }
   str = myList.join(","); 
   if(str.length < 1 )  return;

   var xmlhttp = getXmlhttp();
   var params = "mode=update_contact&contact_list="+str;
   url = "/app/contact/index.php";
   xmlhttp.open('POST', url, true);
   xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xmlhttp.setRequestHeader("Content-length", params.length);
   xmlhttp.setRequestHeader("Connection", "close");
   xmlhttp.onreadystatechange = function(){
     if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
       var res = xmlhttp.responseText;
       //alert(res);
       loadFavorite();
     }
   }
   xmlhttp.send(params);
}

function loadFavorite(){
  xmlHttpGet('/app/search.php?favorite=1&tpl=favorite&get_hits=0', 'onlineArea');
}


function rollover(_tmp) 
{
  var node = document.getElementById(_tmp) ;
  if(!node && document.all) 
  {
    node = eval("document.all."+_tmp);
  }
  var new_src = node.src.substring(0,node.src.length-4) ;
  var new_src = new_src + "_2.gif" ;
  node.src = new_src ;
}

function rollout(_tmp) 
{
  var node = document.getElementById(_tmp) ;
  if(!node && document.all)
  {
    node = eval("document.all."+_tmp);
  }
  var new_src = node.src.substring(0,node.src.length-6) ;
  var new_src = new_src + ".gif" ;
  node.src = new_src ;
}

function display(_tmp)
{
  var node = document.getElementById(_tmp) ;
  if(!node && document.all)
  {
    node = eval("document.all."+_tmp);
  }
  //window.alert(node.style.visibility);
  if(!node.style) alert("should set node.style.visibility=true but node.style is null... crap! dsl .. _tmp->"+_tmp);
  node.style.visibility = "visible";
}

function un_display()
{
  var node = document.getElementById('layer1') ;
    if(!node && document.all) node = eval("document.all.layer1");
    if(node.style) //alert("should set node.style.visibility=true but node.style is null for layer1... crap! dsl");
  node.style.visibility = "hidden";
  
  /*
  var node = document.getElementById('layer2') ;
    if(!node && document.all) node = eval("document.all.layer2");
    if(node.style) //alert("should set node.style.visibility=true but node.style is null for layer2... crap! dsl");
  node.style.visibility = "hidden";
  var node = document.getElementById('layer3') ;
    if(!node && document.all) node = eval("document.all.layer3");
    if(node.style) //alert("should set node.style.visibility=true but node.style is null for layer3... crap! dsl");
  node.style.visibility = "hidden";
  */
}

function blank(){ return; }

function over_td(tmp)
{
  var node = document.getElementById(tmp) ;
    if(!node && document.all) node = eval("document.all."+tmp);
  if(node.style) //alert("should set node.style.visibility=true but node.style is null... crap! dsl .. tmp->"+tmp);
  node.style.backgroundColor = "#ff9";
}

function out_td(tmp)
{
  var node = document.getElementById(tmp) ;
    if(!node && document.all) node = eval("document.all."+tmp);
    if(node.style) //alert("should set node.style.visibility=true but node.style is null... crap! dsl .. tmp->"+tmp);
  node.style.backgroundColor = "#fff";
}

// Uncheck the all checkbox
function chboxoff(){
  for(i=0; i<chn.length; i++) {
    document.getElementById(chn[i]).checked = false;
  }
document.getElementById("noticeemail").value	=	"";
document.getElementById("cellemail").value	=	"";
document.getElementById("fromemail").value	=	"";
}

// cell phone carriers email address domain names	from	http://webpersons.jp/tips/2008/01/post-7.html
celldomains	=	new Array("docomo.ne.jp", "softbank.jp", "softbank.ne.jp", "disney.ne.jp", "d.vodafone.ne.jp", "h.vodafone.ne.jp", "t.vodafone.ne.jp", "c.vodafone.ne.jp", "r.vodafone.ne.jp", "k.vodafone.ne.jp", "n.vodafone.ne.jp", "s.vodafone.ne.jp", "q.vodafone.ne.jp", "jp-d.ne.jp", "jp-h.ne.jp", "jp-t.ne.j", "jp-c.ne.jp", "jp-r.ne.jp", "jp-k.ne.jp", "jp-n.ne.jp", "jp-s.ne.jp", "jp-q.ne.jp", "ezweb.ne.jp", "biz.ezweb.ne.jp", "ido.ne.jp", "ezweb.ne.jp", "ezweb.ne.jp", "sky.tkk.ne.jp", "sky.tkc.ne.jp", "sky.tu-ka.ne.jp", "pdx.ne.jp", "emnet.ne.jp", "timomail.net", "dtiserv.com", "dtiteam.com");

function countoption()	{
	//alert("*countoption*");
	document.getElementById("numofoption").value	=	chn.length;
	i=0;
	okf=0;
	celladdress	=	document.getElementById("cellemail").value;
	//alert(celladdress);

	while( i<celldomains.length )
	{
		pos1	=	0;
		pos1 = celladdress.indexOf(celldomains[i]);
		if(pos1 >= 1)
		{
			okf = 1;
			//alert(celldomains[i]);
			break;
		}
		i++;
	}
	if(celladdress.length == 0)
	{
		okf = 1;
	}
	if(okf == 1)
	{
		return(true);
	}
	else
	{
		alert(celladdress+"\nは携帯電話用メールアドレスではありません。\nご確認ください。");
		return(false);
	}
}
