 // JavaScript Document
function numbersonly(e){
	//alert(e)
	var unicode=e.charCode?e.charCode:e.keyCode; 
    // alert(unicode);
	if(unicode!=8){
		
		if((unicode<48||unicode>57) && unicode!=9 && unicode!=46){
			
			return false;
		}else{
				
				return true;
		}
	}
} 

function tocheck(){
	   if (document.getElementById('emails').value == 'Enter email addresses, separated by commas, of people in your network who should be able to buy your app.') {
		document.getElementById('emails').value =''
		}
}

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true; 
    }else{ 
        return false; 
    } 
}


function onABCommComplete(data) {
	// OPTIONAL: do something here when the new data gets populated in the text area
	// data is an array of selected names/emails, i.e. [name1, email1, name2, email2, ...]
		objemail = document.getElementById("emails");
		txtemail = objemail.value;
		start = objemail.length;
		document.getElementById("edit-tmpids").value = data;
		idstr =  document.getElementById("edit-tmpids").value;
		
		if( idstr.length>0 ){
		emailArray=idstr.split(",");
		strEmail = '';
		
		for( i=1; i<emailArray.length; i=i+2 ){
		  	strEmail = strEmail + emailArray[i] + ',' ;
		}
			
		strEmail = strEmail.substring(0,(strEmail.length-1) );


		textareaEmail = document.getElementById("emails").value;
		if(textareaEmail.substr(textareaEmail.length-1,1)!=',' && textareaEmail.substr(textareaEmail.length-1,1)!=''){
			strEmail = document.getElementById("emails").value + ','+ strEmail;
		}else{
			strEmail = document.getElementById("emails").value +  strEmail;
		}

		document.getElementById("emails").value = strEmail;
	}
}


function integeronly(e){
	//alert(e)
	var unicode=e.charCode?e.charCode:e.keyCode; 
   //  alert(unicode);
	if(unicode!=8){
		
		if((unicode<48||unicode>57) && unicode!=9){
			
			return false;
		}else{
				
				return true;
		}
	}
} 

function makeUnitconversion(amount,stage){
  var wholesalecopies;
   if(stage=1){
 	     var wholesalecopies=floor(parseFloat(amount)/0.25);
   }else{
	     var wholesalecopies=floor(parseFloat(amount)/0.35);
   }
	return wholesalecopies
 	
}



/************************** Start date Validation ********************************************/

var dtCh= "/";
var today= new Date();
var year = today.getFullYear(); 
var minYear=year;
//var maxYear=2500; // 
var today = new Date();
var maxYear=year+1;

//alert(maxYear+""+minYear);

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	var msg='';
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)  
	if (pos1==-1 || pos2==-1){
		msg="Please enter a valid date format mm/dd/yyyy for the Expected Launch Date."; 
 		return msg;
 	}
	if (strMonth.length<1 || month<1 || month>12){
 		msg="Please enter a valid month for the Expected Launch Date."
		return msg;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		msg="Please enter a valid day for the Expected Launch Date."
		return msg;
 	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
 		msg="Please enter a valid year - the Expected Launch Date should be within the next 365 days.";
		return msg;
 	}
	//07/11/2010 - Reema Attar
    // Modified the error message to be more specific.
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
         msg="Please enter the Expected Launch Date.";
        return msg;
    }
return msg;
}

function IsDateLess(DateValue1)
{
 var DaysDiff;
 Date1 = new Date(DateValue1);
 Date2 = new Date();
 DaysDiff = Math.floor((Date1.getTime() - Date2.getTime())/(1000*60*60*24));
 return DaysDiff;
}


function IsEditDateLess(DateValue1,DateValue2)
{
 var DaysDiff2;
 Date1 = new Date(DateValue1);
 Date2 = new Date(DateValue2);
 Date3 = new Date();
 DaysDiff2 = Math.floor((Date1.getTime() - Date2.getTime())/(1000*60*60*24));
	
	if(DaysDiff2<0){
	 DaysDiff2 =  IsDateLess(DateValue1);
	 }
   return DaysDiff2;
   
}

// jQuery plugin for enabling and disabling elements (usually buttons)
(function($) {
/* Enable / Disable function */

 $.fn.disable = function() {
	return this.each(function() {
    	if (typeof this.disabled != "undefined") this.disabled = true;
    });
 }
 $.fn.enable = function() {
	return this.each(function() {
		if (typeof this.disabled != "undefined") this.disabled = false;
	});
 }

})(jQuery);

/* ******************************** End Date Validation ****************************************/
 
function validateEmail(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;	
}

function validateMultipleEmailsCommaSeparated(value) {
   var value=jQuery.trim(value);
   var result = value.split(",");
    for(var i = 0;i < result.length;i++)
    if(!validateEmail(jQuery.trim(result[i]))) 
            return false;               
    return true;
}


 






$(document).ready(function () {
	
	/*$("#popup-sell-app div.internal-tab-content:gt(0)").hide();
 	sellAppPopup = new SellAppPopup($("#popup-sell-app"));
	sellAppPopup.goTo(0);
    $("#popup-sell-app .tabs a").unbind("click");
 	var checkv='';
	$("#popup-sell-app input[type=radio]").parent().addClass("radio");
	*/
	
	
	$("ul.form.disabled input, ul.form.disabled textarea, ul.form.disabled select").disable();
	
	$("#for_network").click(function () {
		$("#network-buy-only-section").removeClass("disabled").find("input, textarea, select").enable();
	});
	
	$("#for_all").click(function () {
		$("#network-buy-only-section").addClass("disabled").find("input, textarea, select").disable();
	});
	
     /////////////// 19July2010 Added By Vivek Mishra //////////////////////////////////////
	//////////////   Use in Step3                    //////////////////////////////////////
	//////////////                                   //////////////////////////////////////
	
	$("#standard_email").click(function () {
		$("#custom_msg_option").addClass("disabled").find("input, textarea, select").disable();
	})
	
	$("#custom_email").click(function () {  
		$("#custom_msg_option").removeClass("disabled").find("input, textarea, select").enable();
	});
	$("#for_network_all").click(function () {
		$("#network-buy-only-section").removeClass("disabled").find("input, textarea, select").enable();
	});
	
	
	
	
	$("#popup-sell-app div.internal-tab-content:gt(0)").hide();
	
	sellAppPopup = new SellAppPopup($("#popup-sell-app"));
	sellAppPopup.goTo(0);

	/*$("#popup-sell-app .tabs a").click(function () {
		var eq = $(this).parent().prevAll().length;
		sellAppPopup.goTo(eq);
	});*/
	var checkv='';
    $("#popup-sell-app input[type=radio]").parent().addClass("radio");
   
   //alert(jQuery("#editproject2").val());
   
   makeNextDisable(jQuery("#app_title").val());
   
   
   
   
   $("input[name=total-set-by]").each(function (i) {
		$(this).click(function () {
			if (i == 0)
			{
				$("#total-amount-table tbody tr:eq(0)").removeClass("disabled").find("input[type=text]").enable();
				$("#total-amount-table tbody tr:eq(1)").addClass("disabled").find("input[type=text]").disable();
			} else {
				$("#total-amount-table tbody tr:eq(1)").removeClass("disabled").find("input[type=text]").enable();
				$("#total-amount-table tbody tr:eq(0)").addClass("disabled").find("input[type=text]").disable();
			}
		});
	});
   
   
   $("input[name=buyer-set-by]").each(function (i) {
		$(this).click(function () {
			if (i == 0)
			{
				$("#buyer-amount-table tbody tr:eq(0)").removeClass("disabled").find("input[type=text]").enable();
				$("#buyer-amount-table tbody tr:eq(1)").addClass("disabled").find("input[type=text]").disable();
			} else {
				$("#buyer-amount-table tbody tr:eq(1)").removeClass("disabled").find("input[type=text]").enable();
				$("#buyer-amount-table tbody tr:eq(0)").addClass("disabled").find("input[type=text]").disable();
			}
		});
	});
	
   
   
   
   
   
   
   
   
 	
});



function Addonclicks(){
	
	    var index = 0;
	    
		$("#popup-sell-app div.internal-tab-content:gt(0)").hide();
 		var sellAppPopup = new SellAppPopup($("#popup-sell-app"));
		sellAppPopup.goTo(0);
		
		 jQuery('#app_title').attr("readonly",false);
		
		 jQuery('#error_step1').html('');
		 jQuery('#error_step2').html('');
		 jQuery('#error_step3').html('');
		 jQuery('#error_step4').html('');
		 
		 jQuery('#error_step1').hide();
		 jQuery('#error_step2').hide();
		 jQuery('#error_step3').hide();
		 jQuery('#error_step4').hide();
		 
		
		 
		jQuery('#expected_launch').attr("readonly",false); 
	    jQuery('#apple_tab_id').attr("readonly",false); 
					
		jQuery("#max_amount").attr("readonly",true);
		jQuery("#min_amount").attr("readonly",true);
		jQuery("#min_purchase_limit").attr("readonly",true);
		jQuery("#max_purchase_limit").attr("readonly",true);
		
		jQuery('#min_wholesale_copies').attr("readonly",false);
		jQuery('#min_wholesale_copies2').attr("readonly",false);
		jQuery('#max_wholesale_copies').attr("readonly",false);
		jQuery('#max_wholesale_copies2').attr("readonly",false); 
		
		
		 $("#popup-sell-app .tabs a").unbind("click");
 		 $("#popup-sell-app input[type=radio]").parent().addClass("radio");
		 
	     var editproject = jQuery("#editproject").val('');
		 jQuery('#head_title').html('Sell App');
		 jQuery("#app_description").val('');
		 jQuery("#app_product_audience  option[value='1']").attr("selected","selected") ;
         jQuery("#month_limit  option[value='1']").attr("selected","selected") ;
		 jQuery("#month_limit  option[value='']").attr("selected","selected") ;
		 jQuery("#app_category  option[value='']").attr("selected","selected") ;
		 jQuery("#app_product_audience  option[value='']").attr("selected","selected") ;
		 jQuery("#expected_launch").val('mm/dd/yyyy');
		 jQuery("#retail_price").val('$');
		 jQuery("#money_purpose").val('') ;
		 jQuery("#wholesale  option[value='']").attr("selected","selected") ;
		 jQuery("#min_amount").val('$');
		 document.getElementById("new_apps").checked=true;
		 jQuery('#launchDate').show();
		 jQuery('#apple_tab_id').hide();
		 jQuery("#apple_app_id").val('');
	     jQuery("#website_app").val('');
		 jQuery("#max_amount").val('');
		 jQuery("#min_purchase_limit").val('');
		 jQuery("#max_purchase_limit").val('');
		 document.getElementById("for_all").checked=false;
		 document.getElementById("for_network").checked=false;
		 jQuery("#subject").val('') ;
		 jQuery("#message").val('') ;
		 jQuery("#emails").val('Enter email addresses, separated by commas, of people in your network who should be able to buy your app.') ;
 		 jQuery("#retail_price3").val('') ;
 		 document.getElementById("sell-app-agree1").checked=false;
		 //document.getElementById("sell-app-agree2").checked=false;
		  
		  
		  
		    /////////////////////// 16July2010 Added By Vivek Mishra //////////////////////
		   ///  
		  ///   Step 2 Variable. 
		   
		        jQuery("#wholesale_price_Step2_span").html('');
		 
		 
		 
		 /////////////////////// 14July2010 Added By Vivek Mishra //////////////////////
		///  
	   ///   Step 4 Variable. 
				 $('#buy_min_purchase_copy').val('');  
				 $('#buy_max_purchase_copy').val('');  
				 $('#min_wholesale_copies').val('');
				 $('#max_wholesale_copies').val('');
 		///
		////////////////////////////////////////////////////////////////////////////////// 
		 
		 
		/* if ($("#sell-app-agree1").is(":checked") && $("#sell-app-agree2").is(":checked"))
				$("#popup-sell-app .popup-actions .next").enable();
			else
				$("#popup-sell-app .popup-actions .next").disable(); */
		 
		 
		  
		  if ($("#sell-app-agree1").is(":checked"))
				$("#popup-sell-app .popup-actions .next").enable();
			else
				$("#popup-sell-app .popup-actions .next").disable();
				
		 
		  $("#sell-app-step-zero").show();
		  $("#sell-app-step-positive").hide();
		 
		 $("#popup-sell-app .popup-actions .back").hide();
		 $("#popup-sell-app .popup-actions .next").disable();
 		// Checkbox conditions to move past the initial screen.
		
		/*$("#sell-app-agree1, #sell-app-agree2").click(function () {
			if ($("#sell-app-agree1").is(":checked") && $("#sell-app-agree2").is(":checked"))
				$("#popup-sell-app .popup-actions .next").enable();
			else
				$("#popup-sell-app .popup-actions .next").disable();
		});*/
		
		 $("#sell-app-agree1").click(function () {
			if ($("#sell-app-agree1").is(":checked"))
				$("#popup-sell-app .popup-actions .next").enable();
			else
				$("#popup-sell-app .popup-actions .next").disable();
		});
		 
 		// The next button is bound in popup_sell_app.js, but there is a specific condition for the initial screen.
		
		$("#popup-sell-app .popup-actions .next").click(function () {
 			    $("#sell-app-step-zero").hide();
			    $("#sell-app-step-positive").show();
                $("#back_buttom").show();
  			    var checkv='';
				
 		});
		 
 		 
   } 


var sellAppPopup;

SellAppPopup = function (jqObj)
{
	
		var me = this;
		var index = 0;
		var backButton = jqObj.find("div.popup-actions").children("button.back");
		var nextButton = jqObj.find("div.popup-actions").children("button.next");
		/* When Pop up open inisilize default value */
		
			     jQuery('#error_step1').html('');
				 jQuery('#error_step2').html('');
				 jQuery('#error_step3').html('');
				 jQuery('#error_step4').html('');
				 
				 jQuery('#error_step1').hide();
				 jQuery('#error_step2').hide();
				 jQuery('#error_step3').hide();
				 jQuery('#error_step4').hide();
		
		 
		
		jQuery('#expected_launch').attr("readonly",false); 
		jQuery('#apple_tab_id').attr("readonly",false); 
					
		jQuery("#max_amount").attr("readonly",true);
		jQuery("#min_amount").attr("readonly",true);
		jQuery("#min_purchase_limit").attr("readonly",true);
		jQuery("#max_purchase_limit").attr("readonly",true);
		
		$('#min_wholesale_copies').attr("readonly",false);
		$('#min_wholesale_copies2').attr("readonly",false);
		$('#max_wholesale_copies').attr("readonly",false);
		$('#max_wholesale_copies2').attr("readonly",false); 
		
		
		jQuery('#app_title').attr("readonly",false);
		 var checkv = jQuery('#next_s').val('');
		 var editproject = jQuery("#editproject").val('');
 	     jQuery("#app_title").val('');
		 jQuery('#head_title').html('Sell App');
		 jQuery("#app_description").val('');
		 jQuery('#dev_stage').show();
		 jQuery("#app_product_audience  option[value='1']").attr("selected","selected") ;
         jQuery("#month_limit  option[value='1']").attr("selected","selected") ;
		 jQuery("#month_limit  option[value='']").attr("selected","selected") ;
         jQuery("#app_category  option[value='']").attr("selected","selected") ;
		 jQuery("#app_product_audience  option[value='']").attr("selected","selected") ;
		 
		 jQuery("#expected_launch").val('mm/dd/yyyy');
		 jQuery("#retail_price").val('$');
		 jQuery("#money_purpose").val('') ;
		// jQuery("#wholesale  option[value='']").attr("selected","selected") ;
		 jQuery("#wholesale").val('') ;
		 jQuery("#min_amount").val('');
		 document.getElementById("new_apps").checked=true;
		 jQuery('#launchDate').show();
		 jQuery('#apple_tab_id').hide();
		 jQuery("#apple_app_id").val('');
		 jQuery("#website_app").val('');
		 jQuery("#max_amount").val('');
		 jQuery("#min_purchase_limit").val('');
		 jQuery("#max_purchase_limit").val('');
		 document.getElementById("for_all").checked=false;
		 document.getElementById("for_network").checked=false;
		 
		 /////////////////////// 19July2010 Added By Vivek Mishra //////////////////////
		///  
		///   Step 3 Variable. 
 		 document.getElementById("for_network_all").checked=false;
		 document.getElementById("standard_email").checked=true;
		 document.getElementById("custom_email").checked=false;
		 
		 
		 
		 jQuery("#subject").val('') ;
		 jQuery("#message").val('') ;
		 jQuery("#emails").val('Enter email addresses, separated by commas, of people in your network who should be able to buy your app.') ;
		 jQuery("#wholesale_price_Step2_span").html('');
		 
		 /////////////////////// 14July2010 Added By Vivek Mishra //////////////////////
		///  
		///   Step 4 Variable. 
				 $('#buy_min_purchase_copy').val('');  
				 $('#buy_max_purchase_copy').val('');  
				 $('#min_wholesale_copies').val('');
				 $('#max_wholesale_copies').val('');
 		///
		////////////////////////////////////////////////////////////////////////////////// 
		 
		
		
		//makeNextDisable(jQuery("#app_title").val());
		
 	
	/*  End */
	
	this.goTo = function (eq)
	{
 		//alert(eq);
		jqObj.find("ol:eq(0)").attr("class","tabs step-" + (eq+1));
		jqObj.find("div.internal-tab-content:eq(" + eq + ")").show().siblings("div.internal-tab-content").hide();
		
		if (eq == 0) { backButton.attr("disabled","disabled"); } else { backButton.removeAttr("disabled"); }
		if (eq == 3) { nextButton.html("Finish");}
		if (eq == 5) {$("ol.tabs").hide(); $(".hr-border").hide(); } else { nextButton.html("Next &raquo;"); $("ol.tabs").show(); $(".hr-border").show(); }
		positionPopup();
  		 
		index=eq;
   		
	}
	
	this.next = function ()	{
		
		
			if(jQuery("#new_apps").attr("checked")){
					jQuery("#Planned_Retail_Price_Stage2").css("display","none");
					jQuery("#Planned_Retail_Price_Stage1").css("display","block");
			}else{
					jQuery("#Planned_Retail_Price_Stage2").css("display","block");
					jQuery("#Planned_Retail_Price_Stage1").css("display","none");
			}
		    
			jQuery('#app_title').attr("readonly",false);
			
 		    var step=$("#action_btn").html();
		    var app_title= jQuery.trim(jQuery("#app_title").val());
			var app_description= jQuery.trim(jQuery("#app_description").val());
			var app_product_audience = jQuery.trim(jQuery("#app_product_audience option:selected").val());
			var app_category = jQuery.trim(jQuery("#app_category option:selected").val());
			var add_stage_value = jQuery("input[@name='app_stage']:checked").val();


           if(document.getElementById("new_apps").checked==true){
 				add_stage_value=1;
			}else{
				add_stage_value=2;
				
			}


 			var expected_launch = jQuery.trim(jQuery("#expected_launch").val());
 			var apple_app_id= jQuery.trim(jQuery("#apple_app_id").val());
 			var website_app= jQuery.trim(jQuery("#website_app").val());
 			var validurl = isValidURL(website_app);
	        var app_description= jQuery.trim(jQuery("#app_description").val());
			var retail_price = jQuery.trim(jQuery("#retail_price").val());
			var money_purpose = jQuery.trim(jQuery("#money_purpose").val());
 			var wholesale = jQuery.trim(jQuery("#wholesale").val());
 			
 			var my_network_only = jQuery("input[@name='network_setting']:checked").val();
			
			document.getElementById("for_all").checked==false ;
			document.getElementById("for_network").checked==false ;
			
 			var subject= jQuery.trim(jQuery("#subject").val());
			var message= jQuery.trim(jQuery("#message").val());
			var emails = jQuery.trim(jQuery("#emails").val());
 			var send = jQuery("input[@name='send']:checked").val();
 			var validemails= validateMultipleEmailsCommaSeparated(emails);
			
			var min_amount = jQuery.trim(jQuery("#min_amount").val());
			var max_amount = jQuery.trim(jQuery("#max_amount").val());
			var min_purchase_limit = jQuery.trim(jQuery("#min_purchase_limit").val());
			var max_purchase_limit = jQuery.trim(jQuery("#max_purchase_limit").val());
			var month_limit = jQuery.trim(jQuery("#month_limit option:selected").val());
			var editproject = jQuery.trim(jQuery("#editproject2").val());
		    var network_setting = jQuery("input[@name='network_setting']:checked").val();
			var editid='';
			
			 var buy_min_purchase_copy=  parseInt(jQuery.trim($('#buy_min_purchase_copy').val()));  
			 var buy_max_purchase_copy= parseInt(jQuery.trim($('#buy_max_purchase_copy').val()));  
			 var min_wholesale_copies = parseInt(jQuery.trim($('#min_wholesale_copies').val()));
			 var max_wholesale_copies = parseInt(jQuery.trim($('#max_wholesale_copies').val()));
				 
			if(jQuery("#editproject2").val()==jQuery("#editproject").val() && jQuery("#editproject2").val()!=''){
 			      editid=jQuery("#editproject2").val();
 			}else if(jQuery("#editproject2").val()!=jQuery("#editproject").val() && jQuery("#editproject2").val()!=''){
 			     editid='';
			}
		   
		   
		   var expected_launch2 = jQuery.trim(jQuery("#expected_launch2").val());
 		   var DaysDiff=IsDateLess(expected_launch);
		   var DaysDiff2=IsEditDateLess(expected_launch,expected_launch2);
		   
 		if(index==0){
 			 
			 if(app_title== '' ){
 			    makeNextDisable(app_title);
 				return false;
 			}else if(app_description== '' ){
 			   $('#error_step1').html('App Description is required.');
			   $('#error_step1').show();
 				return false;
 			}else if(app_category== '' ){
 			   $('#error_step1').html('Please select the Category.');
			   $('#error_step1').show();
 				return false;
 			}else if(app_product_audience== '' ){
 			   $('#error_step1').html('Please select the Product Audience.');
			   $('#error_step1').show();
 				return false;
 			}else if((document.getElementById("new_apps").checked==false && document.getElementById("exists_apps").checked==false)){
 			   $('#error_step1').html('Development Stage is required.');
			   $('#error_step1').show();
 				return false;
 			}else if(add_stage_value=='1' &&  (expected_launch=='')){  
				 $('#error_step1').html('Expected Launch Date is required.');
				 $('#error_step1').show();
				 return false;
  			}else if(add_stage_value=='1' &&  (isDate(expected_launch)!='')){
				 var msg=isDate(expected_launch);
				 $('#error_step1').html(msg);
				 $('#error_step1').show();
				 return false;
  			}else if(  (jQuery("#editproject2").val()==jQuery("#editproject").val()) && (jQuery("#editproject2").val()=='') && (add_stage_value=='1') && (DaysDiff <= 0)  ){
  					$('#error_step1').html('Please enter a valid date - the Expected Launch Date should be within the next 365 days. ');
			        $('#error_step1').show();
 					return false;
 			}else if(  (jQuery("#editproject2").val()!=jQuery("#editproject").val()) && (jQuery("#editproject2").val()!='') && (add_stage_value=='1') && (DaysDiff <= 0)){                  $('#error_step1').html('Please enter a valid date - the Expected Launch Date should be within the next 365 days.');
			         $('#error_step1').show();
 					 return false;
					 
					 
					 
 			}else if((jQuery("#editproject2").val()==jQuery("#editproject").val()) && (jQuery("#editproject2").val()!='') && (add_stage_value=='1') && (DaysDiff2<0) ){                  $('#error_step1').html('Please enter a valid date - the Expected Launch Date should be within the next 365 days.');
			         $('#error_step1').show();
 					 return false;
 					 var expected_launch2 = jQuery.trim(jQuery("#expected_launch2").val());
  			}else if(add_stage_value=='2' &&  apple_app_id==''){
				$('#error_step1').html('Apple App Id is required.');
			    $('#error_step1').show();
 				return false;

                        }else if(validurl!= true && website_app != ''){
                           $('#error_step1').html('Invalid Website URL.');
			   $('#error_step1').show();
  			}else{
 			 	index=1;
  			    me.goTo(index);	
				$('#error_step1').hide();
				checkv='';
			}
		}
  	
	
	   if(index==1){	
	   
	      
		  
	   
				if(add_stage_value==1){
					 
					    jQuery("#retail_price3_label").html("Planned Retail Price <span class='reqd'>*</span>:");
						jQuery("#retail_pricelabel").html("Planned Retail Price <span class='reqd'>*</span>:");
						
					
					
 				     	$('#Planned_Retail_Price_Stage2').hide();
 						$('#Planned_Retail_Price_Stage1').show();
 						
					  	//07/11/2010 - Reema Attar
                        // Modified the help tooltip to be more specific.
							var tooltipmsg='This is the expected selling price of your app in the app store.';
							jQuery("#retail_price_tooltip p").html(tooltipmsg);
							jQuery(".blue_box").show();
                         //07/11/2010 - Reema Attar
                          // Hiding the wholesale span, as we are hardcoding the value to 40,000.
                           $('#whole_sale_span').hide();
						
						   
						
						if(  (jQuery("#editproject2").val()==jQuery("#editproject").val()) && (jQuery("#editproject2").val()=='') ){
							 retail_price=0.99;
							 $('#retail').html('$'+retail_price);
							 $('#whole_sale_span').html('40,000');
							 $('#wholesale').val(40000);
							 $('#retail_price').attr("readonly",false); 
							 $('#retail_price3').attr("readonly",false); 
							 
							 $('#month_limit').show();
				             $('#fundraising_span').hide();
							 
						 }else if(  (jQuery("#editproject2").val()==jQuery("#editproject").val()) && (jQuery("#editproject2").val()!='') ){
							  retail_price=$('#retail_price2').val();
							  $('#retail').html('$'+retail_price);
							  wholesale=$('#wholesale2').val();
							  var whole_amount_format = number_format(wholesale,"","",",");  
							  $('#whole_sale_span').html(whole_amount_format);
							  $('#wholesale').val(wholesale);
							   if (selling_start) {
									$('#retail_price').hide();
							   }
							   else {
									$('#retail_price_label').hide();
							   }
							   
							    $('#retail_price').attr("readonly",true); 
							    $('#retail_price3').attr("readonly",true); 
								
							    $('#month_limit').hide();
				                $('#fundraising_span').html($('#month_limit2').val()+' Month(s)').show();
							   
						 }else if(  (jQuery("#editproject2").val()!=jQuery("#editproject").val()) && (jQuery("#editproject2").val()!='') ){
							  retail_price=0.99;
							  $('#retail').html('$'+retail_price);
							  $('#whole_sale_span').html('40,000');
							  $('#wholesale').val(40000);
							  
							   $('#month_limit').show();
				               $('#fundraising_span').hide();
							  
							    $('#retail_price').attr("readonly",false); 
							    $('#retail_price3').attr("readonly",false); 
								
							  
						 }else{  
							  retail_price=0.99;
							  $('#retail').html('$'+retail_price);
							  $('#whole_sale_span').html('40,000');
							  $('#wholesale').val(40000);
							  
							   
 						 }
                     
					    
                    /// Added By Vivek 
					///  code added for back condition and change on app status
					 
					              retail_price =  parseFloat(jQuery.trim(jQuery("#retail_price3").val()));
 								   if(retail_price>0){  // 07/16/2010 Added By Vivek 
 										 var wholesale_price_Step2 = Math.round(concept_wholesaleprice*(retail_price/base_price)*100)/100;
 										 if (wholesale_price_Step2=='') {
											 $('#wholesale_price_Step2_span').html('0');
										 }else {
											$('#wholesale_price_Step2_span').html(wholesale_price_Step2);
										 }
								  }else{
									  
											  $('#wholesale_price_Step2_span').html('0');
								  }
					 
					  // 07/15/2010 - Reema Kaur Attar
                     // Code added for Wholesale Price. This is for concept app.
					 
                      $('#retail_price3').keyup(function(){
 								  retail_price =  parseFloat(jQuery.trim(jQuery("#retail_price3").val()));
 								   if(retail_price>0){  // 07/16/2010 Added By Vivek 
 										 var wholesale_price_Step2 = Math.round(concept_wholesaleprice*(retail_price/base_price)*100)/100;
 										 if (wholesale_price_Step2=='') {
											 $('#wholesale_price_Step2_span').html('0');
										 }else {
											$('#wholesale_price_Step2_span').html(wholesale_price_Step2);
										 }
								  }else{
									  
											  $('#wholesale_price_Step2_span').html('0');
								  }
                        });
                       
  			       }else{
 					     //07/11/2010 - Reema Attar
                        // Modified the help tooltip to be more specific.
                       var tooltipmsg='This is the selling price of your app in the app store.';
					   jQuery("#retail_price_tooltip p").html(tooltipmsg);
 					   jQuery(".blue_box").hide();
					   
					   
					   
					    jQuery("#retail_price3_label").html("Retail Price<span class='reqd'>*</span>:");
						jQuery("#retail_pricelabel").html("Retail Price<span class='reqd'>*</span>:");
					    
						 jQuery('#month_limit').show();
				         jQuery('#fundraising_span').hide(); 
					  
					  
					  
					  if(  (jQuery("#editproject2").val()==jQuery("#editproject").val()) && (jQuery("#editproject2").val()!='') ){
 						      retail_price=$('#retail_price2').val();
							  $('#retail').html('$'+retail_price);
							  wholesale=$('#wholesale2').val();
 						      var whole_amount_format = number_format(wholesale,"","",",");
 						      $('#whole_sale_span').html(whole_amount_format);
 							 if (selling_start) {
								  $('#retail_price').hide();
							 }
							 else {
								  $('#retail_price_label').hide();
							 }
							  
							  var month_limit2=$("#month_limit2").val();
							  
							 jQuery('#month_limit').hide();
				             jQuery('#fundraising_span').html(month_limit2+' Month(s)').show(); 
							
							
							
							 $('#retail_price').attr("readonly",true); 
							 $('#retail_price3').attr("readonly",true);
							 
 					  }else if((jQuery("#editproject2").val()!=jQuery("#editproject").val()) && (jQuery("#editproject2").val()!='') ){
					    $('#Planned_Retail_Price_Stage1').hide();
						$('#Planned_Retail_Price_Stage2').show();
						$('#retail').html('$'+retail_price);
						var whole_amount_format = number_format(wholesale,"","",",");
 						$('#whole_sale_span').html(whole_amount_format);
						$('#retail_price_label').hide();
						jQuery('#month_limit').show();
				        jQuery('#fundraising_span').hide(); 
							 
							  $('#retail_price').attr("readonly",false); 
							  $('#retail_price3').attr("readonly",false);
							 
						 
 					  }else{
						  $('#Planned_Retail_Price_Stage1').hide(); 
						  $('#whole_sale_span').html(0);
						  $('#retail_price_label').hide();
						  $('#retail_price').attr("readonly",false); 
						  $('#retail_price3').attr("readonly",false);
						  
						  jQuery('#month_limit').show();
				          jQuery('#fundraising_span').hide(); 
						    
						  
					  }
					   
					  
					  
					  if(retail_price!=0){
						 var whole_amount = 14000/(retail_price * buyer_finished_stage_pre_trans_fee);
					   }else{
						 var whole_amount = 0;
					   }
					
					whole_amount = Math.round(whole_amount);
 				    $('#wholesale').val(40000); 
					
					if (isNaN(whole_amount)) {
						 $('#whole_sale_span').html('0');
					 }else{
 						 var whole_amount_format = number_format(whole_amount,"","",",");
 					     $('#whole_sale_span').html(whole_amount_format);
						 $('#wholesale').val(whole_amount);
					 }
                     
                    
					
					
					/// Added By Vivek 
					///  code added for back condition and change on app status
					
					          if(retail_price>0){  // 07/16/2010 Added By Vivek 
 								  var wholesale_price_Step2 = Math.round(payback_finished_stage_per_dev_tran_fee*(retail_price/base_price)*100)/100;
 								  //wholesale_price_Step2 = Math.round(wholesale_price_Step2);
									if (wholesale_price_Step2== '') {
											$('#wholesale_price_Step2_span').html('0');
											}
										else {
										   $('#wholesale_price_Step2_span').html(wholesale_price_Step2);
										}
							  }else{
								       $('#wholesale_price_Step2_span').html('0'); 
 							  }
					
					
					
					// 07/15/2010 - Reema Kaur Attar
                     // Code added for Wholesale Price. This is for finished app.
                      $('#retail_price').keyup(function(){
                         retail_price = parseFloat(jQuery.trim(jQuery("#retail_price").val()));
 							  
							  if(retail_price>0){  // 07/16/2010 Added By Vivek 
 								  var wholesale_price_Step2 = Math.round(payback_finished_stage_per_dev_tran_fee*(retail_price/base_price)*100)/100;
 								  //wholesale_price_Step2 = Math.round(wholesale_price_Step2);
									if (wholesale_price_Step2== '') {
											$('#wholesale_price_Step2_span').html('0');
											}
										else {
										   $('#wholesale_price_Step2_span').html(wholesale_price_Step2);
										}
							  }else{
								       $('#wholesale_price_Step2_span').html('0'); 
 							  }
                       });
					 
					   //07/11/2010 - Reema Attar
                       // Commented the Logic for Wholesale Copies Available, as we are hardcoding the value to  40,000
                            /*
 					       $('#retail_price').keyup(function(){
								  retail_price = parseFloat($('#retail_price').val());
								 //var unit_cost = $('#total_whole_sale_amount').attr('unit_cost');
								if(retail_price!=0){
								   var whole_amount = 14000/(retail_price * buyer_finished_stage_pre_trans_fee);
								}else{
									var whole_amount = 0;
								}
								whole_amount = Math.round(whole_amount);
								
								if (isNaN(whole_amount)) {
									$('#whole_sale_span').html('0');
									$('#wholesale').val(0);
								}
								else {
									var whole_amount_format = number_format(whole_amount,"","",",");
									$('#whole_sale_span').html(whole_amount_format);
									$('#wholesale').val(whole_amount);
								}
						});
   				   
				   $('#retail_price3').keyup(function(){
								  retail_price = parseFloat($('#retail_price3').val());
								 //var unit_cost = $('#total_whole_sale_amount').attr('unit_cost');
								if(retail_price!=0){
								   var whole_amount = 12500/(retail_price * buyer_finished_stage_pre_trans_fee);
								}else{
									var whole_amount = 0;
								}
								whole_amount = Math.round(whole_amount);
								
								if (isNaN(whole_amount)) {
									$('#whole_sale_span').html('0');
									$('#wholesale').val(0);
								}
								else {
									var whole_amount_format = number_format(whole_amount,"","",",");
									$('#whole_sale_span').html(whole_amount_format);
									$('#wholesale').val(whole_amount);
								}
						});*/
   				   }
 				//wholesale=$('#wholesale').val();
 				// alert(checkv);
				
	    /////////////////////// 14July2010 Added By Vivek Mishra //////////////////////
		///  
		///   Step 2 Variable. 
 				
				$('#wholesale').val(40000);
				var wholesale=$('#wholesale').val();
				
 		////////////////////////////////////////////////////////////////////////////////
		
		
				if(checkv=='' || checkv=='undefined'){   //alert(wholesale);
					  checkv =$('#next_s').val('1'); //alert(checkv);
 				      $('#error_step2').hide();
   				      return false;
 			    }else if( (parseFloat(retail_price)==0 || retail_price=='') || retail_price=='$' ){
				      $('#error_step2').html('Please enter the Planned Retail Price.');
				      $('#error_step2').show();
				      return false;	
				}else if( ( (parseFloat($('#retail_price3').val())==0 || $('#retail_price3').val()=='') || $('#retail_price3').val()=='$') && (add_stage_value==1) ){
 				    $('#error_step2').html('Please enter the Planned Retail Price.');
				    $('#error_step2').show();
				    return false;	
				}else if(wholesale == ''  || wholesale == 0){
					 $('#error_step2').html('Number of wholesale units for sale is required.');
			         $('#error_step2').show();
					return false;
                //07/11/2010 - Reema Attar
                // Added mandatory field for Selling Deadline                             
                }else if(month_limit == '' ){
                 $('#error_step2').html('Please select the Selling Deadline.');
                 $('#error_step2').show();
                 return false;	
				}else{
   					index=2;
 					$('#error_step2').hide();
					checkv='';
 					me.goTo(index);	
					
  				}
			}
		 
		if(index==2){
			
			///////////////  Add New Step3 Condition
			
			
  			 if(checkv=='' || checkv=='undefined'){
  				 checkv =1; 
 				 $('#error_step3').hide();
   				 return false;
			 }else if((document.getElementById("for_all").checked==false && document.getElementById("for_network").checked==false && document.getElementById("for_network_all").checked==false)){
 				 $('#error_step3').html('Please choose an option to indicate Who can buy your app.');
			     $('#error_step3').show();
				 return false;
			 }else if( (emails=='' || emails=='Enter email addresses, separated by commas, of people in your network who should be able to buy your app.') && document.getElementById("for_network").checked==true  ){
 			    $('#error_step3').html('Please enter the email addresses of the people you would like to add to your network.');
			    $('#error_step3').show();
  				return false;
			}else if( (document.getElementById("for_network").checked==true || document.getElementById("for_network_all").checked==true) && document.getElementById("custom_email").checked==true && (subject=='')  ){
 				 $('#error_step3').html('Please enter a Subject for the email to be sent to your network.');
			     $('#error_step3').show();
 				return false;
			}else if( (document.getElementById("for_network").checked==true || document.getElementById("for_network_all").checked==true ) && document.getElementById("custom_email").checked==true && (message=='')  ){
 				 $('#error_step3').html('Please enter the Email Message to be sent to your network.');
			     $('#error_step3').show();
 				return false;
			}else if(validemails!=true && (document.getElementById("for_network").checked==true || document.getElementById("for_network_all").checked==true) ) {
 				$('#error_step3').html('Please enter valid email addresses of the people you would like to add to your network.');
			    $('#error_step3').show();
 				return false;
			}else{
 				 index=3;
				 me.goTo(index);
				 $('#error_step3').hide();
				 checkv='';
			}
 		}
		
		if(index==3){
			
 		/////////////////////// 14July2010 Added By Vivek Mishra //////////////////////
		///   New Step4 Code is here below 
		///   add_stage_value=1  use for concept stage variable And add_stage_value=2 use for finished stage 
		///   include/inc_footer.inc
 		///   base_price=0.99
 		///   concept_wholesaleprice=0.35;
		///   concept_dev_pre_revenue=0.25;
		///   finished_wholesaleprice=0.45;
		///   finished_dev_pre_revenue=0.35;
		///   step4_string use in shoow dynamic string on step4.
		
		
		
		
		
		
		
		
			 if(add_stage_value==1){  
				    var retail_price = parseFloat(jQuery.trim(jQuery("#retail_price3").val()));
					
 					var wholesale_price=Math.round(concept_wholesaleprice*(retail_price/base_price)*100)/100;
 					var pre_tran_rev_per_app=Math.round(concept_dev_pre_revenue*(retail_price/base_price)*100)/100;
					var post_tran_rev_per_app=Math.round((wholesale_price-pre_tran_rev_per_app)*100)/100;
 				    var step4_string="The wholesale price of your app is $"+wholesale_price+". You will receive $"+pre_tran_rev_per_app+" upfront  per purchased app and you will receive $"+post_tran_rev_per_app+" where each app sells on the app store.";
 					$('#step4_text').html(step4_string);
					
					   var min_wholesale_copies = parseInt($('#min_wholesale_copies').val());
					   var min_amount         = parseInt(min_wholesale_copies * pre_tran_rev_per_app);
					   var min_purchase_limit = parseInt(min_wholesale_copies * post_tran_rev_per_app);
					   if(min_amount>0){ $('#min_amount').val(min_amount); }else{  $('#min_amount').val('');  }
					   if(min_purchase_limit>0){ $('#min_purchase_limit').val(min_purchase_limit); }else{ $('#min_purchase_limit').val('');  }
					   var max_amount = parseInt(max_wholesale_copies * pre_tran_rev_per_app);
					   var max_purchase_limit = parseInt(max_wholesale_copies * post_tran_rev_per_app);
 					   if(max_amount>0){ $('#max_amount').val(max_amount); }else{  $('#max_amount').val('');  }
					   if(max_purchase_limit>0){ $('#max_purchase_limit').val(max_purchase_limit); }else{ $('#max_purchase_limit').val('');  }
					   //alert(min_amount);
					  
  			 }else{
 				    var retail_price = parseFloat(jQuery.trim(jQuery("#retail_price").val()));
					var wholesale_price=Math.round(payback_finished_stage_per_dev_tran_fee*(retail_price/base_price)*100)/100;
 					var pre_tran_rev_per_app=Math.round(payback_con_stage_per_dev_tran_fee*(retail_price/base_price)*100)/100;
					var post_tran_rev_per_app=Math.round((wholesale_price-pre_tran_rev_per_app)*100)/100;
 					var step4_string="The wholesale price of your app is $"+wholesale_price+". You will receive $"+pre_tran_rev_per_app+" upfront  per purchased app and you will receive $"+post_tran_rev_per_app+" where each app sells on the app store.";
 					$('#step4_text').html(step4_string);
					
					   var min_wholesale_copies = parseInt($('#min_wholesale_copies').val());
					   var min_amount         = parseInt(min_wholesale_copies * pre_tran_rev_per_app);
					   //alert(min_amount);
					   var min_purchase_limit = parseInt(min_wholesale_copies * post_tran_rev_per_app);
					   if(min_amount>0){ $('#min_amount').val(min_amount); }else{  $('#min_amount').val('');  }
					   if(min_purchase_limit>0){ $('#min_purchase_limit').val(min_purchase_limit); }else{ $('#min_purchase_limit').val('');  }
					   var max_amount = parseInt(max_wholesale_copies * pre_tran_rev_per_app);
					   var max_purchase_limit = parseInt(max_wholesale_copies * post_tran_rev_per_app);
 					   if(max_amount>0){ $('#max_amount').val(max_amount); }else{  $('#max_amount').val('');  }
					   if(max_purchase_limit>0){ $('#max_purchase_limit').val(max_purchase_limit); }else{ $('#max_purchase_limit').val('');  }
					
					
					
  			 }
			// alert($('#step4_text').html());
 			 
			if(jQuery("#editproject2").val()==jQuery("#editproject").val() && jQuery("#editproject2").val()==''){   
			
			/* condition for add sell */
    			    jQuery("#max_amount").attr("readonly",true);
				    jQuery("#min_amount").attr("readonly",true);
				    jQuery("#min_purchase_limit").attr("readonly",true);
				    jQuery("#max_purchase_limit").attr("readonly",true);
 					jQuery('#min_wholesale_copies').attr("readonly",false);
 					jQuery('#max_wholesale_copies').attr("readonly",false);
  			   $('#whole_sale_span_step4').show();
			   $('#edit_whole_sale_span_step4').show();
			   $('#edit_section').hide();
			   $('#max_limit').hide();
			   $("#fundraising").show() ;
			   
			  if(add_stage_value==1){  
				 
					if(checkv==''){ 
									   // Comment By Vivek Mishra
									  //  $('#sell_max_copy').val('40000');   
									 //   $('#max_amount').val('10000');
									//    var whole_amount_step4 =10000;
					   
				   }
			  }else{
				   if(checkv==''){  
 						      //  $('#sell_max_copy').val('40000');
							 //  Comment By Vivek Mishra 
 						    //   $('#max_amount').val('14000'); 
						   //    var whole_amount_step4 = Math.round(12500/(retail_price * buyer_finished_stage_pre_trans_fee));	
						  //     var whole_amount_step4_format =  number_format(whole_amount_step4,"","",",");
						 //      $('#whole_sale_span_step4').html(whole_amount_step4_format);
				   }
 			  }
			   
			   
   			}else if(jQuery("#editproject2").val()==jQuery("#editproject").val() && jQuery("#editproject2").val()!=''){
 			  // Edit Case 
			   $('#whole_sale_span_step4').hide();
			   $('#edit_whole_sale_span_step4').hide();
			   $("#fundraising").hide() ;
			
			   if (selling_start) {
			  	 	$('#add_section').show();
					$('#edit_section').hide(); 
			   }
			   else {
			    	$('#edit_section').hide(); 
			   }
			   
			   $('#max_limit').hide();
			   
			 if (selling_start) {
			    jQuery("#max_amount").attr("readonly",true);
				jQuery("#min_amount").attr("readonly",true);
				jQuery("#min_purchase_limit").attr("readonly",true);
				jQuery("#max_purchase_limit").attr("readonly",true);
				jQuery('#min_wholesale_copies').attr("readonly",true);
				jQuery('#max_wholesale_copies').attr("readonly",true);
			 }
			   
			   
			   
			   
 			}else if(jQuery("#editproject2").val()!=jQuery("#editproject").val() && jQuery("#editproject2").val()!=''){
 			   $('#whole_sale_span_step4').show();
			   $('#edit_whole_sale_span_step4').show();
			   $('#edit_section').hide();
			   $("#fundraising").show() ;
			   
			    jQuery("#max_amount").attr("readonly",true);
				    jQuery("#min_amount").attr("readonly",true);
				    jQuery("#min_purchase_limit").attr("readonly",true);
				    jQuery("#max_purchase_limit").attr("readonly",true);
 					jQuery('#min_wholesale_copies').attr("readonly",false);
 					jQuery('#max_wholesale_copies').attr("readonly",false);
			   
			
			if(add_stage_value==1){  
			       if(checkv==''){ 
							   //  $('#max_amount').val('10000');
							  //   var whole_amount_step4 =10000;
							 //    $('#sell_max_copy').val('40000');
				   }
			  }else{
			  	  if(checkv==''){  
				       //    $('#max_amount').val('14000');
			   		  //     var whole_amount_step4 = Math.round(12500/(retail_price * buyer_finished_stage_pre_trans_fee));	
 					 //      var whole_amount_step4_format =  number_format(whole_amount_step4,"","",",");
 			   	    //       $('#whole_sale_span_step4').html(whole_amount_step4_format);
				   //        $('#sell_max_copy').val('40000');
				  }
 			  }
 			}else{
 			  // $('#whole_sale_span_step4').show();
			   $('#edit_whole_sale_span_step4').show();
			   $('#edit_section').hide();
			   $("#fundraising").show() ;
			   if(add_stage_value==1){  
 			   	    
					if(checkv==''){ 
								   // $('#max_amount').val('10000');
								  //  var whole_amount_step4 =10000;
								 //   $('#sell_max_copy').val('40000');
					}
			  }else{
			  	   if(checkv==''){  
							 //  $('#max_amount').val('14000');
							//   var whole_amount_step4 = Math.round(12500/(retail_price * buyer_finished_stage_pre_trans_fee));	
						   // 	 var whole_amount_step4_format =  number_format(whole_amount_step4,"","",",");
						  //     $('#whole_sale_span_step4').html(whole_amount_step4_format);
						 //      var whole_amount_step4 =14000;
						//       $('#sell_max_copy').val('40000');
 				   }
 			  }
 			}
			
		     if(add_stage_value==1){
 					//$('#max_limit').html('Note:  Maximum Amount to Raise should be less than $10,000.');	
 					var price=buyer_concept_stage_pre_trans_fee*100;
					price = Math.round(price);
 					
  			 }else{
				   // $('#max_limit').html('Note:  Maximum Amount to Raise should be less than $14,000.');	
 				    var price = (retail_price * buyer_finished_stage_pre_trans_fee)*100;
 				    price = Math.round(price);
  			 } 
			 
			 
			 
			 
	    /////////////////////// 14July2010 Added By Vivek Mishra //////////////////////
		///   How many wholesale copies do you want to sell?
		///      1- min_wholesale_copies   2- max_wholesale_copies
		///         3- min_amount                          |     4- max_amount
		///         5- min_purchase_limit                  |     5- max_purchase_limit
		 	 
 	       
		   $('#min_wholesale_copies').keyup(function(){
						    var min_wholesale_copies = parseInt($('#min_wholesale_copies').val());
 							 if(min_wholesale_copies<min_copy_limit){
							      $('#error_step4').html('Minimum number of wholesale copies for sale is 100.');
				                  $('#error_step4').show();
								  $('#min_amount').val('');
								  $('#min_purchase_limit').val('');
							 }else{
							      $('#error_step4').html('');
				                  $('#error_step4').hide();
 								   var min_amount         = parseInt(min_wholesale_copies * pre_tran_rev_per_app);
								   var min_purchase_limit = parseInt(min_wholesale_copies * post_tran_rev_per_app);
  							       
								  if(min_amount>0){ $('#min_amount').val(min_amount); }else{  $('#min_amount').val('');  }
								  if(min_purchase_limit>0){ $('#min_purchase_limit').val(min_purchase_limit); }else{ $('#min_purchase_limit').val('');  }
 							}
  		 });
	   
          $('#max_wholesale_copies').keyup(function(){
						     var max_wholesale_copies = parseInt($('#max_wholesale_copies').val());
 							 if(max_wholesale_copies>max_copy_limit){
							      $('#error_step4').html('Maximum number of wholesale copies for sale is '+number_format(max_copy_limit,"","",","));
				                  $('#error_step4').show();
								   $('#max_amount').val('');
								   $('#max_purchase_limit').val(''); 
							 }else{
							      $('#error_step4').html('');
				                  $('#error_step4').hide();
 								  var max_amount = parseInt(max_wholesale_copies * pre_tran_rev_per_app);
								  var max_purchase_limit = parseInt(max_wholesale_copies * post_tran_rev_per_app);
								  
								  if(max_amount>0){ $('#max_amount').val(max_amount); }else{  $('#max_amount').val('');  }
								  if(max_purchase_limit>0){ $('#max_purchase_limit').val(max_purchase_limit); }else{ $('#max_purchase_limit').val('');  }
  							 }
  		 });
		 
		 var buy_min_purchase_copy=parseInt(jQuery.trim($('#buy_min_purchase_copy').val()));  
		 var buy_max_purchase_copy=parseInt(jQuery.trim($('#buy_max_purchase_copy').val()));  
		 var min_wholesale_copies = parseInt(jQuery.trim($('#min_wholesale_copies').val()));
         var max_wholesale_copies = parseInt(jQuery.trim($('#max_wholesale_copies').val()));
		  
		  
		 if(checkv==''  ){
				  checkv =$('#next_s').val('1');  
				  return false;
		  }else if( (min_wholesale_copies<min_copy_limit) && ( min_wholesale_copies!=''  &&  min_wholesale_copies!=0 ) ){
				  $('#error_step4').html('Minimum number of wholesale copies for sale is '+min_copy_limit+'.');
				  $('#error_step4').show();
				  return false;
		  }else if( (max_wholesale_copies>max_copy_limit) && (  max_wholesale_copies!=''  &&  max_wholesale_copies!=0 )){
				  $('#error_step4').html('Maximum number of wholesale copies for sale is '+number_format(max_copy_limit,"","",","));
				  $('#error_step4').show();
				  return false;
		  }else if( (max_wholesale_copies<min_wholesale_copies) && (  max_wholesale_copies!=''  &&  max_wholesale_copies!=0 ) && (  min_wholesale_copies!=''  &&  min_wholesale_copies!=0 ) ){
				  $('#error_step4').html('Minimum number of units that the seller wants to sell should be less than Maximum number of units that the seller wants to sell');
				  $('#error_step4').show();
				  return false;
		  }else if( (buy_min_purchase_copy<min_copy_limit)  && ( buy_min_purchase_copy!=''  &&  buy_min_purchase_copy!=0 ) ){
				  $('#error_step4').html('Minimum wholesale copies that a buyer should buy '+min_copy_limit+'.');
				  $('#error_step4').show();
				  return false;
		  }else if( (buy_max_purchase_copy>max_copy_limit) && ( buy_max_purchase_copy!=''  &&  buy_max_purchase_copy!=0 ) ){
				  $('#error_step4').html('Maximum wholesale copies that a buyer should buy '+number_format(max_copy_limit,"","",","));
				  $('#error_step4').show();
				  return false;
		  }else if( (buy_max_purchase_copy<buy_min_purchase_copy) && (  buy_max_purchase_copy!=''  &&  buy_max_purchase_copy!=0 ) && (  buy_min_purchase_copy!=''  &&  buy_min_purchase_copy!=0 ) ){
				  $('#error_step4').html('Minimum wholesale copies that a buyer should buy should be less than Maximum wholesale copies that a buyer should buy.');
				  $('#error_step4').show();
				  return false;
		  }else if((buy_min_purchase_copy>min_wholesale_copies) && (  buy_min_purchase_copy!=''  &&  buy_min_purchase_copy!=0 ) && (  min_wholesale_copies!=''  &&  min_wholesale_copies!=0 ) ){
				  $('#error_step4').html('Minimum wholesale copies a buyer can buy should be less than or equal to the minimum number of wholesale copies you want to sell.');
				  $('#error_step4').show();
				  return false;
		  }else if( (buy_max_purchase_copy>max_wholesale_copies) && (  max_wholesale_copies!=''  &&  max_wholesale_copies!=0 ) && (  buy_max_purchase_copy!=''  &&  buy_max_purchase_copy!=0 ) ){
				  $('#error_step4').html('Maximum wholesale copies a buyer can buy cannot be greater than the maximum wholesale copies you want to sell.');
				  $('#error_step4').show();
				  return false;
		  }else if(selling_start){
		 
		    if( (parseFloat(max_amount)<=parseFloat(total_selling_amount)) && parseFloat(max_amount)!=0 && max_amount!='' && max_amount!='$' && parseFloat(total_selling_amount)!=0){
				$('#error_step4').html('Maximum amount to raise should be greater than $'+total_selling_amount);
				$('#error_step4').show();
 			    return false;
			}
  		 }else{
								var min_amount = parseFloat(jQuery.trim(jQuery("#min_amount").val()));
								var max_amount = parseFloat(jQuery.trim(jQuery("#max_amount").val()));
								var min_purchase_limit = parseFloat(jQuery.trim(jQuery("#min_purchase_limit").val()));
								var max_purchase_limit = parseFloat(jQuery.trim(jQuery("#max_purchase_limit").val()));
								var month_limit = parseFloat(jQuery.trim(jQuery("#month_limit option:selected").val()));
 								index=4
								me.goTo(index);
								$('#error_step4').hide();
								//checkv='';
 		  }
  		}
		//alert(index);
		//alert(checkv.val());
		if(jQuery.trim(checkv.val())==''){
 			me.goTo(0);
			return false;
		}
		
	   if (index < 3){
		        // me.goTo(++index);
		}else{
  			var free_feature='';
			var premium_feature='';
			var url ='';
			var approval_required=0;
		   	
			if(add_stage_value==1){   
			   retail_price=$("#retail_price3").val();
 			 }
			 
			 
			 if(document.getElementById("for_network").checked==true){
				var my_network_only=1; 
			 }else if(document.getElementById("for_network_all").checked==true){
				var my_network_only=2; 
			 }else{
 				 var my_network_only=0;
			 }
			 
			 
			 if(document.getElementById("standard_email").checked==true){
			   var mail_type=0;       // standard email
			 }else{
			    var mail_type=1;	 //custom email 
			 }
			 
			 
			 
		 // alert(max_amount);
			 
	     var buy_min_purchase_copy = parseInt($('#buy_min_purchase_copy').val());  
		 var buy_max_purchase_copy = parseInt($('#buy_max_purchase_copy').val());  
		 var min_wholesale_copies  = parseInt($('#min_wholesale_copies').val());
         var max_wholesale_copies  = parseInt($('#max_wholesale_copies').val());
		 
		 
		 
		 
		 jQuery.ajax({
					type: "POST",
					url: "../src/post_apps.php",
					data: "app_title="+app_title+"&app_description="+app_description+"&add_product_audience="+app_product_audience+"&add_stage="+add_stage_value+"&expected_launch="+expected_launch+"&retail_price="+retail_price+"&free_feature="+free_feature+"&premium_feature="+premium_feature+"&money_purpose="+money_purpose+"&url="+url+"&wholesale="+wholesale+"&min_amount="+min_amount+"&max_amount="+max_amount+"&min_purchase_limit="+min_purchase_limit+"&max_purchase_limit="+max_purchase_limit+"&my_network_only="+my_network_only+"&approval_required="+approval_required+"&app_category="+app_category+"&month_limit="+month_limit+"&apple_app_id="+apple_app_id+"&website_app="+website_app+"&emails="+emails+"&subject="+subject+"&message="+message+"&editproject="+editid+"&network_setting="+network_setting+"&min_copy_sell="+min_wholesale_copies+"&max_copy_sell="+max_wholesale_copies+"&min_copy_for_buyer="+buy_min_purchase_copy+"&max_copy_for_buyer="+buy_max_purchase_copy+"&mail_type="+mail_type,
					success: function(responsetext){
  						 var res=jQuery.trim(responsetext); 
 						// alert(res);
						 var rsarray= res.split("##"); 
 						 var projectnewid=''; 
						 var error_step=0;
						  if(rsarray[0]!="Success"){
 							 var error_step=jQuery.trim(rsarray[1]);
							 var error_div=parseInt(error_step)+1;
 							 $('#error_step'+error_div).html(rsarray[0]);
							 $('#error_step'+error_div).show();
							
							 index=error_step;
 							 me.goTo(index);
							 
							 jQuery("ol").attr("class","tabs step-"+ (error_div));
							// jqObj.find("div.internal-tab-content:eq(" + error_step + ")").show().siblings("div.internal-tab-content").hide();
							 
  				             return false;	
 						}
						else {
							var projectnewid=jQuery.trim(rsarray[1]);
 			                $('#error_step4').hide();
							if(editid==''){
 							    window.location = "app_detail.php?project_id="+projectnewid+"&new=projectnew" ;
							}else{
							    window.location = "app_detail.php?project_id="+projectnewid+"&new=projectupdate" ;	
 							}
							closePopup();
						}
					}
				}); 
 			
 		}
		
	
	}
	this.prev = function ()	{
		if (index > 0){
 			me.goTo(--index);
			checkv='';
		}
	}
	
	backButton.click(function () { me.prev(); });
	nextButton.click(function () { me.next(); });
}

function number_format( number, decimals, dec_point, thousands_sep ) {


	  var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;

	  var d = dec_point == undefined ? "," : dec_point;

	  var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";

	  var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

	   

	  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");

}


function makeNextDisable(val){
	
	  if(jQuery.trim(val)!=''){ 
	    $("#next_buttom").enable();
 	  }else{
	    $("#next_buttom").disable();
		$(".msg-error").hide();
	  }
	
}


function checkDuplicate(val){
	
	  var editid='';
      if(jQuery("#editproject2").val()==jQuery("#editproject").val() && jQuery("#editproject2").val()!=''){
 			      editid=jQuery("#editproject2").val();
 	  }else if(jQuery("#editproject2").val()!=jQuery("#editproject").val() && jQuery("#editproject2").val()!=''){
 			     editid='';
	  }
 	  if(jQuery.trim(val)!=''){ 
 		 $.post("src/checkduplicateapp.php",{action:"post",editproject:editid,app_title:val},function(data){
 			    var res=jQuery.trim(data); 
				//alert(data)
     			 if(res!=0){
				  $('#error_step1').html(res);
				  $('#error_step1').show();
				  $("#next_buttom").disable();
 				}else{
				   jQuery("#error_step1").hide();
				   $("#next_buttom").enable();
 				}  
 		   });
  	  }else{
	    $("#next_buttom").disable();
		$(".msg-error").hide();
	  }
	
}


