/*---Edit contact popup functions--*/
var fadeOver = function(){
	var selectDDs = document.getElementsByTagName('select');
	for (var iv = 0; iv < selectDDs.length; iv++) {
		var theseSelects = selectDDs[iv];
		if (theseSelects.className == 'heavyFont') {
			theseSelects.style.visibility = 'hidden';
		}
	}
	var overfade =  document.getElementById('overfade');
	var modelTimer = document.getElementById('modelTimer');
	var overlayAll =  document.getElementById('overlayAll');
	overlayAll.style.display = 'block';
	overfade.style.display = 'block';
	modelTimer.style.display = 'block';

}
var fadeOverOff = function(){
	var selectDDs = document.getElementsByTagName('select');
	for (var iv = 0; iv < selectDDs.length; iv++) {
		var theseSelects = selectDDs[iv];
		if (theseSelects.className == 'heavyFont') {
			theseSelects.style.visibility = 'visible';
		}
	}
	var overfade =  document.getElementById('overfade');
	var modelTimer = document.getElementById('modelTimer');
	var overlayAll =  document.getElementById('overlayAll');	
	overfade.style.display = 'none';
	modelTimer.style.display = 'none';
	overlayAll.style.display = 'none';
}
var checkboxCheckers = function(){
	
	
	var allchecks = document.getElementsByTagName('input');
		for (var i = 0; i < allchecks.length; i++) {
			var thischeck = allchecks[i];  

		    if (thischeck.className == 'checkboxformess') { 
				thischeck.onclick = function(){

					if(this.checked){
					this.parentNode.parentNode.style.backgroundColor = '#fbf4d1';
					} else {
						if(this.parentNode.parentNode.className == 'read'){
							this.parentNode.parentNode.style.backgroundColor = '#f2f2f2';
						}
						if(this.parentNode.parentNode.className == 'new'){
							this.parentNode.parentNode.style.backgroundColor = '#ebf2fd';
						}
					}
				}	
			}
			
		}
		
}
var editContactPop = function(){  
 
	var allIms = document.getElementsByTagName('img');
		for (var i = 0; i < allIms.length; i++) {
			var thisIm = allIms[i];  

		    if (thisIm.className == 'editContactPop_btn') { 
				thisIm.onmouseover = function(){
					
					
					var ourImg = this;
					ourImg.src = "images/icon_details_over.gif";
					
					var timedMouseOver = function() {
			   		      var thisLeft = ourImg.offsetLeft;
					      var allDivs = ourImg.parentNode.getElementsByTagName('div');
							for (var ii = 0; ii < allDivs.length; ii++) {
								var thisDiv = allDivs[ii];
								if (thisDiv.className == 'editContactPop') {  
									thisDiv.style.display = 'block';
									thisDiv.style.left = thisLeft + 12 + 'px';
								}
						 	}
						
					}
					window.timedMouseOverInit = setTimeout(timedMouseOver, 500);
					
				}

				thisIm.onmouseout = function(){
					clearTimeout(window.timedMouseOverInit);
					this.src = "images/icon_details.gif"; 
					var allDivs = this.parentNode.getElementsByTagName('div');
						for (var ii = 0; ii < allDivs.length; ii++) {
							var thisDiv = allDivs[ii];

							if (thisDiv.className == 'editContactPop') {  
			                   thisDiv.style.display = 'none';
							}    
					 	} 
				}
				thisIm.onclick = function(){
				
					var selectDDs = document.getElementsByTagName('select');
					for (var iv = 0; iv < selectDDs.length; iv++) {
						var theseSelects = selectDDs[iv];
						if (theseSelects.className == 'heavyFont') {
							theseSelects.style.visibility = 'hidden';
						}
					}
					  	
						var thisLeft = this.offsetLeft;
						var thisTop = this.parentNode.offsetTop;
						
						var allOthers = document.getElementsByTagName('div');
						for (var iii = 0; iii < allOthers.length; iii++) {
							var theseotherDivs = allOthers[iii];
							if (theseotherDivs.className == 'editcontactName_module') {
								theseotherDivs.style.display = 'none';
								
									if(theseotherDivs.parentNode.parentNode.parentNode.parentNode.className == 'read'){	
									theseotherDivs.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '#f2f2f2';
									//theseotherDivs.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '#000';
									}
								
								    if(theseotherDivs.parentNode.parentNode.parentNode.parentNode.className == 'new'){	
								    theseotherDivs.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '#ebf2fd';
								    }
							}
						}
						var allDivs = this.parentNode.getElementsByTagName('div');
						for (var ii = 0; ii < allDivs.length; ii++) {
							var thisDiv = allDivs[ii];
							if (thisDiv.className == 'editcontactName_module') {  
								thisDiv.style.display = 'block';
								thisDiv.style.left = thisLeft + 12 + 'px';
								thisDiv.style.top = thisTop - 100 + 'px';
								var parentColor = thisDiv.parentNode.parentNode.parentNode.parentNode;
								parentColor.style.backgroundColor = '#fbf4d1';
								//thisDiv.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '#ff0000';
								
								var allimBtns = thisDiv.getElementsByTagName('a');
								for (var iii = 0; iii < allimBtns.length; iii++) {
									var thisBtn = allimBtns[iii];
									if (thisBtn.className == 'cancel_btn') {
										thisBtn.onclick = function(){
											thisBtn.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
											
											var selectDDs = document.getElementsByTagName('select');
											for (var iv = 0; iv < selectDDs.length; iv++) {
												var theseSelects = selectDDs[iv];
												if (theseSelects.className == 'heavyFont') {
													theseSelects.style.visibility = 'visible';
												}
											}
											
											
										}
									}
								}
								
							}
							if (thisDiv.className == 'editContactPop') {  
								thisDiv.style.display = 'none';
							}
					 	}
					
				}
			}
	    }    
}

/*--- Navigation Tabs: Voicemail, settings, and help  --*/
var menuOn = function(){
	var tvlistings = document.getElementById('tvlistings');
	var browse = document.getElementById('browse');     
	var search = document.getElementById('search');     

	tvlistings.style.zIndex = 1003;
	browse.style.zIndex = 1002;
	search.style.zIndex = 1001;

	var allDivs = document.getElementsByTagName('div');
		for (var i = 0; i < allDivs.length; i++) {
			var thisDiv = allDivs[i];  

			//if off

		    if (thisDiv.className == 'tab') { 
				thisDiv.style.backgroundImage = 'url(/digitalcable/images/' + thisDiv.id + '_off.gif)';  
				thisDiv.style.zIndex = thisDiv.style.zIndex;
				thisDiv.onmouseover = function(){
					this.style.backgroundImage = 'url(/digitalcable/images/' + this.id + '_onRoll.gif)';
				}
				thisDiv.onmouseout = function(){
				    this.style.backgroundImage = 'url(/digitalcable/images/' + this.id + '_off.gif)';
				}
			}  

			//if on

			if  (thisDiv.className == 'tab_on') {
				thisDiv.style.zIndex =  thisDiv.style.zIndex + 1000;
				thisDiv.style.backgroundImage = 'url(/digitalcable/images/' + thisDiv.id + '_on.gif)';
			}

			//if inactive

			if  (thisDiv.className == 'tab_inact') {
				thisDiv.style.backgroundImage = 'url(/digitalcable/images/' + thisDiv.id + '_inact.gif)'; 
			 }       
			
			 //if the help tab is on

				if (thisDiv.className == 'tab_on' && thisDiv.id == 'help') {
					 voicemail.style.zIndex = 1002;
					 settings.style.zIndex = 1003;
				}
	    }
}
/*--- iblue ---*/
var iblue = function(){
	var allAs = document.getElementsByTagName('a');
		for (var i = 0; i < allAs.length; i++) {
			var thisA = allAs[i];
			if (thisA.className == 'i_onblue' || thisA.className == 'i_onyellow') { 
				thisA.onmouseover = function(){
					var ourImg = this;
					
				var timedMouseOver = function() {
			   		      var thisLeft = ourImg.offsetLeft;
						  var thisTop = ourImg.offsetTop;
					      var allDivs = ourImg.parentNode.getElementsByTagName('div');
							for (var ii = 0; ii < allDivs.length; ii++) {
								var thisDiv = allDivs[ii];
								if (thisDiv.className == 'iBluePop') {  
									thisDiv.style.display = 'block';
									thisDiv.style.right = thisLeft - 208 + 'px';
									thisDiv.style.top = thisTop - 43 + 'px';
									thisDiv.parentNode.parentNode.style.zIndex = '10';
								}
						 	}
					}
					window.timedMouseOverInit = setTimeout(timedMouseOver, 500);
				
				}

				thisA.onmouseout = function(){
					clearTimeout(window.timedMouseOverInit);
					this.src = "images/icon_details.gif"; 
					var allDivs = this.parentNode.getElementsByTagName('div');
						for (var ii = 0; ii < allDivs.length; ii++) {
							var thisDiv = allDivs[ii];

							if (thisDiv.className == 'iBluePop') {  
			                   thisDiv.style.display = 'none';
							   thisDiv.parentNode.parentNode.style.zIndex = '1';
							}    
					 	} 
				}
			}
		}  
	
}

/*--- Dialog close button --*/
function closeMe(parent,selectBoxes){
		document.getElementById(parent).style.display = 'none';
    if (selectBoxes) {
		document.getElementById(selectBoxes).style.visibility = 'visible';
	}
    else {
		var selectDDs = document.getElementsByTagName('select');
		for (var iv = 0; iv < selectDDs.length; iv++) {
			var theseSelects = selectDDs[iv];
				theseSelects.style.visibility = 'visible';
		}
    }
}


/*--- Sliding effect for FAQ box --*/
function motionHandler(fps, scope) {

	var root              = this;
		root.defaults     = {
						  fps      : 30,
						  duration : 0.25
		}
		root.biasTrip     = 2;
		root.scope        = scope || document.body;
		root.elements     = root.scope.getElementsByTagName('*');
		root.queue        = [];
		root.timer        = null;
		root.fps          = fps || root.defaults.fps;
		root.interval     = (1000/root.fps);
		root.isPaused     = false;
		root.onQueueStart = null;
		root.onQueueClear = null;
	root.start = function() {
		if (!root.isPaused) {
			for (var i in root.queue) {
				var jobNode = root.queue[i];
				var jobNodeReady = (
					jobNode.element &&
					typeof(jobNode.element.nodeName) != 'undefined' &&
					!jobNode.isComplete()
				);
				if (jobNodeReady) {
					if (!jobNode.isPaused) {
						jobNode.process();
						jobNode.render();
					}
				} else {
					if (i == 0) {
						root.queue.shift();
					} else {
						root.queue.splice(i, i);
					}
				}
			}
			if (root.queue.length > 0) {
				root.timer = setTimeout(root.start, root.interval);
			} else {
				root.timer = clearTimeout(root.timer);
				root.timer = null;
				if (root.onQueueClear && typeof(root.onQueueClear) == 'function') { root.onQueueClear(); }
			}
		}
	}
	root.pauseQueue = function() {
		root.isPaused = true;
	}
	root.playQueue  = function() {
		root.isPaused = false;
		root.start();
	}
	root.inScope          = function(obj) {
		var childObj = obj;
		if (root.scope != document.body) {
			while (obj != document.body) {
				if (obj == root.scope) { return childObj; }
				obj = obj.parentNode;
			}
			return false;
		} else {
			return childObj
		}
	}
	root.setMethods       = function(childScope) {
		var scope  = childScope || root.scope;
		if (!root.inScope(scope)) { throw('motionHandler.setMethods - cannot influence elements beyond scope of influence set for object.'); }
		var elements = scope.getElementsByTagName('*');
		for (var i = 0; i < elements.length; i++) {
			var thisObj = elements[i];
			if(!thisObj.getAttribute('ignore')) {
				thisObj.move      = root.move;
				thisObj.stop      = root.stop;
				thisObj.reverse   = root.reverse;
				thisObj.end       = root.end;
				thisObj.pause     = root.pause;
				thisObj.play      = root.play;
				thisObj.playPause = root.playPause;
				thisObj.restart   = root.restart;
				thisObj.sequence  = root.sequence;
			}
		}
	}
	root.cutMethods       = function(childScope) {
		var scope  = childScope || root.scope;
		if (!root.inScope(scope)) { throw('motionHandler.cutMethods - cannot influence elements beyond scope of influence set for object.'); }
		var elements = scope.getElementsByTagName('*');
		for (var i = 0; i < elements.length; i++) {
			var thisObj = elements[i];
			thisObj.setAttribute('ignore', 'true');
				thisObj.move      = null;
				thisObj.stop      = null;
				thisObj.reverse   = null;
				thisObj.end       = null;
				thisObj.pause     = null;
				thisObj.play      = null;
				thisObj.playPause = null;
				thisObj.restart   = null;
				thisObj.sequence  = null;
		}
	}
	root.jobProc          = function() {
		for (var i in this.tweening) {
			var jobProp  = this.tweening[i];
			var propName = i;
			if (jobProp.current == jobProp.target) { continue; }
			var difference  = parseFloat(Math.abs(Math.min(jobProp.target, jobProp.origin) - Math.max(jobProp.target, jobProp.origin)));
			var stepLength  = parseFloat(difference / Math.round(this.duration*root.fps));
			var newValue    = parseFloat((Math.max(jobProp.target, jobProp.origin) == jobProp.target) ? parseFloat((jobProp.current + stepLength).toPrecision(9)) : parseFloat((jobProp.current - stepLength).toPrecision(9)));
			var tripTotal   = parseFloat(Math.abs(Math.min(newValue, jobProp.origin) - Math.max(newValue, jobProp.origin)));
			var tripLeft    = parseFloat(difference - tripTotal);
			var finalValue  = (tripTotal >= difference || tripLeft < stepLength) ? jobProp.target : newValue; //<-- adjusts for possibility that remaining steps are smaller than increment, jump to final step.
			if (jobProp.unit == 'px') { finalValue = Math.round(finalValue) };
			jobProp.current = finalValue;
		}
		if (this.element.onMove) {
			this.element.onMove();
		}
		if (this.isComplete()) {
			if (this.sequence)   {
				var thisElement  = this.element;
				var thisSequence = this.sequence
				var delay = function() { thisElement.sequence(thisSequence); }
				setTimeout(delay, root.interval);
			}
			if (this.onComplete) { setTimeout(this.onComplete, root.interval); }
		}
	}
	root.renderFastScript = function() {
		for (var i in this.tweening) {
			if(i == 'opacity' && client.engine == 'msie') {
				this.element.style.filter = 'alpha(opacity=' + Math.round(this.tweening[i].current * 100) + ')'; // support microsofts jacked up transparency "filter"
			} else {
				var currentValue = (this.tweening[i].units == 'px') ? Math.round(this.tweening[i].current) : this.tweening[i].current;
				this.element.style[i] = currentValue + this.tweening[i].units;
			}
		}
	}
	root.renderFastRedraw = function() {
		var styleStr = '';
	 	var statStyles = this.element.getAttribute('style') || '';
		if (statStyles && statStyles != '') {
			statStyles = statStyles.split(/;\s*/);
			for (var i in statStyles) {
				if (typeof(this.tweening[statStyles[i].split(/:\s*/)[0]]) != 'undefined') {
					statStyles[i] = '';
				}
			}
			statStyles  = statStyles.join('; ');
		}
		for (var i in this.tweening) {
			var prefix = i.match(/^[a-z]+(?=[A-Z])/);     // left-side
			var suffix = i.match(/[A-Z][a-z]+/);          // right-side
			var styleName = (prefix && suffix) ? prefix[0] + '-' + suffix[0].toLowerCase() : i;
			var currentValue = (this.tweening[i].units == 'px') ? Math.round(this.tweening[i].current) : this.tweening[i].current;
			statStyles += styleName + ': ' + currentValue + this.tweening[i].units + ';';
		}
		this.element.setAttribute('style', statStyles);
	}
	root.isComplete       = function() {
		for (var i in this.tweening) {
			if (this.tweening[i].current != this.tweening[i].target) { return false; }
		}
		return true;
	}
	root.move             = function(motionProps, duration, onComplete) {
			motionProps = root.preProcess(motionProps);
			var propCount = 0;
			for (var i in motionProps) {
				propCount++;
				if (typeof(motionProps[i].to) == 'undefined')   { throw(this+'.move() - you must specify a "to" property for each css property'); }
				if (root.getUnits(motionProps[i].to) != root.getUnits(motionProps[i].from)) { this+'.move() - the units in your "to" and "from" properties for a given css property must match' }
			}
			if (!motionProps)                                   { throw(this+'.move() - you must specify a motionProps object');                 }
			if (propCount == 0)                                 { throw(this+'.move() - you must specify at least one css property to animate'); }
			if (onComplete && typeof(onComplete) != 'function') { throw(this+'.move() - onComplete must be a function if specified');            }
			var renderBias = (propCount >= root.biasTrip && client.engine != 'msie');
			this.stop();
			var newMotionJob = {
				element    : this,
				isPaused     : false,
				duration   : duration || root.defaults.duration,
				tweening   : { },
				render     : (renderBias) ? root.renderFastRedraw : root.renderFastScript,
				isComplete : root.isComplete,
				process    : root.jobProc,
				onComplete : onComplete || null
			}
			for (var i in motionProps) {
				newMotionJob.tweening[i] = {
					units  : root.getUnits(motionProps[i].to),
					origin : root.getValue(motionProps[i].from) || root.getValue(this.style[i])       || 0,
					current: root.getValue(this.style[i])       || root.getValue(motionProps[i].from) || 0,
					target : root.getValue(motionProps[i].to)
				}
			}
			root.queue.push(newMotionJob);
			if (root.queue.length == 1) {
				if (root.onQueueStart && typeof(root.onQueueStart) == 'function') { root.onQueueStart(); }
				root.start();
			}
	}
	root.reverse          = function() {
		for (var i in root.queue) {
			var thisMotion = root.queue[i];
			if (thisMotion.element === this) {
				for (var ii in thisMotion.tweening) {
					if (typeof(thisMotion.sequence) != 'undefined') {
						thisMotion.sequence.reverse();
					}
					var oldTarget                = thisMotion.tweening[ii].target;
					var oldOrigin                = thisMotion.tweening[ii].origin;
					thisMotion.tweening[ii].target   = oldOrigin;
					thisMotion.tweening[ii].origin   = oldTarget;
				}
			}
		}
	}
	root.stop             = function(executeOnComplete) {
		for (var i in root.queue) {
			var thisMotion = root.queue[i];
			if (thisMotion.element === this) {
				if (i == 0) {
					root.queue.shift();
				} else {
					root.queue.splice(i, i);
				}
			}
		}
	}
	root.pause            = function() {
		for (var i in root.queue) {
			var thisMotion = root.queue[i];
			if (thisMotion.element === this) {
				thisMotion.isPaused = true;
			}
		}
	}
	root.play             = function() {
		for (var i in root.queue) {
			var thisMotion = root.queue[i];
			if (thisMotion.element === this) {
				thisMotion.isPaused = false;
			}
		}
	}
	root.playPause        = function() {
		for (var i in root.queue) {
			var thisMotion = root.queue[i];
			if (thisMotion.element === this) {
				thisMotion.isPaused = (thisMotion.isPaused) ? false : true;
			}
		}
	}
	root.end              = function() {
		for (var i in root.queue) {
			var thisMotion = root.queue[i];
			if (thisMotion.element === this) {
				for (var ii in thisMotion.tweening) {
					thisMotion.tweening[ii].current   = thisMotion.tweening[ii].target;
					thisMotion.process();
					thisMotion.render();
				}
			}
		}
	}
	root.sequence         = function(sequence, onComplete) {
		var thisJob = sequence.shift();
		var motionProps = thisJob[0];
		var duration    = thisJob[1] || root.defaults.duration;
		var onComplete  = thisJob[2] || null;
		this.move(motionProps, duration, onComplete);
		if (sequence.length > 0) {
			for (var i in root.queue) {
				var thisMotion = root.queue[i];
				if (thisMotion.element === this) {
					thisMotion.sequence = sequence;
				}
			}
		}
	}
	root.getValue         = function(str) { 
		try {
			return parseFloat(str.toString().match(/^[^a-zA-z]+/).toString());
		} catch (e) { return null; }
	}
	root.getUnits         = function(str) { 
		try {
			return str.toString().match(/[a-zA-z]+$/).toString();
		} catch (e) { return ''; }
	}
	root.preProcess       = function(motionProps) {
		for (var i in motionProps) {
			if (typeof(motionProps[i].to) != 'string' || motionProps[i].to.indexOf(' ') == -1) { continue; }
			var propName         = i;
			var propValuesOrigin = motionProps[i].from.split(' ');
			var propValuesTarget = motionProps[i].to.split(' ');
			if (propValuesOrigin.length != propValuesTarget.length) { throw(this+'.move() - when using shorthand properties, the number of values in your from and to properties must match.'); }
			switch (propValuesOrigin.length) {
				case 2:
					motionProps[propName+'Top']   = { from:propValuesOrigin[1], to:propValuesTarget[1] };
					motionProps[propName+'Right'] = { from:propValuesOrigin[0], to:propValuesTarget[0] };
					motionProps[propName+'Bottom']= { from:propValuesOrigin[1], to:propValuesTarget[1] };
					motionProps[propName+'Left']  = { from:propValuesOrigin[0], to:propValuesTarget[0] };
				break;
				case 4:
					motionProps[propName+'Top']   = { from:propValuesOrigin[0], to:propValuesTarget[0] };
					motionProps[propName+'Right'] = { from:propValuesOrigin[1], to:propValuesTarget[1] };
					motionProps[propName+'Bottom']= { from:propValuesOrigin[2], to:propValuesTarget[2] };
					motionProps[propName+'Left']  = { from:propValuesOrigin[3], to:propValuesTarget[3] };
				break;
			}
			delete motionProps[i];
		}
		return motionProps;
	}
root.setMethods();
}

var curAccOpen = [null, null, null];

function highOn(arg){
    if(arg.className.indexOf("_perm") == -1)
	    arg.className = arg.className + "_high";
}
function highOff(arg){
    if(arg.className != "row"){
	    if(arg.className.indexOf("_perm") == -1)
		    arg.className = arg.className.substring(0, arg.className.length - 5);
	    if(arg.className.indexOf("_high") != -1)
		    arg.className = arg.className.substring(0, arg.className.length - 5);
    }
}



function openAcc(arg, fh, th){
	var subElement = arg.getElementsByTagName('div')[1];
    if(curAccOpen[0] == null){
	    curAccOpen[0] = arg; curAccOpen[1] = fh; curAccOpen[2] = th;
	    arg.className = arg.className.replace("_high", "_perm");
		subElement.style.display = 'block';
	    arg.move({height:{from: fh, to: th}}, 0.5);
    }
    else{
	    if(curAccOpen[0] == arg){
		    arg.className = arg.className.replace("_perm", "");
		subElement.style.display = 'block';
		    arg.move({height:{from: th, to: fh}}, 0.5);
		    curAccOpen[0] = null;
	    }
	    else{
		    arg.className = arg.className.replace("_high", "_perm");
		    arg.move({height:{from: fh, to: th}}, 0.5);
		    curAccOpen[0].className = curAccOpen[0].className.replace("_perm", "");
			subElement.style.display = 'block';
		    curAccOpen[0].move({height:{from: curAccOpen[2], to: curAccOpen[1]}}, 0.5);
		    curAccOpen[0] = arg; curAccOpen[1] = fh; curAccOpen[2] = th;
	    }
    }

}





/*--- Onload function --*/

window.onload = function(){ 
    window.motion = new motionHandler(24);
    //menuOn(); // shouldn't be needed with new tab system
	editContactPop();
	iblue();
	checkboxCheckers();
}