    var concept_wholesale_price=		0.35;
	var finished_wholesale_price=		0.45;
	
	var concept_backer_received=		0.54;
	var finished_backer_received=		0.57;
	
	var concept_developer_received=	    0.25;
	var finished_developer_received=	0.35;
    var base_price=0.99
	var min_copy_limit=100;
	
	 
	
	
	var dtCh= "/";
	var today= new Date();
	var year = today.getFullYear(); 
	var minYear=year;
	//var maxYear=2500; // 
	var today = new Date();
	var maxYear=year+1;

	
	
     var category_image = new Array(3)
		category_image[1] = "images/icon_search_80x80.png"
		category_image[2] = "images/icon_social_80x80.png"
		category_image[3] = "images/icon_entertainment_80x80.png"
		
		category_image[4] = "images/icon_entertainment_80x80.png"
		category_image[5] = "images/icon_sports_80x80.png"
		category_image[6] = "images/icon_productivity_80x80.png"
		
		category_image[7] = "images/icon_calculate_80x80.png"
		category_image[8] = "images/icon_games_80x80.png"
		category_image[9] = "images/icon_news_80x80.png"
		
		category_image[10] = "images/icon_travel_80x80.png"
		category_image[11] = "images/icon_weather_80x80.png"
		
		
		category_image[12] = "images/icon_productivity_80x80.png"
		category_image[13] = "images/icon_productivity_80x80.png"
		category_image[14] = "images/icon_productivity_80x80.png"
		
		category_image[15] = "images/icon_productivity_80x80.png"
		category_image[16] = "images/icon_productivity_80x80.png"
		category_image[17] = "images/icon_productivity_80x80.png"
		
		category_image[18] = "images/icon_productivity_80x80.png"
		category_image[19] = "images/icon_productivity_80x80.png"
		category_image[20] = "images/icon_productivity_80x80.png"
		
		category_image[21] = "images/icon_productivity_80x80.png"
		category_image[22] = "images/icon_productivity_80x80.png"
		
		
		category_image[23] = "images/icon_productivity_80x80.png"
		category_image[24] = "images/icon_productivity_80x80.png"
		
		
		
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 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 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;					
  }
  function isSpclChar(val){
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    for (var i = 0; i < val.length; i++) {
      if (iChars.indexOf(val.charAt(i)) != -1) {
        jQuery("#register_error").html("Special characters not allowed in Name");
        jQuery("#register_error").show();
        return false;
      }
    }
  }
  
   function isNSpclChar(val){
    var iChars = "1234567890";
    for (var i = 0; i < val.length; i++) {
      if (iChars.indexOf(val.charAt(i)) != -1) {
        jQuery("#register_error").html("Numeric characters are not allowed in Name");
        jQuery("#register_error").show();
        return false;
      }
    }
  }
  
  
  ///////////////////////////////////////  Login Validation    /////////////////////////////////////////////////////////////
  
  function createLoginOnAppfundrAndForum(){
        var response     = loginvalidation();
        var emaillogin1  = jQuery.trim(jQuery("#emaillogin").val());
        var passwordreg1 = jQuery("#txtpassword").val();
		var page_name    = jQuery("#page_name").val(); 
        var appdetail    = jQuery("#appdetail").val(); 
	   // alert(appdetail);
	   
	   var Login1 = "Login";
       
	  if(response){
				
				
				jQuery("#login_error").html('');
				jQuery("#login_error").hide(); 
				
				var emaillogin= jQuery.trim(jQuery("#emaillogin").val());
				var passwordreg=jQuery("#txtpassword").val();	
				var autologin=0;
				
				 if(document.getElementById("autologin").checked==true){
 		          var   autologin=1;
	             } 
				

					
					jQuery('.ajax-loader').show();
					$.post("/src/login.php",{emaillogin:emaillogin1,password:passwordreg,Login:Login1,autologin:autologin},function(data){
				        
						 
						jQuery('.ajax-loader').show();
						
						var rs =jQuery.trim(data);
						var rsarray= data.split("##"); 
						var sessiondata=rsarray[1];
 						      if(jQuery.trim(rsarray[0])== "Success"){	
									 var session_id=data;
								  $.post("/src/forum_login.php",{username:emaillogin1,password:passwordreg,login:"Login"},function(data1){ 
									 
									 if(page_name=="index.php" || page_name=="sign_up.php"){
									     document.location.href = "/my_appbackr.php";
									 }else if(appdetail!=1){
										 document.location.href = "../../"+page_name; 
									 }else{
										 document.location.href = page_name;
									 }
									 
									  //document.location.href = "/marketplaceFeatured.php";
								 	 });	
							  }else{
								 jQuery("#login_error").html(data);
								 jQuery("#login_error").show(); 
							   }	
                 });	
          }	
           return false;	
        }
		
		
		
 		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 numbersonly2(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 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 changePassword(){
	document.getElementById('temp_password').style.display='none';
	document.getElementById('txtpassword').style.display='';
	document.getElementById('txtpassword').focus()
}

function restorePassword(){
	if(document.getElementById('txtpassword').value==''){
		document.getElementById('temp_password').style.display='';
		document.getElementById('txtpassword').style.display='none'
	}
}
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
 	
}



function calculateWholesalePriceForMarket(copies,project_id,stage,retail_price,onprice){
  				 var min_copy_limit=100;	
     			  var copies=$('#unit_'+project_id).val();
 				 if(onprice=='market'){
				    var copies=$('#marketunit_'+project_id).val();
				  }
		    	if(stage==1){  
				    var wholesale_price=(concept_wholesale_price*(retail_price));
  					var pre_tran_rev_per_app=(concept_backer_received*(retail_price));
					var wholesaleBase=concept_wholesale_price;
					var backerBase=concept_backer_received;
					
    			 }else{
 					var wholesale_price=(finished_wholesale_price*(retail_price));
 					var pre_tran_rev_per_app=(finished_backer_received*(retail_price));
					var wholesaleBase=finished_wholesale_price;
					var backerBase=finished_backer_received;
   			  }
				 	//alert(wholesaleBase);	
				 	//alert(backerBase);
			 		
	        if(copies==''){
 				   return false;
			 }else{
 				 var  max_amount        = Math.round(parseFloat(copies * wholesale_price));
				 var  profit_app_per   =   (backerBase - wholesaleBase);
 				 var  profit_app_per   = Math.round(profit_app_per*(retail_price/base_price)*100)/100;
				      profit_total_app =    (profit_app_per * copies).round(2);
 				if(onprice=='market'){
 				   
				   if(max_amount>0){ 
				     $('#market_max_amount_'+project_id).html(max_amount.toPriceString()); 
					 $('#market_profit_amount_'+project_id).html(profit_total_app.toPriceString()); 
 					}else{ 
					  $('#market_max_amount_'+project_id).html('$');
					  $('#market_profit_amount_'+project_id).html('$'); 
					}
					
					
 				 }else{
 				    if(max_amount>0){ 
				     $('#unit_price_'+project_id).html(max_amount.toPriceString()); 
					  $('#unit_profit_amount_'+project_id).html(profit_total_app.toPriceString()); 
				    }else{ 
					  $('#unit_price_'+project_id).html('$');
					  $('#unit_profit_amount_'+project_id).html('$'); 
					}
					 
					 
				 }
 			 }
}


function validateMultipleEmailsCommaSeparated(value) {
   var value=jQuery.trim(value);
   var result = value.split(",");
    for(var i = 0;i < result.length;i++)
    if(!echeck(jQuery.trim(result[i]))) 
            return false;               
    return true;
}

 function isSpclChar(val){
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    for (var i = 0; i < val.length; i++) {
      if (iChars.indexOf(val.charAt(i)) != -1) {
        jQuery("#register_error").html("Special characters not allowed in Name");
        jQuery("#register_error").show();
        return false;
      }
    }
  }
  
   function isNSpclChar(val){
    var iChars = "1234567890";
    for (var i = 0; i < val.length; i++) {
      if (iChars.indexOf(val.charAt(i)) != -1) {
        jQuery("#register_error").html("Numeric characters are not allowed in Name");
        jQuery("#register_error").show();
        return false;
      }
    }
  }
  
  
  ////////////////////////////////  Registration Validation ////////////////////////////////////////////
  
  function registration(){
    var firstname= jQuery.trim(jQuery("#firstname").val());
    var lastname= jQuery.trim(jQuery("#lastname").val());
    var emailreg= jQuery.trim(jQuery("#emailreg").val());
    var passwordreg=jQuery("#passwordreg").val();	
    var confirmpassword=jQuery.trim(jQuery("#confirmpassword").val());
    var username=jQuery.trim(jQuery("#user_screen_name").val());

	
	
    /*var invitecode2=jQuery.trim(jQuery("#invitecode2").val());
    var invite_email=jQuery.trim(jQuery("#invite_email").val());*/
    var splitfirst=firstname.split(' ');
    var splitlast=lastname.split(' ') 

    if(firstname==''){
      jQuery("#register_error").html('First Name is required.');
      jQuery("#register_error").show();
      document.getElementById('firstname').focus();
      return false;
    } 

    if(splitfirst.length>1){
      jQuery("#register_error").html('First Name is required.');
      jQuery("#register_error").show();
      document.getElementById('firstname').focus();
      return false;
    }
    if (isSpclChar(firstname)==false ){
      document.getElementById('firstname').focus();
      return false;
    }
	
	if (isNSpclChar(firstname)==false ){
      document.getElementById('firstname').focus();
      return false;
    } 
	
   if(lastname==''){
      jQuery("#register_error").html('Last Name is required.');
      jQuery("#register_error").show();
      document.getElementById('lastname').focus();
      return false; 
    } 
    if(splitlast.length >2){
      jQuery("#register_error").html('Last Name is required.');
      jQuery("#register_error").show();
      document.getElementById('lastname').focus();
      return false;
    }
    if (isSpclChar(lastname)==false ){
      document.getElementById('lastname').focus();
      return false;
    } 

    if (isNSpclChar(lastname)==false ){
      document.getElementById('lastname').focus();
      return false;
    } 
	
	
	if(username==''){
	  jQuery("#register_error").html('Username is required.');
      jQuery("#register_error").show();
      document.getElementById('user_screen_name').focus();
      return false;	
		
	}
	
	 if(username.length <6){
      jQuery("#register_error").html('Username is minimum 6 character.');
      jQuery("#register_error").show();
      document.getElementById('user_screen_name').focus();
      return false;
    }
	
	

    if (echeck(emailreg)==false ){
      jQuery("#register_error").html('Valid email is required.');
      jQuery("#register_error").show();
      document.getElementById('emailreg').focus();
      return false;
    } 

   
      if(passwordreg==''){
        jQuery("#register_error").html('Password is required.');
        jQuery("#register_error").show();
        document.getElementById('passwordreg').focus();
        return false;
      } 
      if(passwordreg.length<6){
        jQuery("#register_error").html('Password is at minimum 6 characters.');
        jQuery("#register_error").show();
        document.getElementById('passwordreg').focus();
        return false;
      } 

      if(confirmpassword==''){
        jQuery("#register_error").show().html('Confirm Password is required.');
         document.getElementById('confirmpassword').focus();
         return false;
      }

      if(confirmpassword!=passwordreg){
        jQuery("#register_error").html('Confirm Password is not matching with Password.');
        jQuery("#register_error").show();
        document.getElementById('confirmpassword').focus();
        return false;
      } 

       if(document.getElementById("developer_yes").checked==false && document.getElementById("developer_no").checked==false){
 		jQuery("#register_error").html('Choose your sell apps  planning.');
        jQuery("#register_error").show();
        document.getElementById('developer_yes').focus();
        return false;
		
	   }
	   
/*	  
       if(document.getElementById("backer_yes").checked==false && document.getElementById("backer_no").checked==false){
 		jQuery("#register_error").html('Choose your buy apps  planning.');
        jQuery("#register_error").show();
        document.getElementById('backer_yes').focus();
        return false;
		
	   }
	   
*/	   
      if(document.getElementById("accept_terms").checked==false){
        jQuery("#register_error").html('Accept terms of use.');
        jQuery("#register_error").show(); 
		document.getElementById('accept_terms').focus();
        return false;
      }


      return true;
    } 
	
	
	
	 
	
	
	
	
	
	
	
	 function createRegistrationOnAppfundrAndForum(){
      var firstname= jQuery.trim(jQuery("#firstname").val());
      var lastname= jQuery.trim(jQuery("#lastname").val());
      var emailreg= jQuery.trim(jQuery("#emailreg").val());
      var passwordreg=jQuery("#passwordreg").val();	
      var invitecode=jQuery.trim(jQuery("#invitecode").val());	
 	  var username=jQuery.trim(jQuery("#user_screen_name").val());
	  var Login1 = "Login";
      var membertype='';
	   if(document.getElementById("developer_yes").checked==true){
 		     membertype=6;
	   } 
	   
	/*      
	   if(document.getElementById("backer_yes").checked==true){
 		     membertype=4;
	   }
	   
	   if(document.getElementById("developer_yes").checked==true && document.getElementById("backer_yes").checked==true){
 		     membertype=5;
	   } 
	   
	 */ 
	   
	 
	 if(document.getElementById("accept_terms").checked==true){
        var accept_terms=1;
      }else{
        var accept_terms='';
      }
      var response=registration();
     
	 if(response){  ///////////////////// Registration in Appbackr and Forum ////////////////////
	   jQuery('.ajax-loader').show();
       jQuery("#register_error").html('').hide();
	   //jQuery('.btnmedium').attr('disabled', 'disabled');
	   
	   
	   $.post("/src/post_registration.php",{firstname:firstname,lastname:lastname,emailreg:emailreg,passwordreg:passwordreg,invitation_key:invitecode,accept_terms:accept_terms,register:"register",membertype:membertype,username:username},function(data){
           //alert(data);
		   var rs =jQuery.trim(data);
 		   var rsarray= data.split("##"); 
		   var sessiondata=rsarray[1];
 		  
		   
			   if(jQuery.trim(rsarray[0])== "Success"){	 ///////////////////// Registration in Appbackr Forum Login ////////////////////
  						  $.post("/src/forum_login.php",{username:emailreg,password:passwordreg,login:"Login"},function(data1){  
						
						  jQuery('.ajax-loader').hide();
		                  jQuery('.btnmedium').attr('disabled', '');
						// alert(data1);
						   document.location.href = "/thank_you.php";
				 	   });	
				}else{
					jQuery("#register_error").html(data);
					jQuery("#register_error").show(); 
				    jQuery('.ajax-loader').hide();
					//jQuery('.btnmedium').attr('disabled', 'false');
				  //document.location.href = "index.php";
				}	
           });	
        }	

        return false;	
      }
	  
function recover_password(){
			
			 jQuery("#recover_msg").hide();
             jQuery("#recover_error").hide();
			
          var emailreset= jQuery.trim(jQuery("#emailreset").val());
          if (echeck(emailreset)==false) {
            jQuery("#recover_error").html('Invalid Email.');
            jQuery("#recover_error").show(); 
            document.getElementById('emailreset').focus(); 
            return false;  
          }else{
			  
			  jQuery('.ajax-loader').show();
			  
            jQuery.ajax({
              type: "GET",
              url: "/src/home_resetpwd.php",
              data: "emailreset="+emailreset,
              success: function(responsetext){
                var res=jQuery.trim(responsetext);
                
				jQuery('.ajax-loader').hide();
				
				if(res=="Send"){
                  jQuery("#recover_msg").html("A new password has been sent to your appbackr email id.");
                  jQuery("#recover_msg").show();
                  jQuery("#recover_error").hide();
                  jQuery("#emailreset").val('');
				  
				   setTimeout(function() {
					  jQuery("#recover_msg").hide();
 					}, 3000);
 						
				  
                }else{
                  jQuery("#recover_error").html(res);
                  jQuery("#recover_error").show();
                  document.getElementById('emailreset').focus();	
                }
              }
            });
                    return false;  
          }
		  return false;  
        }		  
		
		
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 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='';
	
	//alert(year+"<"+minYear+" || "+year+">"+maxYear);
	
	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;
   
}		


