var page = document.location.href;
var errorMessages = new Array();
var fileName = page.substring(page.lastIndexOf('/') + 1);


//Subnav control
function changeNav(el) {
	var navLinks, contentId, i;
	navLinks = document.getElementById('centeredNav').getElementsByTagName('a');
	for (i = 0; i < navLinks.length; i++) {
		contentId = navLinks[i].id + "Content";
		if (navLinks[i].id !== el) {
			navLinks[i].className = "topNavOff";
			document.getElementById(contentId).className = "hideIt";
		} else {
			navLinks[i].className = "topNavOn";
			document.getElementById(contentId).className = "showIt";
		}
	}
}

function chkValid() {
	var chkboxName, chkboxArry, valueArry, i;
	chkboxName = document.getElementsByName("check_list");
	chkboxArry = new Array();
	valueArry = new Array();
	chkboxArry = chkboxName;
	for (i = 0; i < chkboxArry.length; i++) {
		if (chkboxArry[i].checked) {
			valueArry.push(chkboxArry[i].value);
		}
	}

	if (valueArry.length === chkboxArry.length) {
		document.getElementById('activeLink').className = 'mt10 showIt';
		document.getElementById('inactiveLink').className = 'mt10 hideIt';
		document.getElementById('activeLinkTop').className = 'mt10 mb10 showIt';
		document.getElementById('inactiveLinkTop').className = 'mt10 mb10 hideIt';
	} else {
		document.getElementById('activeLink').className = 'mt10 hideIt';
		document.getElementById('inactiveLink').className = 'mt10 showIt';
		document.getElementById('activeLinkTop').className = 'mt10 mb10 hideIt';
		document.getElementById('inactiveLinkTop').className = 'mt10 mb10 showIt';
	}
}



function showHideCheck(divToChange, thisIsChecked) {
	var x, chkd;
	x = document.getElementById(divToChange);
	chkd = document.getElementById(thisIsChecked).checked;

	if (!chkd) {
		x.style.display = "none";

	} else {
		x.style.display = "block";
	}
}



//Print this links
function printClick() {
	if (!document.getElementById) {return false; }
	if (!document.getElementById("printIt")) {return false; }

	var link = document.getElementById("printIt");
	link.onclick = function () {
		window.print();
		return false;
	};
	link.onkeypress = link.onclick;
}

function replaceRightClass() {
	document.getElementById('rightSide').className = 'rightColumn';
}


//getTns page
function editMode() {
	var url, filename;
	url = window.location.href;
	filename = url.substring(url.lastIndexOf('/') + 1);
	var spanPrimaryNum = document.getElementById('pTn');
	var spanSecondaryNum = document.getElementById('sTn');
	var continueBtnGrn = document.getElementById('continueActive');
	var continueBtnGray = document.getElementById('continueInactive');
	if (filename === 'getTns.jsp?woa_mode=edit' && document.getElementById('totalTns').firstChild.nodeValue === '1') {
		document.getElementById('newTnAssign').className = 'infoBoxBody bb showIt';
		document.getElementById('extraLine').className = 'hideIt';
		document.getElementById('continueActive').className = 'continue showIt';
		document.getElementById('continueInactive').className = 'continue hideIt';
	} else if (filename === 'getTns.jsp?woa_mode=edit' && document.getElementById('totalTns').firstChild.nodeValue === '2') {
		//alert(filename);
		document.getElementById('newTnAssign').className = 'infoBoxBody bb showIt';
		document.getElementById('continueActive').className = 'continue showIt';
		document.getElementById('continueInactive').className = 'continue hideIt';
	}else if(spanPrimaryNum.innerHTML != '' && spanSecondaryNum.innerHTML == '') {
		document.getElementById('newTnAssign').className = 'infoBoxBody bb showIt';
		document.getElementById('extraLine').className = 'hideIt';
		continueBtnGrn.className = 'continue showIt';
		continueBtnGray.className = 'continue hideIt';
	}else if(spanPrimaryNum.innerHTML != '' && spanSecondaryNum.innerHTML != '') {
		document.getElementById('newTnAssign').className = 'infoBoxBody bb showIt';
		continueBtnGrn.className = 'continue showIt';
		continueBtnGray.className = 'continue hideIt';
	}else {
	
	}
}

function disableGenTn() {
	if (document.getElementById('grayGenBtn').style.display !== 'none' && document.getElementById('totalTns').firstChild.nodeValue === '1') {
		document.getElementById('newTnAssign').className = 'infoBoxBody bb showIt';
		document.getElementById('continueActive').className = 'continue showIt';
		document.getElementById('continueInactive').className = 'continue hideIt';
		document.getElementById('extraLine').className = 'hideIt';
	} else if (document.getElementById('grayGenBtn').style.display !== 'none' && document.getElementById('totalTns').firstChild.nodeValue === '2') {
		document.getElementById('newTnAssign').className = 'infoBoxBody bb showIt';
		document.getElementById('continueActive').className = 'continue showIt';
		document.getElementById('continueInactive').className = 'continue hideIt';
	}
}

function showTnexception() {
	if (document.getElementById('yellowBoxMsg').style.display !== 'none') {
		document.getElementById('generateTn').className = 'hideIt';
	} else {
		document.getElementById('generateTn').className = 'showIt';
	}
}

function showActiveBtn() {

	if (document.getElementById('newTnAssign').style.display !== 'none') {
		document.getElementById('continueActive').style.display = 'block';
		document.getElementById('continueInactive').style.display = 'none';
	}else{
	
	}
}

function showSelection() {
	var additionalLine, primary, continueBtn, usrSelection, continueActv, continueInactv, secondLine, secondary;
	additionalLine = document.getElementById('line1');
	primary = document.getElementById('line0').options[document.getElementById('line0').selectedIndex].value;
	continueBtn = document.getElementById('continueButton');
	usrSelection = document.getElementById('displayUserSelection');
	continueActv = document.getElementById('continueActive');
	continueInactv = document.getElementById('continueInactive');
	secondLine = document.getElementById('extraLine');

	if (!document.getElementById('newTnAssign')) {return false; }

	document.getElementById('newTnAssign').style.display = 'block';

	if (document.getElementById('totalTns').firstChild.nodeValue === '1') {
		usrSelection.innerHTML = primary;
		document.generate_tn_form.primary.value = primary;
		document.select_tn_form.primary.value = primary;
		continueActv.className = 'continue showIt';
		continueInactv.className = 'continue hideIt';
		secondLine.className = 'hideIt';
	} else {
		var secondary = document.getElementById('line1').options[document.getElementById('line1').selectedIndex].value;
		if (primary === secondary) {
			usrSelection.innerHTML = 'Error: Please assign a different phone number for each line.';
			document.getElementById('continueActive').className = 'continue hideIt';
			document.getElementById('continueInactive').className = 'continue showIt';
		} else if (primary !== secondary) {
			usrSelection.innerHTML = primary + '<br /><br />' + secondary;
			document.generate_tn_form.primary.value = primary;
			document.generate_tn_form.additional.value = secondary;
			document.select_tn_form.primary.value = primary;
			document.select_tn_form.additional.value = secondary;
			document.getElementById('continueActive').className = 'continue showIt';
			document.getElementById('continueInactive').className = 'continue hideIt';
			document.getElementById('pTn').className = 'hideIt';
			document.getElementById('sTn').className = 'hideIt';
		}
	}
}

function assignValues() {
	var primary, secondary;
	primary = document.getElementById('line0').options[document.getElementById('line0').selectedIndex].value;
	secondary = document.getElementById('line1').options[document.getElementById('line1').selectedIndex].value;
	document.getElementById('finalPrimaryLine').value = primary;
	document.getElementById('finalSecondaryLine').value = secondary;
}

function displayPrice() {
	document.getElementById("rightMonthlyTotalSpanId").firstChild.nodeValue = document.getElementById("rightMonthlyTotalId").firstChild.nodeValue;
}

/*** ADD LOAD EVENT ***/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload !== 'function') {
		window.onload = func;
	} else {
		window.onload = function () {
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}
addLoadEvent(printClick);

//Omniture link tracking function
function linkCode(obj, name, event, prop, eVar) {
	if (event === "" || event === null || event === undefined) {
		event = "None";
	}
	var rsid, s;
	rsid = "cableoptimum.com";
	s = s_gi(rsid);
	switch (prop) {
	case "11": s.prop11 = name; break;
	case "16": s.prop16 = name; break;
	case "17": s.prop17 = name; break;
	case "18": s.prop18 = name; break;
	case "19": s.prop19 = name; break;
	}
	switch (eVar) {
	case "4": s.eVar4 = name; break;
	case "11": s.eVar11 = name; break;
	case "14": s.eVar14 = name; break;
	}
	s.events = event;
	switch (name) {
	case "orderStartType": s.eVar1 = eVar; break;
	}
	s.tl(obj, 'o', name);
}

function boxes(loc) {
	var a, i, scrollLink, scrollImageLink, scrollImage, scrollPara, dotNetTitle;
	a = (loc === "home") ? 2 : 3;

	for (i = 0; i < a; i++) {
		scrollLink = document.createElement("a");
		scrollImageLink = document.createElement("a");
		scrollImage = document.createElement("img");
		scrollPara = document.createElement("p");
		dotNetTitle = "Optimum.net" + title[i];
		if (link[i].indexOf("optimum.net") !== -1) {
			scrollLink.onclick = function () {
				s.linkTrackVars = 'evar13';
				linkCode(this, 'cableoptimum.com', dotNetTitle, '', '', '13');
			};
		}
		scrollLink.appendChild(document.createTextNode(title[i]));
		scrollLink.href = link[i];
		scrollLink.style.fontSize = "125%";
		scrollLink.style.marginBottom = "7px";
		scrollLink.style.color = "#0175ac";
		scrollImageLink.href = link[i];
		if (title[i] === "Optimum Voice Homepage") {scrollLink.style.letterSpacing = "-1px"; }
		scrollImage.setAttribute('src', image[i]);
		scrollImage.setAttribute('width', '177');
		scrollImage.setAttribute('height', '50');
		scrollImage.setAttribute('border', '0');
		scrollImage.className = "mb10 mt10";
		scrollImageLink.appendChild(scrollImage);
		scrollPara.appendChild(document.createTextNode(text[i]));
		if (i === 0) {
			document.getElementById("mainFirst").innerHTML = "";
			document.getElementById("mainFirst").appendChild(scrollLink);
			document.getElementById("mainFirst").appendChild(scrollImageLink);
			document.getElementById("mainFirst").appendChild(scrollPara);
		}
		if (i === 1) {
			document.getElementById("mainSecond").innerHTML = "";
			document.getElementById("mainSecond").appendChild(scrollLink);
			document.getElementById("mainSecond").appendChild(scrollImageLink);
			document.getElementById("mainSecond").appendChild(scrollPara);
		}
		if (i === 2) {
			document.getElementById("mainThird").innerHTML = "";
			document.getElementById("mainThird").appendChild(scrollLink);
			document.getElementById("mainThird").appendChild(scrollImageLink);
			document.getElementById("mainThird").appendChild(scrollPara);
		}
	}
}

function scrollIt(direction, loc) {
	var titleSplice, linkSplice, imageSplice, textSplice, a;
	(loc === "home") ? a = 2 : a = 3;
	if (direction === "next") {
		titleSplice = title.splice(0, a);
		linkSplice = link.splice(0, a);
		imageSplice = image.splice(0, a);
		textSplice = text.splice(0, a);
		title = title.concat(titleSplice);
		link = link.concat(linkSplice);
		image = image.concat(imageSplice);
		text = text.concat(textSplice);
	} else {
		titleSplice = title.splice((title.length - a), a);
		linkSplice = link.splice((link.length - a), a);
		imageSplice = image.splice((image.length - a), a);
		textSplice = text.splice((text.length - a), a);
		title = titleSplice.concat(title);
		link = linkSplice.concat(link);
		image = imageSplice.concat(image);
		text = textSplice.concat(text);
	}
	boxes(loc);
}

function fullWin (url) {
	window.open(url, "new_window", "width=790,height=450,scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,status=yes");
	return false;
}

function openWin (url, name, width, height, scrollbars, resizable, menubar, toolbar, currentWindow) {
	if (!resizable)	{resizable = "no"; }
	if (!menubar) {menubar = "no"; }
	if (!toolbar) {toolbar = "no"; }
 	winFeatures = "width=" + width + ",height=" + height + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",menubar=" + menubar + ",toolbar=" + toolbar + ",top=100,left=100,screenX=100,screenY=100";
	window.open(url, name, winFeatures);
	if (currentWindow === "close") {self.close(); }
}

var isNN = (navigator.appName.indexOf("Netscape") !== -1);
function checkAll (field) {
	for (i = 0; i < field.length; i++) field[i].checked = true;
}
function uncheckAll (field) {
	for (i = 0; i < field.length; i++) field[i].checked = false;
}

var submitted = false;
function doSubmit(form) {
	//alert("check");
	if (!submitted) {
		submitted = true;
		//alert("submitting");
		return (true);
	} else {
		//alert("no");
		return (false);
	}
}

function tabomatic (original, destination) {
	if (original.getAttribute && original.value.length === original.getAttribute("maxlength")) {
		destination.focus();
	}
}

function openIt(name) {
	var temp, win;
	win = window.open('/order/install_calendar.jsp', 'calendar1', 'scrollbars=no,width=450,height=200,top=0,left=10');
	temp = name;
}

function showHide(divToChange) {
	var x = document.getElementById(divToChange);
	if (x.style.display === "block")
	{
		x.style.display = "none";
	} else {
		x.style.display = "block";
	}
}

//Flash Active X fix
function VM_Generateobj(objAttrs, params, embedAttrs) 
{
	var str = '<object ';
	for (var i in objAttrs)
	  str += i + '="' + objAttrs[i] + '" ';
	  str += '>';
	  for (var i in params)
		str += '<param name="' + i + '" value="' + params[i] + '" /> ';
		str += '<embed ';
		  for (var i in embedAttrs)
			str += i + '="' + embedAttrs[i] + '" ';
			str += ' ></embed></object>';
  document.write(str);
    }

function VM_EmbedFlash() {
  var ret = VM_GetArgs (arguments, "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
  VM_Generateobj (ret.objAttrs, ret.params, ret.embedAttrs);
}

function VM_GetArgs (args, srcParamName, classid, mimeType) {
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (i = 0; i < args.length; i = i + 2) {
    var currArg = args[i].toLowerCase();    

	switch (currArg) {	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i + 1];
        break;
      case "src":
      case "movie":	
       ret.embedAttrs["src"] = args[i + 1];
        ret.params[srcParamName] = args[i + 1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i + 1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i + 1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i + 1];
   }
}
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//Controls in-page nav and fades in content
function fadeInContent(mainDiv,navEl) {
	var x = $(mainDiv).getElementsByTagName("div");
	for (i = 0;i < x.length;i++) {
		if (x[i].id === navEl) {
			$(navEl).appear();
			$(navEl + "Link").style.color = "black";
		} 
		if (x[i].id !== navEl) {
			$(x[i].id).hide();
			$(x[i].id + "Link").style.color = "#0175ac";
		}
	} 

}

//Handles HTML form drop down selection box
function dropdown(mySel)
{
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if (myVal)
   {
   if (mySel.form.target)myWin = parent[mySel.form.target];
   else myWin = window;
   if (! myWin) return true;
   myWin.location = myVal;
   }
return false;
}

//TransMotion espanol links
var MP = {
<!-- mp_trans_disable_start --> 
  Version: '1.0.22',
  Domains: {'es':'espanol.optimum.com'},	
  SrcLang: 'en',
<!-- mp_trans_disable_end -->
  UrlLang: 'mp_js_current_lang',
  SrcUrl: unescape('mp_js_orgin_url'),
<!-- mp_trans_disable_start --> 	
  init: function () {
    if (MP.UrlLang.indexOf('p_js_')==1) {
      MP.SrcUrl=window.top.document.location.href;
      MP.UrlLang=MP.SrcLang;
  }
},
getCookie: function (name) {
  var start=document.cookie.indexOf(name+'=');
  if (start < 0) return null;
  start=start+name.length + 1;
  var end=document.cookie.indexOf(';', start);
  if (end < 0) end=document.cookie.length;
  while (document.cookie.charAt(start)==' ') { start++; }
  return unescape(document.cookie.substring(start,end));
},
setCookie: function (name,value,path,domain) {
  var cookie=name+'='+escape(value);
  if (path)cookie+='; path='+path;
  if (domain)cookie+='; domain='+domain;
  var now=new Date();
  now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365);
  cookie+='; expires='+now.toUTCString();
  document.cookie=cookie;
},
switchLanguage: function (lang) {
  if (lang !== MP.SrcLang) {
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[lang]+'/'+MP.SrcLang+lang+'/?1023749632;'+encodeURIComponent(MP.SrcUrl);
	document.body.appendChild(script);
  } else if (lang === MP.SrcLang && MP.UrlLang !== MP.SrcLang) {
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[MP.UrlLang]+'/'+MP.SrcLang+MP.UrlLang+'/?1023749634;'+encodeURIComponent(location.href);
	document.body.appendChild(script);
  }
  return false;
},
switchToLang: function (url) {
  window.top.location.href=url; 
}
<!-- mp_trans_disable_end -->   
};

function createIt(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readIt(name) {
	var nameEQ, ca;
	nameEQ = name + "=";
	ca = document.cookie.split(';');
	for (var i = 0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseIt(name) {
	createCookie(name,"",-1);
}
//test works
/*
function chooseBeta (checked) {
	//clear out div 
	$("#continueOrder").html("");
	//create random number
	var randomChooser = Math.floor(Math.random()*5);
	//populate entry continue button div
	if (checked === "true") {
		if (randomChooser === 3) {
			$("#continueOrder").html("<a href='choose-beta.jsp' rel='shadowbox;width=400;height=400'><img src='/images/buttons/continue.gif' class='signIn' align='right' width='56' height='22' border='0' alt='Continue' title='Continue'/></a>");
		} else {
			$("#continueOrder").html("<input align='right' class='signIn' type='image' src='/images/buttons/continue.gif'/>");
		}
	} else {
		$("#continueOrder").html("<input align='right' class='signIn' type='image' src='/images/buttons/continue.gif'/>");
	}
}
*/
var b = navigator.userAgent.toLowerCase();
	// Figure out what browser is being used
	jQuery.browser = {
		safari: /webkit/.test(b),
		opera: /opera/.test(b),
		msie: /msie/.test(b) && !/opera/.test(b),
		msie6: /msie 6.0/.test(b) && !/opera/.test(b),
		mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
	};

