// JavaScript Document
function show_text_with_box(val)
{
	if(val==1)
	{
	//alert(val);
	document.getElementById("a1").style.visibility ='visible';
	}
}
function hide_text(val)
{
	if(val==1)
	{
	//alert(val);
	document.getElementById("a1").style.visibility ='hidden';
	}
}

function show_text(val)
{
	if(val==1)
	{
	document.getElementById("text_disp1").innerHTML = "<div class='hover-overlay' id='a1' onmouseout='javascript:hide_text(1);' onmouseover='javascript:show_text_with_box(1);' style='position:absolute; height:150px; width:150px; margin-left:100px; margin-top:-10px; color:#666666; background:url(http://www.mibura.com/oldsite/images/150-150.gif) no-repeat;'><p style='margin-top:8px;'><a href='tierad_storage.php'>Tiered Storage</a><br /><a href='backup_archiving.php'>Storage Clustering </a><br /><a href='replication.php'>Backup/ Archiving & Recovery</a><br /><a href='data_governance.php'>Data Replication</a><br /><a href='data_governance.php'>Data Governance</a><br /><a href='data_governance.php'>Parallel File System</a><br /><a href='data_governance.php'>Dynamic Data</a></p></div>";
	}
	
	if(val==3)
	{
	document.getElementById("text_disp1").innerHTML = "<div class='hover-overlay' id='a1' onmouseout='javascript:hide_text(1);' onmouseover='javascript:show_text_with_box(1);' style='position:absolute; height:130px; width:150px; margin-left:100px; background:url(http://www.mibura.com/oldsite/images/150-130.gif) no-repeat;'><p style='margin-top:8px;'><a href='application_acceleration.php'>Business Intelligence</a><br /><a href='wan_acceleration.php'>Collaboration</a><br /><a href='load_balancing.php'>Infrastructure</a><br /><a href='data_center_failover.php'>Enterprise Application</a><br /><a href='vpn.php'>Managed Services</a><br /><a href='mobile_client_acceleration.php'>Exchange &amp; SQL</a></p></div>";
	}
	if(val==5)
	{
	document.getElementById("text_disp1").innerHTML = "<div class='hover-overlay' id='a1' onmouseout='javascript:hide_text(1);' onmouseover='javascript:show_text_with_box(1);' style='position:absolute; height:100px; width:150px; margin-left:100px; background:url(http://www.mibura.com/oldsite/images/150-100.gif) no-repeat;'><p style='margin-top:8px;'><a href='virtual_computing.php'>Server Control</a><br /><a href='clustering.php'>I\O, Process, Utilization </a><br /><a href='server_automation.php'>High Performance Computing</a><br /><a href='compliance_configuration.php'>Clustering</a></p> </div>";
	}
}

function showbox(num){
	var box = document.getElementById("lbox"+num);
	box.style.display = "block";
}

function hidebox(num){
	var box = document.getElementById("lbox"+num);
	box.style.display = "none";
}

function submitForm(form){
	
	//validate fields
	
	var valid = true; //assume we're good for now.
	
	var reqd = {
		name : 	form['name'],
		email : form['email'],
		message : form['message']
	}
		
	for(field in reqd){
		if(reqd[field].value == '')	{
			
			reqd[field].style.background = "#ffffcc";
			reqd[field].style.border = "2px solid #ccc";
			
			valid = false;	
		}else{
			//restore 
			reqd[field].style.background = "#ffffff";
			reqd[field].style.border = "1px solid #ccc";
		}
	}
		
	if(!valid){	alert("Please fill all required fields"); return false; }
	
	//validate email
	if(!emailVal(reqd.email.value)) { 
		reqd.email.style.background = "#ffffcc";
		reqd.email.style.border = "2px solid #ccc";
		alert("Please enter a valid email");
		return false;
	}			 
	
	
	//disable form
	form.submit.disabled=true;
	
	var preloader = new Image();
	preloader.src = "images/ajax-loader-inline.gif";
	
	form.submit.parentNode.insertBefore(preloader, form.submit.nextSibling);
	
	form.submit.style.display = "none";
	//form.submit.value = "Comment Posted";
		
	var data = {
		name : reqd.name.value,
		email : reqd.email.value,
		message : escape(reqd.message.value)
	};
	
	var url = "contact-proc.php";
	
	var callback = {
		
		callback : function(response){
						
			if(/error/.test(response)){
				
				var error = response.split("=")[1];
				
				switch(error){
					case "failed_captcha":
					this.form["captcha"].style.background = "#ffffcc";
					this.form["captcha"].style.border = "1px solid #ccc";
					
					alert("Please enter the correct captcha");
					
					this.form.submit.disabled = false;
					this.form.comment.disabled = false;
					
					this.preloader.parentNode.removeChild(this.preloader);
					
					this.form.submit.style.display = "block";
					break;
				}
				
			}else{
				//var json = eval('(' + response + ')');								
				//restore form 								
				
				this.preloader.parentNode.removeChild(this.preloader);
				
				document.getElementById("msg").innerHTML = response;
				
				this.form.submit.style.display = "block";
			}
		
			
		},
		
		form : form,
		
		preloader : preloader
	};
		
	ajaxGet(url, data, callback);
	
	return false;

}

function emailVal(email) {
	
	if(email == '') { return false; }
	
	else if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return true;
	}
	
	
	return false;
}

