function emoticon( txtarea, text ) {

	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function DeleteUser(UID){
	if(UID!="") {
		alert("Do You really want to delete your own account?");		
		new ajax ('ajax.php', {postBody: 'method=delete_uid&uid='+UID,onComplete: deleteUser_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
		return false;
	}
}

function deleteUser_callback(request){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
		window.location.href="index.php";
	}
			
	
}
function send_password(value,type){
	new ajax ('ajax.php', {postBody: 'method=send_pass&value='+value+'&type='+type, onComplete: sendpassword_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function sendpassword_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
		alert('Password has been sent to your email. Dont forget to check your bulk folder !!\n\nIf you have not received any mail you can write us at support@cookinamos.com');
	}else if(request.responseText=="NOEMAIL"){
		alert("The specified email address is not register with us");
	}else if(request.responseText=="NOUSER"){
		alert("We could not find the Username");
	}else if(request.responseText=="INVALIDDATA"){
		alert("Failed processing. Please checked the username and email !!");
	}else{
		alert("We are sorry that there was a problem communicating with the server.\n\nPlease try later on");
	}
	
}
function insert_question(RID,UID,question)
	 {//alert(question);
		if(document.getElementById(question).value == "")
		{
			alert("Please enter Question");
		}
		else
		{ 
	 	new ajax ('ajax.php', {postBody: 'method=insert_comment&recipe_id='+RID+'&user_id='+UID+'&question='+document.getElementById(question).value, onComplete: reply_callback});	
		}
	}

function insert_reply(ID,RID,UID,description,status,user_id,new_url,mail_body)
	 {
		 if(document.getElementById(description).value == "")
		 {
			alert("Pleae enter Reply")	 
		 }
		 else
		 {
		 new ajax ('ajax.php', {postBody: 'method=insert_reply&recipe_post_id='+ID+'&recipe_id='+RID+'&user_id='+UID+'&description='+document.getElementById(description).value+'&status='+status+'&uid='+user_id+'&new_url='+new_url+'&mail_body='+mail_body, onComplete: reply_callback});		
		 }
	 }
	 
function reply_callback(request)
{
	if(request.responseText=="OK"){
	window.location.reload();
	}
	else{
		alert("problem while adding comment,Pleaes try next time");
		}
	
}



function check_username(username, email,captcha){
	if(username==""){
		alert("Please enter your login username");
		return;
	}else if(email==""){
		alert("Please enter your email address");
		return;
	}else if(captcha==""){
		alert("Please enter Security Code");
		return;
	}else{
		
		new ajax ('ajax.php', {postBody: 'method=check_username&username='+username+'&email='+email+'&security_code='+captcha, onComplete: checkusername_callback});
		
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	}
	
}
function checkusername_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
		document.frm_register.submit();
	}else if(request.responseText=="DUPEMAIL"){
		alert("This email address is already registered !!");
	}else if(request.responseText=="DUPUSER"){
		alert("This username has already been used !! Please choose another one");
	}else if(request.responseText=="INVALIDDATA"){
		alert("Failed processing. Please check the username and email !!");
	}else if(request.responseText=="CODE_INVALID"){
		alert("Failed processing. Please enter correct security Code !!");
	}

}

function ajax_validatelogin(username, pass){
	new ajax ('ajax.php', {postBody: 'method=validate_login&username='+username+'&pass='+pass, onComplete: validatelogin_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function validatelogin_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			document.frm_login.submit();
		}else{
			alert("Login Failed !! Did you entered username and password properly?");
		}
	}else{
		alert("Temporary failure. Please try again later");
	}
}

function ajax_validateloginres(username, pass){
	new ajax ('ajax.php', {postBody: 'method=validate_reslogin&username='+username+'&pass='+pass, onComplete: validateloginres_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function validateloginres_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			document.frm_login.submit();
		}else{
			alert("Login Failed !! Did you entered username and password properly?");
		}
	}else{
		alert("Temporary failure. Please try again later");
	}
}
//===========================CHANGE PASSWORD===============
function check_password(password,user_id){
	new ajax ('ajax.php', {postBody: 'method=checkpassword&password='+password+"&user_id="+user_id, onComplete: check_password_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	return false;
}

function check_password_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
		if(document.frm_change_password.login_password.value == document.frm_change_password.login_password_new.value){
			alert('Your current password and new password can not be same!!');
		}else{
			document.frm_change_password.submit();	
		}
	}else if(request.responseText=="INVALID"){
		alert('Your current password does not match with our record');	
	}else{
		alert('There was a problem communicating with the server\nPlease try later');
	}
}

function display_mail(id){		
	new ajax ('ajax.php', {postBody: 'method=getmaildetails&id='+id, onComplete: display_mail_callback});
	document.getElementById("mail_display").style.left = (Screen.getViewportWidth()/2 - (500/2))+"px";
	document.getElementById("mail_display").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-150)+"px";
	document.getElementById("mail_body").innerHTML = "Please wait... Getting Mail From Server...";
	document.getElementById("mail_display").style.display = '';
}

function display_mail_callback(request, uservar){
	if(request.responseText.length!=0){
		x = request.responseText.indexOf("<fromuser>");
		if(x>=0){
			x = x+10;
			y = request.responseText.indexOf("</fromuser>", x);
			if(y>=0){
				document.getElementById("mail_sender").innerHTML = request.responseText.substr(x, y-x);
				x = request.responseText.indexOf("<sentdate>", y);
				if(x>=0){
					x = x+10;
					y = request.responseText.indexOf("</sentdate>", x);
					if(y>=0){
						document.getElementById("mail_sent_on").innerHTML = request.responseText.substr(x, y-x);
						x = request.responseText.indexOf("<subject>", y);
						if(x>=0){
							x = x+9;
							y = request.responseText.indexOf("</subject>", x);
							if(y>=0){
								document.getElementById("mail_subject").innerHTML = request.responseText.substr(x, y-x);
								x = request.responseText.indexOf("<body>", y);
								if(x>=0){
									x = x+6;
									y = request.responseText.indexOf("</body>", x);
									if(y>=0){
										document.getElementById("mail_body").innerHTML = request.responseText.substr(x, y-x);
										return;
									}
								}
							}
						}
					}
				}
			}
		}		
	}
	document.getElementById("mail_body").innerHTML = "<strong>There was a problem getting the mail from srever !!</strong>";
}

function close_mail(){
	document.getElementById("mail_display").style.display = 'none';
}
//=========================================================
/*======================== Album images scripts ==================================*/
function verify_image_upload_limit(){
	new ajax ('ajax.php', {postBody: 'method=verify_image_upload', onComplete: verify_image_upload_limit_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	return false;
}

function verify_image_upload_limit_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
		show_upload_window()
	}else if(request.responseText=="ERROR"){
		alert("You can not upload any more images. Consider upgrading your membership !!");
	}else{
		alert("There was a problem communicating with the server. Plrease try later on\n\nIf you face the problem continously then please report us at support@getasexpartner.com");
	}
}

function delete_album_image(id,album_id){
	if(confirm("Do you really want to delete this image?")){
		new ajax ('ajax.php', {postBody: 'method=update_album_image&act=delete&id='+id, onComplete: delete_album_image_callback, userVariable: album_id});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
		return false;
	}
}
function delete_album_image_callback(request, album_id){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';   
	if(request.responseText=="OK"){
		alert("Image has been deleted successfully");
			window.location="index.php?view=myimages&id="+album_id;
	}else {
		alert("Image deletion failed !!\n\nPlease try later on");
	}  
	return true;   
}
function delete_album(id){
	if(confirm("Do you really want to delete this Album?")){
		new ajax ('ajax.php', {postBody: 'method=delete_album_image&act=delete&id='+id, onComplete: delete_album_recipe_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
		return false;
	}
}
function delete_album_recipe_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';   
	if(request.responseText=="OK"){
		alert("Album has been deleted successfully");
			window.location="index.php?view=category";
	}else {
		alert("Album deletion failed !!\n\nPlease try later on");
	}  
	return true;   
}
function delete_category(id){
	if(confirm("Do you really want to delete this Category?")){
		new ajax ('ajax.php', {postBody: 'method=add_category&act=delete&id='+id, onComplete: delete_category_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
		return false;
	}
}
function delete_category_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';   
	if(request.responseText=="OK"){
		alert("The category has been deleted successfully");
			window.location="index.php?view=category";
	}else {
		alert("category deletion failed !!\n\nPlease try later on");
	}  
	return true;   
}

function album_image_stat_change(id, type){
	new ajax ('ajax.php', {postBody: 'method=update_album_image&act=changetype&id='+id+'&type='+type, onComplete: album_image_action_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	return false;
}

function album_image_action_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText!="OK"){
		alert("There was a problem completing your request\n\nPlease try again later");
	}
	window.location.reload();
}
function show_upload_window(){
	document.getElementById("div_uploader").style.left = (Screen.getViewportWidth()/2 - (500/2))+"px";
	document.getElementById("div_uploader").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-121)+"px";
	document.getElementById("div_uploader").style.display = '';
}
function show_upload_window1(){
	document.getElementById("category_name").value="";
	document.getElementById("desc").value="";		
	document.getElementById("upload_target").value="Add Category";		
	document.getElementById("public").checked=false;
	document.getElementById("div_uploader").style.left = (Screen.getViewportWidth()/2 - (500/2))+"px";
	document.getElementById("div_uploader").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-121)+"px";
	document.getElementById("div_uploader").style.display = '';
}
/*================================================================================*/
/*========================= My Images Upload Scripts ==============================*/
function start_album_image_upload(){
	document.getElementById('div_uploader').style.display = 'none';
    document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
    return true;
}
function album_image_upload_done(success,id){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';   
	if (success == 1){
		alert("The image has been uploaded successfully");
		//window.location.reload();
				window.location="index.php?view=myimages&id="+id;
	}else {
		alert("Image upload failed !!\n\nPlease try later on");
	}  
	return true;   
}
/*================================================================================*/
/*=========================MY ALBUM PASSWORD ==============================*/
function check_album(password,pid,id){
	new ajax ('ajax.php', {postBody: 'method=check_album&password='+password+'&id='+id+'&pid='+pid, onComplete: check_album_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	return false;
}

function check_album_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
			window.location.reload();
	}else{
		alert('Please enter correct password');
	}
}
/*================================================================================*/
/*========================= My Category Add ==============================*/
function show_upload_window_edit(id,name,desc,public){
	document.getElementById("category_name").value=name;
	document.getElementById("desc").value=desc;	
	if(public==1){
	document.getElementById("public").checked=true;		
	}else{
			document.getElementById("public").checked=false;
		}
	document.getElementById("act").value="update";	
	document.getElementById("upload_target").value="Update Category";		
	document.getElementById("id_id").value=id;		
	document.getElementById("div_uploader").style.left = (Screen.getViewportWidth()/2 - (500/2))+"px";
	document.getElementById("div_uploader").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-121)+"px";
	document.getElementById("div_uploader").style.display = '';
	
}

function add_new_category(){

	document.getElementById('div_uploader').style.display = 'none';
    document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
    return true;
}

function add_category_done(success){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';   
	if (success == 1){
		alert("The category has been added successfully");
		window.location="index.php?view=category";
	}else {
		alert("category add failed !!\n\nPlease try later on");
	}  
	return true;   
}
function update_category_done(success){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';   
	if (success == 1){
		alert("The category has been updated successfully");
			window.location="index.php?view=category";
	}else {
		alert("category add failed !!\n\nPlease try later on");
	}  
	return true;   
}
/*================================================================================*/
function get_image(request, image, alt){

	new ajax ('ajax.php', {postBody: 'method=get_image&id='+request+'&image='+image+'&alt='+alt, onComplete: get_image_callback, userVariable: alt});
}

function get_image_callback(request, uservar1){
	if(request.responseText!=""){
			
			document.getElementById('display').innerHTML = request.responseText;
	}
	else{
		document.getElementById('display').innerHTML = "<strong><center>There was a problem getting image from server !!</center></strong>";
		}
}

/*================================================================================*/

function play_music(id){		
	new ajax ('ajax.php', {postBody: 'method=get_music&id='+id, onComplete: play_music_callback});
    document.getElementById("music_display").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("music_display").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("music_body").innerHTML = "Please wait... Getting Music From Server...";	
	document.getElementById("music_display").style.display = '';
}

function play_music_callback(request, uservar){ 
	if(request.responseText.length!=0){
										document.getElementById("music_body").innerHTML = request.responseText;
										return;
									}
		document.getElementById("music_body").innerHTML = "<strong>There was a problem getting the music from srever !!</strong>";
		return;
}

function close_music(){
	document.getElementById("music_body").innerHTML="";
	document.getElementById("music_display").style.display = 'none';

}
//=========================================================
/*================================================================================*/

function autocopmlete(data){		
	new ajax ('ajax.php', {postBody: 'method=response&data='+data, onComplete: autocopmlete_callback});
	document.getElementById("ajax_response").style.display = '';
}

function autocopmlete_callback(request, uservar){
	if(request.responseText.length!=0){
										document.getElementById("ajax_response").innerHTML = request.responseText;
										return;
									}
		document.getElementById("ajax_response").innerHTML = "<strong>There was a problem getting the music from srever !!</strong>";
		return;
}

//=========================================================
function add_fav_chef(user_id){	
	new ajax ('ajax.php', {postBody: 'method=add_fav_chef&user_id='+user_id, onComplete: add_fav_chef_callback});
	document.getElementById("ajax_response").style.display = '';
}

function add_fav_chef_callback(request, uservar){
			if(request.responseText.length!=0){
				alert(request.responseText);
			}
		return;
}

//=========================================================
function show_hide_rest(user_id){	
	document.getElementById('rest1').style.display = 'none';
	document.getElementById('rest2').style.display = 'none';
	document.getElementById('rest3').style.display = 'none';
if(document.getElementById(user_id).style.display=='table-row')
	document.getElementById(user_id).style.display = 'none';
else
	document.getElementById(user_id).style.display = 'table-row';
}
function nitin(){
alert("asdf");
}
//=========================================================

