function autoFillUp(source, target) {
	if(true) {
		value = source.value;
		value = value.toLowerCase();
		value = value.replace(/[']/ig, '');
		value = value.replace(/[^a-z0-9\_]/ig, '_');
		value = value.replace(/_+/ig, '_');
		value = value.replace(/(^_+|_+$)/ig, '');
		target.value = value;
	}
}

function addToLikes(videoId, userId, flag) {
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     'addToLikes',
			video_id: videoId,
			user_id: userId,
			flag: flag
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) {
				var obj = document.getElementById('ajaxMessageViewArea'); 
				obj.style.display = '';
				obj.innerHTML = msg;
			}
		}
	});
}

function addToFavs(videoId, userId, flag) {
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     'addToFavs',
			video_id: videoId,
			user_id: userId,
			flag: flag
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) { 
				var obj = document.getElementById('ajaxMessageViewArea'); 
				obj.style.display = '';
				obj.innerHTML = msg;
			}
		}
	});
}

function showPlaylistsToAdd(videoId, userId, flag, pStart) {
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     'showPlaylists',
			video_id: videoId,
			user_id: userId,
			flag: flag,
			pStart: pStart
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) { document.body.innerHTML = msg; }
		}
	});
}

function addToPlaylist(videoId, userId, flag, playlistId, newPlaylistTitle, pStart) {
	if(((playlistId=='') || (playlistId==0)) && (newPlaylistTitle=='')) {
		alert('Either select playlist or enter playlist title to create new one.');
	} else {
		$.ajax({
			url: '?',
			type: "POST",
			data: {
				action:     'addToPlaylist',
				video_id: videoId,
				playlist_id: playlistId,
				addNewPlaylistName: newPlaylistTitle,
				user_id: userId,
				flag: flag,
				pStart: pStart
			},
			error:  function(XMLHttpRequest, textStatus, errorThrown){
				alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
			},
			success: function(msg){
				if (msg) { document.body.innerHTML = msg; }
			}
		});
	}
}

function checkAvailability(username,firstname,lastname,email,confirmemail) {
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     'checkAvailability',
			txtUsername: username,
			txtFirstName: firstname,
			txtLastName: lastname,
			txtEmail: email,
			txtConfirmEmail: confirmemail
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) { document.body.innerHTML = msg; }
		}
	});
}

/*function autoCompleteMainSearch(keyword) {
	$.ajax({
		url: 'http://204.232.233.8/processAjax.html',
		type: "POST",
		data: {
			action:     'autocompletemainsearch',
			keyword: keyword
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) {
				var data = msg.split("|-|");
				$("#mainSearchKeyword").autocomplete(data);
			}
		}
	});
}*/

function autoCompleteMainSearch(data) {
	$("#mainSearchKeyword").autocomplete(data.split("|-|"));
}

function acceptComment(commentId) {
}

function rejectComment(commentId) {
}

function rejectChannelComment(commentId) {
	document.body.style.cursor = 'wait';
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     'removechannelcomment',
			comment_id: commentId,
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) {
				document.getElementById(commentId+'_img').style.display = 'none';
				document.getElementById(commentId+'_usr').style.display = 'none';
				document.getElementById(commentId+'_clr').style.display = 'none';
				document.getElementById(commentId+'_cmt').style.display = 'none';
				document.body.style.cursor = 'default';
			}
		}
	});
}

function commentThumbAction(videoId, commentId, actionValue) {
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     actionValue,
			comment_id: commentId,
			video_id: videoId
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) { document.body.innerHTML = msg; }
		}
	});
}

function validateMarketplaceForm(formObj) {
	var apply = formObj.txtarApply.value;
	
	if(apply=="") {
		alert("What will you do is required.");
		formObj.txtarApply.focus();
		return false;
	} 

	formObj.submit();
}

function validateUserchannelForm(formObj) {
	var apply = formObj.txtarComment.value;
	
	if(apply=="") {
		alert("Comment is required.");
		formObj.txtarComment.focus();
		return false;
	} 

	formObj.submit();
}

function eventRatingThumbAction(eventId, videoId, actionValue) {
	$.ajax({
		url: '?',
		type: "POST",
		data: {
			action:     actionValue,
			event_id: eventId,
			video_id: videoId
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){
			if (msg) {
				document.getElementById('eventPLikesId_'+videoId).innerHTML = msg;
			}
		}
	});
}

function getVideosByGeodata(tUrl, keyword) {
	var searchResultGeoData = "dfsdg";	
	alert(searchResultGeoData); 
	$.ajax({
		url: tUrl,
		type: "POST",
		data: {
			txtKeyword: keyword
		},
		error:  function(XMLHttpRequest, textStatus, errorThrown){
			alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
		},
		success: function(msg){		
			var finalResult = msg.split('__||__||__');
			searchResultHTML = finalResult[0];
			searchResultGeoData = finalResult[1];			
			var obj = document.getElementById('searchVideosByGeodataDiv'); 
			var objGeo = document.getElementById('geoData'); 			
			obj.style.display = '';
			objGeo.value = searchResultGeoData;			
			obj.innerHTML = searchResultHTML;
			searchResultGeoData = searchResultGeoData.split('+');
			alert("inner: "+ searchResultGeoData);			
		}
	});
	//split code comes here to convert string into array		
	alert("outer: "+ searchResultGeoData);	
	return searchResultGeoData;
	
}

function resetTextField(obj, defaultValue) {
	var newValue = obj.value;
	if(newValue==defaultValue) {
		obj.value = '';
	}
}

function setTextField(obj, defaultValue) {
	var newValue = obj.value;
	if(newValue=='') {
		obj.value = defaultValue;
	}
}