var whitespace = " \t\n\r";


for (var i=0; i < document.theForm.t1style.length; i++)
{
	if (document.theForm.t1style[i].checked)
	{
	var t1style = document.theForm.t1style[i].value;
	}
}


	if (t1style == "dt-mini-shiny"){
		var iMaxInput = 11;
		var iNumTagRows = 3;
	}else if(t1style == "dt-mega-shiny"){
		var iMaxInput = 19;  
		var iNumTagRows = 8;  
	}else if(t1style == "dt-cdn"){
		var iMaxInput = 15;  
		var iNumTagRows = 4;  
	}else if(t1style == "dt-dpad"){
		var iMaxInput = 15;  
		var iNumTagRows = 3;
	}else if(t1style == "dt-med-al"){
		var iMaxInput = 19;  
		var iNumTagRows = 6;  
	}else if(t1style == "card-ss"){
		var iMaxInput = 30;  
		var iMaxInput1 = 30;  
		var iMaxInput2 = 30;  
		var iNumTagRows = 2;
	}else{
		var iMaxInput = 15;
		var iNumTagRows = 5;  
	}





function CopyTag1() {
	document.theForm.t2r1.value = document.theForm.t1r1.value;
	document.theForm.t2r2.value = document.theForm.t1r2.value;
	document.theForm.t2r3.value = document.theForm.t1r3.value;
	document.theForm.t2r4.value = document.theForm.t1r4.value;
	document.theForm.t2r5.value = document.theForm.t1r5.value;
	document.theForm.t2r6.value = document.theForm.t1r6.value;
}
   
function CopyTag2() {
	document.theForm.t1r1.value = document.theForm.t2r1.value;
	document.theForm.t1r2.value = document.theForm.t2r2.value;
	document.theForm.t1r3.value = document.theForm.t2r3.value;
	document.theForm.t1r4.value = document.theForm.t2r4.value;
	document.theForm.t1r5.value = document.theForm.t2r5.value;
	document.theForm.t1r6.value = document.theForm.t2r6.value;

}

function ClearTag1() {
	document.theForm.t1r1.value = "";
	document.theForm.t1r2.value = "";
	document.theForm.t1r3.value = "";
	document.theForm.t1r4.value = "";
	document.theForm.t1r5.value = "";
	document.theForm.t1r6.value = "";
	document.theForm.t1r7.value = "";
	document.theForm.t1r8.value = "";

	for (i=0;i<document.theForm.elements.length;i++){
		if (document.theForm.elements[i].type == 'checkbox'){
			document.theForm.elements[i].checked = false;
		}
	}
}
   
function ClearTag2() {
	document.theForm.t2r1.value = "";
	document.theForm.t2r2.value = "";
	document.theForm.t2r3.value = "";
	document.theForm.t2r4.value = "";
	document.theForm.t2r5.value = "";
	document.theForm.t2r6.value = "";
}
 

function tagmatrix(checked,row,column){
	if (checked == false){
		chr = document.theForm.pixel.value;
	} else {
		chr = ' ';
	}
	document.theForm[row].value = setCharAt(document.theForm[row].value,column,chr);
}

function setCharAt(str,index,chr) {
	if(chr == "") chr = " ";
	while(index > str.length-1) {
		str = str + " " ;
	}		
	return str.substr(0,index) + chr + str.substr(index+1);
}



function add_spaces(n)
{
	spaces = ""
	for (i=0; i<no_spaces; i++)
	{
		spaces += " "
	}
	return spaces
}

function CenterTag(tagID)
{

   for(var x=1;x<=iNumTagRows;x++)
   {

      var tagline = document.getElementById('t' + tagID + 'r' + x);

      tagline.value = trimWhitespace(tagline.value);
      linelength = tagline.value.length;
      temp_no_spaces = Math.floor((iMaxInput-linelength)/2);
      no_spaces = (iMaxInput<temp_no_spaces)?iMaxInput:temp_no_spaces;

      new_text = add_spaces() + tagline.value;
      tagline.value = new_text;
   }
}

function Un_CenterTag(tagID)
{
    for(var x=1;x<=iNumTagRows;x++)
   {
      var tagline = document.getElementById('t' + tagID + 'r' + x);
      text = tagline.value;
      word_start=0;
      for (i=text.length; i>=0; i--)
      {
         if (text.charCodeAt(i) != 32)
         {
            word_start = i;
         }
      }
      new_text = text.substr(word_start);
      tagline.value = new_text;
   }
}


function trimWhitespace (s)
{
   var trimmedString = "";

   trimmedString = stripInitialWhitespace (s);
   trimmedString =   stripTrailingWhitespace (trimmedString);

   return trimmedString;
}

function stripInitialWhitespace (s)
{   
   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;   
    return s.substring (i, s.length);
}

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}


function stripTrailingWhitespace (s)
{   
   var i = s.length - 1;
    while ((0 < i) && charInString (s.charAt(i), whitespace))
       i--;

    return s.substring (0, i + 1);
}




