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 SubmitResume(f)
{
	if(f.name.value == "")
	{
		alert("Provide name");	
		f.name.focus();
		return false;
	}
	if(f.email.value == "" || !echeck(f.email.value))
	{
		alert("Provide valid E-mail");
		f.email.focus();
		return false;
	}
	if(f.phone.value == "")
	{
		alert("Provide valid phone number");
		f.phone.focus();
		return false;
	}
	if(f.skils.value == "")
	{
		alert("Provide your primary skill set");
		f.skils.focus();
		return false;
	}
	if(f.filepath.value == "")
	{
		alert("Please upload your resume");	
		return false;
	}
	$("#loader").show();
	var d = $("#resume").serialize();
	$.ajax({
	   type: "POST",
	   url: "submit-resume.php",
	   data: d,
	   success: function(msg)
	   {
		 if(msg == "Success")
		 {
			 alert("Your application successfully submitted");
			 $("#loader").hide();
			 overlay.close();
		 }
		 else
		 {
			alert("Failed. Try again"); 
		 }
	   }
	 });	
	return false;
}

function jobapply(s)
{
	document.resume.jobcode.value = s;
	overlay.load();
}

window.size = function() {
    var w = 0;
    var h = 0;
    //IE
    if (!window.innerWidth) {
        //strict mode
        if (!(document.documentElement.clientWidth == 0)) {
            w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
        }
        //quirks mode
        else {
            w = document.body.clientWidth;
            h = document.body.clientHeight;
        }
    }
    //w3c
    else {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    return { width: w, height: h };
}

window.center = function() {
    var hWnd = (arguments[0] != null) ? arguments[0] : { width: 0, height: 0 };
    var _x = 0;
    var _y = 0;
    var offsetX = 0;
    var offsetY = 0;
    //IE
    if (!window.pageYOffset) {
        //strict mode
        if (!(document.documentElement.scrollTop == 0)) {
            offsetY = document.documentElement.scrollTop;
            offsetX = document.documentElement.scrollLeft;
        }
        //quirks mode
        else {
            offsetY = document.body.scrollTop;
            offsetX = document.body.scrollLeft;
        }
    }
    //w3c
    else {
        offsetX = window.pageXOffset;
        offsetY = window.pageYOffset;
    }
    _x = ((this.size().width - hWnd.width) / 2) + offsetX;
    _y = ((this.size().height - hWnd.height) / 2) + offsetY;
    return { x: _x, y: _y };
}

function SendRequest(file)
{
	var f = document.download;
	var x = "";
	if(f.name.value == "")
	{
		$('#nameerror').html("Please provide your name");
		x = "1";
	}
	else
		$('#nameerror').html("");
	
	if(!echeck(f.email.value))
	{
		$('#emailerror').html("Please provide valid E-mail Address");
		x = "1";
	}
	else
		$('#emailerror').html("");
	
	if(f.phone.value == "")
	{
		$('#phoneerror').html("Please provide your phone number");
		x = "1";
	}
	else
		$('#phoneerror').html("");
		
	if(f.company.value == "")
	{
		$('#companyerror').html("Please provide your name");
		x = "1";
	}
	else
		$('#companyerror').html("");
	
	if(x == "")
	{
		$('#loader').css('visibility', 'visible');
		$.ajax({
		   type: "POST",
		   url: "submitRequest.php",
		   data: $('#download').serialize(),
		   success: function(msg){
			 //alert(msg);
			 if(msg == "Success")
			 {
				 $('#loader').html('<img src="images/ajax-loader.gif" width="16" height="16" align="absmiddle"/> Please wait PDF download will start shortly. If it is not started <a href="download.php?file=ZIETA_SAP_Services">click here</a>.');
				 //window.open("images/ezsief.pdf","ezSIEF");
				 window.location = 'download.php?file=' + file;
				 
			 }
			 else
			 {
				alert("Request Failed. Try again.");
				$('#loader').css('visibility', 'hidden');
			 }
		   }
		});	
	}
}