function newHTTPRequest(){
    var ajaxRequest; 
	var noerror = true;
    try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support ajax!");
				noerror =  false;
			}
		}
	}
    if(noerror){
    return ajaxRequest;
}else{
    return false;
}
}


function isNumber(_target){
    var result;
    for(i = 0; i < _target.length; i++){
        if(_target.charCodeAt(i)>47 && _target.charCodeAt(i)<58){
            result=true;
        }else{
            result = false;
            break;
        }
    } 
    return result;
}


function isValidEmail(email_id) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email_id) == false) {
      return false;
   }else{
    return true;
   }
}


function onStart(){
        document.getElementById('bottombar').innerHTML = '<a  href="javascript: toggleRequestForm()"id="formclose" align="right">X</a>'+
                                                            '<form id="callbackform" name="callbackform" class="cbform">'+
                                                            '<div><a>Name</a><br /><input type="text" size="10"/></div>'+
                                                            '<div><a>Phone</a><br /><input type="text" size="10"/></div>'+
                                                            '<div><a>Email</a><br /><input type="text" size="10"/></div>'+
                                                            '<div><a>Description</a><br />'+
                                                            '<textarea  style="width: 90%; font-size: 10px; padding: 0px; margin: 0px; height: 70px; font-family: verdana, arial, sans-serif;'+
                                                            ' font-style: normal; color: black; font-weight: normal; border: 1px solid yellow; resize: none;" rowds="5"></textarea></div>'+
                                                            '<div align="center"><button type="button" onclick="toggleRequestForm()">Submit</button></div>'+
                                                            '</form>';
    document.callbackform.reset();
    var s = setTimeout("slide()", 1000);

}
function hideRequestForm(){
     document.getElementById('bottombar').style.display = 'none';   
}

 var sliding;
function slide(){
    sliding = true;
    document.getElementById('bottombar').style.display = 'block';
    document.getElementById('bottombar').style.position = 'fixed';
    document.getElementById('bottombar').style.left= parseInt(document.documentElement.clientWidth)-parseInt(document.getElementById('bottombar').style.width) + 'px';
    document.getElementById('bottombar').style.zIndex = 1006;
    var clientheight = parseInt(document.documentElement.clientHeight);
    var finalTop = clientheight  - parseInt(document.getElementById('bottombar').style.height);
    var t = new Tween(document.getElementById('bottombar').style, 'top', Tween.strongEaseOut, clientheight, finalTop, 2, 'px')
    t.onMotionFinished = function(){
        sliding = false;
        document.getElementById('formclose').innerHTML = 'X'
    }
    t.start();
}
function toggleRequestForm(){
    if(sliding) return;
    var _from = parseInt(document.getElementById('bottombar').style.top);
    var _to = parseInt(document.documentElement.clientHeight)-20;
    if(_from <_to){
    var t1 = new Tween(document.getElementById('bottombar').style, 'top', Tween.strongEaseOut, _from, _to, 2, 'px');  
    t.onMotionFinished = function(){
    document.getElementById('formclose').innerHTML = '^'
    }
    t1.start();
    
    }else{
        slide();
    }
}
function slideRequestForm(){ 
   var limit = (parseInt(document.documentElement.clientHeight)/2) - (parseInt(document.getElementById('bottombar').style.height)/2);
   if (parseInt(document.getElementById('bottombar').style.top) < (limit+90)){
    //alert(document.getElementById('bottombar').style.top)
    document.getElementById('bottombar').style.top = parseInt(document.getElementById('bottombar').style.top)+10 + 'px';
   }else{
   alert(parseInt(document.getElementById('bottombar').style.top))
    window.clearInterval(slideInterval);
   }
}
//**************************AJAX FUNCTIONS************************



var isBusy = false;
function submitForm(){
    if(!isBusy){
        isBusy = true;
    var httpRequest = newHTTPRequest();
    httpRequest.onreadystatechange = function(){
		if(httpRequest.readyState == 4){
		      isBusy = false;
        	if(httpRequest.responseText == '1'){
        	   document.getElementById('status').style.color = "black";
        	   document.getElementById('status').innerHTML = 'Message sent successfully!';
               document.enquiry_form.reset();
        	}else{
        	   document.getElementById('status').style.color = "red";
        	   document.getElementById('status').innerHTML = 'Failed! could not send the message. Please try again.';
        	};
            
		}
	}
   var name = document.getElementById('custname').value;
   var email = document.getElementById('email').value;
   var p1 = document.getElementById('phone1').value;
   var p2 = document.getElementById('phone2').value;
   var message = document.getElementById('message').value;
if (document.getElementById('timec')!=undefined && document.getElementById('timez')!=undefined){
var time = document.getElementById('timec').value +' TZ: '+ document.getElementById('timez').value;
message = message +'&time='+time;
}
   if(name == '' || email == '' ||p1 == '' ||p2 == '' || message == ''){
            document.getElementById('status').style.color = "red";
            document.getElementById('status').innerHTML = 'Error! Please enter the required information.';
            isBusy = false;
            return false;
   }

   if (!isValidEmail(email)){
            document.getElementById('status').style.color = "red";
            document.getElementById('status').innerHTML = 'Error! invalid Email Address.';
            isBusy = false;
            return false;
   }

   if(!isNumber(p1) || !isNumber(p2) || (p1.toString()+p2.toString()).length<10){
            document.getElementById('status').style.color = "red";
            document.getElementById('status').innerHTML = 'Error! Please enter correct phone number.';
            isBusy = false;
            return false;
   }
if   (document.getElementById('dept')!= undefined){
 var dept = document.getElementById('dept').options[document.getElementById('dept').selectedIndex].value;
}else
{
 var dept = "Call back request form."
}
   var qstring = 'formsubmit.php?custname='+name+'&email='+email+'&phone1='+p1+'&phone2='+p2+'&dept='+dept+'&message='+message;
    //document.enquiry_form.action = qstring;
   //if(window.open(qstring, 'form submit', 'width=200, height=50, resizable=no, location=no'))     document.enquiry_form.reset();
	document.getElementById('status').innerHTML = '<img src="images/icons/4.gif" style="height: 16px; width: 16px;"/>&nbsp;&nbsp;&nbsp;Sending message, please wait...';
    httpRequest.open('POST', qstring, true);
    httpRequest.setRequestHeader("Content-Type", "text/xml");
	httpRequest.send(null); 
}//end if
}//end function


function showComments(){
var comments = ["Great resource, like having a tech team of your own.", "Very thorough and eventually solved what appeared to be a very knotty problem.", "The techs were very nice and knew exactly what to do very sure of himself and completely fixed my problem, confident tech… just keep the quality techs you have, and bless them for their patience foe people like me without much knowledge.", "Technicians were very friendly, helpful, knowledgeable and polite.", "I am grateful that I am able to have my home office function properly, thanks to your experts efforts. If provided with the opportunity, I will recommend friends and family to consult Fixtor with their technical difficulties.", "He is not only extremely knowledgeable about systems; he is one of the best examples of excellent customer service we have ever experienced. He spent the time to correctly analyze the problems and worked hard at resolving them. We felt confident that he would not only fix the mess on the hard drive, but also that he would not rush just to get the job done"];
var names = ["Carol, UK", "Steve, S.Africa", "Carol, Washington", "James, USA", "Eric, Alabama", "Rose, Washington", "Denise, Texas"];
var index = parseInt(document.getElementById('comnum').innerHTML);
document.getElementById('fbtext').innerHTML = comments[index];
document.getElementById('fbname').innerHTML = names[index];
document.getElementById('comnum').innerHTML = index + 1;

if(index==comments.length-1){ 
document.getElementById('comnum').innerHTML = 0;
}
var s = setTimeout("showComments()", 5000);
}

