/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;
var GB_ANIMATION = '';

function GB_show(caption, url, height, width) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
	if(caption == 'Recommend Us' || caption == 'FullView' || caption == 'DocView'|| caption == 'ContactForm'){
		var GB_DONE = false;
	 }
  if(!GB_DONE) {
	  if(caption != 'ContactForm'){
		var display = "<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>";
	  }else{
		var ContactDisplay = "<div id='GB_overlay'></div><div id='contact_window_1'></div>";
	  }
	  if(caption == 'Recommend Us'){
		  	  display += "<div id='rec_closeButton'><img src='closebox.png' alt='Close window'/></div>";
	  }
	  display += "</div>";
	  var rec_display =  "<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div><div id='rec_closeButton'><img src='/wp-content/round/closebox.png' alt='Close window'/></div>";

	  var full_display_top = "<div id='GB_overlay'></div><div  id='GB_window_1' >";
		full_display_top += "<div id='tellMeMore' class='iniWidth' style='width:0px;'><img src='/wp-content/round/TellMeMore.gif' border='0' alt='Tell Me More' align='right'>";
		full_display_top += "<div id='tmmForm' class='text'><div id='tmmError'></div>Hello,<br />My name is&nbsp;<input type='text' size='50' maxlength='50' id='tmmName' name='tmmName' class='midText italics' value='Your Name' title=''>&nbsp;and my email id is&nbsp;<input type='text' size='70' maxlength='50' id='tmmEmail' name='tmmEmail' class='midText italics' value='Your Email Address' title=''>.<br /> I work at&nbsp;<input type='text' size='50' maxlength='50' id='tmmCompany' name='tmmCompany' class='minText italics' value='Your Company Name' title=''>&nbsp;as&nbsp;<input type='text' size='50' maxlength='50' id='tmmDesignation' name='tmmDesignation' class='minText italics' value='Your Designation' title=''>&nbsp;and am based out of&nbsp;<input type='text' size='50' maxlength='50' id='tmmLocation' name='tmmLocation' class='minText italics' value='Your Location' title=''> .<br />I would like to know more about your solutions.<br /> Do please call me on my phone number which is&nbsp;<input type='text' size='50' maxlength='50' id='tmmPhone' name='tmmPhone' class='minText italics' value='Your Phone' title=''>.<br /><br />I think the demo is&nbsp;<input type='text' size='100' maxlength='255' id='tmmComment' name='tmmComment' class='maxText italics' value='Your Comment' title=''>.&nbsp;<input type='button' name='tmmSubmit' id='tmmSubmit' value='Send' class='tmButton normal'><input type='hidden' id='store' name='store' value=''><input type='hidden' id='tmmSession' name='tmmSession' value=''></div></div></div>";
	 var doc_display_top = "<div id='GB_overlay'></div><div  id='GB_window_1' ></div></div>"
	  if(caption == 'Recommend Us'){
		  $(document.body).append(rec_display);
	  }else if(caption == 'FullView'){
		  $(document.body).append(full_display_top);
	  }else if(caption == 'DocView'){
		  $(document.body).append(doc_display_top);
	  }else if(caption == 'ContactForm'){
		  $(document.body).append(ContactDisplay);
	  }else{
		$(document.body).append(display);
	  }
 
    $("#rec_closeButton img").click(JosephHide);
    $(window).resize(GB_position);
    GB_DONE = true;

  }


  $("#GB_frame").remove();
  if(caption == 'Recommend Us'){
	  $("#GB_window").append("<iframe id='GB_frame' src='"+url+"' frameborder='0'></iframe>");
	  $("#GB_caption").html(caption);
  }else if(caption == 'FullView'){
	 $("#GB_window_1").append("<div class='roundTop'></div> <div id='rec_closeButton_1'><img src='/wp-content/round/closebox.png' alt='Close window'/></div><div class='roundBack'><iframe  id='GB_frame_1' src='"+url+"' frameborder='0' scrolling='auto' class='autoHeight'></iframe></div><div class='roundBottom'></div>");
  }else if(caption == 'DocView'){
	 $("#GB_window_1").append("<div class='roundTop'></div> <div id='rec_closeButton_1'><img src='/wp-content/round/closebox.png' alt='Close window'/></div><div class='roundBack'><iframe  id='GB_frame_1' src='http://docs.google.com/gview?url="+url+"' frameborder='0' scrolling='auto' class='autoHeight'></iframe></div><div class='roundBottom'></div>");
  }else if(caption == 'ContactForm'){
	 $("#contact_window_1").append("<div class='contactRoundTop'></div> <div id='contact_closeButton'><img src='/wp-content/round/closebox.png' alt='Close window'/></div><div class='contactRoundBack'><div id='contactLoad' align='center'><img src='/stylusinc/Loader/ajax-loader.gif' border='0' align='center'><br>Page Loading. Please wait.</div><iframe  id='GB_frame_1' src='"+url+"' frameborder='0' scrolling='auto' class='autoHeight'></iframe></div><div class='contactRoundBottom'></div>");
  }

	$("#rec_closeButton_1 img").click(JosephHide_1);
	$("#tellMeMore img").click(JosephSlide);
	$("#tmmForm input").focus(function(){
		var textValue = $(this).val();
		var findValue = textValue.indexOf('Your');
		$('#store').val(textValue);
		if(findValue == '-1'){
			$(this).val(textValue);
		}else{
			$(this).val('');
		}
		$(this).removeClass('italics');
		$(this).addClass('normal');
	});
	$("#tmmForm input").blur(function(){
		var sValue = $('#store').val();
		var tValue = $(this).val();
		if(tValue == ''){
			$(this).val(sValue);
		}
		$(this).removeClass('normal');
		$(this).addClass('italics');
	});
	$("#tmmSubmit").click(JosephTmmForm);
	$("#contact_closeButton img").click(ContactHide);


	$("#GB_overlay").show();
	GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
}

function GB_hide() {
	$("#GB_frame").remove();
	 $("#GB_window,#GB_overlay").hide();
}

function JosephHide(){
    $("#GB_window").slideUp(300, function() { $(this).remove(); } ) ;
    $("#GB_overlay").slideUp(400, function() { $(this).remove(); } ) ;
	$("#GB_window,#GB_overlay").hide(500, function() { $(this).remove(); } ) ;
}

function ContactHide(){
    $("#contact_window_1").slideUp(300, function() { $(this).remove(); } ) ;
    $("#GB_overlay").slideUp(400, function() { $(this).remove(); } ) ;
	$("#GB_window,#GB_overlay").hide(500, function() { $(this).remove(); } ) ;
}

function JosephHide_1(){
    $("#GB_window_1").slideUp(300, function() { $(this).remove(); } ) ;
    $("#GB_overlay").slideUp(400, function() { $(this).remove(); } ) ;
}

function JosephSlide(){
    if($('#tellMeMore img').parent().attr('class') == 'iniWidth'){
		$('#tellMeMore img').parent().animate({width: 800}, '7000', function() {});
		$('#tellMeMore img').parent().removeClass('iniWidth');
		$('#tellMeMore img').parent().addClass('finalWidth');
		$('#tmmForm').show('slow');
	}else{
		$('#tellMeMore img').parent().animate({width: 35}, '7000', function() {});
		$('#tellMeMore img').parent().removeClass('finalWidth');
		$('#tellMeMore img').parent().addClass('iniWidth');
		$('#tmmForm').hide();
	}
	$.post("/stylusinc/tmmSession.php",{},
			function(data){
				if(data != 'Error'){
					$('#tmmSession').val(data);
				}
					
			}
	);
	return false;
}

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: ((w - GB_WIDTH)/2)+"px" });
  $("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
}

function JosephTmmForm(){
	$('#tmmError').hide();
	var tmmName			= $('#tmmName').val();
	var tmmEmail		= $('#tmmEmail').val();
	var tmmCompany		= $('#tmmCompany').val();
	var tmmDesignation	= $('#tmmDesignation').val();
	var tmmLocation		= $('#tmmLocation').val();
	var tmmPhone		= $('#tmmPhone').val();
	var tmmComment		= $('#tmmComment').val();
	var tmmSession		= $('#tmmSession').val();
	$.post("/stylusinc/tmmValidation.php",
		{ 'tmmName': tmmName,'tmmEmail': tmmEmail,'tmmCompany':tmmCompany,'tmmDesignation':tmmDesignation,'tmmLocation':tmmLocation,'tmmPhone':tmmPhone,'tmmComment':tmmComment,'tmmSession':tmmSession},
			function(data){
				if(data == 'Success'){
					var thankYou = "Thanks for sharing your views. We will contact you in the next 24 hours.<br />";
					thankYou += "If you like this solution, you might also like our specialised BI services such as<br />";
					/*thankYou += "<ul>";
					thankYou += "<li><a href='http://www.stylusinc.net/the-intelligent-business/technology-architecture/?menuId=32&parentId=2' border='0' title='Business and solutions metrics consulting'>Business and solutions metrics consulting</a></li>";
					thankYou += "<li><a href='http://www.stylusinc.net/the-intelligent-business/application-design/?menuId=11&parentId=2' border='0' title='Inbuilt intelligence for custom solutions'>Inbuilt intelligence for custom solutions</a></li>";
					thankYou += "<li><a href='http://www.stylusinc.com/services/EMR_Software.php' border='0' title='EMR software' target='_blank'>EMR software</a></li>";
					thankYou += "<li><a href='http://www.stylusinc.net/smart-framework/intelligence-in-your-pocket-mobile-technologies/?menuId=69&parentId=3' border='0' title='Mobile alerts for KPIs'>Mobile alerts for KPIs</li>";
					thankYou += "<li><a href='http://www.stylusinc.net/smart-framework/sql-server-reporting-services/?menuId=71&parentId=3' border='0' title='SQL server and related services'>SQL server and related services</a></li>";
					thankYou += "<li><a href='http://www.stylusinc.net/smart-framework/bi-using-ms-excel-2010-reports/?menuId=70&parentId=3' border='0' title='MS Excel real-time reports and dashboards'>MS Excel real-time reports and dashboards</li>";
					thankYou += "</ul>";*/
					thankYou += "<a href='http://www.stylusinc.net/the-intelligent-business/technology-architecture/?menuId=32&parentId=2' border='0' title='Business and solutions metrics consulting'>Business and solutions metrics consulting</a><br />";
					thankYou += "<a href='http://www.stylusinc.net/the-intelligent-business/application-design/?menuId=11&parentId=2' border='0' title='Inbuilt intelligence for custom solutions'>Inbuilt intelligence for custom solutions</a><br />";
					thankYou += "<a href='http://www.stylusinc.net/smart-framework/intelligence-in-your-pocket-mobile-technologies/?menuId=69&parentId=3' border='0' title='Mobile alerts for KPIs'>Mobile alerts for KPIs</a><br />";
					thankYou += "<a href='http://www.stylusinc.net/smart-framework/sql-server-reporting-services/?menuId=71&parentId=3' border='0' title='SQL server and related services'>SQL server and related servicesM</a><br />";
					thankYou += "<a href='http://www.stylusinc.net/smart-framework/bi-using-ms-excel-2010-reports/?menuId=70&parentId=3' border='0' title='MS Excel real-time reports and dashboards'>MS Excel real-time reports and dashboards</a><br />";
					$('#tmmForm').html(thankYou);
				}else{
					$('#tmmError').show();
					$('#tmmError').html('<center>Error. Please check the input.</center>');
				}
			}
	);

}