 function Show_Popup(action, userid) {
	$('#pop').fadeIn(800);
 }

 function Close_Popup(id) {
  $('#pop').fadeOut(400);
  customweb_clear();
 } 

//custon web site
var interval;
function startCalc(){
   interval = setInterval("calc()",1);
}

function calc(){
   var check = 0;
   var main=0; 
   var calmainPage=0;
   var mainPage = document.getElementById("mainPage").value;
    if(mainPage >= 1){ 
      main = (mainPage-1) * 150;
      calmainPage =  200 + main;  
      document.getElementById("mainAuto").value = calmainPage;
    } 
   var inPage = document.getElementById("inPage").value; 
    document.getElementById("inAuto").value = inPage * 50;
     
   var antispamPage = document.getElementById("antispamPage").value; 
    document.getElementById("antispamAuto").value = antispamPage * 75;
   if(document.webForm.checkWB.checked){
    check += 270;
   }
    if(document.webForm.checkLogo.checked){
    check += 200;
   }
  
     document.getElementById("total").value = calmainPage + (inPage * 50)  + (antispamPage * 75) + check;

}

function stopCalc(){
  if(interval != null){
    clearInterval(interval);
  }
}

function web_validate(){
  
  var errors = "";
  var valid = true;
  var webName = document.getElementById("webName").value
    if((webName == "* Your Name:") ||(webName == "")){
      errors +="*Name is Required\n";
      valid = false;
      $("#webName").addClass('error'); 
     } else{ $("#webName").removeClass('error'); }
  var webEmail = document.getElementById("webEmail").value
    if((webEmail == "* E-Mail:") ||(webEmail == "")){
       errors += "*Email is Required  \n";
       valid = false;
        $("#webEmail").addClass('error');
     } else { $("#webName").removeClass('error'); } 
   if(!echeck(webEmail)){
      errors += "*Inavlid Email Format";
      valid = false;
      $("#webEmail").addClass('error'); 
   } else { $("#webName").removeClass('error');}
  if(!valid){
     addError(errors);  
   }
  else{
   
     update();
   }
}


function addError(id){
  alert(id);	

}


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					
	}

//post custom web file:

function update()
{	
	
	var customweb_name = $("#webName").val();
	var customweb_email = $("#webEmail").val();
	var customweb_pn = $("#webPhone").val();
	if((customweb_pn == "Phone:" ) || (customweb_pn == "" ))
	{
		customweb_pn = " ";
	}
	var customweb_link = $("#webUrl").val();
	if((customweb_link == "Website URL:" ) || (customweb_link == "" ))
	{
		customweb_link = " ";
	}
	var customweb_note = $("#webComment").val();
	if((customweb_note == "Need a 2 page custom web design." ) || (customweb_note == "" ))
	{
		customweb_note = " ";
	}
//
        var WB = "NO";
        if(document.getElementById("wpBlog").checked == true){ WB = "YES"; }

        var logoDesign = "NO";
        if(document.getElementById("logoDesign").checked == true){ logoDesign = "YES"; }
        var customweb_antiSpam = $("#antispamPage").val(); 
//
	var customweb_HPD = $("#mainPage").val();
 	var customweb_APS = $("#inPage").val();
        var filename = "";
	var customwebdesignTOTAL = $("#total").val();	
  // alert(customwebdesignTOTAL);
		$.ajax({
	   type: "POST",
	   url: "update.php",	     
	   data:"field=CustomWeb&Name="+customweb_name+
	         "&Email="+customweb_email+
			 "&Phone="+customweb_pn+
	         "&URL="+customweb_link+"&Note="+customweb_note+"&HomePage="+customweb_HPD+
			 "&InsidePage="+customweb_APS+"&Wordpress="+WB+"&Logodesign="+logoDesign+"&AntiSpam="+customweb_antiSpam+			      			 			 
			 "&TOTAL="+customwebdesignTOTAL+"&Filename="+filename,
			 
	   success: function(msg){	   	
	   	//$("#pop").html("<img src='images/loading_green.gif' alt='Loading..'></img>");
        $("#paypalform").html(msg);
	$("#paypalform form")[0].submit();	
	   }
	 });
}

function customweb_clear()
{
	$("#webName").val("* Your Name:");
	$("#webName").removeClass('error');	
	$("#webEmail").val("* E-Mail:");
	$("#webEmail").removeClass('error');		
	$("#webPhone").val("Phone:");
	$("#webPhone").removeClass('error');
	$("#webUrl").val("Website URL:");
	$("#webComment").val("Need a 2 page custom web design.");
	$("#mainPage").val("1");
	$("#mainAuto").val("200");
        $("#antispamPage").val("1");
	$("#antispamAuto").val("75");
        $("#inPage").val("1");
        $("#inAuto").val("50");
        $("#total").val("325");
}

