// Copyright 2008 do.maini.ca Inc //

function $(element) {
	if (arguments.length > 1) {
		for (var i = 0, elements = []; i<arguments.length; i++)
			elements.push($(arguments[i]));
		return elements;
	} else {
		element = document.getElementById(element);
		return element;
	}
}

Array.prototype.unique =
  function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j])
          j = ++i;
      }
      a.push(this[i]);
    }
    return a;
  };

function showDiv(obj) {
	obj.style.display = 'block';
}

function hideDiv(obj) {
	obj.style.display = 'none';
}

function toggleDiv(obj) {
	if (obj.style.display == 'none') {
		showDiv(obj);
	} else if (obj.style.display == 'block') {
		hideDiv(obj);
	}
}

function toggleValue(obj, text1, text2) {
	if (obj.innerHTML == text1) {
		obj.innerHTML = text2;
	} else if (obj.innerHTML == text2) {
		obj.innerHTML = text1;
	}
}


function loading(obj, text) {
	obj.innerHTML = '<div class="loadButton">&nbsp;</div> ';
	if(text) obj.innerHTML += text+'...';
}

function toggleChild(par, obj) {
	if (obj.style.display == 'none') {
		if (par.className == 'boxMin' || par.className == 'boxPlus') par.className = 'boxMin';
		obj.style.display = 'block';
	} else {
		if (par.className == 'boxMin' || par.className == 'boxPlus') par.className = 'boxPlus';
		obj.style.display = 'none';
	}
	return;
}

function closeParent(obj) {
	var id = obj.parentNode.id;
	var t = id.substring(0,1);	
	id = id.substring(1,id.length);	
	
	var urlString = '';
	if (t == 't') {
		urlString = 'delTLD=1&ald_ID=';
		listString = 'getTLDList=1&search=1';
	} else if (t == 'm') {
		urlString = 'delMOD=1&mod_ID=';
		listString = 'getMODList=1&search=1';
	}
	
	var url = "/fct/settings.php?"+urlString+id;
	if (url) xmlreqGET(url, '1');
	
	url = "/fct/settings.php?"+listString; // update lists
	if (url) xmlreqGET(url, '1');

	obj.parentNode.parentNode.removeChild(obj.parentNode);
	
	return;
}


// col fundtion commands
function delThis(obj, url) {
	var element = obj.parentNode.parentNode;
	var id = obj.parentNode.id;
	element.removeChild(obj.parentNode);

	if (url) xmlreqGET(url, '1');
	return;
}



function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

function tackOn(o, t) { // adds text to the end of a div
	o.innerHTML = t+o.innerHTML;
}
//** Fade in and Out **//
function fade(id) {
	opacity(id, 100, 0, 2000);
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
	if (opacEnd == 0) {
		setTimeout("clearDiv('" + id + "')", (timer * speed));
	}
}

function clearDiv(id) {
	//$(id).innerHTML = '';
	hideDiv($(id));
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = $(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

// place COMODO view
function placeDiv(thisObj, obj, pos, lr, tb) { //(object, [fixed or absolute], [left or right]))
	var widthValue = thisObj.offsetWidth, heightValue = thisObj.offsetHeight;
	var topValue= 0,leftValue= 0,rightValue= 0;
  while(thisObj){
		leftValue+= thisObj.offsetLeft;
		topValue+= thisObj.offsetTop;
		thisObj= thisObj.offsetParent;
  }
	
	obj.style.position = pos;
	var sideOffset = 0;
	var topOffset = 0;
	if (lr == 'left') {
		sideOffset = leftValue - obj.offsetWidth + 0.5*widthValue;
	}
	else if (lr == 'right') {
		sideOffset = leftValue + 0.5*widthValue;
	}
	if (tb == 'top') {
		topOffset = topValue - obj.offsetHeight + 0.5*heightValue;
	}
	else if (tb == 'bottom') {
		topOffset = topValue + 0.5*heightValue;
	}
	
	
	obj.style.left = sideOffset+'px';
	obj.style.top = topOffset+'px';
	
}


function badBroswer(ver) {
	showDiv($('fade_bottom'))
	showDiv($('bottom_holder'));
	//$('bottom_holder').innerHTML = '<div id="bottom"></div>';
	//$('bottom').innerHTML = '<center><table><tr><td colspan="2">We haven\'t fully tested RFQs.ca with your browser yet.<br />Please upgrade or use one of the following:<br /><br /></td></tr><tr><td><b>FireFox</b><br /><a href="http://www.mozilla.com/firefox?from=sfx&uid=247045&t=306" target="_blank">Download Now</a></td><td><b>Internet Explorer</b><br /><!--<a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx" target="_blank">Download Now</a>-->In Testing Stage</td></tr></table><br /><i>*For optimal viewing use FireFox.</i></center><br /><small>You are currently using '+ver+'</small>';
	$('bottom').innerHTML = '<center><table><tr><td colspan="2">We haven\'t fully tested RFQs.ca with your browser yet.<br />Please upgrade or use one of the following:<br /><br /></td></tr><tr><td><b>FireFox</b><br /><a href="http://www.mozilla.com/firefox?from=sfx&uid=247045&t=306" target="_blank">Download Now</a></td><td><b>Internet Explorer</b><br /><a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx" target="_blank">Download Now</a></td></tr></table><br /><i>*For optimal viewing use FireFox.</i></center><br /><small>You are currently using '+ver+'</small>';
//loading($('search_results'), 'Loading Search Results');
}
