/* Code for track website Start added 15 march 2010*/
	var req;
function GetWebSiteClickSatelliteCity(id,ProfileMultiCitySatelliteID)
{


	loadXMLDoc("http://"+document.domain+"/PremiumEmail/Track/Track.aspx?ProfileID="+id+"&TrackID="+2+"&ProfileMultiCitySatelliteID="+ProfileMultiCitySatelliteID+"&ProductTypeID=3");
}
function GetWebSiteClick(id)
{
	loadXMLDoc("http://"+document.domain+"/PremiumEmail/Track/Track.aspx?ProfileID="+id+"&TrackID="+2+"&ProductTypeID=3");
}
function processReqChange() {
    // only if req shows "loaded"
  
    if (req.readyState == 4) 
    {
        if (req.status == 200) {
       
            // ...processing statements go here...
        } else {
            //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

/*function _Org()
 {
 if (document.referrer=="0" || document.referrer=="" || document.referrer=="-") return "";
 var i=0,h="",k;
 if ((i=document.referrer.indexOf("://")) < 0) return "";
 h=document.referrer.substring(i+3,document.referrer.length);
 if (h.indexOf("/") > -1) 
 {
  h=h.substring(0,h.indexOf("/"));
 }
 return h;
}


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}


//retrieve the keyword thru which user search the site
function _uOrg() 
{
	
	if (document.referrer=="0" || document.referrer=="" || document.referrer=="-") 
		return "";
	var i=0,h,k;
	if ((i=document.referrer.indexOf("://")) < 0) 
		return "";
	h=document.referrer.substring(i+3,document.referrer.length);
	if (h.indexOf("/") > -1) 
		h=h.substring(0,h.indexOf("/"));
	 
	for (var ii=0;ii<_uOsr.length;ii++) 
	{
		if (h.indexOf(_uOsr[ii]) > -1) 
		{
			if ((i=document.referrer.indexOf("?"+_uOkw[ii]+"=")) > -1 || (i=document.referrer.indexOf("&"+_uOkw[ii]+"=")) > -1) 
			{
				k=document.referrer.substring(i+_uOkw[ii].length+2,document.referrer.length);
				if ((i=k.indexOf("&")) > -1) k=k.substring(0,i);
					return _uEC(k);
			}
		}
	}
	
	if ((i=document.referrer.indexOf("?q=")) > -1 || (i=document.referrer.indexOf("&q=")) > -1) 
			{
				k=document.referrer.substring(i+_uOkw[ii].length+2,document.referrer.length);
				if ((i=k.indexOf("&")) > -1) k=k.substring(0,i);
					return _uEC(k);
			}
			
	return "";
}

// Encode the string
function _uEC(s) 
{
	var n="";
	if (!s || s=="") return "";
	for (var i=0;i<s.length;i++) 
	{
		if (s.charAt(i)==" ") 
			n+="+"; 
		else 
			n+=s.charAt(i);
	}
	return n;
}*/

function loadXMLDoc(url) 
{
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
	
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}

/* Code for track website end*/
// Javascript File //
/* Validations on the Profile Page "Mail Sending" and "Text Messaging" Send Buttons. */

/* This Function is called on the "Page Body Load" */
function Fill()
{
	var fullURL = parent.document.URL;
	var strKey = "";
	var strK = "";
	if(fullURL.indexOf('&r=')>-1)
	{
		var stIndex = fullURL.indexOf('&r=');
		var endIndex = 0;
		for(var m=stIndex+3; m<fullURL.length; m++)
		{
			if(fullURL.charAt(m) == '&')
			{
				endIndex = m;
				break;
			}
		}
		if(endIndex != 0)
		{
			strKey = fullURL.substring(stIndex + 3, endIndex);
		}
		if(strKey != "")
		{
			var key = "";
			for(var n=0;n<strKey.length;n++)
			{
				strKey = strKey.replace('+',' ');
			}
			for(var n=0;n<strKey.length;n++)
			{
				strKey = strKey.replace('%2B','+');
				strKey = strKey.replace('%2C',',');
				strKey = strKey.replace('%3B',';');
				strKey = strKey.replace('%3D','=');
				strKey = strKey.replace('%2F','/');
				strKey = strKey.replace('%3F','?');
				strKey = strKey.replace('%3A',':');
				strKey = strKey.replace('%26','&');
			}
			document.getElementById("r").value = strKey;
		}
		if(fullURL.indexOf('&p=')>-1)
		{
			var stIndex = fullURL.indexOf('&p=');
			var endIndex = 0;
			for(var m=stIndex+3; m<fullURL.length; m++)
			{
				if(fullURL.charAt(m) == '&')
				{
					endIndex = m;
					break;
				}
			}
			if(endIndex != 0)
			{
				strK = fullURL.substring(stIndex + 3, endIndex);
			}
			if(strK != "")
			{
				if(strK.indexOf('+in+')>-1)
				{
					strK = strK.substring(0,strK.indexOf('+in+'));
				}
				var key = "";
				for(var n=0;n<strK.length;n++)
				{
					strK = strK.replace('+',' ');
				}
				for(var n=0;n<strK.length;n++)
				{
					strK = strK.replace('%2B','+');
					strK = strK.replace('%2B','+');
					strK = strK.replace('%2C',',');
					strK = strK.replace('%3B',';');
					strK = strK.replace('%3D','=');
					strK = strK.replace('%2F','/');
					strK = strK.replace('%3F','?');
					strK = strK.replace('%3A',':');
					strK = strK.replace('%26','&');
				}
				document.getElementById("p").value = strK;
			}
		}
	}
}

/* This Function is called from the "Search Button" Click */
function combine()
{
	var str = "";
	if(document.getElementById("p").value != '' && document.getElementById("r").value != '')
	{
		str = document.getElementById("p").value + ' in ' + document.getElementById("r").value;
	}
	else if(document.getElementById("p").value != '')
	{
		str = document.getElementById("p").value;
	}
	else
	{
		str = document.getElementById("r").value;
	}

	if(document.getElementById("p").value != '' || document.getElementById("r").value != '')
	{
		document.getElementById("q").value = str;
	}
}

/* This function is used for preventing Post-Backing on different Events */
function noPostBack(e)
{
	if(document.all)
	{
		event.returnValue = false;
	}
	else
	{
		e.preventDefault();
		event.returnValue = false;
	}
}

function CheckDivheight()
{
	var contactbar = document.getElementById("contactbar").offsetHeight;
	var businessinformation = document.getElementById("businessinformation").offsetHeight; 

	if(contactbar > businessinformation)
	{
		document.getElementById("businessinformation").style.height = (contactbar) + 'px';
		document.getElementById("contactbar").style.height = (contactbar) + 'px';
	}
	else
	{
		document.getElementById("contactbar").style.height = (businessinformation) + 'px';
		document.getElementById("businessinformation").style.height = (businessinformation) + 'px';
	}
}

function unhideDivsAfterImageOnload()
{
    document.getElementById('imgCaptcha').style.display = 'block';
    /* For adjusting height of both the Divs (businessinformation and contactbar) on page load */
    CheckDivheight();
}

function CheckVideoHeightWidth()
{
    if(document.getElementById("imgCaptcha"))
	{
		document.getElementById("imgCaptcha").src = "http://"+document.domain+"/MultiCityEmail/SendEmailSMS/CaptchaImage.aspx";
        document.getElementById('imgCaptcha').onload = unhideDivsAfterImageOnload ;
	}

    if(document.getElementById("video") != null)
	{
	    document.getElementById("video").style.display = "";
		var divHeight = document.getElementById("video").offsetHeight;
		var divWidth = document.getElementById("video").offsetWidth;

		if(divHeight > 230 || divWidth > 280)
		{
			if (document.all)
			{
				var objV = document.getElementById("video").getElementsByTagName("object");
				var objembed = document.getElementById("video").getElementsByTagName("embed");
				if(objV[0])
				{
					objV[0].width = 280 + 'px';
					objV[0].height = 230 + 'px';
				}
				if(objembed[0])
				{
					objembed[0].width = 280 + 'px';
					objembed[0].height = 230 +'px';
				}
			}
			else
			{
				var tds = document.getElementById("video").getElementsByTagName("object");
				if(tds[0])
				{
					var objembed = tds[0].getElementsByTagName("embed");
					tds[0].width = 280 + 'px';
					tds[0].height = 230 + 'px';
					if(objembed[0])
					{
						objembed[0].width = 280 + 'px';
						objembed[0].height = 230 + 'px';
					}
				}
			}
		}
	}
}

function CheckLogoDivheight()
{
	var thumbWidth = null;
    var thumbHeight = null;

	if(document.getElementById("complogo") != null)
	{
	    document.getElementById("complogo").style.display = "";
		var divHeight = document.getElementById("complogo").offsetHeight;
		var divWidth = document.getElementById("complogo").offsetWidth;
    	var objimg = document.getElementById("complogo").getElementsByTagName("img");

		if(divWidth > 258)
		{
			thumbWidth = 258;
			thumbHeight = (258*divHeight)/divWidth;
		}

		var h1 = 0,w1 = 0;
		h1 = thumbHeight;
		w1 = thumbWidth;

		if(h1 > 179)
		{
			thumbHeight = 179;
			thumbWidth = (w1*179)/h1;
		}

        if(thumbWidth != null && thumbHeight != null)
	        document.getElementById('complogo').innerHTML='<img src="'+objimg[0].src+'" height="'+thumbHeight+'" width="'+ thumbWidth +'" >'; 
	}
}

/* This Function is called from the Text Messaging "Send" Button which prevents 
the loading of the Mobile.aspx Page and reloads the current Profile Page */
function FromUrlMob(e)
{
	document.getElementById('hdnMobileCurrentURL').value = document.location.href;
}

/* This Function is called from the Mail Sending "Send" Button which prevents 
the loading of the Email.aspx Page and reloads the current Profile Page */
function FromUrl(e)
{
    document.getElementById('hdnCurrentURL').value = document.location.href;
}

/* This Function is used for trimming the string */
function TrimString(str)
{
	if(!str || typeof str != 'string')
    return null;
	return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function EmailAndMobilevalidation(e)
{
	var strError = "";
	if(document.getElementById('chkTextMessage') != null && document.getElementById('chkEmail') != null)
	{
		if(document.getElementById('chkTextMessage').checked == false && document.getElementById('chkEmail').checked == false)
		{
			strError = 'Please select atleast one Communication Mode \n';	
		}
	}
	else
	{
		if(document.getElementById('chkTextMessage') != null && document.getElementById('chkEmail') == null)
		{
			if(document.getElementById('chkTextMessage').checked == false)
			{
				strError = 'Please select Communication Mode \n';	
			}
		}
		else
		{
			if(document.getElementById('chkTextMessage') == null && document.getElementById('chkEmail') != null)
			{
				if(document.getElementById('chkEmail').checked == false)
				{
					strError = 'Please select Communication Mode \n';	
				}
			}
		}
	}

    validation(e, strError);
    noPostBack(e);
}

/* Regular Expression Vaidator for Phone Number Format (xxx) xxx-xxxx ... */
function checkPhoneNumber(phoneNo) 
{
    var flag = false;
    var phoneRE = /^\(\d\d\d\) \d\d\d-\d\d\d\d$/;
    if (phoneNo.match(phoneRE)) 
    {
        flag = true;
    } 
    else 
    {
        flag = false;
        if(phoneNo.length == 10)
        {
            var objRegExp = /(^-?\d\d*$)/;
            flag = objRegExp.test(phoneNo); 
        }
        return flag;
    }
}

/* Regular Expression Vaidator for Phone Number Format xxx-xxx-xxxx ... */
function checkPhoneNumber1(phoneNo) 
{
    var flag = false;
    var phoneRE = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
    if (phoneNo.match(phoneRE)) 
    {
        flag = true;
    } 
    else 
    {
        flag = false;
        if(phoneNo.length == 10)
        {
            var objRegExp = /(^-?\d\d*$)/;
            flag = objRegExp.test(phoneNo); 
        }
        return flag;
    }
}

/* This function is called from the Mail Sending "Send" Button which Validates the Text Fields */
function validation(e, strError)
{
	if(document.getElementById('txtName').value == '' || TrimString(document.getElementById('txtName').value) == '' || document.getElementById('txtName').value == 'Name')
    {
        strError = strError + 'Please enter Name \n';
    }
    else
    {
		if((document.getElementById('txtName').value).indexOf('<')==0 || (document.getElementById('txtName').value).indexOf('<') > 0)
		{
			strError = strError + 'Please enter valid Name \n';
		}
		else
		{
			if((document.getElementById('txtName').value).indexOf('>')==0 || (document.getElementById('txtName').value).indexOf('>') > 0)
			{
				strError = strError + 'Please enter valid Name \n';
			}
		}
    }

    if(document.getElementById('txtPhone').value == 'Phone Number' || TrimString(document.getElementById('txtPhone').value) == '')
    {
        strError = strError + 'Please enter Phone Number \n';
    }
    else
    {
		var	nIndex;
		var	sString = new String('');
		var	bError = false;
		var strPhoneNumber = "";
		var objFormField = document.getElementById('txtPhone');

		if(objFormField.value.length > 0 )
		{
//			for( nIndex = 0; nIndex < objFormField.value.length; ++nIndex )
//			{
//				if( ( objFormField.value.charAt(nIndex) >= '0' ) && ( objFormField.value.charAt(nIndex) <= '9' ) )
//					sString = sString + objFormField.value.charAt(nIndex);
//			}

            strPhoneNumber = stripCharsInBag(objFormField.value, validWorldPhoneChars);
            if(isInteger(strPhoneNumber) == false)
            {
                strError = strError + 'Please enter valid Phone Number \n';
            }

//			if( sString.length < 10 )
//			{
//				strError = strError + 'Please enter valid Phone Number \n';
//			}
//			if(checkPhoneNumber(objFormField.value) == false)
//			{  
//			    strError = strError + 'Please enter valid Phone Number \n';
//			}
//			if( checkPhoneNumber1(objFormField.value) == false )
//			{
//				strError = strError + 'Please enter valid Phone Number \n';
//			}

			// Displayting the phone number back into (xxx) xxx-xxxx Format ...
			////if( sString.length >= 10 )
				////objFormField.value = '(' + sString.substring(0,3) + ') ' + sString.substring(3,6) + '-' + sString.substring(6,10);
		}
    }

    if(document.getElementById('txtEmail').value== 'Email Address' || TrimString(document.getElementById('txtEmail').value)=='')
    {
        strError = strError + 'Please enter Email Address \n';
    }
    else 
    {
		objFormFieldID = document.getElementById('txtEmail')
		var regMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/
		if(objFormFieldID.value!="")
		{
			if(regMail.test(objFormFieldID.value)==false)
			{
				strError = strError + 'Please enter valid Email Address\n';
			}
		}
    }
    if(document.getElementById('txtComments').value != 'Please Type a Brief Message')
    {
		if(document.getElementById('txtComments').value != '' || TrimString(document.getElementById('txtComments').value) != '')
		{
			if((document.getElementById('txtComments').value).indexOf('<') == 0 || (document.getElementById('txtComments').value).indexOf('<') > 0)
			{
				if((document.getElementById('txtComments').value).indexOf('>') == 0 || (document.getElementById('txtComments').value).indexOf('>') > 0)
				{
					strError = strError;
				}
				else
				{
					var ValueWithHtml = document.getElementById('txtComments').value;
					document.getElementById('txtComments').value = ValueWithHtml.replace(/</, "");
				}
			}
		}
    }

    if( document.getElementById('txtCaptcha').value=='' || TrimString(document.getElementById('txtCaptcha').value) == '')
    {
        strError = strError + 'Please enter Letters \n';
    }

    if(strError != "")
    {
		document.getElementById('email_message').style.display = "none";
		alert(strError);
        noPostBack(e);
    }
    else
    {
        ajaxBusinessFunction();
    }
}

// non-digit characters which are allowed in phone numbers ...
var validWorldPhoneChars = "()- ";

// Check if the phone number entered is Integer or not ...
function isInteger(s)
{
    var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) 
        {
            return false;
        }
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) 
        {
            returnString += c;
        }
    }
    return returnString;
}

function ajaxBusinessFunction()
{
	var ajaxRequest;  // The variable that makes Ajax possible!

	try 
	{ 	// Opera 8.0+, Firefox, Safari   
        ajaxRequest = new XMLHttpRequest();
    } 
	catch (e)
	{
	    // Internet Explorer Browsers
        try 
        {
          	ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        { 	
			try 
			{ 
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{	
				 // If Something went wrong 
 				 alert("Could not load results");
                 return false;	
            } 
        }
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{ 
		if(ajaxRequest.readyState == 4)
		{
		    var ChkEmail='';
	        if(document.getElementById('chkEmail') != null)
	            ChkEmail = document.getElementById('chkEmail').checked;

            var TextMessage='';
	        if(document.getElementById('chkTextMessage') != null)
	            TextMessage = document.getElementById('chkTextMessage').checked;

	        if(TextMessage == true || ChkEmail == true )
	        {
	            if(document.getElementById('txtEmail').value != '')
	            objFormFieldID = document.getElementById('txtEmail');
		        var regMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/
		        if(objFormFieldID.value!="")
		        {
			        if(regMail.test(objFormFieldID.value) == false)
			        {
				        
			        }
			        else
			        {
			        	var v = ajaxRequest.responseText;

			            if(v == 1)
			            {
			                document.getElementById('email_message').innerHTML="<br /><span class=\'submitsuccess\'>Thank you. Your message was sent successfully. </span><br />" 
			                document.getElementById('email_message').style.display='block'; 
			                document.getElementById("imgCaptcha").src="http://"+document.domain+"/MultiCityEmail/SendEmailSMS/CaptchaImage.aspx?" +Math.random() +"=3" ;
			                document.getElementById('txtCaptcha').value='';
			                document.getElementById('imgCaptcha').style.display='block';
			            }
			            else if(v == 2) 
			            {
			                document.getElementById('email_message').innerHTML="<br /><span class=\'submitsuccess\'>The letters you entered didn't match the word verification. Please try again.</span>" 
			                document.getElementById('email_message').style.display='block'; 
			                document.getElementById("imgCaptcha").src="http://"+document.domain+"/MultiCityEmail/SendEmailSMS/CaptchaImage.aspx?" +Math.random() +"=3" ;
			                document.getElementById('imgCaptcha').style.display='block';
			            }
			            else if(v == 0)  
			            {
			               document.getElementById("imgCaptcha").src="http://"+document.domain+"/MultiCityEmail/SendEmailSMS/CaptchaImage.aspx?" +Math.random() +"=3" ;
			                document.getElementById('imgCaptcha').style.display='block';
			            } 

			            if(v != 2 && v != 0)  
			            {
			                document.getElementById('txtName').value = 'Name';
                            document.getElementById('txtPhone').value = 'Phone Number';
	                        document.getElementById('txtEmail').value = 'Email Address';
                            document.getElementById('txtComments').value = 'Please Type a Brief Message';
		                    if(document.getElementById('chkEmail') != null)
                            {
		            	        document.getElementById('chkEmail').checked = false;
		                    }
		                    if(document.getElementById('chkTextMessage') != null)
		                    {
		            	       document.getElementById('chkTextMessage').checked = false;   
			        	    }
			        	}
			        }
		        }   
		    } 
		}
	}

	var Name='';
	if(document.getElementById('txtName') != null)
	    Name = document.getElementById('txtName').value;

    var Phone='';
	if(document.getElementById('txtPhone') != null)
	    Phone = document.getElementById('txtPhone').value;

	var Email='';
	if(document.getElementById('txtEmail') != null)
	    Email = document.getElementById('txtEmail').value;

    var Comments='';
	if(document.getElementById('txtComments') != null)
	    Comments = document.getElementById('txtComments').value.replace("&", "%26").replace("+", "%2b");

	var SatelliteCityProfileID='';
	if(document.getElementById('hdnSatelliteCityProfileID') != null )
	    SatelliteCityProfileID = document.getElementById('hdnSatelliteCityProfileID').value;

	var ProfileID='';
	if(document.getElementById('hdnProfileID') != null )
	    ProfileID = document.getElementById('hdnProfileID').value;

	var CurrentURL='';
	if(document.getElementById('hdnCurrentURL') != null )
	    CurrentURL = document.getElementById('hdnCurrentURL').value;

	var Message='';
	if(document.getElementById('hdnMessage') != null )
	    Message = document.getElementById('hdnMessage').value;             

	var ChkEmail="";
	if(document.getElementById('chkEmail') != null)
	{
	    if(document.getElementById('chkEmail').checked)
	    {
	    	ChkEmail = document.getElementById('chkEmail').value;
    	}
    }

    var TextMessage = "";
	if(document.getElementById('chkTextMessage') != null)
	{
	    if(document.getElementById('chkTextMessage').checked)
	    {
		    TextMessage = document.getElementById('chkTextMessage').value;
	    }
	}

	var queryString = "?txtName="+ Name +"&txtPhone="+ Phone +"&txtEmail="+ Email +"&txtComments="+ Comments +"&chkEmail="+ 
    ChkEmail +"&chkTextMessage="+ TextMessage +"&hdnSatelliteCityProfileID="+SatelliteCityProfileID+"&hdnProfileID="+ProfileID+
    "&hdnCurrentURL="+CurrentURL+"&hdnMessage="+Message+"&hdnCustomerName="+document.getElementById('hdnCustomerName').value+
    "&hdnCompanyName="+document.getElementById('hdnCompanyName').value+"&CaptchaCode="+document.getElementById('txtCaptcha').value;

	ajaxRequest.open("GET", "http://"+document.domain+"/MultiCityEmail/SendEmailSMS/email.aspx"+queryString , true);
	ajaxRequest.send(null); 
}