﻿function MM_swapImgRestore(){var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)x.src=x.oSrc;}
function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)
if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}
function MM_findObj(n,d){var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);if(!x&&d.getElementById)x=d.getElementById(n);return x;}
function MM_swapImage(){var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc)x.oSrc=x.src;x.src=a[i+2];}}
function swapImage(strObject,strImage)
{var obj=document.getElementById(strObject);obj.src=strImage;}
function toggleMe(a){var e=document.getElementById(a);if(!e)return true;if(e.style.display=="none"){e.style.display="block"}else{e.style.display="none"}
return true;}
function CheckUser(emVal) {
    var password = document.getElementById("password"); var email = document.getElementById("email"); var retype_email = document.getElementById("confirm_email"); var retype_password = document.getElementById("retype_password"); var sfCaseIDValue = ""; var sfCaseID = document.getElementById("hidSFCaseID"); var sfAgentCode = document.getElementById("hidSFAgentCode"); var sfAgentCodeValue = "";
if(email.value!=retype_email.value)
{alert("Email and Confirm Email Fields do not match");ShowProcessing(false); return;}
if(!verifyEmail(email.value))
{ alert("You have entered an invalid email address. Please make sure your email address is in the format yourname@example.com"); ShowProcessing(false); return; }
if(password.value=="")
{alert("Password Field is empty");ShowProcessing(false);return;}
if(password.value!=retype_password.value)
{alert("Password and Confirm Password Fields do not match");ShowProcessing(false);return;}
if(password.value.length<4)
{ alert("The password you have entered is too short. Please choose longer password."); ShowProcessing(false); return; }
if(password.value.length>12)
{ alert("The password you have entered is too long. Please choose shorter password."); ShowProcessing(false); return; }
if (sfAgentCode != null) { sfAgentCodeValue = sfAgentCode.value }
if (sfCaseID != null) { sfCaseIDValue = sfCaseID.value }
var URL = "NewPaymentHandler.aspx?Username="; URL += email.value; URL += "&Password="; URL += password.value; URL += "&Step1=1"; URL += "&sfCaseID="; URL += sfCaseIDValue; URL += "&sfAgentCode="; URL += sfAgentCodeValue; postFile(URL, HandleRegistration);
}
function HandleRegistration(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200) {
    result1 = theXMLHttp.responseText; result = result1.split("~~|~~"); if (result[0] == "UserCredentialsOK") {
    if (result[2].length > 0)
    { document.location.href = "watchindiacart.aspx?agentCode=" + result[2]; }
    else
    { document.location.href = "watchindiacart.aspx"; }    
}
if(result=="GeneralFail")
{ShowProcessing(false); alert(result1.split("~~|~~")[1]);}}}}
function postFile(pURL,pHandlerFunc)
{pParameters="";if(pURL.split("?").length>1)
pParameters=pURL.split("?")[1];if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();xmlhttp.open("POST",pURL,false);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlhttp.send(pParameters);return pHandlerFunc(xmlhttp);}
else if(window.ActiveXObject)
{xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');if(xmlhttp)
{xmlhttp.open('POST',pURL,false);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlhttp.send(pParameters);return pHandlerFunc(xmlhttp)}}}
function CheckLogin(emVal)
{ ShowProcessing('true'); var uName = document.getElementById("txtEmail"); var uPass = document.getElementById("txtPass"); return postFile("Login.aspx?uname=" + uName.value + "&upass=" + uPass.value, HandleLogin); }
function HandleLogin(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{result1=theXMLHttp.responseText;result=result1.split("~~|~~")[0];if(result=="LOGINOK")
{ShowProcessing(false); window.location.href="player.aspx";}
if(result=="LOGINFAIL")
{ShowProcessing(false); alert(result1.split("~~|~~")[1]);}}}}
function EmptyBoxes(obj)
{var box2Empty=document.getElementById(obj);box2Empty.value="";var cVal="";if(box2Empty.id=="txtEmail")
{cVal=getCookie("WatchIndiaUserName");if(cVal!="")
{box2Empty.value=cVal;}}}
function CheckKeyLogin(e)
{if(window.event)
{if(e.keyCode==13)
{ShowProcessing(true, "CheckLogin(1)");}}
else if(e.which==13)
{ShowProcessing(true, "CheckLogin(1)");}}
function CheckKeyRegistration(e)
{if(window.event)
{if(e.keyCode==13)
{ShowProcessing(true, "CheckUser(1)");}}
else if(e.which==13)
{ShowProcessing(true, "CheckUser(1)");}}
function getCookie(c_name)
{if(document.cookie.length>0)
{c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1)
{c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}
return"";}
function ForgotPassword(emVal)
{var from=document.getElementById("txtEmail");if(from.value==""||from.value=="Email")
{ShowProcessing(false);alert("Please fill you email address");return;}
var Url="Sender.aspx?UserName=";Url+=from.value;Url+="&ForgotPass=1";postFile(Url,HandleSending);}
function HandleSending(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{ShowProcessing(false); alert("Password was sent to the provided Email");}}}
var bError = false;
function CheckPersonalInfo() {
    bError = false; var Err = ""; var fname = document.getElementById("fname"); var lname = document.getElementById("lname");
    var address = document.getElementById("address"); var city = document.getElementById("city"); 
    var Country = document.getElementById("Country"); var zip = document.getElementById("zip");
    var phone1 = document.getElementById("phone1"); var phone2 = document.getElementById("phone2");
    var sstate = document.getElementById("state"); var divState = document.getElementById("divState");
    if (divState.style.display == "none")
    { sstate = document.getElementById("province"); } 
    var phone3 = document.getElementById("phone3"); var phone4 = document.getElementById("phone4"); 
    var address2 = document.getElementById("address2"); if (!CompareValues(fname.value, fname.value))
    { Err += "Please fill in First Name Field\r \n"; fname.style.borderColor = "Red"; }
if(!CompareValues(lname.value,lname.value))
{ Err += "Please fill in Last Name Field\r \n"; lname.style.borderColor = "Red"; }
if(!CompareValues(address.value,address.value))
{ Err += "Please fill in Address Field\r \n"; address.style.borderColor = "Red"; }
if(!CompareValues(city.value,city.value))
{ Err += "Please fill in City Field\r \n"; city.style.borderColor = "Red"; }
if(!CompareValuesList(Country.value,Country.value))
{ Err += "Please fill in Country Field\r \n"; Country.options[0].style.backgroundColor = "Red"; }
if(!CompareValues(zip.value,zip.value))
{ Err += "Please fill in Zip Code Field\r \n"; zip.style.borderColor = "Red"; }
if(!CompareValues(phone1.value,phone1.value))
{ Err += "Please fill in Phone Number Country Code Field\r \n"; phone1.style.borderColor = "Red"; }
if (!CompareValues(phone2.value, phone2.value))
{ Err += "Please fill in Phone Number Area Code Field\r \n"; phone2.style.borderColor = "Red"; }
if(!CompareValues(phone3.value,phone3.value))
{ Err += "Please fill in Phone Number Field\r \n"; phone3.style.borderColor = "Red"; }
if(Err!="")
{ShowProcessing(false); bError=true; alert(Err);return;}
var URL = "NewPaymentHandler.aspx?Step2=1"; URL += "&FirstName="; URL += fname.value; URL += "&LastName="; URL += lname.value; URL += "&Address="; URL += address.value; URL += "&Address2="; URL += address2.value; URL += "&City="; URL += city.value; URL += "&Country="; URL += Country.value; URL += "&Zip="; URL += zip.value; URL += "&State="; URL += sstate.value; URL += "&Phone="; URL += phone1.value + "-" + phone2.value + "-" + phone3.value + "-" + phone4.value; postFile(URL, HandleRegistrationStep2);
}
function CompareValues(obj1,obj2)
{var obj1Val="";var obj2Val="";if(obj1.value==null)
{obj1Val=obj1;obj2Val=obj2;}else
{obj1Val=obj1.value;obj2Val=obj2.value;}
if(obj1Val!="")
{if(obj1Val!=obj2Val)
{return false;}
return true;}
return false;}
function CompareValuesList(obj1,obj2)
{var obj1Val=0;if(obj1.value==null)
{obj1Val=obj1;}else
{obj1Val=obj1.value;}
if(obj1Val!=0)
{return true;}
return false;}
function HandleRegistrationStep2(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{result1=theXMLHttp.responseText;result=result1.split("~~|~~")[0];if(result=="UserPrivacyOK"){}//document.location.href="BuildCart.aspx";}
if(result=="GeneralFail")
{alert("An internal error occured. Please Try Again Later");ShowProcessing(false);}}}}
function CheckKeyRegistrationPI(e)
{if(window.event)
{if(e.keyCode==13)
{CheckPersonalInfo();}}
else if(e.which==13)
{CheckPersonalInfo();}}
function CheckKeyRegistrationHP(e)
{if(window.event)
{if(e.keyCode==13)
{ShowProcessing(true, "CheckUser(1)");}}
else if(e.which==13)
{var check=ShowProcessing(true, "CheckUser(1)");}}
var current="faq1";function toggleMe1(a){var e=document.getElementById(a);var qlink="q"+a;var l;if(!e)return true;if(e.style.display=="none")
{document.getElementById(current).style.display="none";e.style.display="block"
l=document.getElementById(qlink);document.getElementById("q"+current).style.fontWeight='400';l.style.fontWeight='bold';current=a;}
return true;}
function verifyEmail(email){var status=false;var emailRegEx=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;if(email.search(emailRegEx)!=-1){status=true;}
return status;}
function ShowProcessing(show, func, showError)
{
    var divProcess = $("[id$=divProcessing]")
    var hiddenDiv = $("[id$=hiddenDiv]");
    if (divProcess.length == 0 || hiddenDiv.length == null)
        return;
    if (show) { divProcess.show(); hiddenDiv.show(); if (showError) { var error = document.getElementById("errorMessage"); if (error != undefined) error.style.display = "block"; } }
    else { divProcess.hide(); hiddenDiv.hide(); }
    if(func != undefined)
        setTimeout(func, 3000);
}
function ShowCloseSTB(show)
{
    var divSTB = document.getElementById("divWISTB");
    var hiddenDiv = document.getElementById("hiddenDiv");
    if(divSTB == null 
    || hiddenDiv == null)
        return;
    if(show){divSTB.style.display = "block"; hiddenDiv.style.display = "block";}
    else{divSTB.style.display = "none";hiddenDiv.style.display = "none";}
}

function ShowCloseSTBUpSell(show)
{
    var divSTB = document.getElementById("divSTBSell");
    var hiddenDiv = document.getElementById("hiddenDiv");
    if(divSTB == null 
    || hiddenDiv == null)
        return;
    if(show){divSTB.style.display = "block"; hiddenDiv.style.display = "block";}
    else{divSTB.style.display = "none";hiddenDiv.style.display = "none";}
    window.scrollTo(0,0);
}

function ShowCloseSTBSuccess(show)
{
    var divSuccess = document.getElementById("divSuccess");
    var hiddenDiv = document.getElementById("hiddenDiv");
    if(divSuccess == null 
    || hiddenDiv == null)
        return;
    if(show){divSuccess.style.display = "block"; hiddenDiv.style.display = "block";}
    else{divSuccess.style.display = "none";hiddenDiv.style.display = "none";}
}

function CheckLoginWNB(uname, pass)
{return postFile("Login.aspx?uname="+uname+"&upass="+pass,HandleLogin);}
function HandleLogin(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{result1=theXMLHttp.responseText;result=result1.split("~~|~~")[0];if(result=="LOGINOK")
//{ShowProcessing('false'); window.location.href="http://www.watchindia.tv/player.aspx";}
{ShowProcessing('false'); window.location.href="player.aspx";}
if(result=="LOGINFAIL")
{ShowProcessing(false); alert(result1.split("~~|~~")[1]);}}}}
function CheckUserNF(emVal)
{var password=document.getElementById("password");var email=document.getElementById("email"); var retype_email=document.getElementById("confirm_email"); var retype_password=document.getElementById("retype_password");
if(email.value!=retype_email.value)
{alert("Email and Confirm Email Fields do not match");ShowProcessing(false); return;}
if(!verifyEmail(email.value))
{ alert("You have entered an invalid email address. Please make sure your email address is in the format yourname@example.com"); ShowProcessing(false); return; }
if(password.value=="")
{alert("Password Field is empty");ShowProcessing(false);return;}
if(password.value!=retype_password.value)
{alert("Password and Confirm Password Fields do not match");ShowProcessing(false);return;}
if(password.value.length<4)
{ alert("The password you have entered is too short. Please choose longer password."); ShowProcessing(false); return; }
if(password.value.length>12)
{ alert("The password you have entered is too long. Please choose shorter password."); ShowProcessing(false); return; }
var URL="NewPaymentHandler.aspx?Username=";URL+=email.value;URL+="&Password=";URL+=password.value;URL+="&Step1=1";postFile(URL,HandleRegistrationNF);}
function HandleRegistrationNF(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{result1=theXMLHttp.responseText;result=result1.split("~~|~~")[0];
if(result=="GeneralFail")
{ShowProcessing(false); alert("An error occured during mail sending. Please Try Again Later");}}}}
//Initiates sequence of OTP for STB only for existing subscriber
function InitOTPforSTBforES(sid)
{var Err = "";
var sFName = document.getElementById("sfullname"); var saddress = document.getElementById("saddress"); 
var saddress2=document.getElementById("saddress2"); saddress.value = saddress.value + " " + saddress2.value;
var scity=document.getElementById("scity"); 
var divState = document.getElementById("divState");var sstate=document.getElementById("sstate"); 
var scountry=document.getElementById("scountry");
var szip=document.getElementById("szip"); 
var sphone1=document.getElementById("sphone1"); var sphone2=document.getElementById("sphone2"); 
var sphone3=document.getElementById("sphone3"); var sphone4=document.getElementById("sphone4");
Err += CheckField(sFName, "Full Name");
Err += CheckField(saddress, "Address");
Err += CheckField(scity, "City");
if (divState.style.display == "none")
{ sstate = document.getElementById("sprovince"); }
else
{ Err += CheckField(sstate, "State"); }
Err += CheckField(scountry, "Country");
Err += CheckField(szip, "ZIP");
Err += CheckField(sphone1, "Phone Number 1st");
Err += CheckField(sphone2, "Phone Number 2nd");
Err += CheckField(sphone3, "Phone Number 3rd");
if(Err!="")
{alert(Err);return;} 
var URL="NewPaymentHandler.aspx?SID=";URL+=sid;URL+="&Step4=1";
URL += "&FULLNAME="; URL += sFName.value; URL += "&ADDRESS="; URL += saddress.value; URL += "&COUNTRY="; URL += scountry.value; 
URL+="&STATE=";URL+=sstate.value; URL+="&CITY=";URL+=scity.value; 
URL+="&ZIP=";URL+=szip.value; URL+="&PHONE=";URL+=sphone1.value + "-" + sphone2.value + "-" + sphone3.value +" Ext. "+ sphone4.value;
postFile(URL,HandleOTP);}
function HandleRegistrationNF(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{result1=theXMLHttp.responseText;result=result1.split("~~|~~")[0];
if(result=="GeneralFail")
{ShowProcessing(false); alert("An error occured during mail sending. Please Try Again Later");}}}}
function HandleOTP(theXMLHttp)
{if(theXMLHttp.readyState==4)
{if(theXMLHttp.status==200)
{result1=theXMLHttp.responseText;result=result1.split("~~|~~")[0];
if(result=="OTPOK")
{var divSTB = document.getElementById("divSTBSell"); 
var divSuccess = document.getElementById("divSuccess");
divSTB.style.display = "none"; divSuccess.style.display = "block";}
if(result=="OTPOKPP")
{var shipfee=result1.split("~~|~~")[1];
var theAmount=result1.split("~~|~~")[2];
var theSubID = result1.split("~~|~~")[3];
document.getElementById("paypal_item_custom").value = theSubID;
document.getElementById("paypal_price").value=theAmount;
document.getElementById("paypal_price1").value=theAmount;
document.getElementById("paypal_t3").value="D";
theSubName = "WatchIndia.TV TV Box(at $" + theAmount + " + $" + shipfee + " shipping fee.)"; 
document.getElementById("paypal_item_name").value=theSubName;
submitASPForm("https://www.paypal.com/cgi-bin/webscr");return true;}
if(result=="GeneralError" 
|| result=="GeneralFail")
{var err = result1.split("~~|~~")[1]; alert(err);}}}}
function CheckField(field, fieldName)
{var Err="";
if(!CompareValues(field.value,field.value) 
|| field.value == "0"
|| field.value == "None")
{ Err += "Please fill in " + fieldName + " Field\r \n"; field.style.borderColor = "Red"; }
return Err;}
function checkCountry(sender)
{
    var divState = document.getElementById("divState");
    var divProvince = document.getElementById("divProvince");
    var divPrice = document.getElementById("divPrice");
    var divTotal = document.getElementById("divTotal");
    var divSP = document.getElementById("divSP");
    var popa = sender.value;
    if(sender.value == 227 
    || sender.value == 0)
    {divState.style.display = "block"; divProvince.style.display = "none";
    divPrice.innerText = divPrice.textContent = "$14.99";
    divTotal.innerText = divTotal.textContent = "$164.99";
    divSP.innerText = divTotal.textContent = "*State";}
    else {
        divSP.innerText = divTotal.textContent = "*Province";
        divProvince.style.display = "block"; divState.style.display = "none";
    }
    // Fetch the country shipping price
    SetShippingPriceByCountryID(sender.value);
}

function SetShippingPriceByCountryID(nCountryID) {
    // TODO: Fetch the correct product ID, currently the product id is Tv Box
    var nLAProductID = 2;

    // Should work only in pages where the BoxPrice div element exist
    if ($("[id$=divBoxPrice]").length != 0) {
        $.ajax(
        { type: 'POST',
            contentType: 'application/json; charset=utf-8',
            url: 'WIServices.asmx/GetShippingPriceByCountryID',
            data: '{nCountryID: "' + nCountryID + '", nLAProductID: "' + nLAProductID + '"}',
            dataType: 'json',
            async: true,
            success: function (data) {
                var priceShipping = data.d;
                var nPriceShip = Number(priceShipping);
                var nBoxPrice = $("[id$=divBoxPrice]").html();
                nBoxPrice = Number(nBoxPrice.replace('$', ''));
                var nTotal = nBoxPrice + nPriceShip;
                $("[id$=divPrice]").html('$' + priceShipping);
                $("[id$=divTotal]").html('$' + nTotal);
            }
        });
    }
}

function checkState(sender)
{
    var divState = document.getElementById("divState");
    var divProvince = document.getElementById("divProvince");
    var divPrice = document.getElementById("divPrice");
    var divTotal = document.getElementById("divTotal");
    if(sender.value == "Alaska" 
    ||sender.value == "Hawaii")
    {divState.style.display = "block"; divProvince.style.display = "none";
    divPrice.innerText = divPrice.textContent = "$14.99";
    divTotal.innerText = divTotal.textContent = "$169.99";
    divSP.innerText = divTotal.textContent = "*State";}
}

function AddSubscriberEmailOnly(emVal) {
    var password = "1";
    var email = document.getElementById("email");

    // call ajax function that adds new user with the default short signup box password (1)
    $.ajax(
    { type: 'POST',
        contentType: 'application/json; charset=utf-8',
        url: 'WIServices.asmx/AddSubscriber',
        data: '{strEmail: "' + email.value + '", strPassword: "' + password + '"}',
        dataType: 'json',
        success: function (data) {
            var email_remove = document.getElementById("email");
            email_remove.value = '';
            $("[id$=ucAddEmail_lblAddEmailMsg]").html('Thank you for sign in!');
        }
    });    
}


