// JavaScript Document - made by Quangmd@g3ws.com

var myimages = new Array();
function preloading(){
	for (x=0; x<preloading.arguments.length; x++){
		myimages[x] = new Image();
		myimages[x].src = preloading.arguments[x];
	}
}

function setObjHTML(obj, val) {
	tmp = getobj(obj);
	
	if (tmp.innerHTML)
		tmp.innerHTML = val;
	else 
		tmp.value = val;
	
}

function setObjText(obj, val) {
	tmp = getobj(obj);
	
	if (tmp.innerText)
		tmp.innerText = val;
	else if (tmp.textContent)
		tmp.textContent = val;
	else
		tmp.text = val;
	
}

function openWnd(alink,aname,atitle,modal,awidth,aheight,showcenter) {

	var win = new Window(aname, {className:"dialog", title: atitle, width:awidth, height:aheight, zIndex:150, opacity:1, resizable: true});
	win.setAjaxContent(alink);
	win.setDestroyOnClose();
	win.toFront();
	if (modal || showcenter)
		win.showCenter(true);
	else
		win.showCenter();
			
}
function showpPopup(lnk, title) {
	openWnd(lnk + "&nocache=" + Math.random(),'popup222',title,true,540,350);
}
function require(names)
{
  if (checkNames(names))
    return true;
  alert('Please fill in all required inputs marked with * !');
  return false;
}

function checkEmail2(one) {
	
	if (one=='') {
	 return false;	
	}
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(one)){
		return (true)
	}
	
	//alert("Invalid E-mail Address! Please re-enter.")
	
	return (false)
}

function checkNames(names)
{
  var anArray = names.split(",");
  for (var i = 0; i < anArray.length; i++)
  {
    if (!checkName(anArray[i]))
      return false;
  }
  return true;
}

function checkName(name)
{
  if (name.length == 0)
    return true;
  var inputs = document.forms[0].elements;
  for (var i = 0; i < inputs.length; i++)
  {
    var anInput = inputs[i];
    if ( (anInput != null) && (anInput.name == name) )
    {
      if (checkInput(anInput))
        return true;
    }
  }
  return false;
}

function checkInput(anInput)
{
  var type = anInput.type;
  if ( (type == "text") || (type == "textarea") )
    return checkText(anInput);
  if (type == "radio")
    return checkRadio(anInput);
  if ( (type == "select-one") || (type == "select-multiple") )
    return checkSelect(anInput);
  alert("Unsupported type for required input: " + type);
  return false;
}

function checkText(anInput)
{
  var aString = anInput.value;
  if (aString == null)
    return false;
  return (aString.length > 0);
}

function checkRadio(anInput)
{
  var aBoolean = anInput.checked;
  if (aBoolean == null)
    return false;
  return aBoolean;
}

function checkSelect(anInput)
{
  if (anInput.selectedIndex < 0)
    return false;
  var option = anInput.options[anInput.selectedIndex];
  var aString = option.value;
  if ( (aString != null) && (aString.length > 0) )
    return true;
  aString = option.text;
  if ( (aString != null) && (aString.length > 0) )
    return true;
  return false;
}


//set to 1 if you want to show debug
var MyStatusActive = 0;
function setTargets() {
var link, l = 0;
while (link = document.links[l++]) {
if (link.href.indexOf('uhelpcanhelpforum') == -1)
link.target = '_blank';
}
}

function bb_setHomepage(obj)
{
    obj.style.behavior='url(#default#homepage)';
    if (document.all)
    {
        obj.setHomePage('http://www.deals2spot.com');
    }
    else
    {
        alert("Drag the link in the address bar to Home button to set deals2spot.com as the homepage!");
    }
}
function bb_bookmarksite(title, url)
{
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}

function changetitle() {	
	st = readCookie('lasttitle');
	if (st!=null) {
		document.title = 'Spot the Best Buy - ' + st;
		//eraseCookie('lasttitle');
	}
}

function showAd(id) {
	window.open("adclick.php?id=" + id);
}
function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		
		subobj.style.display=(subobj.style.display!="block")? "block" : "none";
		
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		
		subobj.style.left=xpos+"px"
		subobj.style.top=ypos+"px"
		return false
	}
	else
		return true
}

function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}



function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}

function getobj(name) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		return document.getElementById(name)
	}
	else {	
		if (document.layers) { // Netscape 4
			return document(name)
		}
		else { // IE 4
			return document.all(name)
		}
	}
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollX() {
  var scrOfX = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function ds(st) {
	window.status = st;
}
function GoMasterPage(url) {
	window.location = url;
}	
	
function useSourceLink(theFormName, optvalue) {
	
	getAjaxVal('selectors/getvendorlink.php?id=' + optvalue,'deallink');
	
	//theForm = getobj(theFormName);	
	//theForm.elements('deallink').value = opsource[optvalue];
}

function mystatus(st) {
	if (MyStatusActive==1) {
		var tmp = getobj('mystatusbar');
		mystatusbar.innerHTML = st + '<br>' + mystatusbar.innerHTML;
	}
}

function getparentobj(name) {
if (document.getElementById) { // DOM3 = IE5, NS6
	return parent.document.getElementById(name)
}
else {	
if (document.layers) { // Netscape 4
 	return parent.document(name)
}
else { // IE 4
	return parent.document.all(name)
}
}
}

function toogleitem(anid, myset) {	
	obj = getobj(anid);	

	if (obj.style.display=="block") {
		obj.style.display="none"; 
	} else {
		obj.style.display="block";
	}
}

function showitem(obj) {
	if (obj.style.display!="block") {
		obj.style.display="block";
	}
}

function hideitembyname(obid) {
	obj = getobj(obid);
	if (obj.style.display!="none") {
		obj.style.display="none";
	}
}
function showitembyname(obid) {
	obj = getobj(obid);
	if (obj.style.display!="block") {
		obj.style.display="block";
	}	
}

function hideitem(obj) {
	if (obj.style.display!="none") {
		obj.style.display="none";
	}
}

function divclose(nm) {
	obj = getobj(nm);
	obj.innerHTML = '';
	obj.style.height = 0;
	obj.style.width = 0;
	obj.style.display = 'none';
}

function swapImg(imgob, imgurl) {
	obj = getobj(imgob);
	obj.src = imgurl;
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}
function navBar( tableCellRef, hoverFlag, navStyle ) {
	if ( hoverFlag ) {
		switch ( navStyle ) {
			case 1:
//This defines rollover color
				tableCellRef.style.backgroundColor = '#CCCCFF';
				break;
			default:
//tableCellRef.style.backgroundColor = '#ccc';
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#fff000';
				}
		}
	} else {
		switch ( navStyle ) {
			case 1:
//This defines return color
				tableCellRef.style.backgroundColor = '';
				break;
			default:
//tableCellRef.style.backgroundColor = '#ddd';
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#00ff89';
				}
		}
	}
}

function iresize(frameid, minheight, maxheight){

	var fr=document.getElementById(frameid);

	fr.height = 5;
	
	if (fr && !window.opera){

		if (fr.contentDocument && fr.contentDocument.body.offsetHeight) //ns6 syntax
			fr.height = fr.contentDocument.body.offsetHeight+45;
		else if (fr.document && fr.document.body.scrollHeight) //ie5+ syntax
			fr.height = fr.Document.body.scrollHeight + 5;

		if (minheight && (minheight > fr.height)) {
			fr.height = minheight + 'px';
		}
		if (maxheight && (maxheight < fr.height)) {
			fr.height = maxheight + 'px';
		}
	}		
}


////////////////////////////////////////////////////////////////
// setThisTabActive(itemindex, increment)
// Anthony Carcelli, Covibe 7/11
//
// selectDiv: the indexes of the tabs and divs to be turned on/off
// increment: forward or backward represented by -1, 1
//
// for all LI tags and associated div tags, **MUST BE IN SAME ORDER
// all tags are turned off in loop
// if arrows are used to change tabs, the class name in arrows is
// used with increment to cycle through index values doing a check
// to determine the ends of the range (0, x) and resets the selectDiv
// value.
// If no increment sent (arrows weren't used) then selectDiv is passed
// and new tab class is set, arrows ID class is set to reflect which
// index is the current one and divs are set to block.
//
// To reuse, assign a class to any unclassed element of what index
// you want to start in (stored in objTracking), i.e. for the first tab,
// hardcoded class is 0.
////////////////////////////////////////////////////////////////

function setThisTabActive(selectDiv, increment) {

  var divs = getobj('tabbed_divs').getElementsByTagName('div');
  var obj_li = getobj('hotbox_tabs').getElementsByTagName('li');
  var objTracking = getobj('tabbed_divs');
  var current_index = objTracking.className;

  for (i=0; i < obj_li.length; i++) {
		divs[i].style.display = "none";
		obj_li[i].className = "";
  }

  if(increment) {
		current_index = parseInt(current_index);
		increment = parseInt(increment);

		 if ( current_index == 0 && increment == -1 ){
				selectDiv = obj_li.length - 1;
		 } else if ( current_index == obj_li.length-1 && increment == 1 ) {
				selectDiv = 0;
		 } else {
				selectDiv = current_index + increment;
		 }
  }

  objTracking.className = selectDiv;
  divs[selectDiv].style.display = "block";
  obj_li[selectDiv].className = "active";

}