var minopacdiv;
var minopacdiv2;
var signinbuttonclicked = false;
var speed=5;
  function opacFileCall(fileName,width,height)
  {	
	var divtag=document.createElement('div');
	divtag.id="opcMaindiv";		
	divtag.className="opacfadediv";	
	divtag.style.width=document.body.scrollWidth+"px";
	divtag.style.height=document.body.scrollHeight+"px";		

	var divtag2=document.createElement('div');
	divtag2.id="opcSubdiv";
	divtag2.className="opacfadeinnerdiv";
	divtag2.innerHTML='<div><div style="position:absolute;left:'+(width-19)+'px;top:25px;"><img src="images/opacity-close-icon.gif" width="32" height="32" border="0" alt="" class="clink" onClick="opacCls();"></div><table border="0" cellpadding="0" cellspacing="0"><tr><td style="background:url(images/opacity-topcurve-left.png) !important;background:url(images/opacity-topcurve-left.gif);width:18px;height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-bg.png) !important;background:url(images/opacity-topcurve-bg.gif);height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-right.png) !important;background:url(images/opacity-topcurve-right.gif);width:19px;height:22px;"><!--  --></td></tr> <tr> <td style="background:url(images/opacity-curve-bg-left.png) !important;background:url(images/opacity-curve-bg-left.gif);width:19px;"><!--  --></td> <td bgcolor="#ffffff"><div id="poploading" style="display:block;" align="center"><IMG SRC="images/ajax-loader.gif" WIDTH="42" HEIGHT="42" BORDER="0" ALT=""></div><iframe id="opacframe" src="'+fileName+'" name="opacframe" frameborder="0" scrolling="no" width="'+width+'px" height="'+height+'px"></iframe></td> <td style="background:url(images/opacity-curve-bg-right.png) !important;background:url(images/opacity-curve-bg-right.gif);width:19px;"><!--  --></td>  </tr>   <tr> <td style="background:url(images/opacity-botcurve-left.png) !important;background:url(images/opacity-botcurve-left.gif);width:19px;height:30px;"><!--  --></td> <td style="background:url(images/opacity-botcurve-bg.png) !important;background:url(images/opacity-botcurve-bg.gif);height:30px;"><!--  --></td>	<td style="background:url(images/opacity-botcurve-right.png) !important;background:url(images/opacity-botcurve-right.gif);width:19px;height:30px;"><!--  --></td>  </tr> </table> </div>';
//	divtag2.innerHTML='<div><div style="position:absolute;width:100%;text-align:right;margin-right:50px;"><div style="padding:20px 40px 0px 0px;"><img src="images/opacity-close-icon.gif" width="32" height="32" border="0" alt="" class="clink" onClick="opacCls();"></div></div><table border="0" cellpadding="0" cellspacing="0"><tr><td style="background:url(images/opacity-topcurve-left.png) !important;background:url(images/opacity-topcurve-left.gif);width:18px;height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-bg.png) !important;background:url(images/opacity-topcurve-bg.gif);height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-right.png) !important;background:url(images/opacity-topcurve-right.gif);width:19px;height:22px;"><!--  --></td></tr> <tr> <td style="background:url(images/opacity-curve-bg-left.png) !important;background:url(images/opacity-curve-bg-left.gif);width:19px;"><!--  --></td> <td bgcolor="#ffffff"><div id="poploading" style="display:block;" align="center"><IMG SRC="images/ajax-loader.gif" WIDTH="42" HEIGHT="42" BORDER="0" ALT=""></div><iframe id="opacframe" src="'+fileName+'" name="opacframe" frameborder="0" scrolling="no" width="'+width+'px" height="'+height+'px"></iframe></td> <td style="background:url(images/opacity-curve-bg-right.png) !important;background:url(images/opacity-curve-bg-right.gif);width:19px;"><!--  --></td>  </tr>   <tr> <td style="background:url(images/opacity-botcurve-left.png) !important;background:url(images/opacity-botcurve-left.gif);width:19px;height:30px;"><!--  --></td> <td style="background:url(images/opacity-botcurve-bg.png) !important;background:url(images/opacity-botcurve-bg.gif);height:30px;"><!--  --></td>	<td style="background:url(images/opacity-botcurve-right.png) !important;background:url(images/opacity-botcurve-right.gif);width:19px;height:30px;"><!--  --></td>  </tr> </table> </div>';
	document.body.appendChild(divtag);
	document.body.appendChild(divtag2);	
	divtag2.style.top=document.body.scrollTop+50+ "px";
	divtag2.style.left=((document.documentElement.offsetWidth - divtag2.offsetWidth) / 2) +"px";
  }
  
  
  function opacFileCall_norefresh(fileName,width,height)
  {	
	var divtag=document.createElement('div');
	divtag.id="opcMaindiv";		
	divtag.className="opacfadediv";	
	divtag.style.width=document.body.scrollWidth+"px";
	divtag.style.height=document.body.scrollHeight+"px";		

	var divtag2=document.createElement('div');
	divtag2.id="opcSubdiv";
	divtag2.className="opacfadeinnerdiv";
	divtag2.innerHTML='<div><div style="position:absolute;left:'+(width-19)+'px;top:25px;"><img src="images/opacity-close-icon.gif" width="32" height="32" border="0" alt="" class="clink" onClick="opacCls(1);"></div><table border="0" cellpadding="0" cellspacing="0"><tr><td style="background:url(images/opacity-topcurve-left.png) !important;background:url(images/opacity-topcurve-left.gif);width:18px;height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-bg.png) !important;background:url(images/opacity-topcurve-bg.gif);height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-right.png) !important;background:url(images/opacity-topcurve-right.gif);width:19px;height:22px;"><!--  --></td></tr> <tr> <td style="background:url(images/opacity-curve-bg-left.png) !important;background:url(images/opacity-curve-bg-left.gif);width:19px;"><!--  --></td> <td bgcolor="#ffffff"><div id="poploading" style="display:block;" align="center"><IMG SRC="images/ajax-loader.gif" WIDTH="42" HEIGHT="42" BORDER="0" ALT=""></div><iframe id="opacframe" src="'+fileName+'" name="opacframe" frameborder="0" scrolling="no" width="'+width+'px" height="'+height+'px"></iframe></td> <td style="background:url(images/opacity-curve-bg-right.png) !important;background:url(images/opacity-curve-bg-right.gif);width:19px;"><!--  --></td>  </tr>   <tr> <td style="background:url(images/opacity-botcurve-left.png) !important;background:url(images/opacity-botcurve-left.gif);width:19px;height:30px;"><!--  --></td> <td style="background:url(images/opacity-botcurve-bg.png) !important;background:url(images/opacity-botcurve-bg.gif);height:30px;"><!--  --></td>	<td style="background:url(images/opacity-botcurve-right.png) !important;background:url(images/opacity-botcurve-right.gif);width:19px;height:30px;"><!--  --></td>  </tr> </table> </div>';
//	divtag2.innerHTML='<div><div style="position:absolute;width:100%;text-align:right;margin-right:50px;"><div style="padding:20px 40px 0px 0px;"><img src="images/opacity-close-icon.gif" width="32" height="32" border="0" alt="" class="clink" onClick="opacCls();"></div></div><table border="0" cellpadding="0" cellspacing="0"><tr><td style="background:url(images/opacity-topcurve-left.png) !important;background:url(images/opacity-topcurve-left.gif);width:18px;height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-bg.png) !important;background:url(images/opacity-topcurve-bg.gif);height:22px;"><!--  --></td><td style="background:url(images/opacity-topcurve-right.png) !important;background:url(images/opacity-topcurve-right.gif);width:19px;height:22px;"><!--  --></td></tr> <tr> <td style="background:url(images/opacity-curve-bg-left.png) !important;background:url(images/opacity-curve-bg-left.gif);width:19px;"><!--  --></td> <td bgcolor="#ffffff"><div id="poploading" style="display:block;" align="center"><IMG SRC="images/ajax-loader.gif" WIDTH="42" HEIGHT="42" BORDER="0" ALT=""></div><iframe id="opacframe" src="'+fileName+'" name="opacframe" frameborder="0" scrolling="no" width="'+width+'px" height="'+height+'px"></iframe></td> <td style="background:url(images/opacity-curve-bg-right.png) !important;background:url(images/opacity-curve-bg-right.gif);width:19px;"><!--  --></td>  </tr>   <tr> <td style="background:url(images/opacity-botcurve-left.png) !important;background:url(images/opacity-botcurve-left.gif);width:19px;height:30px;"><!--  --></td> <td style="background:url(images/opacity-botcurve-bg.png) !important;background:url(images/opacity-botcurve-bg.gif);height:30px;"><!--  --></td>	<td style="background:url(images/opacity-botcurve-right.png) !important;background:url(images/opacity-botcurve-right.gif);width:19px;height:30px;"><!--  --></td>  </tr> </table> </div>';
	document.body.appendChild(divtag);
	document.body.appendChild(divtag2);	
	divtag2.style.top=document.body.scrollTop+50+ "px";
	divtag2.style.left=((document.documentElement.offsetWidth - divtag2.offsetWidth) / 2) +"px";
  }

  function opacCls(norefresh)
  {
	obj = 'opcMaindiv';
	obj2 = 'opcSubdiv';
	var d1=document.getElementById(obj);
	var d2=document.getElementById(obj2);
	if(signinbuttonclicked) {
		signinbuttonclicked = false;
		if (d2) {
			d2.style.overflow="hidden";
			d2.style.top=findPosY(document.getElementById('signin'))+"px";
			d2.style.left=(findPosX(document.getElementById('signin'))-d2.offsetWidth)+document.getElementById('signin').offsetWidth+"px";

			opacdivWScroll();		 	
			opacdivHScroll();		 	
		}
	} else {
		if (d1) { document.body.removeChild(d1); }
		if (d2) { document.body.removeChild(d2); }
	if(!norefresh)
		parent.document.location="index.php";

	}
  }

function selfCloseTimer(milliseconds){
	var t=setTimeout("opacCls()",milliseconds);
}

function opacCls_for_post_before_login1(norefresh)
{  
       
	obj = 'opcMaindiv';
	obj2 = 'opcSubdiv';
	var d1=document.getElementById(obj);
	var d2=document.getElementById(obj2);
	if(signinbuttonclicked) {
		signinbuttonclicked = false;
		if (d2) {
			d2.style.overflow="hidden";
			d2.style.top=findPosY(document.getElementById('signin'))+"px";
			d2.style.left=(findPosX(document.getElementById('signin'))-d2.offsetWidth)+document.getElementById('signin').offsetWidth+"px";

			opacdivWScroll();		 	
			opacdivHScroll();		 	
		}
	} else {
		if (d1) { document.body.removeChild(d1); }
		if (d2) { document.body.removeChild(d2); }
	
	}
}

function opacCls_for_post_before_login2()  
{  
   var url='recipe.php?post_recipe_before_login=1';           
   opacFileCall(url,750,400);    
   	
}

function close_forcibly_to_open_another(milliseconds){
	upload_recipe_image();    
	var t=setTimeout("opacCls_for_post_before_login1()",milliseconds);   
	opacCls_for_post_before_login2();   
}

function openSignup() {
	opacCls(true);
	opacFileCall('signup.php',700,750);
}

function openSignin() {
	opacCls(true);
	signinbuttonclicked = true;
	opacFileCall('signin.php',700,400);
}

function openSignin_with_post_title() {  
	var posted_title=$.trim($('#default_content').val());
	if((posted_title!='Today, I am cooking ...')&&(posted_title!="")){   
	upload_recipe_image();  
	opacCls(true);
	signinbuttonclicked = true;
	var url='signin.php?carry_title='+escape(posted_title);          
	opacFileCall(url,700,400);  
	}
	else {
	alert('Please enter recipe title'); 
	return false; 
	}
}

function openRecipe() {
	if(document.pstRecipe.postInput.value!='' && document.pstRecipe.postInput.value!='Today, I am cooking ...') {
		upload_recipe_image();
		opacCls(true);
		opacFileCall('recipe.php',750,750);
	} else {
		alert('Please enter recipe title');
		document.pstRecipe.postInput.focus();
	}
}
 
function post_recipe_without_details(){
	if(document.pstRecipe.postInput.value!='' && document.pstRecipe.postInput.value!='Today, I am cooking ...' && ($.trim(document.pstRecipe.postInput.value)!="")) { 
		upload_recipe_image();
		opacCls(true);
		opacFileCall('recipe.php?post_without_data=1',750,750);  
	} else { 
		alert('Please enter recipe title'); 
		document.pstRecipe.postInput.focus();
		return false; 
	}
}

function post_recipe_without_details_with_image(){
	if(document.pstRecipe.postInput.value!='' && document.pstRecipe.postInput.value!='Today, I am cooking ...' && ($.trim(document.pstRecipe.postInput.value)!="")) { 
		upload_recipe_image();
		opacCls(true);
		opacFileCall('recipe.php?post_without_data=1&with_image_data=1',750,550);     
	} else { 
		alert('Please enter recipe title'); 
		document.pstRecipe.postInput.focus();
		return false; 
	}
}

function openDropDwnOBJ(SelectBoxName) {	
	Sobj = document.getElementById(SelectBoxName+'-dropdown');
	if (Sobj.style.display=="none") { Sobj.style.display="block"; }	
	Sobj.style.width=document.getElementById(SelectBoxName+'-dpdn').offsetWidth-1+"px";
	Sobj.style.top=findPosY(document.getElementById(SelectBoxName+'-dpdn'))+document.getElementById(SelectBoxName+'-dpdn').offsetHeight-5+"px";
	Sobj.style.left=findPosX(document.getElementById(SelectBoxName+'-dpdn'))+1+"px";	
}

function selectDropDwnOBJ(selName,optTxt,optVal) {
	document.getElementById(selName+'-txt').value=optTxt;
	document.getElementById(selName).value=optVal;
	document.getElementById(selName+'-dropdown').style.display="none";	
}

//animation
function opacdivHScroll()
{	
	var innrDiv=document.getElementById('opcSubdiv');	
	var MnDiv=document.getElementById('opcMaindiv');	
	if (innrDiv.offsetHeight>=30)
	{		
		innrDiv.style.height = (innrDiv.offsetHeight - 30)+"px";			
		minopacdiv=setTimeout("opacdivHScroll()", speed);		
	}else {
		clearTimeout(minopacdiv);
		if (innrDiv.offsetWidth<30) { 
			document.body.removeChild(innrDiv); 
			document.body.removeChild(MnDiv); 
			parent.document.location="index.php";
		}
	}
}

function opacdivWScroll()
{	
	var innrDiv=document.getElementById('opcSubdiv');	
	var MnDiv=document.getElementById('opcMaindiv');
	if (innrDiv.offsetWidth>=30)
	{		
		innrDiv.style.width = (document.getElementById('opcSubdiv').offsetWidth - 35)+"px";	
		innrDiv.style.left=(findPosX(document.getElementById('signin'))-innrDiv.offsetWidth)+document.getElementById('signin').offsetWidth+"px";		
		minopacdiv2=setTimeout("opacdivWScroll()", speed);		
	} else {
		clearTimeout(minopacdiv2);
		if (innrDiv.offsetHeight<30) { 
			document.body.removeChild(innrDiv); 
			document.body.removeChild(MnDiv); 
			parent.document.location="index.php";
		}	
	}
}

function opacAdjust(innerOBJheight)
{
 
 if (document.getElementById('opcMaindiv').offsetHeight < (innerOBJheight+50)) { document.getElementById('opcMaindiv').style.height = innerOBJheight+150+"px"; }

 if (document.getElementById('opacframe').offsetHeight  < innerOBJheight) {
  HeightAdjtInc(innerOBJheight);
 } else { HeightAdjtDec(innerOBJheight); }

}


var opacInnerobjAnimation;
var newspeed=1;
function HeightAdjtInc(innerOBJheight)
{ 
 if (document.getElementById('opacframe').offsetHeight  < innerOBJheight) {
  document.getElementById('opacframe').style.height=document.getElementById('opacframe').offsetHeight+10+"px";
  opacInnerobjAnimation = setTimeout("HeightAdjtInc('"+innerOBJheight+"')", newspeed);
 } else { clearTimeout(opacInnerobjAnimation); }
}

function HeightAdjtDec(innerOBJheight)
{ 
 if (document.getElementById('opacframe').offsetHeight  > innerOBJheight) {
  document.getElementById('opacframe').style.height=document.getElementById('opacframe').offsetHeight-10+"px";
  opacInnerobjAnimation = setTimeout("HeightAdjtDec('"+innerOBJheight+"')", newspeed);
 } else { clearTimeout(opacInnerobjAnimation);}
}

function upload_recipe_image(){   
	if($('#img_for_recipe').val()!=''){   
		$('#add_recipe_picture').ajaxSubmit({
		 type: "post",
		 dataType:"json", 
		 url : 'resize_images/upload_recipe_img.php',    
		 iframe:true,
		 success:upload_image_return_success
		 
	 });
	} 
	
}

function upload_image_return_success(data){
	
	if(data.return_value=="larger image"){
		alert("Please upload image with less than 350 KB size");  
	}
}

/**completing the recipe posting **/ 
function complete_recipe_posting(recipe_id){
	var url='recipe.php?edit_recipe=1&recipe_id='+recipe_id;
	opacFileCall(url,750,750); 
}

function opacCls_for_editing_recipe_title(recipe_id)  
{  
   var url='edit_recipe_title.php?recipe_id_change_title='+recipe_id;                 
   opacFileCall_norefresh(url,700,400);    
   	
}

function opacCls_for_editing_recipe_content(recipe_id)  
{  
   var url='edit_recipe.php?recipe_id_change_content='+recipe_id;                    
   opacFileCall_norefresh(url,750,700);     
   	
}


function opacCls_for_editing_member_peronal_details()  
{  
   var url='edit_member_details.php';                  
   opacFileCall_norefresh(url,700,400);     
   	
}

function opacCls_for_editing_member_about_me_details()  
{  
   var url='edit_member_about_me.php';                   
   opacFileCall_norefresh(url,700,500);     
   	
}

function check_pressed_key_before_login(){
	
	if(event.keyCode==13)
	   {
	      /*document.getElementById("same as your submit button's id").focus();*/
	      //document.getElementById("submit_without_login").focus();
	      openSignin_with_post_title();return false; 
	   }
}

function change_edit_title_text(recipe_id){
	var recipe_link_id='#edit_recipe_title'+recipe_id;
	$(recipe_link_id).text("Edit recipe");  
}


