// JavaScript Document
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function showSignUp()
{
document.getElementById("signup").style.display="block";
  singnupRelocate();
  document.getElementById("signup").style.display = "block";
  document.body.onscroll = singnupRelocate;
  window.onscroll = singnupRelocate;
 // window.setTimeout("closeSignUp()", 10000);//This is for to close the Popup window within mentioned seconds
 
 //document.body.onload = window.setTimeout("showSignUp()", 10000);//This is for to open the Popup window within mentioned seconds
 
disablePage();
}

function closeSignUp()
{
document.getElementById("signup").style.display="none";
enablePage();
}

function disablePage()
{

   var blurDiv = document.createElement("div");
   blurDiv.id = "blurDiv";
   //blurDiv.style.cssText = "position:absolute; top:0; right:0; width:" + screen.width + "px; height:" + screen.height + "px; 								background-color: #000000; opacity:0.5; filter:alpha(opacity=50)";
   
   blurDiv.style.cssText = "position:absolute; top:0; right:0; width:" + screen.width + "px; height:1060px; 								background-color: #000000; opacity:0.5; filter:alpha(opacity=50)";
    
   document.getElementsByTagName("body")[0].appendChild(blurDiv);
   }


function enablePage()
{
    var blurDiv = document.getElementById("blurDiv");
    blurDiv.parentNode.removeChild(blurDiv);
}

/***** Start the Singup Popup window to fixed position(Center of the page) *****/
function singnupRelocate() {
  var scrolledX, scrolledY;
  if( self.pageYOffset ) {
    scrolledX = self.pageXOffset;
    scrolledY = self.pageYOffset;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
  } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
  }

  var centerX, centerY;
  if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
  } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
  }

  var leftOffset = scrolledX + (centerX - 450) / 2;
  var topOffset = scrolledY + (centerY - 200) / 2;

  document.getElementById("signup").style.top = topOffset + "px";
  document.getElementById("signup").style.left = leftOffset + "px";
}

/***** End of Singup Popup window to fixed position(Center of the page) *****/


/***** Start the Signup Drag function *****/
var Drag = {
	obj : null,
	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;
		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}
		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},
	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
/***** End of Signup Drag function *****/


var signUpCheckHttp; 
function signupValid()
{
   var userEmail=document.signup.email.value.trim();
   var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,15})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
   	if(document.signup.email.value=="")
	{
		alert("Please enter an email id");
		document.signup.email.focus();
		return false;
	}
	
	if (filter.test(userEmail))
	{
	testresults=true
	}
	else
	{
	alert("Please enter a valid email id")
	document.signup.email.focus();
	testresults=false;
	return (testresults)
	}
	var requestUrl="signup.jsp?email="+userEmail+"";
//alert(requestUrl);
addComments(requestUrl);
return false;
}

/* Send the mail to Administrator from signup.jsp */

function addComments(getUrl) 
	{
try
 {
 // Firefox, Opera 8.0+, Safari
 signUpCheckHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 
 try
  {
  signUpCheckHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  signUpCheckHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
 if(signUpCheckHttp==null)
{
alert("Your Browser doesn't support HTTP request");
}
  /* Print the message to use while checking the database: */

  document.getElementById('signup_send').innerHTML = "<img src='images_conference/ajax.gif'><br/>Please Wait...";

  signUpCheckHttp.onreadystatechange = CommentsRequestHttpResponse;
  signUpCheckHttp.open("POST",getUrl,true);
  //signUpCheckHttp.setRequestHeader("Content-length", parameters.length);
  //signUpCheckHttp.setRequestHeader("Connection", "close");
  signUpCheckHttp.send(null);

}

function CommentsRequestHttpResponse() 
  {
  //alert("Status = "+signUpCheckHttp.status);
  if (signUpCheckHttp.readyState == 4) 
  {
	  if (signUpCheckHttp.status == 200) 
	  {
		//alert("TExt:"+signUpCheckHttp.responseText);
		document.signup.reset();
		document.getElementById('signup_box_btn').style.display="none";
		document.getElementById('signup_send').innerHTML = "";
	    document.getElementById('signup_msg').innerHTML = "Thank you for your interest towards LocalBizSemiar.<br/>Your email id has been added to our mailing list.";
	    //alert("Thank you for your interest towards LocalBizSemiar.\nYour email id has been added to our mailing list.");
	  } 
	  else 
	  {
	  alert('Server connectivity problem. Please try again later.');
	  document.getElementById('signup_send').innerHTML = "";
	  }

  }
}


