// Porktey JavaScript Document
function makefav(favid, userid, id) {
	var url = 'makefav.php';
	var pars = 'fav_id=' + favid + '&userid=' + userid + '&id=' + id ;
	var myAjax = new Ajax.Request(url, {method: 'get', 	parameters: pars});
	var theid = 'favicon'+favid;
	var newinner = "<a onClick=\"unfav('"+favid+"', '"+userid+"', '"+id+"');\"><img src=\"http://www.hplex.info/images/icons/new/favorite.gif\" /></a>";
	document.getElementById(theid).innerHTML = newinner;

}

function unfav(favid, userid, id) {
	var url = 'unfav.php';
	var pars = 'fav_id=' + favid + '&userid=' + userid + '&id=' + id ;
	var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars});
	var theid = 'favicon'+favid;
	document.getElementById(theid).innerHTML = "<a onClick=\"makefav('"+favid+"', '"+userid+"', '"+id+"');\"><img src=\"http://www.hplex.info/images/icons/new/favorite-gray.gif\" /></a>";
}

function tabme (group) {
	var tab = new Array ('tab1', 'tab2', 'tab3', 'tab4', 'tab5', 'tab6', 'tab7')
	for (i=0;i<7;i++){
		document.getElementById(tab[i]).className='';
	}
	document.getElementById(group).className='current';
	document.getElementById('tabcontent').innerHTML = tabcontent[group];
}

function showAdvanced() {
	oID = document.getElementById('advancedSearch');
	if (oID.style.display == 'none') {
		oID.style.display = 'block';
	} else {
		oID.style.display = 'none';
	}
}

function SelectMoveRows(SS1,SS2)
{
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
        if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
            SS1.options[i]=null;
        }
    }
    SelectSort(SS2);
}
function SelectSort(SelList)
{
    var ID='';
    var Text='';
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}

function grabCookie(name) {
	var sRE = "(?:; )?" + name + "=([^;]*);?";
	var oRE = new RegExp(sRE);
	
	if (oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	} else {
		return null;
	}
}

function cbox (id) {
	var boxid = 'CB'+id;
	var checkit = $(boxid).checked;
	var munchie = grabCookie('selected');
	var expireDate = new Date;
	expireDate.setMonth(expireDate.getMonth()+6);
	if (checkit) {
		if (munchie) {
			var munchieArray = munchie.split('.');
			var flag = 0;
			for (x=0; x < munchieArray.length; x++) {
				if (munchieArray[x] == id) {
					flag = 1;
				}
			}
			if (flag == 0) {
				munchieArray.push(id);
			}
			var munchieString = munchieArray.join('.');
		} else {
			var munchieString = id;
		}
	} else {
		if (munchie) {
			var newArray = new Array();
			var munchieArray = munchie.split('.');
			var count=0;
			for (x=0; x < munchieArray.length; x++) {
				if (munchieArray[x] != id) {
					if (munchieArray[x] != 'undefined') {
						newArray[count] = munchieArray[x];
						count++;
					}
				}
			}
			var munchieString = newArray.join('.');
		}
	}
	document.cookie = "selected="+munchieString+";expires="+expireDate.toGMTString();
}

function checkem() {
	var munchie = grabCookie('selected');
	if (munchie) {
		var munchieArray = munchie.split('.');
		for (x=0; x < munchieArray.length; x++) {
			var boxid = 'CB'+munchieArray[x];
			if ($(boxid)) {
				$(boxid).checked = 'true';
			}
		}
	}
}
function allSelect(){
	List = document.form1.searchTags;
	if (List.length && List.options[0].value == 'temp') return;
	for (i=0;i<List.length;i++) {
		List.options[i].selected = true;
	}
	List = document.form1.searchIcons;
	if (List.length && List.options[0].value == 'temp') return;
	for (i=0;i<List.length;i++) {
		List.options[i].selected = true;
	}
}

function addicon(id) {
	SS1 = document.getElementById('searchIcons');
	icon = nameArray[id].replace("&#39;","'");
	var newRow = new Option(icon, id);
	SS1.options[SS1.length]=newRow;
}

function removeIcon(id) {
	innertext ='';
	SS1 = document.getElementById('searchIcons');
	for (i=SS1.options.length - 1; i>=0; i--) {
		if (SS1.options[i].value == id) {
			SS1.options[i] = null;
		}
	}
	for (i=SS1.options.length - 1; i>=0; i--) {
		id = SS1.options[i].value;
		innertext += '<img src="http://www.hplex.info/images/icons/new/'+ urlArray[id] + '" onClick="removeIcon('+id+');" />';
	}
	$('dropzone').innerHTML = innertext;
}

function addtag(tag) {
	list = document.form1.usertags.value;
		if (list) {
		document.form1.usertags.value += ', '+tag;
	} else {
		document.form1.usertags.value = tag;
	}
}

function closetagbox() {
	$('tagentry').innerHTML = '<div></div>';
}
	