function swapStars(stars, halfstars, maxstars, redstars, id) {
	var onImage = '/images/redstar.gif';
	var offImage = '/images/emptystar.gif';
	var redImage = '/images/star.gif';
	var halfImage = '/images/redhalfstar.gif';
	var count = 1;
	
	stars = stars - redstars;
	
	
	//alert(redstars);
	
	for (x = 1; x <= redstars; x++) {
		document.getElementById(id+count).src=redImage;
		count++;
	}
	for (x = 1; x <= stars; x++) {
		document.getElementById(id+count).src=onImage;
		count++;
	}
	for (x = 1; x <= halfstars; x++) {
		document.getElementById(id+count).src=halfImage;
		count++;
	}
	for (x = 1; x <= (maxstars-halfstars-stars-redstars); x++) {
		document.getElementById(id+count).src=offImage;
		count++;
	}
}

function swapStars2(yellowstars, yellowhalfstars, redstars, redhalfstars, maxstars, id) {
	var redStar = '/images/redstar.gif';
	var redHalfStar = '/images/redhalfstar.gif';
	var yellowStar = '/images/star.gif';
	var yellowHalfStar = '/images/halfstar.gif';
	var emptyStar = '/images/emptystar.gif';
	var count = 1;
	
	//stars = stars - redstars;
	
	//alert(redstars);
	
	for (x = 1; x <= yellowstars; x++) {
		document.getElementById(id+count).src=yellowStar;
		count++;
	}
	for (x = 1; x <= yellowhalfstars; x++) {
		document.getElementById(id+count).src=yellowHalfStar;
		count++;
	}
	for (x = 1; x <= redstars; x++) {
		document.getElementById(id+count).src=redStar;
		count++;
	}
	for (x = 1; x <= redhalfstars; x++) {
		document.getElementById(id+count).src=redHalfStar;
		count++;
	}
	for (x = 1; x <= (maxstars-yellowstars-yellowhalfstars-redstars-redhalfstars); x++) {
		document.getElementById(id+count).src=emptyStar;
		count++;
	}
}

function swapImage(imageid, imagefile) {
	document.getElementById(imageid).src="/images/tabs/"+imagefile;
}

/*function profileLink(handle) {
	alert('profilelink');
	if (document.getElementById('changepath').value != "no") {
		alert('change');
		handle = handle.replace(/[\s]+/g, '');
		if (document.getElementById('profilepath')) {
			alert('profilepath');
			document.getElementById('profilepath').value = handle;
		}
		else {
			alert('span');
			document.getElementById('spanprofile').innerHTML = 'http://www.traxinspace.com/profile/'+handle;
		}
	}
}*/

/*function fileManager(path, js) {
	myRef = window.open('/fileselect?path='+path+'&js='+js,'filemanager', 'left=20,top=20,width=500,height=300,toolbar=0,resizable=0,scrollbars=1,status=0,directories=0,location=0,menubar=0');
}*/

var xmlHttp;

function showCity(str) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="inc/getcities.php?u="+str;

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("ajaxresults").innerHTML=xmlHttp.responseText;
	} 
}

function checkPrompt(focusblur, value, id, message) {
	if (value == "" && focusblur == 'B') document.getElementById(id).value = message;
	else if (value == message && focusblur == 'F') document.getElementById(id).value = '';
}

function disableElements(test, value, element1, element2, element3) {
	if (test == value) {
		if (element1 != '') document.getElementById(element1).disabled = true;
		if (element2 != '') document.getElementById(element2).disabled = true;
		if (element3 != '') document.getElementById(element3).disabled = true;
	}
	else {
		if (element1 != '') document.getElementById(element1).disabled = false;
		if (element2 != '') document.getElementById(element2).disabled = false;
		if (element3 != '') document.getElementById(element3).disabled = false;
	}
}

function makeRequired(test, value, span1, span2, span3) {
	if (test == value) {
		if (span1 != '') document.getElementById(span1).style.display = '';
		if (span2 != '') document.getElementById(span2).style.display = '';
		if (span3 != '') document.getElementById(span3).style.display = '';
	}
	else {
		if (span1 != '') document.getElementById(span1).style.display = 'none';
		if (span2 != '') document.getElementById(span2).style.display = 'none';
		if (span3 != '') document.getElementById(span3).style.display = 'none';
	}
}

function showImageFile(ext) {
	if (ext != '.jpg' && ext != '.gif' && ext != '.png') document.getElementById('divimagefile').style.display = '';
	else document.getElementById('divimagefile').style.display = 'none';
}

function trim(sString) {
	while (sString.substring(0,1) == ' ') sString = sString.substring(1, sString.length);
	while (sString.substring(sString.length-1, sString.length) == ' ') sString = sString.substring(0,sString.length-1);
	return sString;
}


function submitRating(id, str) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="/inc/submitrating.php?id="+id+"&rating="+str;

	xmlHttp.onreadystatechange=ratingStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ratingStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("spanrating").innerHTML=xmlHttp.responseText;
	} 
}


function checkEmail(str) { 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="/inc/checkemail.php?t="+str;

	xmlHttp.onreadystatechange=emailStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function emailStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("spanemail").innerHTML=xmlHttp.responseText;
	} 
}

function checkUser(str) { 
	//alert(str);
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="/inc/checkuser.php?t="+str;

	xmlHttp.onreadystatechange=userStateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function userStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("spanuser").innerHTML=xmlHttp.responseText;
	} 
}


function GetXmlHttpObject() { 
	http_request = false;
   	if (window.XMLHttpRequest) { // Fireox, Safari, etc.
      	http_request = new XMLHttpRequest();
       	if (http_request.overrideMimeType) {
       		//set type accordingly to anticipated content type
       		//http_request.overrideMimeType('text/xml');
       		http_request.overrideMimeType('text/html');
       	}
   	} 
	else if (window.ActiveXObject) { // IE
       	try {
       		http_request = new ActiveXObject("Msxml2.XMLHTTP");
       	} 
		catch (e) {
       		try {
           		http_request = new ActiveXObject("Microsoft.XMLHTTP");
           	} catch (e) {}
       	}
    }
	return http_request;
}


function swapVisibility(show, hide) {
	if (show != '') document.getElementById(show).style.display = '';
	if (hide != '') document.getElementById(hide).style.display = 'none';
}

function toggleVisibility(divid) {
	if (document.getElementById(divid).style.display == 'none') document.getElementById(divid).style.display = '';
	else document.getElementById(divid).style.display = 'none';
}
	
function resetSelect(selectid, value) {
	var selectbox = document.getElementById(selectid);

	for (i = 0; i < selectbox.length; i++) {
		if (selectbox[i].text == value) {
			selectbox.selectedIndex = i;
			break;
		}
	}
}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
}

function toggleAssociate(show, hide1, hide2, hide3) {
	//alert(show + " " + hide1 + " " + hide2);
	if (show != '') document.getElementById(show).style.display = '';
	if (hide1 != '') document.getElementById(hide1).style.display = 'none';
	if (hide2 != '') document.getElementById(hide2).style.display = 'none';
	if (hide3 != '') document.getElementById(hide3).style.display = 'none';
}

function checkVisibility(value, id) {
	if (value == 'private') {
		document.getElementById(id).bgColor = '#ffebe8';
		document.getElementById('spanvisible').style.display = '';
	}
	else {
		document.getElementById(id).bgColor = '#ffffff';
		document.getElementById('spanvisible').style.display = 'none';
	}
}

function checkSelect(selectid, value1, id1, value2, id2, value3, id3, eitheror) {
	//alert(document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value);
	if (document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value == value1) {
		document.getElementById(id1).style.display = '';
		if (id2 != '') document.getElementById(id2).style.display = 'none';
		if (id3 != '') document.getElementById(id3).style.display = 'none';
	}
	else if (value2 != '' && document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value == value2) {
		document.getElementById(id1).style.display = 'none';
		if (id2 != '') document.getElementById(id2).style.display = '';
		if (id3 != '') document.getElementById(id3).style.display = 'none';
	}
	else if (value3 != '' && document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value == value3) {
		document.getElementById(id1).style.display = 'none';
		if (id2 != '') document.getElementById(id2).style.display = 'none';
		if (id3 != '') document.getElementById(id3).style.display = '';
	}
	else if (eitheror == 1) {
		if (id1 != '') document.getElementById(id1).style.display = 'none';
		if (id2 != '') document.getElementById(id2).style.display = 'none';
		if (id3 != '') document.getElementById(id3).style.display = 'none';
	}
}

function checkUS(selectid, id1, id2) {
	//alert(document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].text);
	if (document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].text == 'United States') {
		document.getElementById(id2 + 'label').style.display = '';
		document.getElementById(id2 + 'input').style.display = '';
		document.getElementById(id1 + 'label').style.display = 'none';
		document.getElementById(id1 + 'input').style.display = 'none';
	}
	else {
		document.getElementById(id1 + 'label').style.display = '';
		document.getElementById(id1 + 'input').style.display = '';
		document.getElementById(id2 + 'label').style.display = 'none';
		document.getElementById(id2 + 'input').style.display = 'none';
	}
}

function selectShowHide(selectid, value, showid, hideid, value2, value3) {
	if (document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value == value) {
		document.getElementById(showid).style.display = '';
	}
	else if (value2 != undefined && document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value == value2) {
		document.getElementById(showid).style.display = '';
	}
	else if (value3 != undefined && document.getElementById(selectid).options[document.getElementById(selectid).selectedIndex].value == value3) {
		document.getElementById(showid).style.display = '';
	}
	else {
		document.getElementById(hideid).style.display = 'none';
	}

}

/*function resetText(textid) {
	document.getElementById(textid).value = '';
}

function concatCollections() {
	var c, k, j, i = arguments.length;
	var a = [];
	for ( j=0; j<i; j++ ) {
		c = arguments[j];
		h = c.length;
		for ( k=0; k<h; k++ ){
			a.push(c[k]);
		}
	}
	return a;
}*/

/*sfFocus = function() {
	var type1 = document.getElementsByTagName("INPUT");
	var type2 = document.getElementsByTagName("TEXTAREA");
	var type3 = document.getElementsByTagName("SELECT");
	var sfEls = concatCollections(type2, type1);
	//var sfEls = concatCollections(sfEls, type3);
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);*/


function removeFile(divNum) {
	var count = document.forms['formadd'].elements.length;
	var c = 0;
	
	for (i = 0; i < count; i++) {
		var element = document.forms['formadd'].elements[i]; 
		if (element.name.match("photo")) c++;
	}
	//if (c == 1 || c == 0) document.getElementById('attachlink').innerHTML = "Attach a photo";
	
	var d = document.getElementById('filedivs');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
}

function addFile() {
	var count = document.forms['formadd'].elements.length;
	var fd = document.getElementById('filedivs');
	var c = 0;
	var html = "";

	for (i = 0; i < count; i++) {
		var element = document.forms['formadd'].elements[i]; 
		if (element.name.match("source")) c++;
	}
	//alert(c);
	c=c+1
	
	var newdiv = document.createElement('div');
	var divIdName = 'filediv'+c;
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = "<input type=\"file\" name=\"source" + c + "\" size=\"38\"> <a href=\"#asource\" onclick=\"removeFile('" + divIdName + "')\">Remove</a>";
	fd.appendChild(newdiv);
	
	//document.getElementById('attachlink').innerHTML = "Add another source file";
}

function removeSN(divNum) {
	var count = document.forms['formbasics'].elements.length;
	var c = 0;
	
	for (i = 0; i < count; i++) {
		var element = document.forms['formbasics'].elements[i]; 
		if (element.name.match("sn")) c++;
	}
	
	var d = document.getElementById('sndivs');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
}

function addSN() {
	var count = document.forms['formbasics'].elements.length;
	var fd = document.getElementById('sndivs');
	var c = 0;
	var html = "";

	for (i = 0; i < count; i++) {
		var element = document.forms['formbasics'].elements[i]; 
		if (element.name.match(/^sn/)) c++;
	}
	//alert(c);
	c=c+1
	
	var newdiv = document.createElement('div');
	var divIdName = 'sndiv'+c;
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = "<input type=\"text\" name=\"sn" + c + "\" class=\"medbox\"> <select name=\"screenname" + c + "type\"><option value=\"AIM\">AIM</option><option value=\"Yahoo\">Yahoo Messenger</option><option value=\"Windows Live\">Windows Live (MSN)</option><option value=\"Google Talk\">Google Talk</option><option value=\"Skype\">Skype</option><option value=\"Gadu-Gadu\">Gadu-Gadu</option><option value=\"ICQ\">ICQ</option></select>"; //<a href=\"#asource\" onclick=\"removeSN('" + divIdName + "')\" class=\"details\">Remove</a>";
	fd.appendChild(newdiv);
}
