var pop_window;

// For Production
var h_s_ad = "https://secure.talk011.com/";
var h_ad = "http://www.talk011.com/";

/*
// For Systest
var h_s_ad = "https://4.47.56.202/t/";
var h_ad = "http://4.47.56.202/t/";
*/

// Retrieves particular cookie
function getCookie(cookieName)
{
	var cookieFoundAt;
	var cookieValue;

	// find start position in cookie string
	cookieFoundAt = document.cookie.indexOf(cookieName + "=");
	//alert(cookieName);
	
	if (cookieFoundAt < 0)
	{
		cookieValue = "";
	}
	else
	{
		// move to actual start of cookie's data
		cookieFoundAt = document.cookie.indexOf("=",cookieFoundAt);
		cookieFoundAt++;

		// find end position of cookie's data
		cookieEnd = document.cookie.indexOf(";", cookieFoundAt);
		if (cookieEnd == -1)
		    cookieEnd = document.cookie.length - 1;

	     cookieValue = document.cookie.substring(cookieFoundAt, cookieEnd);
	}
	return cookieValue;
}
function showPri()
{
	window.location.href = "privacy.asp";
	return;
}
function showTerm()
{
	window.location.href = "terms.asp";
	return;
}
function showIntAccess()
{
	window.location.href = "IntAccess.asp";
	return;
}
function showTalkTrack()
{
	window.location.href = "TalkTrack.asp";
	return;
}
function showAboutSite()
{
	window.location.href = "AboutSite.asp";
	return;
}
function showTollFree()
{
	window.location.href = "tollfree.asp";
	return;	
}
function showContact()
{
	window.location.href = "contact.asp";
	return;
}
function showFaqs()
{
	window.location.href = "faq.asp";
	return;
}
function showCusts()
{
	window.location.href = "cust_service.asp";
	return;
}
function showHome()
{
	window.location.href = "default.asp";
	return;
}
function showProd()
{
	window.location.href = "ProdList.asp";
	return;
}
function showLogin()
{
	str = h_s_ad + "Login.asp";
	window.location.href = str;
	return;
}
function showBasket()
{
	window.location.href = "ViewBasket.asp";
	return;
}
function showAreaCodes()
{
	window.location.href = "AreaCodes.asp";
	return;
}
function clearAll()
{
	if(confirm("Are your sure you want to clear Shopping Cart?"))
	{
		window.location.href = "ClearAll.asp";
	}
}
function cancelOrder()
{
	if(confirm("Are you sure you want to cancel Order?"))
	{
		window.location.href = "default.asp";
	}
}
function logOff()
{
	if(confirm("Are you sure you want to Logoff from TALK011?"))
	{
		window.location.href = "Logoff.asp";
	}
}
function showAccount()
{
	document.all("Acc").submit();
}
function showCheckOut()
{
//	document.all("Check").submit();
	link = h_s_ad + "CheckOut.asp";
	window.location.href = link;
}
function showEdAccount()
{
	window.location.href = "EditAccount.asp";
}
function showAHistory()
{
	link = h_s_ad + "OrderHistory.asp";
	window.location.href = link;
}
function showNAccount()
{
	link = h_s_ad + "NewAccount.asp";
	window.location.href = link;
}
function showRefLrn()
{
	//alert("Hold on! GOD DAMMIT..... Still working on this.");
	window.location.href = "rewards.asp";
}
function showAffDetails()
{
	//alert("Hold on! GOD DAMMIT..... Still working on this.");
	window.location.href = "ReffDetails.asp";
}
function showRedeem()
{
	link = h_s_ad + "Redeem.asp";
	window.location.href = link;
}
function showRecharge()
{
	//link = h_s_ad + "Recharge.asp";
	link = h_s_ad + "Recharge_Pre.asp";
	window.location.href = link;
}
function AddInst()
{
	if(document.frmItems2.AddInstList.value == "")
	{
		alert("Please select desired card.");
		return;
	}
	else
	{
		var str = h_s_ad + "AddToBasket.asp?" + document.frmItems2.AddInstList.value;
		window.location.href = str;
		return;
	}
}
function checkQtys(theForm)
{
	for (var iElement = 0; iElement < theForm.length;iElement++)
	{
		if (theForm[iElement].type == "text")
		{
			if (isNaN(parseInt(theForm[iElement].value)))
				{
					alert("Entered quantity is invalid.  Allowable quantity values are: 1 – 9.");
					theForm[iElement].focus();
					theForm[iElement].select();
					return false;
				}
		}
	}
	return true;
}
function checkDel(theForm)
{
	var linesSpecified = 0;
	var ids="";
	
	for (var iElement = 0; iElement < theForm.length;iElement++)
	{
		if (theForm[iElement].type == "checkbox")
		{
			if (theForm[iElement].checked )
			{
				linesSpecified++ ; 
				ids+= theForm[iElement].value + ",";
			}
		}
	}
	if ( linesSpecified == 0 )
	{
		alert("Please select desired item(s) to delete.");
		return;
	}
	if(confirm("Are you sure you want to delete selected item(s)?"))
	{
		var str = "RemFromBasket.asp?" + ids;
		window.location.href = str;
		return;
	}

	return true;
}

function filterNonNumber(f)
{
	var res = new String();
	var num = "0123456789";
	var chars = f.value.split("");
	
	for(i=0; i<chars.length; i++)
	{
		if(num.indexOf(chars[i]) != -1)
			res += chars[i];
	}
	if(f.value != res)
		f.value = res;
}
function filterPassSpl(f)
{
	var res = new String();
	var num = " !@#$%^&*()~`-_+={}[]\"':;?/>.<,\\";
	var chars = f.value.split("");
	
	for(i=0; i<chars.length; i++)
	{
		if(num.indexOf(chars[i]) == -1)
			res += chars[i];
	}
	if(f.value != res)
		f.value = res;
}
function filterNoSpl(f)
{
	var res = new String();
	var num = " !@#$%^&*()~`+={}[]\"':;?/>.<,\\";
	var chars = f.value.split("");
	
	for(i=0; i<chars.length; i++)
	{
		if(num.indexOf(chars[i]) == -1)
			res += chars[i];
	}
	if(f.value != res)
		f.value = res;
}
function filterNoSplBSpace(f)
{
	var res = new String();
	var num = "0123456789!@#$%^&*()~`-+={}[]\"':;?/>.<,\\";
	var chars = f.value.split("");
	
	for(i=0; i<chars.length; i++)
	{
		if(num.indexOf(chars[i]) == -1)
			res += chars[i];
	}
	if(f.value != res)
		f.value = res;
}
function filterNoSplc(f)
{
	var res = new String();
	var num = "!@#$%^&*()~`-_+={}[]\"':;?/><,\\";
	var chars = f.value.split("");
	
	for(i=0; i<chars.length; i++)
	{
		if(num.indexOf(chars[i]) == -1)
			res += chars[i];
	}
	if(f.value != res)
		f.value = res;
}
function filterNoSple(f)
{
	var res = new String();
	var num = " !#$%^&*()~`+={}[]\"':;?/><,\\";
	var chars = f.value.split("");
	
	for(i=0; i<chars.length; i++)
	{
		if(num.indexOf(chars[i]) == -1)
			res += chars[i];
	}
	if(f.value != res)
		f.value = res;
}
function pop_med(link,name)
{
	if (pop_window)
	{
		if (pop_window.closed == false)
		{
			pop_window.focus();
		}
	}
	pop_window = window.open(link,name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=350,height=275');
}
function pop_med2(link,name)
{
	if (pop_window)
	{
		if (pop_window.closed == false)
		{
			pop_window.focus();
		}
	}
	pop_window = window.open(link,name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=350,height=350');
}
// center of the screen and custom width and height
function pop_med_local(link,name,w,h)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	if (pop_window)
	{
		if (pop_window.closed == false)
		{
			pop_window.focus();
		}
	}
	var settings = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width='+ w +',height='+ h  +',top='+ TopPosition +',left='+ LeftPosition +',resizable=1';
	pop_window = window.open(link,name,settings);
}

// Check whether cookies enabled
function frasetMain_onload()
{
	document.cookie = "Enabled=true";
	var cookieValid = document.cookie;

	// if retrieving the value we just set actually works
	// then we know cookies enabled
	if (cookieValid.indexOf("Enabled=true") != -1)
	{
		cookiesEnabled = true;
	}
	else
	{
		cookiesEnabled = false;
		alert("Please check your Internet Security Settings and allow acceptance of Cookies.");
	}
}

function CheckCC(CC_Num,CC_Type)
{
    var CCN_digits = CC_Num;
    var validcard = false;
    var msgind = 0;

// Card			Len		Prefix
// AMEX		15		34,37
// Discover	16		6011
// Master		16		51,52,53,54,55
// Visa			13/16	4

    if (CC_Type == "American Express")
    {
        if (CCN_digits.length == 15)
        {
            if ((CCN_digits.substring (0, 2) == "34") || (CCN_digits.substring (0, 2) == "37"))
            {
                validcard = true;
			}
            else
            {
                msgind = 1;
			}
		}
        else
        {
            msgind = 2;
        }
	}
    else if (CC_Type == "Discover")
	{
        if (CCN_digits.length == 16)
    	{
    		if (CCN_digits.substring (0, 4) == "6011")
    		{
    			validcard = true;
    		}
    		else
    		{
                msgind = 1;
			}
		}
        else    
		{
            msgind = 2;
		}
	}
    else if (CC_Type == "Master")
	{
        if (CCN_digits.length == 16)
		{
            if ((CCN_digits.substring (0, 2) >= "51") && (CCN_digits.substring (0, 2) <= "55"))
            {
                validcard = true;
			}
            else
            {
                msgind = 1;
			}
		}
        else
        {
            msgind = 2;
		}
	}
    else if (CC_Type == "Visa")
	{
        if ((CCN_digits.length == 16) || (CCN_digits.length ==13))
        {
            if (CCN_digits.substring (0, 1) == "4")
                validcard = true;
            else
                msgind = 1;
        }
        else    
            msgind = 2;
	}
    else
	{
		alert ("Currently TALK011.com is only accepting Visa and MasterCard as a payment method.");
	}
    
    if (!validcard)
	{
        if (msgind == 1)
            alert ("The Card Number ("+CC_Num + ") and the Card Type (" + CC_Type + ") do not match.");
        else if (msgind == 2)
			alert ("The Credit Card Number entered is invalid for entered Card Type (" + CC_Type + "). Please verify.");
	}

    if (!validcard)
        return (validcard);

//////////////////////////////////////////////////////////////////////////////////////////////
// Perform the mod10 check sum routine on the digits in the card number
// 1) Go through the Credit Card Number digits, starting on the RIGHT.
// 	If the position is odd add the digit to the checksum tally. If the position is 
//		even multiply the digit by 2 if the result is greater than 9 divide the result 
//		by 10 and add the remainder to the checksum tally add 1 to the checksum 
//		tally if the result is 9 or less add the result to the checksum tally 
//		Repeat for each digit.
// 
//	2) Divide the checksum tally by 10
//  3) If there is a remainder the Credit Card Number is not valid.

    var CheckSum = 0;
    for (var x = 1; x <= CCN_digits.length; x++)
	{
		var CurrentDigit = CCN_digits.charAt(CCN_digits.length - x);
        if (x % 2 == 0)
		{
            var WorkDigit = CurrentDigit * 2;    
            if (WorkDigit > 9)
			{ 
				CheckSum = CheckSum + (1 - 0);
				CheckSum = CheckSum + (WorkDigit % 10);
			}
            else
			{
				CheckSum = CheckSum + (WorkDigit - 0);
			}     
		}
        else
		{
            CheckSum = CheckSum + (CurrentDigit - 0);
		}
	}

    if (CheckSum % 10) 
	{ 
        validcard = false; 
        alert ("The Credit Card Number entered is invalid.  Please verify Credit Card Number and re-enter."); 
	} 
    return (validcard); 
}

function IsEmailAddress(s)
{
	re = /\s+/g
	if (re.test(s))
	{
		return false;
	}
	//validate email address syntax and remove any emails that don't 
	//match the basic syntax pattern below.
	re = /^(\w|[^_]\.|[\-])+((\@){1}([^_]))(([a-z]|[\d]|[\-]|\.)+|([^_]\.[^_])*)+\.[a-z]{2,6}$/i
	if (!re.test(s))
	{
		return false;
	}

	//fix the .. problem...
	re = /\.\./
	if (re.test(s))
	{
		return false;
	}

	//fix the @@ problem...
	re = /\@\@/
	return(!re.test(s));
}

function popUpVeriSign(url)
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=725,height=450');
	self.name = "mainWin";
}
