$(document).ready(function(){
	$('div#loading').hide();
	process = 'conti';
	form_submit = function()
	{
		equiry = $("select#equiry").val();
		file   = $("input#attach_file").val();
		email  = $("input#email").val();
		//alert(file);return false;
		if(equiry == "Please select area of equiry")
		{
		  alert("Please select area of equiry.");
		  process = 'stop';
		  return false;
		}
		if(file == "")
		{
			$("input#attach_file").focus();
			alert("Please select a file.");
			process= 'stop';
			//$('<br/><span class="error-message">Please enter Your name.</span><br>').insertAfter("input#fname");
			return false;
		}else{
			process= 'conti';
		}
	
		if(email == "" || email == 'Enter your email')
		{
			$("input#email").focus();
			alert("Please enter Your email.");
			process= 'stop';
			//$('<br/><span class="error-message">Please enter Your email.</span><br>').insertAfter("input#email").show();
			return false;
		}else{
			process= 'conti';
		}
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(email) == false && email != '')
		{
			$("input#email").focus();
			alert("Please enter valid email address.");
			process= 'stop';
			//$('<br/><span class="error-message">Please enter valid email address.</span><br>').insertAfter("input#email");
			return false;
		}else{
			process= 'conti';
		}
		
		if(process == 'conti'){
			$('form#send_cv').submit();
			$('div#form-layout').hide();
			$('span.error-message').hide();
			$('div#loading').show('fast');
		}
	}
	stopUpload = function (success){
		if (success == 1){
			if(process == 'conti'){
				send_mail();
			}
		}
		return false;   
	}					   
						   
	send_mail = function(event){//alert("This is testing");
		
		//$('br ,span.error-message').remove();
		
		equiry = $("select#equiry").val();
		enquiry_text = $('select#equiry :selected').text()
		file   = $("input#attach_file").val();
		email  = $("input#email").val();
		//if(checkVersion()){
			var file_array = file.split("\\");
			if(file_array.length > 1)
				file = file_array[file_array.length-1];
			
			
		//}
		dataString = 'equiry='+equiry+'&file='+file+'&email='+email+'&message='+enquiry_text+'&send_mail='+1;
		$.ajax({
			url:"process.php",
			type: 'POST',
			data: dataString,
			cache: false,
			success:function(html)
			{
				if(html)
				{
						$('div#loading').fadeOut(5000).hide('fast', function(){
							$('div#form-layout').show();
							$("input#attach_file").val('');
							$("input#textbox").val('');
							$("input#email").val('');
							$('<div style="float:left"><span class="error-message success" style="color:#FFFFFF;">Your CV has been sent successfully.</span></div>').insertAfter("div#form-layout")
						});
					
				}else{
					
						$('div#loading').fadeOut(5000).hide('fast', function(){
							$('div#form-layout').show();
							$('<div style="float:left"><span class="error-message" style="color:#FFFFFF;">There is some issue with CV send process. Please try again.</span></div>').insertAfter("div#form-layout")
						});
				} 
			}
		});
		return false;
	}
});

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    return 1;
  } else {
	  return 0;
  }
  
}

