var xmlHttp;var visitorNo;var custtoken;var sourceIP;var intervalId=0;var uniqueid;var callResponse;var CancelCallResponse;var responseStatus;var requestID;var localvariable=0;var timeOut=-1;var domainName='c4c.phonon.in';var IDLE=0;var CONNECTED=1;var BUSY=2;var NO_REPLY=3;var OTHER=4;var SUCCESS=5;var USER_HANGUP=6;var TO_BE_CONNECTED=7;var NOT_CONNECTED=8;var INVALID_NUMBER_FORMAT=9;var UNOBTAINABLE_NUMBER=10;var CANCEL_CALL=11;var CONNECTION_ALIVE='-6';var ADV_CAN_NOT_CONTACTED="The advertiser can not be contacted at this moment.";var VIS_CAN_NOT_CONTACTED="We are unable to contact your number at this moment.</br>Please check if your phone is free and available with sufficient network coverage and </br>try again in a while.";var VIS_ADV_CONNECTED="Connected to the advertiser";var CALLING_VIS="calling you...<br/>you'll get a call from +912653930100.";var VIS_ADV_CANCELED="Your call has been Cancelled";var CALLING_ADV="calling advertiser...<br/>please stay on the line.";var INVALID_NO="You have entered an invalid number";var INVALID_NO_MSG="<br/>Please enter a valid 10 digit India number without 0 but with city code / full mobile number and no spaces.";var THANK_YOU="Thank you for using Click-to-Call.";var SORRY="Sorry, We are unable to contact you. Please call us later.";var CAPTCHA_INVALID="Captcha entered is invalid.";var NUMBER_BLACKLISTED="Sorry, Your Phone number is in Blacklist.";var IP_BLACKLISTED="Sorry, Your IP address is in Blacklist.";var TRY_AGAIN="Unable to contact you. Please try again later.";var MAX_TRY="You have exceeded the maximum number of attempts.<br>Please close this window and try again.";var REASON="Reason:";var ADV_HANGUP="The advertiser has disconnected the call.";includeCSS();DHTML_modalMessage=function()
{var url;var htmlOfModalMessage;var divs_transparentDiv;var divs_content;var iframe;var layoutCss;var width;var height;var existingBodyOverFlowStyle;var dynContentObj;var cssClassOfMessageBox;var shadowDivVisible;var shadowOffset;var MSIE;this.url='';this.htmlOfModalMessage='';this.layoutCss='modal-message.css';this.height=200;this.width=400;this.cssClassOfMessageBox=false;this.shadowDivVisible=true;this.shadowOffset=5;this.MSIE=false;if(navigator.userAgent.indexOf('MSIE')>=0)this.MSIE=true;}
DHTML_modalMessage.prototype={close:function(){this.divs_content.style.display='none';this.divs_shadow.style.display='none';if(this.MSIE)this.iframe.style.display='none';},setHtmlContent:function(newHtmlContent){this.htmlOfModalMessage=newHtmlContent;},setSize:function(width,height){if(width)this.width=width;if(height)this.height=height;},display:function(){if(!this.divs_transparentDiv){this.__createDivs();}
this.divs_content.style.display='block';this.divs_shadow.style.display='block';if(this.MSIE)this.iframe.style.display='block';this.__resizeDivs();window.refToThisModalBoxObj=this;setTimeout('window.refToThisModalBoxObj.__resizeDivs()',150);this.__insertContent();},__createDivs:function()
{this.divs_content=document.createElement('DIV');this.divs_content.className='modalDialog_contentDiv';this.divs_content.id='DHTMLSuite_modalBox_contentDiv';this.divs_content.style.zIndex=100000;if(this.MSIE){this.iframe=document.createElement('<IFRAME src="about:blank" frameborder=0>');this.iframe.style.zIndex=90000;this.iframe.style.position='absolute';document.body.appendChild(this.iframe);}
document.body.appendChild(this.divs_content);this.divs_shadow=document.createElement('DIV');this.divs_shadow.className='modalDialog_contentDiv_shadow';this.divs_shadow.style.zIndex=95000;document.body.appendChild(this.divs_shadow);},__resizeDivs:function()
{var topOffset=Math.max(document.body.scrollTop,document.documentElement.scrollTop);if(this.cssClassOfMessageBox)
this.divs_content.className=this.cssClassOfMessageBox;else
this.divs_content.className='modalDialog_contentDiv';var st=Math.max(document.body.scrollTop,document.documentElement.scrollTop);var sl=Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);window.scrollTo(sl,st);setTimeout('window.scrollTo('+sl+','+st+');',10);this.__repositionTransparentDiv();var brSize=this.__getBrowserSize();var bodyWidth=brSize[0];var bodyHeight=brSize[1];this.divs_content.style.width=this.width+'px';this.divs_content.style.height=this.height+'px';var tmpWidth=this.divs_content.offsetWidth;var tmpHeight=this.divs_content.offsetHeight;this.divs_content.style.left=Math.ceil((bodyWidth-tmpWidth)/2)+'px';this.divs_content.style.top=(Math.ceil((bodyHeight-tmpHeight)/2)+topOffset)+'px';if(this.MSIE){this.iframe.style.left=this.divs_content.style.left;this.iframe.style.top=this.divs_content.style.top;this.iframe.style.width=this.divs_content.style.width;this.iframe.style.height=this.divs_content.style.height;}
this.divs_shadow.style.left=(this.divs_content.style.left.replace('px','')/1+this.shadowOffset)+'px';this.divs_shadow.style.top=(this.divs_content.style.top.replace('px','')/1+this.shadowOffset)+'px';this.divs_shadow.style.height=tmpHeight+'px';this.divs_shadow.style.width=tmpWidth+'px';if(!this.shadowDivVisible)this.divs_shadow.style.display='none';},__repositionTransparentDiv:function()
{},__insertContent:function()
{if(this.url){ajax_loadContent('DHTMLSuite_modalBox_contentDiv',this.url);}else{this.divs_content.innerHTML=this.htmlOfModalMessage;}},__getBrowserSize:function()
{var bodyWidth=document.documentElement.clientWidth;var bodyHeight=document.documentElement.clientHeight;var bodyWidth,bodyHeight;if(self.innerHeight){bodyWidth=self.innerWidth;bodyHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){bodyWidth=document.documentElement.clientWidth;bodyHeight=document.documentElement.clientHeight;}else if(document.body){bodyWidth=document.body.clientWidth;bodyHeight=document.body.clientHeight;}
return[bodyWidth,bodyHeight];}}
var messageObj=new DHTML_modalMessage();messageObj.setShadowOffset;messageObj.setCssClassMessageBox;messageObj.setShadowDivVisible;function callme(custtoken,udf1,udf2,udf3,udf4,udf5)
{var url="http://"+domainName+"/C4CWidgetNew/CallMe.jsp";var width="315";var height="325";var titulo="Call Me Now. Free !!!";var closeImagePath="http://www.phonon.in/C4C/Images/close.gif";var tradeindiaImage="http://www.phonon.in/C4C/Images/tradeindia.png";var urlWithParameter=url+'?custtoken='+custtoken+'&udf1='+udf1+'&udf2='+udf2+'&udf3='+udf3+'&udf4='+udf4+'&udf5='+udf5+'&newSession=T';var messageTitle='<table class="modalDialog_titleArea" width = "100%"><tr><td align="center" width="90%"><img src="'+tradeindiaImage+'"/></td><td align="center" width="10%"><img src="'+closeImagePath+'" border="0" WIDTH="14" HEIGHT="14" onclick="closeMessage();return false"></td></tr></table>'
var messageContent='<IFRAME src="'+urlWithParameter+'" id="iframePopupPhonon" class="frame" width="'+(width-20)+'" height="'+(height-55)+'" frameborder="0"></IFRAME>';messageObj.setHtmlContent(messageTitle+messageContent);messageObj.setSize(width,height);messageObj.display();}
function closeMessage()
{messageObj.close();}
function getCurrCallStatus(reqID)
{requestID=reqID;var str="retriveCurrCallStatus()";intervalId=window.setInterval(str,5000);}
function retriveCurrCallStatus()
{if(localvariable>12)
return;localvariable++;if(uniqueid!=null||custtoken!=null||uniqueid!=''||custtoken!='')
{xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Your browser not support AJAX");return;}
var url="http://"+domainName+"/C4CWidgetNew/RetrieveStatus";var d=new Date();url=url+"?reqID="+requestID+"&time="+d.getTime();xmlHttp.onreadystatechange=iresponse
xmlHttp.open("GET",url,true)
xmlHttp.send(null);}}
function iresponse()
{if(xmlHttp.readyState==4)
{responseStatus=xmlHttp.responseText;xmlHttp=null;retriveCallAcknowledge();}}
function performCrossDomainAction(visitor_No,cust_Token,source_IP,udfParaList,referrer,country,sessionID,rcChallange,rcResponse,captchaAnswer,JSessionID)
{visitorNo=visitor_No;custtoken=cust_Token;sourceIP=source_IP;xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Your browser not support AJAX");return;}
var unlimted_calls=document.getElementById("hdnIsUnlimitedCalls").value;var url="";if(unlimted_calls=="true")
url="http://"+domainName+"/C4CWidgetNew/C2CRequestNew";else
url="http://"+domainName+"/C4CWidgetNew/C2CRequest";url=url+"?visitor="+visitorNo+"&custtoken="+custtoken+"&sourceIP="+sourceIP+"&"+udfParaList+"&referrer="+referrer+"&visitorLocation="+country+"&sessionID="+sessionID+"&challenge="+rcChallange+"&response="+rcResponse+"&captcha="+captchaAnswer+"&JSessionId="+JSessionID;xmlHttp.onreadystatechange=CrossDomainStatusResponse
xmlHttp.open("GET",url,true)
xmlHttp.send(null);}
function retryCaptcha(captchaAnswer,JSessionID){document.getElementById('div_response').innerHTML=CALLING_VIS;document.getElementById('imgLoading').style.visibility="visible";xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Your browser not support AJAX");return;}
var url="http://"+domainName+"/C4CWidgetNew/C2CRequest";url=url+"?IsRetry=T&captcha="+captchaAnswer+"&JSessionId="+JSessionID;xmlHttp.onreadystatechange=CrossDomainStatusResponse
xmlHttp.open("GET",url,true)
xmlHttp.send(null);}
function CrossDomainStatusResponse()
{if(xmlHttp.readyState==4)
{callResponse=xmlHttp.responseText;xmlHttp=null;if(callResponse.indexOf('NACK')>=0)
{REASON="Reason : "+callResponse.substring(5);if(callResponse.indexOf('Session Timeout')>=0)
{msg="Your session timed out. Please try again after closing this window."
document.getElementById("imgLoading").style.visibility="hidden";}
else if(callResponse.indexOf('Captcha Not Verified')>=0||callResponse.indexOf('Captcha Spam Blocked')>=0)
{var d=new Date();var JSessionID=document.getElementById("JSessionId").value;var anchorRetry="<br><img src='CaptchaServlet?time="+d.getTime()+"&sessionID="+JSessionID+"'><br><span id='captchamsg' style='color:red'>Please enter the characters shown in above image.</span><br><input type='text' name='textCaptcha' id='textCaptcha'><br><input type='button' value='Retry' id='btnRetry' style='background-color:#EF9A48;'>";msg=CAPTCHA_INVALID+anchorRetry;document.getElementById('div_response').innerHTML=msg;var JSessionID=document.getElementById("JSessionId").value;document.getElementById("imgLoading").style.visibility="hidden";var anchorRetry=document.getElementById("btnRetry");anchorRetry.onclick=function()
{var captchaAnswer=document.getElementById("textCaptcha").value;if(captchaAnswer!=null||captchaAnswer!="")
{retryCaptcha(captchaAnswer,JSessionID);}
else
{alert("Please enter Captcha text first.");}}}
else if(callResponse.indexOf('Captcha Retry Exceeded')>=0)
{msg=MAX_TRY;document.getElementById('div_response').innerHTML=msg;document.getElementById("imgLoading").style.visibility="hidden";}
else if(callResponse.indexOf('IP Blacklisted')>=0)
{var anchorIP="<br><a href='#' id='anchUnblockIP'>Request Unblock</a>";msg=IP_BLACKLISTED+"<br><br>"+REASON+anchorIP;document.getElementById('div_response').innerHTML=msg;document.getElementById("imgLoading").style.visibility="hidden";var anchIP=document.getElementById("anchUnblockIP");anchIP.onclick=function()
{addRequestToUnblock(custtoken,sourceIP,true);}}
else if(callResponse.indexOf('Number Blacklisted')>=0)
{var anchorNo='<br><a href="#" id="anchUnblockNo">Request Unblock</a>';msg=NUMBER_BLACKLISTED+"<br><br>"+REASON+anchorIP;document.getElementById('div_response').innerHTML=msg;document.getElementById("imgLoading").style.visibility="hidden";var anchNo=document.getElementById("anchUnblockNo");anchNo.onclick=function()
{addRequestToUnblock(custtoken,visitorNo,false);}}
else if(callResponse.indexOf('Max Simultaneous Calls')>=0)
{msg="Sorry, we could not start your call presently <br> since maximum simultaneous call limit of customer is reached. <br> Please try again after some time.";document.getElementById('div_response').innerHTML=msg;document.getElementById("imgLoading").style.visibility="hidden";}
else
{msg=TRY_AGAIN+"<br><br>"+REASON;document.getElementById('div_response').innerHTML=msg;document.getElementById("imgLoading").style.visibility="hidden";document.getElementById("anchRetry").style.visibility="hidden";}}
else if(callResponse.indexOf('ACK')>=0)
{document.getElementById("CancelRow").style.display="block";document.getElementById("CancelColumn").style.display="block";var index=callResponse.length-20;var reqID=callResponse.substring(index);getCurrCallStatus(reqID);}}}
function GetXmlHttpObject()
{var xmlHttp=null;try
{xmlHttp=new XMLHttpRequest();}
catch(e)
{try
{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
return xmlHttp;}
function updateCurrCallStatus()
{var arrValue=responseStatus.split(';');for(var i=0;i<arrValue.length;i++)
{var temp=arrValue[i].split(':');arrValue[i]=temp[1];}
var vis_status=arrValue[1];var adv_status=arrValue[0];var con=arrValue[2];var msg='';if(vis_status==CANCEL_CALL||adv_status==CANCEL_CALL)
{msg=VIS_ADV_CANCELED+"<br>"+THANK_YOU;clearInterval(intervalId);document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==IDLE||vis_status==TO_BE_CONNECTED||vis_status==NOT_CONNECTED)&&(adv_status==TO_BE_CONNECTED))
{msg=CALLING_VIS;}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==TO_BE_CONNECTED))
{msg=CALLING_ADV;}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==CONNECTED||adv_status==SUCCESS))
{msg=VIS_ADV_CONNECTED;}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==BUSY))
{msg=ADV_CAN_NOT_CONTACTED;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==NO_REPLY))
{msg=ADV_CAN_NOT_CONTACTED;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==OTHER||adv_status==NOT_CONNECTED||adv_status==UNOBTAINABLE_NUMBER))
{msg=ADV_CAN_NOT_CONTACTED;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==USER_HANGUP))
{msg=ADV_HANGUP+"</br>"+THANK_YOU;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==CONNECTED||vis_status==SUCCESS)&&(adv_status==INVALID_NUMBER_FORMAT))
{msg=INVALID_NO;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==BUSY)&&(adv_status==TO_BE_CONNECTED))
{msg=VIS_CAN_NOT_CONTACTED;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==NO_REPLY)&&(adv_status==TO_BE_CONNECTED))
{msg=VIS_CAN_NOT_CONTACTED;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==OTHER||vis_status==NOT_CONNECTED||vis_status==UNOBTAINABLE_NUMBER)&&(adv_status==TO_BE_CONNECTED))
{msg=VIS_CAN_NOT_CONTACTED;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==USER_HANGUP))
{msg=THANK_YOU;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
else if((vis_status==INVALID_NUMBER_FORMAT)&&(adv_status==TO_BE_CONNECTED))
{msg=INVALID_NO+INVALID_NO_MSG;document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";}
document.getElementById('div_response').innerHTML=msg;if(con!=CONNECTION_ALIVE)
{if(intervalId!=0)
clearInterval(intervalId);document.getElementById("imgLoading").style.visibility="hidden";}}
function retriveCallAcknowledge()
{var ACK="ACK";var resp=callResponse.substring(0,3);if(resp==ACK||CancelCallResponse=="ACK")
{updateCurrCallStatus();}
else
{document.getElementById('imgLoading').style.visibility="hidden";document.getElementById('div_response').innerHTML=SORRY;}}
function includeCSS()
{var v_css=document.createElement('link');v_css.rel='stylesheet'
v_css.type='text/css';v_css.href="http://www.phonon.in/C4C/modal-message.css";document.getElementsByTagName('head')[0].appendChild(v_css);}
function addRequestToUnblock(cust_Token,source_IP_Number,isRequestForIp){xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Your browser not support AJAX");return;}
var url="http://"+domainName+"/C4CWidgetNew/setUnblockRequest";url+="?custtoken="+cust_Token+"&sourceIP_Number="+source_IP_Number;if(isRequestForIp)
url+="&requestFor=1";else
url+="&requestFor=2";xmlHttp.onreadystatechange=updateStatusOfRequest
xmlHttp.open("GET",url,true)
xmlHttp.send(null);}
function updateStatusOfRequest(){if(xmlHttp.readyState==4){var output=parseInt(xmlHttp.responseText);if(output>=1)
document.getElementById('div_response').innerHTML='Request Successfully Sent !!!';else if(output==0)
document.getElementById('div_response').innerHTML='Request Exist !!!';else if(output==-1)
document.getElementById('div_response').innerHTML='Request Failure - DB Error !!!';else
document.getElementById('div_response').innerHTML='Request Failure - Other Error !!!';}}
function chkNumberBlacklist(cust_Token,source_IP_Number,hdnSourceIP,hdnUDFParams,referrerURL,countryName,sessionID,rcChallange,rcResponse,captchaAnswer,JSessionID)
{xmlHttp=GetXmlHttpObject();if(xmlHttp==null){alert("Your browser not support AJAX");return false;}
var url="http://"+domainName+"/C4CWidgetNew/chkNumberBlacklist";url+="?custtoken="+cust_Token+"&sourceIP_Number="+source_IP_Number;xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4)
{var output=parseInt(xmlHttp.responseText);var anchor='<a href="#" id="anchUnblock">Request Unblock</a>';if(output==1)
{document.getElementById('div_response').innerHTML='This Number is not valid for Click4Call Services.'+anchor;document.getElementById("imgLoading").style.visibility="hidden";var anch=document.getElementById("anchUnblock");anch.onclick=function(){addRequestToUnblock(cust_Token,source_IP_Number,false);}}
else if(output==0)
{performCrossDomainAction(source_IP_Number,cust_Token,hdnSourceIP,hdnUDFParams,referrerURL,countryName,sessionID,rcChallange,rcResponse,captchaAnswer,JSessionID);}
else
{document.getElementById('div_response').innerHTML='Number Blacklist Exception';document.getElementById("imgLoading").style.visibility="hidden";}}}
xmlHttp.open("GET",url,true)
xmlHttp.send(null);}
function CancelCall()
{xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Your browser not support AJAX");return false;}
var url="http://"+domainName+"/C4CWidgetNew/cancelCall?requestID="+requestID+"&orignalIP="+sourceIP;xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=function()
{if(xmlHttp.readyState==4)
{var resp=xmlHttp.responseText.substring(0,3);if(resp=="ACK")
{document.getElementById('div_response').innerHTML='Please wait...<br> While we cancel your call.';document.getElementById("CancelRow").style.visibility="hidden";document.getElementById("CancelColumn").style.visibility="hidden";CancelCallResponse="ACK";}
else
{document.getElementById('div_response').innerHTML='Sorry, Your call Can not be disconnected.';document.getElementById("imgLoading").style.visibility="hidden";}}}
xmlHttp.send(null);}
