function addItem(ItemList,Target)
{
    for(var x = 0; x < ItemList.length; x++)
    {
        var opt = ItemList.options[x];
        if (opt.selected)
        {
            flag = true;
            for (var y=0;y<Target.length;y++)
            {
                var myopt = Target.options[y];
                if (myopt.value == opt.value)
                {
                    flag = false;
                }
            }
            if(flag)
            {
                Target.options[Target.options.length] = new Option(opt.text, opt.value, 0, 0);
            }
        }
    }
}

function delItem(ItemList)
{
    for(var x=ItemList.length-1;x>=0;x--)
    {
        var opt = ItemList.options[x];
        if (opt.selected)
        {
            ItemList.options[x] = null;
        }
    }
}

function languagechange(e1)/*Lirz add for call js variable*/
{
	document.write(e1)
}


function check_text_input()
{
	var ftitle= "";
	var inputs=document.getElementsByTagName("input");
	var num=0;
	var r, re; 
	for(var i=0;i<inputs.length;i++){
		var obj = inputs[i];
		if(obj.type=='text'){
			for(var q=0; q<obj.value.length; q++)
			{
				if(ftitle.indexOf(obj.value.charAt(q)) != -1)
				{ 
					alert(errmsg.err51);
					 return false;
				}
				else if(obj.value.charAt(q)== ' ')
				{
					num++;
				}
			}
			if(num>0)
			{
				re = /\ /g;
				r=obj.value.replace(re, "~");
				obj.value=r;
			}
		}
	}

}
function check_filearea(e1)
{
	var num = e1.length;
	if(num > 512 || num <= 0){
		alert(errmsg.file1);
		return false
		}
	else
		return true
}
function checkip(ip)
{
		var pcount = 0;
    var ip_length = ip.length;
    var ip_letters = "1234567890.";
    for (p=0; p < ip_length; p++)
		{
				var ip_char = ip.charAt(p);
				if (ip_letters.indexOf(ip_char) == -1)
				{
					return false;
				}
    }
    for (var u = 0; u < ip_length; u++) { (ip.substr(u,1) == ".") ? pcount++ : pcount; }
    if(pcount != 3) { return false; }
    firstp = ip.indexOf(".");
    lastp = ip.lastIndexOf(".");
    str1 = ip.substring(0,firstp);
    ipstr_tmp = ip.substring(0,lastp);
    secondp = ipstr_tmp.lastIndexOf(".");
    str2 = ipstr_tmp.substring(firstp+1,secondp);
    str3 = ipstr_tmp.substring(secondp+1,lastp);
    str4 = ip.substring(lastp+1,ip_length);
    if (str1 == '' || str2 == '' || str3 == '' || str4 == '') { return false; }
    if (str1.length > 3 || str2.length > 3 || str3.length > 3 || str4.length > 3) { return false; }
    if (str1 <= 0 || str1 > 255) { return false; }
    else if (str2 < 0 || str2 > 255) { return false; }
    else if (str3 < 0 || str3 > 255) { return false; }
    else if (str4 < 0 || str4 > 255) { return false; }
    return true;
}
function checkip2(ip)
{
		var pcount = 0;
    var ip_length = ip.length;
    var ip_letters = "1234567890.";
    for (p=0; p < ip_length; p++)
		{
				var ip_char = ip.charAt(p);
				if (ip_letters.indexOf(ip_char) == -1)
				{
					return false;
				}
    }
    for (var u = 0; u < ip_length; u++) { (ip.substr(u,1) == ".") ? pcount++ : pcount; }
    if(pcount != 3) { return false; }
    firstp = ip.indexOf(".");
    lastp = ip.lastIndexOf(".");
    str1 = ip.substring(0,firstp);
    ipstr_tmp = ip.substring(0,lastp);
    secondp = ipstr_tmp.lastIndexOf(".");
    str2 = ipstr_tmp.substring(firstp+1,secondp);
    str3 = ipstr_tmp.substring(secondp+1,lastp);
    str4 = ip.substring(lastp+1,ip_length);
    if (str1 == '' || str2 == '' || str3 == '' || str4 == '') { return false; }
    if (str1.length > 3 || str2.length > 3 || str3.length > 3 || str4.length > 3) { return false; }
    if (str1 < 0 || str1 > 255) { return false; }
    else if (str2 < 0 || str2 > 255) { return false; }
    else if (str3 < 0 || str3 > 255) { return false; }
    else if (str4 < 0 || str4 > 255) { return false; }
    return true;
}
function checknull(none) {
    if (none != '') { return false; }
    return true;
}
function put_error_msg(error_msg,i)
{
    alert(error_msg);
    return false;
}
function checkhours(num)
{
	var num_length=num.length;
	var num_letters="1234567890";
	for (p=0; p < num_length; p++)
	{
		var num_char = num.charAt(p);
		if (num_letters.indexOf(num_char) == -1)
		{
		    return false;
		}
	}
	if (num < 0 || num > 23) { return false; }
	return true;
}
function checkminut(num)
{
	var num_length=num.length;
	var num_letters="1234567890";
	for (p=0; p < num_length; p++)
	{
		var num_char = num.charAt(p);
		if (num_letters.indexOf(num_char) == -1)
		{
		    return false;
		}
	}
	if (num < 0 || num > 59) { return false;}
	return true;
}
function check_url(e1)
{
	var filter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.@/:=&?";
	for(var i=0; i<e1.length; i++)
	{
		if( filter.indexOf(e1.charAt(i)) == -1 )
		{
			return false;
		}
	}
	return true
}
jQuery.fn.highlight = function(pat) {
 function innerHighlight(node, pat) {
  var skip = 0;
  if (node.nodeType == 3) {
   var pos = node.data.toUpperCase().indexOf(pat);
   if (pos >= 0) {
    var spannode = document.createElement('span');
    spannode.className = 'highlight';
    var middlebit = node.splitText(pos);
    var endbit = middlebit.splitText(pat.length);
    var middleclone = middlebit.cloneNode(true);
    spannode.appendChild(middleclone);
    middlebit.parentNode.replaceChild(spannode, middlebit);
    skip = 1;
   }
  }
  else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
   for (var i = 0; i < node.childNodes.length; ++i) {
    i += innerHighlight(node.childNodes[i], pat);
   }
  }
  return skip;
 }
 return this.length && pat && pat.length ? this.each(function() {
  innerHighlight(this, pat.toUpperCase());
 }) : this;
};

jQuery.fn.removeHighlight = function() {
 return this.find("span.highlight").each(function() {
  this.parentNode.firstChild.nodeName;
  with (this.parentNode) {
   replaceChild(this.firstChild, this);
   normalize();
  }
 }).end();
};

function input_search(){
		jQuery(".dataTables_filter input").each(function(){  
			var txt = "Search";
			if(jQuery(this).val() == "") 
				jQuery(this).val(txt).css({"color":"#888"});  
			jQuery(this).focus(function(){	
			if(txt === jQuery(this).val()) 
				jQuery(this).val("").css({"color":"#000"});  
			}).blur(function(){  
			if(jQuery(this).val() == "") 
				jQuery(this).val(txt).css({"color":"#888"});  
			});  
		}); 
}