function add_category()
{
	if(document.form123.cats.value!=0)
	{
		var id=document.form123.cats.selectedIndex;
		//////-------checking duplicate category
		var cid_list=form123.cid.value.split(";");
		var cnt=0;
		var posted="no";
		while(cnt<cid_list.length)
		{
			if(cid_list[cnt]==document.form123.cats.value)
				posted="yes";
			cnt++;
		}
		if(posted=="yes")
		{
			alert('This category is already in the list');
			return false;
		}

		if(document.form123.category.value=="")
		{
			document.form123.cid.value=document.form123.cats.value;
			document.form123.category.value=document.form123.cats.options[id].text;
			document.form123.category.focus();
			document.form123.cats.selectedIndex=0;
		}
		else
		{
			document.form123.cid.value=document.form123.cid.value+";"+document.form123.cats.value;
			document.form123.category.value=document.form123.category.value+";"+document.form123.cats.options[id].text;
			document.form123.category.focus();
			document.form123.cats.selectedIndex=0;
		}
	}
	else
	{
		alert('Choose a Category to add');
		document.form123.cats.focus();
	}
}

function remove_category()
{
	var s1=window.document.form123.category.value;
	var s2=s1.split(";");
	var i=0;
	var id=document.form123.cats.selectedIndex;
	var s3=document.form123.cats.options[id].text;
	
	var id_list=document.form123.cid.value;
	var id_split=id_list.split(";");
	var rem_id=document.form123.cats.value;
	
	window.document.form123.category.value="";
	window.document.form123.cid.value="";
	
	while(i<s2.length)
	{
	//alert('Checking '+s2[i]+' nnn  with'+s3+' mm');
		if(s3==s2[i])
		{
		//continue;
		//	alert('Removing'+s3);
		}
		else
		{
			if(document.form123.category.value=="")
				document.form123.category.value=s2[i];
			else
				document.form123.category.value=document.form123.category.value+";"+s2[i];
		}
		if(rem_id==id_split[i])
		{
		//continue;
		//	alert('Removing'+s3);
		}
		else
		{
			if(document.form123.cid.value=="")
				document.form123.cid.value=id_split[i];
			else
				document.form123.cid.value=document.form123.cid.value+";"+id_split[i];
		}
		i++;
	}
//window.document.form123.related.value="";
//window.document.form123.rel_id.value="";
}

function add_category_ex()
{
	if(document.form123.cats_ex.value!=0)
	{
		var id=document.form123.cats_ex.selectedIndex;
		//////-------checking duplicate category
		var cid_list=form123.cid_ex.value.split(";");
		var cnt=0;
		var posted="no";
		while(cnt<cid_list.length)
		{
			if(cid_list[cnt]==document.form123.cats_ex.value)
				posted="yes";
			cnt++;
		}
		if(posted=="yes")
		{
			alert('This category is already in the list');
			return false;
		}

		if(document.form123.category_ex.value=="")
		{
			document.form123.cid_ex.value=document.form123.cats_ex.value;
			document.form123.category_ex.value=document.form123.cats_ex.options[id].text;
			document.form123.category_ex.focus();
			document.form123.cats_ex.selectedIndex=0;
		}
		else
		{
			document.form123.cid_ex.value=document.form123.cid_ex.value+";"+document.form123.cats_ex.value;
			document.form123.category_ex.value=document.form123.category_ex.value+";"+document.form123.cats_ex.options[id].text;
			document.form123.category_ex.focus();
			document.form123.cats_ex.selectedIndex=0;
		}
	}
	else
	{
		alert('Choose a Category to add');
		document.form123.cats_ex.focus();
	}
}

function remove_category_ex()
{
	var s1=window.document.form123.category_ex.value;
	var s2=s1.split(";");
	var i=0;
	var id=document.form123.cats_ex.selectedIndex;
	var s3=document.form123.cats_ex.options[id].text;
	
	var id_list=document.form123.cid_ex.value;
	var id_split=id_list.split(";");
	var rem_id=document.form123.cats_ex.value;
	
	window.document.form123.category_ex.value="";
	window.document.form123.cid_ex.value="";
	
	while(i<s2.length)
	{
	//alert('Checking '+s2[i]+' nnn  with'+s3+' mm');
		if(s3==s2[i])
		{
		//continue;
		//	alert('Removing'+s3);
		}
		else
		{
			if(document.form123.category_ex.value=="")
				document.form123.category_ex.value=s2[i];
			else
				document.form123.category_ex.value=document.form123.category_ex.value+";"+s2[i];
		}
		if(rem_id==id_split[i])
		{
		//continue;
		//	alert('Removing'+s3);
		}
		else
		{
			if(document.form123.cid_ex.value=="")
				document.form123.cid_ex.value=id_split[i];
			else
				document.form123.cid_ex.value=document.form123.cid_ex.value+";"+id_split[i];
		}
		i++;
	}
//window.document.form123.related.value="";
//window.document.form123.rel_id.value="";
}  
/////////////email function
function emailCheck (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 valid domain, or two letter country.")
   return false
}
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}
return true;
}

function sbis_empty(sbstr)
{ 
 	sbnew_str=sbstr.replace(/^\s+|\s+$/g,"");
	if(sbnew_str.length>0)
		return (false);
	else
		return (true);
}

