// Copyright 2009 RFQs Inc //
//** Nav **//

function subNav(str) {
	var titles = ['home', 'profile', 'tenders', 'search', 'admin', 'comm', 'support'];
	for(var i=0, s=titles.length; i< s; i++) {
		hideDiv($(titles[i]+'_sub'));
		$(titles[i]+'_top').className = '';
	}
	showDiv($(str+'_sub'));
	$(str+'_top').className = 'active';
}

//** Search Calls **//
function onEnter( obj, e ) {
	if(obj.value) obj.value = obj.value.replace(/[\/\\.,`~!@#$%^&*()_=+\[{}\]|;:'"<>?]/gi, "").toLowerCase();
	if( 13 == e ) {
		if(obj.id == 'keywords') toggleSelect(obj);
		if(obj.id == 'search_name') saveSearch(obj);
	}
}

function deleteKeyword(str) {
	hideDiv($('keyword-'+str));
	doAjax('/fct/search/ajax.toggle?s=keywords&id='+escape(str)+'&state=false');
}

function deletePlugin(id) {
	hideDiv($('plugin-'+id));
	doAjax('/fct/search/ajax.toggle?s=plugin_ID&id='+id+'&state=false');
}

function deleteSoftware(id) {
	hideDiv($('software-'+id));
	doAjax('/fct/search/ajax.toggle?s=software_ID&id='+id+'&state=false');
}

function deleteCertification(id) {
	hideDiv($('certification-'+id));
	doAjax('/fct/search/ajax.toggle?s=certification_ID&id='+id+'&state=false');
}

function toggleInput(obj) {
	doAjax('/fct/search/ajax.toggle?s='+obj.name+'&id='+escape(obj.value)+'&state='+obj.checked);
}

function toggleSelect(obj) {
	obj.value.replace(/[\/\\.,`~!@#$%^&*()_=+\[{}\]|;:'"<>?]/gi, "").toLowerCase()
	doAjax('/fct/search/ajax.toggle?s='+obj.name+'&id='+escape(obj.value)+'&state=true');
}

function saveInput(obj) {
	doAjax('/fct/search/ajax.set?s='+obj.name+'&id='+obj.value);
}

function saveSearch(obj) {
	obj.value.replace(/[\/\\.,`~!@#$%^&*()_=+\[{}\]|;:'"<>?]/gi, "").toLowerCase()
	doAjax('/fct/search/ajax.save?s='+escape(obj.value)+'&t='+search_type+'&id='+user_ID);
}

function deleteSearch(id) {
	hideDiv($('search-'+id));
	doAjax('/fct/search/ajax.delete?s='+id);
}

//** Tender Calls **//
function tenderEmail(id) {
	loading($('top'), 'Loading Emailer');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/tender/ajax.email?id='+id);
}

//** Profile Calls **//
function profileEmail(id, u) {
	loading($('top'), 'Loading Emailer');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/directory/ajax.email?id='+id+'&u='+u);
}

function profilePhone(id, u) {
	loading($('top'), 'Loading Phone');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/directory/ajax.phone?id='+id+'&u='+u);
}

function profileMap(to, from) {
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	//alert('from:'+from+' to:'+to);
	$('top').innerHTML='<div style="overflow: auto;height: 400px; width: 415px;"><div id="map_view"></div><div id="map_route"></div></div><a href="javascript:showRoute(\''+to+'\',\''+from+'\')">Load Directions</a>';
	showRoute(to,to);
	//doAjax('/fct/directory/ajax.map?id='+id);
}

//** Ajax Calls **//
function doSearch(p) {
	loading($('search_results'), 'Searching Databases');
	doAjax('/fct/search/ajax.search?p='+p+'&st='+search_type+'&t='+search_time+'&a='+search_all+'&id='+user_ID);
}

function doMore(p) {
	loading($('search_more'), 'Searching Databases');
	doAjax('/fct/search/ajax.search?more&p='+p+'&st='+search_type+'&t='+search_time+'&a='+search_all+'&id='+user_ID);
}

function doLoad(s, st, t, a) {
	search_type = st;
	search_time = t;
	search_all = a;
	loading($('search_settings_box'), 'Loading Search Settings');
	doAjax('/fct/search/ajax.load?s='+s+'&st='+search_type+'&t='+search_time+'&a='+search_all+'&id='+user_ID);
}

function getDetails(id) {
	loading($('bottom'), 'Loading Details');
	showDiv($('fade_bottom'));
	showDiv($('bottom_holder'));
	doAjax('/fct/search/ajax.details?id='+id);
}

function getAgreement(id) {
	loading($('top'), 'Loading Agreement');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/tender/ajax.agreement?id='+id);
}

function getTenderDownloads(id) {
	loading($('top'), 'Zipping Tender Files and Documents');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/tender/ajax.download.tender?id='+id);
}

function getBidDownloads(id, getall) {
	loading($('top'), 'Zipping Bid Files and Documents');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/tender/ajax.download.bid?id='+id+'&all='+getall);
}

function getFeedback(s, m) {
	loading($('top'), 'Loading Feedback Form');
	showDiv($('fade_top'));
	showDiv($('top_holder'));
	doAjax('/fct/root/ajax.contact?s='+s+'&m='+m);
}

function placeBid(id) {
	widthVal = 415;
	heightVal = 280;
	leftVal = (widthVal - screen.width) / 2;
	topVal = (heightVal - screen.height) / 2;
	
	window.open('/tender/popup.bid?id='+id,'Place_Bid',
'left='+leftVal+',top='+topVal+',width='+widthVal+',height='+heightVal+',toolbar=0,resizable=0, scrollbars=1, locatation=1, directories=0, status=1, menubar=0');
}

function popExt(id) {
	widthVal = 230;
	heightVal = 150;
	leftVal = (widthVal - screen.width) / 2;
	topVal = (heightVal - screen.height) / 2;
	
	window.open('/popup.ext?ext='+id,'Approved_File_Extentions',
'left='+leftVal+',top='+topVal+',width='+widthVal+',height='+heightVal+',toolbar=0,resizable=0, scrollbars=1, locatation=1, directories=0, status=1, menubar=0');
}

// Copyright 2009 RFQs Inc //
