var d = new Date();
t=d.getTime();
var queueSize2=0;
function initPics(){
	
	
	$('#fileField').fileUpload({
			'uploader': 'upload/uploader.swf',
			'script': 'upload/upload.php',
			'folder': 'rfp',
			'cancelImg': 'upload/cancel.png',
			'cancelImg': 'upload/cancel.png',
			'onComplete': function (evt, qid, file, resp, data){
						submitForm(resp);
						queueSize2 = 0;
						},
			onCancel: function (a, b, c, d) {
					 queueSize2 = d.fileCount;
					  },
			onClearQueue: function (a, b) {
							queueSize2 = b.fileCount;
							},
			onSelect: function (a, b) {
						queueSize2++;
						},
			onSelectOnce: function (a, b) {
							queueSize2 = b.fileCount;
							}
	});
	
	$('#contactForm').submit(function() {
				checkForm();
        })
	return false;
	
}

function submitForm(fileName){
          var inputs = [];
          $(':input', '#contactForm').each(function() {
            inputs.push(this.name + '=' + (this.value));
          })
		  jQuery.ajax({
            data: "fileName="+fileName+"&"+inputs.join('&'),
			type: "GET",
            url: "submitRFP.php",
			dataType: "json",
            timeout: 10000,
            error: function() {
				//alert("fokus");
            },
            success: function(json) { 
			 if(json.status==1){
				 $("#contactForm").hide("slow", function(){
														  $("#contactForm").html("<center><img src=images/thankyou.jpg vspace=80></center>");
														  $("#contactForm").show("slow");
														  });
				} else {
					error=json.status;
					alert (error);
				}
            }
          })
		  return false;
	}

function checkForm(){
		//alert (t);
		var inputs = [];
		var wrong=0;
		  for(var i=0; i<=2;i++){
			  if($("input:eq("+i+")","#contactForm").val()==''){
					  $("input:eq("+i+")","#contactForm").css({"border":"solid 1px #ff0000","background-color":"#FFEBEB"});
					  wrong++;
			  } else {
				  $("input:eq("+i+")","#contactForm").css({"border":"solid 1px #00cc00","background-color":"#EBFFED"});
					 
			  }
		  }
		  if(wrong==0){
			  	$("#error").html("Please wait!");
				//document.getElementById("contactForm").submit();
				if(queueSize2>0){
				  $('#fileField').fileUploadSettings('scriptData','&fileName='+t);
				  $('#fileField').fileUploadStart();
				  } else {submitForm(0);}
			  } else $("#error").html("Please fill all required filds!");
	}
function submitRFP() {
                   $("#apDiv1").show();
				   $("#submitDiv").fadeIn("slow");
				   $("#poloska").hide();
				   //$("#ani").hide();   
         // return false;
        };	
$(function() { // onload...do
      initPics();
	  $("#closeRfp").click(function(){
				   $("#apDiv1").fadeOut();
				   $("#submitDiv").fadeOut("slow");
				   $("#poloska").show();
				   //$("#ani").show()
		  return false;
        });
	  })