	$(document).ready(function(){	
			$(".img_upload").colorbox({
					width:"650px", 
					height:"500px", 
					iframe:true,
					overlayClose: false
				});
	});

	//img
	function getLastImg() {
		alert('test');
		var file_id = $("#newfileid").val();
		var type = 'img';
		$.post("ajax_getlastimg.php",{file_id:file_id, type:type},function(data) {
			$("#uploadedimg").append('<img src="../images/ajaxloader.gif" id="loaderimg" />');
			if(data) {
				var image=data.split(","); 
				$("#loaderimg").remove();
				$("#uploadedimg").append('<span id="new_img'+image[0]+'"><br /><img src="image.php?image=/'+image[1]+'&width=80" id="file_img'+image[0]+'" onclick="selectImage(\''+image[1]+'\',\''+image[0]+'\');" class="uploadimgs" style="cursor:pointer;border:2px solid #fff;"> <img src="../images/action_delete.png" onclick="delFileImg(\''+image[0]+'\');" style="cursor:pointer;"></span>');
			}
		});
	}
	
	function selectImage(imgloc,ctr) {
		$("#fileimglocation").val(imgloc);
		$(".uploadimgs").css('border','2px solid #FFFFFF');
		$("#file_img"+ctr).css('border','2px solid #000000');
	}
	
	function delFileImg(img_id) {
		var type = 'img';
		if(confirm("Are you sure you want to remove this image?")) {			
			$.post("ajax_remimg.php",{img_id:img_id, type:type},function(data) {
				if(data) {
					$("#new_img"+img_id).remove();
				} else {
					alert("Error removing. Please try again!");
					return false;
				}
			});
		}
	}
	
	//banner
	function getLastBanner() {
		var file_id = $("#newfileid").val();
		var type = 'banner';
		$.post("ajax_getlastimg.php",{file_id:file_id,type:type},function(data) {
			$("#uploadedbanner").append('<img src="../images/ajaxloader.gif" id="loaderbanner" />');
			if(data) {
				var image=data.split(","); 
				$("#loaderbanner").remove();
				$("#uploadedbanner").append('<span id="new_banner'+image[0]+'"><br /><img src="image.php?image=/'+image[1]+'&width=80" id="file_banner'+image[0]+'" onclick="selectBanner(\''+image[1]+'\',\''+image[0]+'\');" class="uploadbanner" style="cursor:pointer;border:2px solid #fff;"> <img src="../images/action_delete.png" onclick="delFileBanner(\''+image[0]+'\');" style="cursor:pointer;"></span>');
			}
		});
	}
	
	function selectBanner(imgloc,ctr) {
		$("#filebannerlocation").val(imgloc);
		$(".uploadbanner").css('border','2px solid #FFFFFF');
		$("#file_banner"+ctr).css('border','2px solid #000000');
	}
	
	function delFileBanner(img_id) {
		var type = 'banner';
		if(confirm("Are you sure you want to remove this image?")) {			
			$.post("ajax_remimg.php",{img_id:img_id, type:type},function(data) {
				if(data) {
					$("#new_banner"+img_id).remove();
				} else {
					alert("Error removing. Please try again!");
					return false;
				}
			});
		}
	}








function checkBusinessSubmit() {
		var errors = new Array();
		var business_terms = tinyMCE.get('business_terms').getContent();
		var business_advertisement = tinyMCE.get('business_advertisement').getContent();
		var business_headline = tinyMCE.get('business_headline').getContent();
		var business_desc = tinyMCE.get('business_desc').getContent();
		
		
		
		if($("#seller_name").val()=='') {
			errors[0] = '*Seller Name - Required';
		}
		
		
		
		if($("#total_revenue").val()=='' && $("#select_revenue").val()=='' && $("#weekly_revenue").val()=='') {
			errors[17] = '*Total annual revenues/sales or Total Weekly revenues or Select a Range - Required ';
		}
		
		if($("#annual_profit").val()=='' && $("#select_profit").val()=='' && $("#weekly_profit").val()=='') {
			errors[18] = '*Adjusted Annual Net profit or Weekly adjusted Profit or Select a Profit - Required ';
		}
		
		
		
		
		if(errors.length > 0) {
			var error_msg = 'Please review:';
			for(i=0;i<errors.length;i++) {
				if(errors[i]!=undefined) {
					error_msg = error_msg + "\n" + errors[i];
				}
			}
			alert(error_msg);
			return false;
		}
		
		return true;
	}
	
	
	function timeLoad() {
	
		var email = $("#email").val();		
		if(email=='') {
			return false;
		}
		$("#img_result").html('<img src="/admin/images/ajaxloader.gif">');
		setTimeout("checkEmail();",500);
	}
	
	function checkEmail() {
	
		var email = $("#email").val();		
		$.post("ajax_checkemail.php",{email:email},function(data) {
			//if(data==1) {		
				if (echeck($("#email").val())==false){
					$("#img_result").html('<img src="/admin/images/x.png" alt="Invalid email ID" id="emailimage">');
				} else {
					$("#img_result").html('<img src="/admin/images/check.png" id="emailimage">');
				}
			/* } else {
				alert("Email already in use.");
				$("#img_result").html('<img src="images/x.png" alt="Already in use" id="emailimage">');
			} */
		});
	}

	function timeLoad2() {
	
		var email = $("#l_email").val();		
		if(email=='') {
			return false;
		}
		$("#img_result").html('<img src="/admin/images/ajaxloader.gif">');
		setTimeout("checkEmail2();",500);
	}
	
	function checkEmail2() {
	
		var email = $("#l_email").val();		
		$.post("ajax_checkemail.php",{email:email},function(data) {
			//if(data==1) {		
				if (echeck($("#l_email").val())==false){
					$("#img_result").html('<img src="/admin/images/x.png" alt="Invalid email ID" id="emailimage">');
				} else {
					$("#img_result").html('<img src="/admin/images/check.png" id="emailimage">');
				}
			/* } else {
				alert("Email already in use.");
				$("#img_result").html('<img src="images/x.png" alt="Already in use" id="emailimage">');
			} */
		});
	}
	
	function timeLoad3() {
	
		var email = $("#org_email").val();		
		if(email=='') {
			return false;
		}
		$("#img_result").html('<img src="/admin/images/ajaxloader.gif">');
		setTimeout("checkEmail3();",500);
	}
	
	function checkEmail3() {
	
		var email = $("#org_email").val();		
		$.post("ajax_checkemail.php",{email:email},function(data) {
			//if(data==1) {		
				if (echeck($("#org_email").val())==false){
					$("#img_result").html('<img src="/admin/images/x.png" alt="Invalid email ID" id="emailimage">');
				} else {
					$("#img_result").html('<img src="/admin/images/check.png" id="emailimage">');
				}
			/* } else {
				alert("Email already in use.");
				$("#img_result").html('<img src="images/x.png" alt="Already in use" id="emailimage">');
			} */
		});
	}
	
	
	
	
	
	
	function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			return false
		 }
		
		 if (str.indexOf(" ")!=-1){
			return false
		 }

		 return true					
	}
