int_obj = '';

function loadField(id) {

	if($(id)) {

		attachTooltip(id);
		Highlight(id);
		clearInterval(int_obj);
	}
}

//Baloon functions

function attachTooltip(elementId){
	if($(elementId)){
		Event.observe(elementId, 'focus', onfocusEle, false);
		Event.observe(elementId, 'blur', onblurEle, false);
		//	   Event.observe(elementId, 'mouseover', onfocusEle, false);
		//	   Event.observe(elementId, 'mouseout', onblurEle, false);
	}
};



//only for home page tool-tip

function onblurEle(e){
	var id = Event.element(e).id;
	$(id).className = "inputstyle" ;
	$("h-" + id).className = "field-hint-inactive" ;
};

function onfocusEle(e){

	if($(selected_field)) {
		$("h-" + selected_field).className = "field-hint-inactive" ;
		$(selected_field).className = "inputstyle" ;
	}
	var id = Event.element(e).id;
	$(id).className = "inputstyle-focus" ;
	$("h-" + id).className = "field-hint" ;
};

selected_field = '';

function Highlight(id){
	selected_field = id;
	$(id).focus();
};

clearField = function(eleM, compString){
	var fieldValue = eleM.value;
	if(fieldValue.toLowerCase() == compString.toLowerCase()){
		eleM.value = '';
	}
}

fillField = function(eleM, compString){
	var fieldValue = eleM.value;
	if(fieldValue.toLowerCase() == ''){
		eleM.value = compString;
	}
}
function displayAlert(msg_div,msg)
{
	
	if(msg) $(msg_div).innerHTML = msg;
	$(msg_div).className = 'errorDiv';
}
function displayAlert1(msg_div,msg)
{
	
	if(msg) $(msg_div).innerHTML = msg;
	$(msg_div).className = 'errorDiv2';
}
function displayAlert2(msg_div,msg)
{
	
	if(msg) $(msg_div).innerHTML = msg;
	$(msg_div).className = 'errorDiv7';
}
function dispVideoComments(videoId,start){
	
	var url =  'video.php';
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'get',
		parameters: {mode:'viewVideoComments',videoId:videoId,start:start},
		onComplete:showVideoComments
	});
}

function showVideoComments(originalRequest){
	
	$('dispVideoComments').innerHTML = originalRequest.responseText;
}
function addVideoComments(commentOnWhichId,commentUserId){
	
	$('e_comments').style.display = 'none';
	if(alltrim($F('commentDesc')) == '') {

		$('e_comments').style.display = '';
		displayAlert('e_comments','Comment is blank!');
		return false;
	}
	var comments=$F('commentDesc');
	var url =  'video.php';
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'post',
		parameters: {mode:'insertVideoComments',commentOnWhichId:commentOnWhichId,commentUserId:commentUserId,comments:comments},
		onComplete:showInsertVideoComments
	});
}
function showInsertVideoComments(originalRequest){
	
	var response = originalRequest.responseText;
	
	$('e_comments').style.display = 'none';
	if(response.indexOf('failure')!=-1){
		
		$('e_comments').style.display = '';
		displayAlert('e_comments','Comment posting failed!');
		return false;
	}
	else if(response.indexOf('visitor')!=-1){
		
		$('e_comments').style.display = '';
		displayAlert('e_comments','Please <a href=\"login.php\">login</a> to post your comments!');
		return false;
	}
	else{
		Effect.toggle('dispAddVideoComm','BLIND');
		dispVideoComments(response);
	}

}

function dispAddVideoCommDiv(status,uid){
	
	if(uid==""){
		$('e_comments1').style.display = '';
		displayAlert1('e_comments1','Please <a href=\"login.php\">login</a> to post comments!');
	}
	else if(status=='deactive'){
		displayAlert2('e_comments1','Your account has been deactivated. To activate your account, go to your profile page.');
	}
	else{
		 Effect.toggle('dispAddVideoComm','BLIND');
	}
	
}