EmailPageHelper = function( )
{
}
EmailPageHelper.createInstance = function( doc, dynamicProperties)
{
	if( doc != null )
	{
		var helper = new EmailPageHelper();
		return helper;
	}
	return null;
}
var sendemailvar=null;
var self_ptr_sms_email=null;
var sendsmsvar=null;
var self_ptr_sms=null;
var divs="";
var spans="";
var index=0;
var checkList = null;

/**
 * Javascript function to send the promotional Emails.
 * The funtion makes an AJAX request to the Server and sends the 
 * list of email Id's
 */
EmailPageHelper.prototype.sendEmail=function()
{
  
  var your_name = document.getElementById('your_name').value;
  your_name=this.encode(your_name)
  var your_email = document.getElementById('your_email').value;
  var frend_email = document.getElementById('frend_email').value;
  var your_message = document.getElementById('your_message').value;
  var productPrice = document.getElementById('productPrice').value;
  var not_include_price = document.getElementById('not_include_price').value;
  var productUIDParameter=document.getElementById("productUIDParameter").value;
  your_message=this.encode(your_message)
	
  this.setMailResponse("Sending e-mail..");

  if(window.XMLHttpRequest)
    this.sendemailvar = new XMLHttpRequest();
  else
    this.sendemailvar = new ActiveXObject("MSXML2.XMLHTTP");
  var url = "/email-send-to-friend.do"+"?your_name="+your_name+"&your_email="+your_email+"&frend_email="+frend_email+"&your_message="+your_message+"&productPrice="+productPrice+"&not_include_price="+not_include_price+"&productUIDParameter="+productUIDParameter;
  this.sendemailvar.onreadystatechange = this.SendEmailCallBack;

  this.sendemailvar.open( "POST", url, true );
  self_ptr_sms_email = this;
  this.sendemailvar.send(null);
}
/**
 * The AJAX Call back function which is invoked when the client recieves a response from server
 * 1) This method resets the email text field
 * 2) Interprets the response of the server and conveys it to the user.
 */
EmailPageHelper.prototype.SendEmailCallBack=function()
{
  if(self_ptr_sms_email)
  {    
    var ajaxvar = self_ptr_sms_email.sendemailvar;

    //alert(self_ptr_sms_email);    
    if(ajaxvar.readyState == 4)
    {
      if(ajaxvar.status == 200)
      {
        var get1 = ajaxvar.responseText;
        self_ptr_sms_email.setMailResponse(get1);
        setTimeout(self_ptr_sms_email.resetMailResponse,2000);
      }
    }
  }
}
/**
 * Function to reset the mail response text
 */

EmailPageHelper.prototype.resetMailResponse=function()
{
  document.getElementById('your_name').value="Your name";
  document.getElementById('your_email').value="Your email address";
  document.getElementById('frend_email').value="Your friends' email address(es)";
  document.getElementById('your_message').value="";
  document.getElementById('mailresponse').innerHTML="";
  if(document.getElementById('cont_1'))
  {
    var y = document.getElementById('cont_1');
    y.style.display='none';
   }
   
}

	/**
	 * Sets the Email response box with the passed message
	 * @param textToSet The message which is to be set in the Email response box
	 */ 
	EmailPageHelper.prototype.setMailResponse=function(textToSet)
	{
	  document.getElementById('mailresponse').innerHTML=textToSet;
	   //document.getElementById('InputEmail').value="";
	}
	
	// public method for url encoding
	EmailPageHelper.prototype.encode=function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	EmailPageHelper.prototype.decode=function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	EmailPageHelper.prototype._utf8_encode=function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	EmailPageHelper.prototype._utf8_decode=function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 