$(function(){
	$('#a a')
		.css( {backgroundPosition: "-20px 35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-20px 35px"})
			}})
		})
	/*$('#b a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-150px 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-300px 0)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
			}})
		})
	$('#c a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
	$('#d a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})*/
});
            $(document).ready(function(){
				
                $("#contactLink").click(function(){
					document.getElementById('names').value=''	;
					document.getElementById('email').value=''	;
					document.getElementById('message').value=''	;
					document.getElementById('spam').value=''	;
                    if ($("#contactForm").is(":hidden")){
                        $("#contactForm").slideDown("slow");
						$("#contactLink").hide();
                    }
                    else{
                        $("#contactLink").show();
						$("#contactForm").slideUp("slow");
						
                    }
                });
                
			$("#closed").click(function(){
					document.getElementById('names').value=''	;
					document.getElementById('email').value=''	;
					document.getElementById('message').value=''	;
					document.getElementById('spam').value=''	;
                    if ($("#contactForm").is(":hidden")){
                        $("#contactForm").slideDown("slow");
						 setTimeout('$("#contactLink").show()',2000);
						
                    }
                    else{
                        $("#contactLink").show();
						$("#contactForm").slideUp("slow");
						
                    }
                });
  	    //setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
		   
		   
		   });
            
            function closeForm()
			{
			 var email = $('[name=email]').val();
			 var spam = document.getElementById('spam').value;
			 if($('[name=names]').val()=='')
				 {
				 $("#messageError").show("slow");
				 $("#messageValidEmail").hide();
				 $('[name=names]').focus();
				 }
			 	else if (echeck(email)==false)
					{
					$("#messageValidEmail").show("slow");
					$("#messageError").hide();				
					$('[name=email]').focus();
					}
			 else if(document.getElementById('message').value=='')
			  	{
				$("#messageValidEmail").hide();
				$("#messageError").show("slow");
				//document.getElementById('message').focus();
				}
				else if((spam=='') ||(spam!='11'))
			  	{
				$("#messageValidEmail").hide();
				$("#messageError").show("slow");
				$('[name=spam]').focus();
				//document.getElementById('message').focus();
				}
				else
				{
				$("#messageError").hide();
				$("#messageValidEmail").hide();
				var names 	= $('[name=names]').val();
				var message = $('[name=message]').val();
				Do_Email(names,email,message);
				}
           }

function Do_Email(names,email,message) {   

if (searchReq.readyState == 4 || searchReq.readyState == 0) {
//	var str = escape(document.getElementById('txtSearch').value);
		searchReq.open("GET", 'ajax.php?mail='+email+'&cname='+names+'&des='+message, true);
		searchReq.onreadystatechange = handleEmailResult; 
		searchReq.send(null);
	}		
}
function handleEmailResult() {
	if (searchReq.readyState == 4) 
	{
	var str = trim(searchReq.responseText);
		if(str=='send')
		{
	//$("#messageError").show("slow");
	$("#messageSent").show("slow");
    setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
		}
		else
		{
	$("#messageSentError").show("slow");
    setTimeout('$("#messageSentError").hide();$("#contactForm").slideUp("slow")', 2000);
		}
	}
}



function Contact_sales()
{
var fname 		= escape(document.getElementById('fname').value);	
var company 	= escape(document.getElementById('company').value);	
var ccode		= escape(document.getElementById('ccode').value);	
var scode 		= escape(document.getElementById('scode').value);	
var phone 		= escape(document.getElementById('phone').value);	
var ext 		= escape(document.getElementById('ext').value);	
var mail 		= escape(document.getElementById('mail').value);	
var web 		= escape(document.getElementById('web').value);	
var des 		= escape(document.getElementById('des').value);	
var comment 	= escape(document.getElementById('comment').value);	
var spam 		= escape(document.getElementById('spam').value);	

if((spam=='') ||(spam!='11'))
{
//$("#messageSent").hide();	
$("#spamerror").show("slow");	
//alert('cc');
}
else if (fname=='')
{
$("#spamerror").hide();		
$("#fnameerror").show("slow");		
}
else if (echeck(mail)==false)
{
$("#spamerror").hide();		
$("#fnameerror").hide();
$("#emailerror").show("slow");
}
else if (des=='')
{
$("#spamerror").hide();		
$("#fnameerror").hide();
$("#emailerror").hide();
$("#detailserror").show("slow");
}
else
{
$("#detailserror").hide();
$("#spamerror").hide();		
$("#fnameerror").hide();
$("#emailerror").hide();
 phone = ccode + scode + phone + ext;
Contact_Sales(fname,company,  phone, mail, web, des, comment )
}
}
var searchReq = getXmlHttpRequestObject();
function Contact_Sales(name,company,  phone, mail, web, des, comment)
{
if (searchReq.readyState == 4 || searchReq.readyState == 0) {
	//	var str = escape(document.getElementById('txtSearch').value);
searchReq.open("GET", 'ajax.php?mail='+mail+'&cname='+name+'&phone='+phone+'&web='+web+'&des='+des+'&comment='+comment+'&company='+company, true);
		searchReq.onreadystatechange = handleContatctResult; 
		searchReq.send(null);
	}
}

function handleContatctResult() {
	if (searchReq.readyState == 4) 
	{
	var str = trim(searchReq.responseText);
		if(str=='send')
		{
	$("#ContactSent").show("slow");
//    $("#ContactSent").hide();
		}
		else
		{
	$("#ContactSentError").show("slow");
   // $("#messageSentError").hide();
		}
document.getElementById('fname').value=''	
document.getElementById('company').value=''	
document.getElementById('ccode').value=''	
document.getElementById('scode').value=''	
document.getElementById('phone').value=''	
document.getElementById('ext').value=''	
document.getElementById('mail').value=''	
document.getElementById('web').value=''	
document.getElementById('des').value=''	
document.getElementById('comment').value=''	
document.getElementById('spam').value=''	
	}
}


function echeck(str) 
{          // email validations 
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		  //  alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		  //  alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		  //  alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
	
/********* Ajax Blood *********/
function getXmlHttpRequestObject() 
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	} 
	else if(window.ActiveXObject) 
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
		alert("Your Browser is old!\nIt's about time to upgrade don't you think?");
	}
}





function trim(stringValue)
{
//return stringValue.replace(/(^\s*|\s*$)/, "");
return stringValue.replace(/^\s*(.*?)\s*$/,"$1")
}