// Copyright 2009 RFQs Inc //

/*global escape:true*/
/*global s:true, t:true, u:true, y:true*/ // var.global.js
/*global $:true, setDisplay:true, getName:true, getValue:true, setValue:true */ // obj.js
/*global ajax:true */ // ajax.js
/*global saveFields:true */ // forms.js
/*global loading:true */ // design.js

//** Search Calls **//

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

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

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

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

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

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

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

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

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

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

//** Ajax Calls **//

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

function doSearch(p) {
	loading($('search_results'), 'Searching Databases');
	ajax('/fct/search/ajax.search?p='+p+'&st='+y+'&t='+t+'&a='+s+'&id='+u);
}

function doMore(p) {
	loading($('search_more'), 'Searching Databases');
	ajax('/fct/search/ajax.search?more&p='+p+'&st='+y+'&t='+t+'&a='+s+'&id='+u);
}

function doLoad(search_ID, search_type, search_time, search_all) {
	y = search_type;
	t = search_time;
	s = search_all;
	//u = // from page
	loading($('search_results'), 'Loading Search Settings');
	ajax('/fct/search/ajax.load?s='+search_ID+'&st='+y+'&t='+t+'&a='+s+'&id='+u);
}

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

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

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

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



function onEnter( obj, e ) {
	if(getValue(obj)) { setValue(obj.value.replace(/[\/\\.,`~!@#$%\^&*()_=+\[{}\]|\;:'"<>?]/gi, "").toLowerCase()); }
	
	if( 13 === e ) {
		if(obj.id === 'keywords') { toggleSelect(obj); }
		else if(obj.id === 'search_name') { saveSearch(obj); }
		else if(obj.name === 'password') { saveFields($('formBox'), '/fct/user/login'); }
	}
}


/*
getFeedback(s, m) {
	//loading($('top'), 'Loading Feedback Form');
	//showDiv($('fade_top'));
	//showDiv($('top_holder'));
	ajax('/fct/root/ajax.contact?s='+s+'&m='+m);
}
*/
/*
placeBid(id) { // moved to on-page
	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');
}*/



