$(document).ready(function(){					   

		$("#addnewbutton").click(function(){
				$("#mcf-overlay").remove();
				$("body").append("<div id=\"mcf-overlay\" class=\"simplemodal-overlay\" ></div><div class=\"popupdiv\" id=\"popup\"><a href=\"javascript:;\" id=\"close\" onclick=\"close_popup()\">close</a></div>");
				/*$.ajax({
						cache:false,
						url:"slider_image_form.php",
						type:"GET",
						success:function(return_data){
							
							//$('#category_form').remove();
							$('#popup').fadeIn('slow').append(return_data); 
					}						   
				});	*/
				var window = window.open("slider_image_form.php", 'window_name', wparams);
   				window.focus();

		});
		
		$("#addnewproduct").click(function(){
										   window.location="product_form.php";
										//   var wparams = 'toolbar=0,location=0,directories=0,status=0,menubar=0,';
      //  wparams += 'scrollbars=0,resizable=0,width=700,height=500';
				//$("#mcf-overlay").remove();
				//$("body").append("<div id=\"mcf-overlay\" class=\"simplemodal-overlay\" ></div><div class=\"popupdiv\" id=\"popup\"><a href=\"javascript:;\" id=\"close\" onclick=\"close_popup()\">close</a></div>");
				/*$.ajax({
						cache:false,
						url:"product_form.php",
						type:"GET",
						success:function(return_data){
							
							//$('#category_form').remove();
							$('#popup').fadeIn('slow').append(return_data); 
					}						   
				});		*/		
			//	window.open("product_form.php", 'window_name', wparams);
   				
		});
		$("#addnewuser").click(function(){
				$("#mcf-overlay").remove();
				$("body").append("<div id=\"mcf-overlay\" class=\"simplemodal-overlay\" ></div><div class=\"popupdiv\" id=\"popup\"><a href=\"javascript:;\" id=\"close\" onclick=\"close_popup()\">close</a></div>");
				$.ajax({
						cache:false,
						url:"user_form.php",
						type:"GET",
						success:function(return_data){
							
							//$('#category_form').remove();
							$('#popup').fadeIn('slow').append(return_data); 
					}						   
				});						  
		});
		
});
 function close_popup()
 { 
 		$("#product_form").hide('slow').remove();
	 	$("#mcf-overlay").hide('slow').remove();
		$("#popup").hide('slow').remove();
	
 }
function editSlider( id  )
{
	$("#mcf-overlay").remove();
	$("body").append("<div id=\"mcf-overlay\" class=\"simplemodal-overlay\" ></div><div class=\"popupdiv\" id=\"popup\"><a href=\"javascript:;\" id=\"close\" onclick=\"close_popup()\">close</a></div>");
	$.ajax({
			cache:false,
			url:"slider_image_form.php",
			type:"GET",
			data:"id="+id,
			success:function(return_data){
				
				//$('#slider_form').remove();
				$('#popup').fadeIn('slow').append(return_data); 
		}						   
	});	
}
function deleteSlider( id )
{
	var image_name = $("#hidden_image_path"+id).val();
	$.ajax({
			cache:false,
			url:"slider_image_form.php",
			type:"GET",
			data:"id="+id+"&act=del&image="+image_name,
			success:function(return_data){
				
				$('#slider_form').remove();
				$('#popup').fadeIn('slow').append(return_data); 
		}						   
	});	
}

function editProduct( id  )
{
	window.location="product_form.php?id="+id;
	//$("#mcf-overlay").remove();
	//$("body").append("<div id=\"mcf-overlay\" class=\"simplemodal-overlay\" ></div><div class=\"popupdiv\" id=\"popup\"><a href=\"javascript:;\" id=\"close\" onclick=\"close_popup()\">close</a></div>");
	/*$.ajax({
			cache:false,
			url:"product_form.php",
			type:"GET",
			data:"id="+id,
			success:function(return_data){					
				$('#slider_form').remove();
				$('#popup').fadeIn('slow').append(return_data); 
		}						   
	});	*/
	//var wparams = 'toolbar=0,location=0,directories=0,status=0,menubar=0,';
  //      wparams += 'scrollbars=0,resizable=0,width=700,height=500';
		//window.showModalDialog("product_form.php?id="+id,window,"dialogHeight:500px;dialogWidth: 700px; dialogTop: 286px; edge: Raised; center: Yes; resizable: No; status: No;"); 
		///window.open("product_form.php?id="+id, 'window_name', wparams);
}
function deleteProduct( id )
{
	var image_name = $("#hidden_image_path"+id).val();
	var slide_name = $("#hidden_slide_path"+id).val();
	var conf = confirm("Are you sure to delete ?");
	if(conf) {
		
		$.ajax({
				cache:false,
				url:"product_form.php",
				type:"GET",
				data:"id="+id+"&act=del&image="+image_name+"&slideshow="+slide_name,
				success:function(return_data){
					if(return_data == 1)
						$("#tr_"+id).remove();
					//$('#popup').fadeIn('slow').append(return_data); 
			}						   
		});	
	}
}
function editUsers( id  )
{
	$("#mcf-overlay").remove();
	$("body").append("<div id=\"mcf-overlay\" class=\"simplemodal-overlay\" ></div><div class=\"popupdiv\" id=\"popup\"><a href=\"javascript:;\" id=\"close\" onclick=\"close_popup()\">close</a></div>");
	$.ajax({
			cache:false,
			url:"user_form.php",
			type:"GET",
			data:"id="+id,
			success:function(return_data){					
				$('#slider_form').remove();
				$('#popup').fadeIn('slow').append(return_data); 
		}						   
	});	
}
function deleteUsers( id )
{
	var conf = confirm("Are you sure to delete ?");
	if(conf) {
		$.ajax({
				cache:false,
				url:"user_form.php",
				type:"GET",
				data:"id="+id+"&act=del",
				success:function(return_data){				
					if(return_data == 1)
						$("#tr_"+id).remove();
					//$('#popup').fadeIn('slow').append(return_data); 
			}						   
		});	
	}
}


/**************************** QUICK CONTACT AND CONTACT FORM VALIDATION ************************************/
function validate_quick()
{	
	$("#errortitle").remove();
	if($('#txt_quickname').val() == "" || $('#txt_quickname').val() == null || $('#txt_quickname').val() == "Name :")
	{
		make_errormessage('txt_quickname', "Please fill your name");
		$("#txt_quickname").val('').focus();
		return false;
	}
	if($("#txt_quickemail").val() !="" || $("#txt_quickemail").val() !=null || $("#txt_quickemail").val() != "Email :")
	{
		if(emailvalidation('txt_quickemail') == false )
		{
			make_errormessage('txt_quickemail', "Please fill with an valid email");
			$("#txt_quickemail").val('').focus();
			return false;
		}
	}
	else
	{
		make_errormessage('txt_quickemail', "Please fill with an email");
		$("#txt_quickemail").val('').focus();
		return false;
	}
	
	if($('#txt_quickphone').val() == "" || $('#txt_quickphone').val() == null || isNaN(parseInt($('#txt_quickphone').val()))== true ||  $('#txt_quickphone').val() == "Phone :" )
	{
		make_errormessage('txt_quickphone', "Please fill with your phone number");
		$("#txt_quickphone").val('').focus();
		return false;
	}
	
	
	//'txt_quickmessage';
}

function validate_contact()
{	
	$("#errortitle").remove();
	if($('#txt_name').val() == "" || $('#txt_name').val() == null || $('#txt_name').val() == "Name :")
	{
		make_errormessage('txt_name', "Please fill your name");
		$("#txt_name").val('').focus();
		return false;
	}
	if($("#txt_email").val() !="" || $("#txt_email").val() !=null || $("#txt_email").val() != "Email :")
	{
		if(emailvalidation('txt_email') == false )
		{
			make_errormessage('txt_email', "Please fill with an valid email");
			$("#txt_email").val('').focus();
			return false;
		}
	}
	else
	{
		make_errormessage('txt_email', "Please fill with an email");
		$("#txt_email").val('').focus();
		return false;
	}
	
	if($('#txt_phone').val() == "" || $('#txt_phone').val() == null || isNaN(parseInt($('#txt_phone').val()))== true  )
	{
		make_errormessage('txt_phone', "Please fill with your phone number");
		$("#txt_phone").val('').focus();
		return false;
	}
}

function emailvalidation(thisform) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  // var address = thisform.value;
   var address = $("#"+thisform).val();
   var email = address.split(',');
   
   for (var i = 0; i < email.length; i++) {
   if(reg.test(email[i]) == false) {
     // alert('Invalid Email Address');
      return false;
   }
   else
   {
    }
   }
}
function make_errormessage(input, message)
{
	$('#'+input).before("<div id=\"errortitle\" class=\"errorformElement\"><div class=\"formErrorContent\">"+message+"</div></div>");
}
/***********************************************************************************************************/
