/**
 * Take a list of names, and return a map of those
 * names to their values as variables, for all such
 * variables that exist.
 */
function get_variable_map(list) {
  var map = {};
  for (var index in list) {
    var name = list[index];
    try {
      map[name] = eval(name);
    }
    catch (e) {
      // So it's not defined....
    }
  }
  return map;
}

/**
 * Takes a map of names to values, and returns a
 * string suitable for use as a "query string" of an
 * HTTP GET request.
 */
function get_param_list(map) {
  var result = "?";
  var list = [];
  for (var name in map) {
    list.push(name + "=" + map[name]);
  }
  return list.join("&");
 }


function validateSearch() {
	var text = document.getElementById("search-box").value;
	if(text.length > 2) {
		text = text.trim();
		document.getElementById('search-box').value = text.toLowerCase();
		return true;
	} else {
		errorString = "Please make sure that you have entered at least three characters and try again.";
	}
	var panel =  new YAHOO.widget.Panel("error-explanation",
	            { width: "280px",
	            height: "125px", 
	            fixedcenter:true, 
	            close:true,  
	            draggable:false,  
	            modal:true, 
	            visible:false,
	            zindex:4
	            } );                         
	panel.setBody("<div style='position:absolute;top:25px;left:30px;width:220px;height:75px;vertical-align:middle;'>" +
	"We are unable to process your request at this time. " + errorString +
	"</div>"
	);
	panel.render(document.body);
	panel.show(); 
	return false;
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/*--------------- Send to a friend validation fields -----------------*/
function validateFields(){
	
	 var filter= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	 if($('#senderName').val()!=""){		 
		 if (filter.test($('#senderEmailStr').val())){
			 if (filter.test($('#recipientsEmailStr').val())){
			 	$('#senderError').css("display","none");
			 	$('#senderEmailError').css("display","none");
			 	$('#senderRecipientsError').css("display","none");
				 return true;
			 }
			 else{
			 	$('#senderError').css("display","none");
			 	$('#senderEmailError').css("display","none");
			 	$('#senderRecipientsError').css("display","block");
			 	return false;
			 }
		 }	 
		 else{
		 	$('#senderError').css("display","none");
			$('#senderEmailError').css("display","none");
		 	$('#senderEmailError').css("display","block"); 	    
			 return false;
		 }
	 }
	 else{
	 	//document.getElementById("errorField").style.display ="block";
	 	$('#senderError').css("display","block");
		 return false;
		 
	 }
	

}
