function Seperate_into_Commas (Type) {

	if (Type == "PostTopic") {
		var Tags_Textbox =  document.Post_Topic.Tag_Lists;
	}
	else if (Type == "CreateCommunity") {
		var Tags_Textbox =  document.CreateCommunity.Tag_Lists;
	}
	else if (Type == "PostAd") {
		var Tags_Textbox =  document.PostAd.Key_Terms;
	}
	else if (Type == "Invite_Friends_To_Community") {
		var Tags_Textbox =  document.Invite_Friends_To_Community.Emails_Textarea;
	}	
	else {
		var Tags_Textbox =  document.Tags_Form.Tags_Text;
	}

// (1) Take a string like "Hobs, wrote a,post did you?" and turn it into "Hobs wrote a post did you?"
Tags_Textbox_Array_A = explodeArray (Tags_Textbox.value, ", ");
Tags_Textbox.value = "";

	for (i = 0; i < Tags_Textbox_Array_A.length; i++) {
 		Tags_Textbox.value = Tags_Textbox.value + Tags_Textbox_Array_A[i] + "";
	}

// (2) In the second step, we divide the entire string into commas. "Hobs wrote a post did you?" will be turned into "Hobs, wrote, a, post, did, you?"
Tags_Textbox_Array_B = explodeArray (Tags_Textbox.value, " ");
Tags_Textbox.value = "";

	for (i = 0; i < Tags_Textbox_Array_B.length; i++) {
	  if (i == (Tags_Textbox_Array_B.length - 1)) {
 		Tags_Textbox.value = Tags_Textbox.value + Tags_Textbox_Array_B[i];
		// ^ This makes sure we don't have a commas at the end of the string		
	  }
	  else {
 		Tags_Textbox.value = Tags_Textbox.value + Tags_Textbox_Array_B[i] + ", ";	  
	  }
	}

if (Type != "Invite_Friends_To_Community") {
	Color_Tags(Type);
}
} // Take a string and divide it into commas [ Seperate into Commas ]

function Color_Tags (Type) {

	if (Type == "PostTopic") {
		var All_The_Tags =  document.Post_Topic.Tag_Lists.value;
	}
	else if (Type == "CreateCommunity") {
		var All_The_Tags =  document.CreateCommunity.Tag_Lists.value;
	}
	else if (Type == "PostAd") {
		var All_The_Tags =  document.PostAd.Key_Terms.value;
	}	
	else {
		var All_The_Tags =  document.Tags_Form.Tags_Text.value;		
	}

All_The_Tags_Array = explodeArray (All_The_Tags, ",");

var Color_Tags_Div = document.getElementById("Color_Tags");
Color_Tags_Div.innerHTML = "<span id = 'Field'><strong>Your Terms: </strong></span>";

	for (i = 0; i < All_The_Tags_Array.length; i++) {
	Random_Color = genHex();
	All_The_Tags_Array[i] = capitalizeMe (All_The_Tags_Array[i]);
	// ^capitalize the first letter of each term.
	
	  if (i == (All_The_Tags_Array.length - 1)) {
		Color_Tags_Div.innerHTML = Color_Tags_Div.innerHTML + "<strong><span id = 'Field' style = 'Color:" + Random_Color + ";'>" + All_The_Tags_Array[i] + "</span></strong>";
		// ^ This makes sure we don't have a commas at the end of the string
	  }
	  else {
		Color_Tags_Div.innerHTML = Color_Tags_Div.innerHTML + "<strong><span id = 'Field' style = 'Color:" + Random_Color + ";'>" + All_The_Tags_Array[i] + "</span></strong>,";
	  }

	}

} // Attach a random color to each individual tag and display it [ Color Tags ]

function explodeArray(itemx,delimiter) {

tempArray=new Array(1);
var Count=0;
var tempString=new String(itemx);

while (tempString.indexOf(delimiter)>0) {

	tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
	tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);

	Count=Count+1
}

tempArray[Count]=tempString;
return tempArray;
} // Explode a string according to its delimiter and then store the individual extracted strings into an array [ Explode Array ]

function genHex(){
colors = new Array(14)
colors[0]="0"
colors[1]="1"
colors[2]="2"
colors[3]="3"
colors[4]="4"
colors[5]="5"
colors[5]="6"
colors[6]="7"
colors[7]="8"
colors[8]="9"
colors[9]="a"
colors[10]="b"
colors[11]="c"
colors[12]="d"
colors[13]="e"
colors[14]="f"

digit = new Array(5)
color="#"

for (m=0;m<6;m++){
	digit[m]=colors[Math.round(Math.random()*14)]
	color = color+digit[m]
}

return color;
} // Generate a random color [ genHex ]

function capitalizeMe(val) {
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
        }
        
return newVal;
} // Capitalize the first letter of every term [ capitalize Me ]
