
function checkSNElement(input) 
{ 
	var validSN = false;
	var SN = new Array;
	var SNContainer = document.getElementById('SNContainer').getElementsByTagName('input');
	var current = input.id.substring(12)*1;

	for (i=0; i<SNContainer.length; i++)
	{
		SN[i] = SNContainer[i].value;
		if (SN[i] == '') SN[i] = 0;
		else 
		{
			check = SNContainer[i].value.match(/^(ds(?:r|x)s)\s*-*(1010)\s*-*(0{2}[\d]{2})\s*-*([\d]{4})\s*-*([\d]{4})\s*-*([\d]{4})$/i) !=null;
			if (check == true) SN[i] = 1;
			else SN[i] = 2;
		}
	}
	if (SN[current] == 2) 
	{
		abbyy.form.wrong(input);
		return false;
	}
	else 
	{
		if (SN.length == 1)
		{
			if (SN[current] == 1)
			{
				abbyy.form.right(input);
				mean = input.value.replace(/^(ds(?:r|x)s)\s*-*(1010)\s*-*(0{2}[\d]{2})\s*-*([\d]{4})\s*-*([\d]{4})\s*-*([\d]{4})$/i,"$1$2$3$4$5$6").toUpperCase();
				input.value = mean.toUpperCase();
				return true;
			}
			if (SN[current] == 0) 
			{
				abbyy.form.wrong(input);
				return false;
			}
		}
		else return checkSNBlock(SN,input);
	}
}



function checkSNBlock(SN,input) 
{
	var maxSN = Math.max.apply(Math,SN);
	switch (maxSN)
	{
		case 2: 
		{
			abbyy.form.wrong(input); 
			return false;
		}
		case 1: 
		{
			abbyy.form.right(input); 
			mean = input.value.replace(/^(ds(?:r|x)s)\s*-*(1010)\s*-*(0{2}[\d]{2})\s*-*([\d]{4})\s*-*([\d]{4})\s*-*([\d]{4})$/i,"$1$2$3$4$5$6");
			input.value = mean.toUpperCase();
			return true;
		}
		case 0:
		{
			abbyy.form.wrong(input); 
			return false;
		}
	}
}



abbyy.validateSubmitSN = function(form)
{
var valid=true;
for(var k=0; k<form.elements.length; k++)
{
	var input = form.elements[k];
	if(input.onchange != null && input.name != 'SN')
		valid = input.onchange() && valid;
	if(input.onchange !==null && input.name == 'SN') validSN = input.onchange();
}
if(valid && validSN==true)form.submit();
}