var selEle = document.getElementsByTagName('select');
var optionHiveSearchSelection = function(optVal){
	var opt = document.getElementById('tx_hivesearch_pi1[searchstrategy]');
//	alert(typeof(opt.options));
	if(opt!=null && typeof(opt.options)!='undefined'){
		//try{
			for(var ctr=0;ctr<opt.options.length;ctr++){
				if(opt.options[ctr].value==optVal){
					opt.options[ctr].selected = true;
				}
			}
		/*}
		catch
		{
			/// Some Comments
		}*/
	}
}

var hiveSearchFormSubmit = function(){
	
	var frmHiveSearch = document.getElementById('tx_hivesearch_pi1_frm')
	for(var i=0;i<selEle.length;i++){
		if(selEle[i].name.substr(0,3)=="md:" && selEle[i].value!=''){
			var input = document.createElement('input');
			input.type = 'hidden';
			input.name = 'tx_hivesearch_pi1['+selEle[i].name+']';
			input.value = selEle[i].value;
			frmHiveSearch.appendChild(input);
		}
	}
}
var optAdvanceFilter = function(){
	for(var i=0;i<selEle.length;i++){
		if(selEle[i].name.substr(0,3)=="md:"){
			alert(selEle[i].value);
		}
	}
}

var publishedrecord=function(url){
	new Ajax.Request(url, {
		onSuccess: function(data) {
			$('publishedobjects').update(data.responseText);
		},
		onFailure: function(transport){
			alert('Error Please try Later');	
		},
		evalScripts: true
	});
}

var ratingFilter=function(url,reUrl){
	new Ajax.Request(url, {
					onSuccess: function(transport) {
						if(transport.responseText==='na'){
							var ans;
 							ans=window.confirm('Please Login to rate the content.');
 							if (ans==true)
							  {
							   location.href = (reUrl);   
							   }
						}else{
							alert('Your rating was submitted');
						}
					},
					onFailure: function(transport){
						alert('Error Please try Later');	
					},
					evalScripts: true
				}
			);
}

var ratingsUpdate=function(){
	//
	jQuery.each(params, function(i,data){
	    eval('var updateDiv = \'#'+data.item_id+'_'+data.rating_type+'\';');
	    var imgStr='<img src="' + data.hostname + 'typo3conf/ext/hivesearch/src/images/indicator_orange.gif" alt="Updating"/>';
	    jQuery(updateDiv).html(imgStr);
	    jQuery.ajax({
		type:'GET',
		url:data.queryUrl,
		success:function(msg){
			jQuery(updateDiv).html(msg);
		}
	});
	    
	});
}

var People = Class.create();
People.prototype ={
	initialize: function(){
			//
	},
	
	addfriend: function(url,optional,redirect){		
		new Ajax.Request(url, {
					onSuccess: function(transport) {
						if (optional === undefined) {
    						optional = "no";
  						}
  						if (redirect === undefined) {
    						  redirect = "";
  						}
						if(optional =="yes") {		
							window.location.href=window.location.href;
						}else {
							window.location.href = redirect;
						} 	
						  
					}.bind(this),
					onFailure: function(transport){
						alert('Error Please try Later');	
					},
					evalScripts: true
				}
			);
	}
}
var people = new People();