function refinesearch (f) {
        var refined;
        for(var t=0;t<f.refine.length;t++){ if(f.refine[t].checked==true) refined=f.refine[t].value; }
        if(refined==1){f.s.value= (f.s.value ? f.s.value+" "+f.l.value : f.l.value);}
        f.l.value="";
        f.submit();
}

function popupsearch (table, idfield, namefield, whichform) {
	var w = window.open ("../search/popup.php?table=" + table + (idfield ? "&idfield=" + idfield : "") + (namefield ? "&namefield=" + namefield : "") + (whichform ? "&whichform=" + whichform : ""), "b2b_search_popup", "width=550,height=500,status=yes,titlebar=no,locationbar=no,scrollbars=yes");
	w.focus();
}

function email(id) { 
	document.location = "emailcontact.php?id=" + id;
	return true; 
}

function vcard(id) {
//	var width=200;
//	var height=200;
//	var w=window.open("vcard.php?id=" + id,"vcard","location=0, status=0, width=" + width + ", height=" + height + ", scrolling=no");
	top.document.location.href="http://www.caribbeanb2b.com/directories/vcard.php?id=" + id;
//	w.resizeTo(200,200);
//	w.setX((screen.width/2)-(width/2));
//	w.setY((screen.height/2)-(height/2));
//	w.moveTo((screen.width/2)-(width/2),(screen.height/2)-(height/2));
//	w.focus();
}

function showarrow(el,color) { document.images[el].src = "/images/" + color + "arrow.gif"; }

// highlights rows on mouseover in the register section
function hr(el,color,image) {
	switch(color) {
		case "yellow":
			usecol="#fff6e9";
			break;
		case "white":
			usecol="#ffffff";
			break;
		default:
			usecol="#ffffff";
			break;
	}		
	el.style.background=usecol; document.images["i" + image].src="/images/listicon" + image + color + ".gif";
}

function hrpreload() {
	for(x=1;x<=4;x++) {
		image = new Image(); image.src="/images/listicon" + x + "white.gif"; 
		image = new Image(); image.src="/images/listicon" + x + "yellow.gif"; 
	}	
}

function website(theurl) {
	var w = window.open(theurl,"website","");
	w.focus();
}



////////////////////////////// FORM CHECKING AND ORDERING //////////////////////////////
//This is an enhanced check form which takes a list of field names to check against. It treats e-mail addresses and
//passwords specially. Arguments should be field names followed by display values.
function checkForm (f) {
	var s = "";
	var i; //loops through the arguments
	for (i=1; i<arguments.length; i+=2) {
		var field = f.elements[arguments[i]]; //get the field name
		if (!field || !field.name) continue; //if the form property doesn't exist
		var display = arguments[i+1] ? arguments[i+1] : arguments[i];  //get the text to display
		var value = field.value; //get the value for this field
		if (field.type.indexOf ("select") >= 0) {value = field.options[field.selectedIndex].value;} //value for a select list
		if (field.name == "password" && value.length < 6) {s += display + " (with at least 6 characters), ";} //password checking
		else if (field.name == "password2" && f.elements["password"] && f.elements["password"].value != value) {s += display + ", ";} //password confirmation
		else if (field.name.indexOf ("email") >= 0 && (value.indexOf("@") < 1 || value.indexOf(".") < 3 || value.length < 6)) {s += "valid " + display + ", ";} //email address checking
		else if (value=="0" || !value) {s += display + ", ";} //normal fields
	}
	if (s) {alert ("Please fill in a " + s + "and resubmit."); return false;} //the last argument can be an article (a, the, your, etc)
	else {if (f.updatethis) {f.updatethis.value = "yes";} return true;} //submit it
}

//The remove function which is commonly used by forms
function removeThis (f, label, setvalue) {
	if (confirm ("Are you sure you wish to remove this" + (label ? " " + label : "") + "?")) {
		if (f.removethis) {f.removethis.value = setvalue ? setvalue : "yes";}
		f.submit();
	}
}

//Update the database whenever anything is sorted or a name is changed.
function swapOrdering (f, whichone) {
	var props = new Array ("name_", "sortorder_");
	//change the orders up to this number
	if (f.changeorders && f.changeorders.value <= whichone) f.changeorders.value = whichone + 1;
	for (var i=0; i<props.length; i++) {
		var temp = f[props[i] + whichone].value;
		f[props[i] + whichone].value = f[props[i] + (whichone + 1)].value;
		f[props[i] + (whichone + 1)].value = temp;
	}
}
////////////////////////////// FORM CHECKING AND ORDERING //////////////////////////////

