// Social Media Toolbar

// This toolbar has three modes of display:
// Open:	Fully opened and expanded, viewer can see recent tweets and social media links - not stored as a state in webstateManager
// Closed:	Still visible, but viewer can only see the top "Facebook" area - uses code "c" in webstateManager
// Hidden:	No longer visible, with the exception of the tab - uses code "h" in webstateManager

$(function() {
	$("#social-media-toolbar #toolbar-tab a").click(function(e) {
		e.preventDefault();
		toggleSMT();
	});
	
	$("#social-media-toolbar #toolbar-tab1 a").click(function(e) {
		e.preventDefault();
		toggleSMT();
	});

	$("#social-media-toolbar a#hide-bar").click(function(e) {
		e.preventDefault();
		hideSMT();
	});

    // get the value from the webstate cookie for the social media toolbar (smt) key
    var cookieValue = webstateManager.getWebstateValue("smt");

    // only valid starting states are hidden and closed
    // default to closed state
    var clazz = "closed";

    // if the value is hidden, use that value
    if (cookieValue == "h") {
        clazz = "hidden";
    }

    // Set the toolbar class to value determined above
    $("#social-media-toolbar").attr("class", clazz);
});

function toggleSMT() {

	// I'll animate my content closed
	$("#social-media-toolbar .content").animate({
		"height": "toggle"
	}, 500);

	// Class-setting logic: If I was open before, I must be closed now
	if ($("#social-media-toolbar").hasClass("open")) {
		$("#social-media-toolbar").attr("class","closed");
        // store the closed value in the webstateManager for next visit
        webstateManager.setWebstateValue("smt","c");
        twitterWidget.stop();
	}

	// Class-setting logic: If I was closed (or hidden) before, I must be open now
	else {
		$("#social-media-toolbar").attr("class","open");
        twitterWidget.start();
	}
}

function hideSMT() {

	// If the user wants to hide me:
	// I'll hide my content, I'll put a "hidden" class on myself, and I'll remember to stay discreet
	$("#social-media-toolbar").attr("class", "hidden");
	$("#social-media-toolbar .content").css("display","none");
    // store the hidden value in the webstateManager for next visit
    webstateManager.setWebstateValue("smt","h");
    twitterWidget.stop();
}



 function valid()
{
  
 if( document.ask_now.name.value=="")
  {
   alert("Please enter your name!!");
   document.ask_now.name.focus();
   return false;
  }
  
   if( document.ask_now.enquiry.value=="")
  {
   alert("Please enter your enquiry!!");
   document.ask_now.enquiry.focus();
   return false;
  }
  
 if(document.ask_now.email.value == "" ) {
	alert("Kindly enter your E-mail ID.");
	document.ask_now.email.focus();
	return false;
   }
   if (document.ask_now.email.value.length != 0){ 
		var e_check  = document.ask_now.email.value;
		if(document.ask_now.email.value.indexOf(" ") != -1)	{
			alert("Kindly enter correct E-Mail ID without any spaces in it.");
			document.ask_now.email.focus(); 
			return false;
		}

		if(document.ask_now.email.value.indexOf("@") == -1)	{
		alert("Invalid E-Mail ID! Kindly enter correct E-Mail ID.");
		document.ask_now.email.focus(); 
		return false;
		}
	   	validarr = document.ask_now.email.value.split("@");
	   	if(validarr[0].length==0) {
	   		alert("Invalid E-Mail ID! Kindly enter the correct E-mail ID.");
	   		document.ask_now.email.focus(); 
	   	return false;
   		}
	  	if(validarr[1].indexOf("@") >=0) {
		   	alert("Invalid E-Mail ID! Kindly enter the correct E-mail ID.");
		   	document.ask_now.email.focus(); 
	   	return false;
	   	}
	   	if(validarr[1].length==0) {
		   	alert("Invalid E-Mail ID! Kindly enter the correct E-mail ID.");
		   	document.ask_now.email.focus(); 
		   	return false;
	   	}
	   	if(validarr[1].length != 0){ 
			if(validarr[1].indexOf(".") == -1){
				alert("Invalid E-Mail ID! Kindly enter the correct E-mail ID.");
				document.ask_now.email.focus(); 
				return false;
			}
			validemail = validarr[1].split(".");
		   if(validemail[0].length==0){ 
			 alert("Invalid E-Mail ID! Kindly enter the correct E-mail ID.");
			 document.ask_now.email.focus(); 
			 return false;
			}
			if(validemail[1].length==0){
				alert("Invalid E-Mail ID! Kindly enter the correct E-mail ID.");
				document.ask_now.email.focus(); 
				return false;
			}
		}
	}


}


 function demo_valid()
{
  
 if( document.appointment.datetime.value=="")
  {
   alert("Please select appointment date!!");
   document.appointment.datetime.focus();
   return false;
  }
  
 if( document.appointment.msg.value=="")
  {
   alert("Please write your enquiry!");
   document.appointment.msg.focus();
   return false;
  }
  
   if( document.appointment.email_a.value=="")
  {
   alert("Please enter your email!");
   document.appointment.email_a.focus();
   return false;
  }
  

return true;
}

