//This Fucntion is added for save functionality---Anu
function saveOrder(appId,User,btn)
{
	if(User != "" && User != 0)
	{
		alert('Thank you! Your order will be saved for 5 days.  You can access your order by signing in and clicking on "My Order" in "My Account".')
	}
	else
	{
		if(appId == "NC")
		{
			if(btn == null || btn == "") 
			{
				if(User != "" && User != 0)
				{
					alert('Thank you! Your order will be saved for 5 days.  You can access your order by signing in and clicking on "My Order" in "My Account".')
				}
				else
				{
					alert('Thank you! Your order will be saved for 5 days. After choosing a User ID and Password on the next page, you will be able to access your order by signing in and clicking on "My Order" in "My Account". To ensure your privacy, your SSN and Business Tax ID Number will not be saved.You will be asked to re-enter it when you return to the order.');
				}
			}
			else
			{
				alert('Thank you! Your order will be saved for 5 days. After choosing a User ID and Password on the next page, you will be able to access your order by signing in and clicking on "My Order" in "My Account". To ensure your privacy, your SSN and Business Tax ID Number will not be saved.You will be asked to re-enter it when you return to the order. Telephone number selection is not final until the order is submitted and the service is installed and working.');
			}
		}
		else
		{
			alert('Thank you! Your order will be saved for 5 days. You can access your order by signing in and clicking on "My Order" in "My Account." To ensure your privacy, your SSN and Business Tax ID Number will not be saved.You will be asked to re-enter it when you return to the order.');
		}
		document.location.href  = "/foryourbusiness/order/common/NCSaveMyOrder.aspx"
	}
}
//End of This Fucntion is added for save functionality---Anu
function load() {
	var imgs = load.arguments;
	if (document.images) {
		if (document.preload == null) document.preload = new Array();
		var i = document.preload.length;
		for (var j = 0; j < imgs.length; j++) {
			document.preload[i] = new Image();
			document.preload[i++].src = imgs[j];
		}
	}
}

function restore(){ 
	var i, x, a = document.swaps; 
	if( a ) for( i = 0; i < a.length; i++)
		if( a[i].oldSrc ) a[i].src=a[i].oldSrc;
}

function getDescrption(hcid)
{
//Changes By Sasanka for FireFox
if(window.location.href.indexOf("ChangeOrder")>=0)
		window.location.href="/ForYourBusiness/Order/ChangeOrder/common/DisplayDescription.aspx?hcid=" + hcid;
	else
		window.location.href="/ForYourBusiness/Order/NewConnect/common/DisplayDescription.aspx?hcid=" + hcid;
}


function swap(){ 
	var i, j = 0, a = swap.arguments; 
	document.swaps = new Array; 
	for( i = 0; i < ( a.length - 1 ); i += 2 ){
		document.swaps[j++] = a[i];
		if( !a[i].oldSrc ) a[i].oldSrc = a[i].src;
		a[i].src = a[i + 1];
	}
}

function openW(url, name, w, h) {
	
	var windowprops = "width=" + w + ",height=" + h;
	popup = window.open(url, name, windowprops);
	setTimeout('popup.focus();',250);
}
function openWSizable(url,w, h) {
	var windowprops = "width=" + w + ",height=" + h + ",scrollbars=yes";
	popup = window.open(url, name, windowprops);
	setTimeout('popup.focus();',250);
}

//////////////////////////////////////////////////////////////////
function setCheckboxvalues(){
	for(i=0;i<document.mainForm.elements.length;i++){
		if (document.mainForm.elements[i].type=="checkbox"){
			
			if (document.mainForm.elements[i+1].name == "hd_" + document.mainForm.elements[i].name){
				if (document.mainForm.elements[i].checked==true){
				document.mainForm.elements[i+1].value=document.mainForm.elements[i].value;
				}
				else{
				document.mainForm.elements[i+1].value="0";
				}
			}
		}
	}
}

//////////////////////////////////////////////////////////////////
function SelectAllCheckboxes()
{
	for(i=0;i<document.mainForm.elements.length;i++)
	{
		if (document.mainForm.elements[i].type=="checkbox")
		{
			document.mainForm.elements[i].checked = true
		}
	}
}
//////////////////////////////////////////////////////////////////
function submitForm(strPage,strMethod)
{ 
	document.mainForm.action=strPage;
	document.mainForm.method=strMethod;
	document.mainForm.submit();
	//return true;
}
//////////////////////////////////////////////////////////////////
function AssignProductValues(prodid,prodnsme,prodcateg,prodpricedrc,prodpricenrc,strPage,strMethod)
{

	document.mainForm.elements["productid1"].value=prodid;
	document.mainForm.elements["productname"].value=prodnsme;
	document.mainForm.elements["productquantity"].value= document.mainForm.productquantity.value;
	document.mainForm.elements["productcategory"].value=prodcateg;
	document.mainForm.elements["productpricedrc"].value=prodpricedrc;
	document.mainForm.elements["productpricenrc"].value=prodpricenrc;
	document.mainForm.action=strPage;
	document.mainForm.method=strMethod;
	document.mainForm.submit();     
}

//////////////////////////////////////////////////////////////////
function Checkcreditinfo() {
		if(document.mainForm.bus_type_Owner[0].checked) {
			document.mainForm.action='credit_info.asp';
			document.mainForm.method='post'; 
			}
		else if (document.mainForm.bus_type_Owner[1].checked){
				document.mainForm.action='credit_infopartner.asp';
				document.mainForm.method='post';
			}	
		else if (document.mainForm.bus_type_Owner[2].checked){
				document.mainForm.action='credit_infocorporation.asp';
				document.mainForm.method='post';
			}		
		else{
				document.mainForm.action='credit_info.asp';
				document.mainForm.method='post';
				}
		
		document.mainForm.submit();
			
}
//********************************************************

//********************************************************
function jumpAnchor(targ,selObj,restore)
{ 
    
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    
	if (restore) selObj.selectedIndex=0;
}
//-------------------------------
//Validate For Number
function validateForNumber(sText){
		var sText=new String(sText);
		var notFound;
		var validNumbers=new Array(0,1,2,3,4,5,6,7,8,9);
		var stringLength=sText.length;
		var numberLength=validNumbers.length;
		for (i=0; i < stringLength;i++){
			notFound=0;
			for (j=0; j < numberLength;j++){
				if (sText.charAt(i)!= validNumbers[j]){
					notFound=notFound+1
				}
			}
	}
if (notFound==numberLength)
	return false;
else
	return true;
}
//-----------------------------

//-checking for Wire Plan Selection------
function checkforthis(btn){
var len,lenChecked,stValue,msgError;
msgError=""
lenChecked=0;
stValue=0;
var strName=new String();
len=document.mainForm.elements.length;
for (i=0;i<len;i++){
	strName=document.mainForm.elements[i].name;
	if ((strName.indexOf(btn) > -1) && (document.mainForm.elements[i].type =="radio")){
		if (document.mainForm.elements[i].checked==true){
		lenChecked=lenChecked+1;
			if (document.mainForm.elements[i].value != "NO,0,0,0"){
				if (document.mainForm.elements["nos"].value =="1"){ 
					
					if ((Trim(document.mainForm.elements["st"+btn].value)=="")||(Trim(document.mainForm.elements["st"+btn].value) =="0")||(Trim(document.mainForm.elements["st"+btn].value) =="00"))
						stValue=1;
					else if (isNaN(Trim(document.mainForm.elements["st"+btn].value))) 
						stValue=2;
					
					//else if (!validateForNumber(document.mainForm.elements["st"+btn].value))
					//	stValue=2;
					
				 }   	
			}		
		}
	}
}
	if (lenChecked == 0){
	msgError="Error: Please select Wire Plan Radio Button for Telephone Number " + btn + "\n" }
	else{
		if (stValue==1)
			msgError="Error: Please Enter the Number of Stations for Telephone Number " + btn + "\n" 
		else if (stValue==2)
			msgError="Error: Please Enter Correct Value for Number of Stations for Telephone Number " + btn + "\n"	
	}
	return msgError;
}
//-checking for Wire Plan Selection------
function OpenWindow(url)
{
	window.open(url)

}
//*****************************************
/*function validateForNumber(strText)
	{
		var sNum=new String(strText);
		var len;
		//var i, j, iEmailIdLength, iNumValidValues, iNumAts			//counters and subscripts
		var aValidValues = new Array("0","1","2","3","4","5","6","7","8","9")		 //array that stores valid values
		//var pEmailId
		iNumAts = 0
		//iEmailIdLength = pEmailId.length
		iNumValidValues = aValidValues.length
		len=strText.Length;
		alert(len)
		for (i = 0; i < sNum.Length; i++) 
		{   alert(sNum.charAt(i))
			for (j = 0; j < iNumValidValues; j++) 
			{  
				if (sNum.charAt(i) == aValidValues[j])
				iNumAts++;
				break;            
			}
			if (j > (iNumValidValues -1))
				return false;
		}
		alert(iNumAts)
		if (iNumAts ==0) 
		{
			return false;
		}
		return true;
	}*/
//******************************
/*
** This function will trim leading
** and trailing spaces from the
** passed string with the
** result returned as the return value.
*/

function Trim(xstrValue){
	// Trim leading characters
	xstrValue = xstrValue.replace(/^\s+/, "");

	// Trim trailing characters
	xstrValue = xstrValue.replace(/\s+$/, "");

	return xstrValue;
}

function isZipCode(zipcode){
	if ((Trim(zipcode).length == 10) || (Trim(zipcode).length == 5)|| (Trim(zipcode).length == 9)){
	//alert(Trim(zipcode).length)
	if (Trim(zipcode).length==10) {
			var len=Trim(zipcode).indexOf("-");
			if (len==5) {
				var str1,str2;
				str1=Trim(zipcode).substr(0,len)
				str2=Trim(zipcode).substr(len+1,Trim(zipcode).length)
				if ((isNaN(str1)) ||(isNaN(str2))){
					return false;
				}
			}
			else 
			{return false;}
		}	
		else if ((Trim(zipcode).length==5)||(Trim(zipcode).length==9)) {
			if (isNaN(Trim(zipcode))){
				return false;
			}
		}	
		
	}
	else
	{	//alert(Trim(zipcode).length)
		return false;
	}
}

//*******************************
function selectState(controlName,value){
	if (value!=""){
	var len=controlName.options.length;
	for (i=0;i<len;i++){
		if (controlName.options[i].value==value){
			controlName.selectedIndex=i;
		}
		//controlName.value=value;
		}
	}
}
//*****************************

function showpopup(filelink){
	var mywin ; 
	
	mywin = window.open(filelink,'myWindow','scrollbars=yes,resizable=yes,status=yes,width=600,height=500') ;	
}
//******************************



// This function is specif to FeatureCalatog page and Other Feature Additions pages 
// dinakar Oct 30 2005 
// CID - 392000.5 
function isDeniedProductSelected()
{
	var vBasicInd = document.mainForm.hdnBasicInd.value;
	var vNonBasicInd = document.mainForm.hdnNonBasicInd.value;
	var vTollInd = document.mainForm.hdnTollInd.value;

	vBasicInd = vBasicInd.toUpperCase();
	vNonBasicInd = vNonBasicInd.toUpperCase();
	vTollInd = vTollInd.toUpperCase();

	var strName = "";
	var strValue = "";
	var len = document.mainForm.elements.length;
	for (i=0; i<len; i++)
	{
		strName = document.mainForm.elements[i].name;
		if ((document.mainForm.elements[i].type == "radio") || (document.mainForm.elements[i].type == "checkbox"))
		{
			if (document.mainForm.elements[i].checked == true)
			{
				strValue = document.mainForm.elements[i].value; 
				if (strName.indexOf("prd") > -1)
				{
					var page_hc_ids = strValue.split(",");
					if (page_hc_ids.length > 0) 
					{
						var page_hc_id = page_hc_ids[0];
						var retValue = checkTreatmentStatus(page_hc_id, vBasicInd, vNonBasicInd, vTollInd);
						if (retValue == "DENIED") 
						{
							document.mainForm.hdnDueDays.value = "";
							alert("Due to a credit issue on your account, we cannot continue your order at this time. \nWe suggest that you either pay your bill online https://www20.verizon.com/secure/pages/paybill/ \n(or)\n pay your bill by phone call at 1-800-345-6563.");
							return true;
						}
						else if (retValue == "TERMINATED") 
						{
							document.mainForm.hdnDueDays.value = "30";
							alert("Due to a credit issue on your account, we cannot provide a due date for this order.  You can continue and submit your order and a credit representative will contact you by email.");
							return false; // we need to continue order so return false
						}
					}
				}
			}
		}
	}
	return false;
}


// This function is specif to WorkSmart pages 
// dinakar Oct 30 2005 
// CID - 392000.5 
function isWorkSmartPackageDenied()
{
	var vBasicInd = document.mainForm.hdnBasicInd.value;
	var vNonBasicInd = document.mainForm.hdnNonBasicInd.value;
	var vTollInd = document.mainForm.hdnTollInd.value;

	vBasicInd = vBasicInd.toUpperCase();
	vNonBasicInd = vNonBasicInd.toUpperCase();
	vTollInd = vTollInd.toUpperCase();

	var strName = "";
	var strValue = "";
	var len = document.mainForm.elements.length;
	for (i=0; i<len; i++)
	{
		strName = document.mainForm.elements[i].name;
		if ((document.mainForm.elements[i].type == "radio") || (document.mainForm.elements[i].type == "checkbox"))
		{
			if (document.mainForm.elements[i].checked == true)
			{
				strValue = document.mainForm.elements[i].value; 
				if (strName.indexOf(",") > -1)
				{
					var page_hc_ids = strValue.split(",");
					if (page_hc_ids.length > 0) 
					{
						var page_hc_id = page_hc_ids[0];
						var retValue = checkTreatmentStatus(page_hc_id, vBasicInd, vNonBasicInd, vTollInd);
						if (retValue == "DENIED") 
						{
							document.mainForm.hdnDueDays.value = "";
							alert("Due to a credit issue on your account, we cannot continue your order at this time. \nWe suggest that you either pay your bill online https://www20.verizon.com/secure/pages/paybill/ \n(or)\n pay your bill by phone call at 1-800-345-6563.");
							return true;
						}
						else if (retValue == "TERMINATED") 
						{
							document.mainForm.hdnDueDays.value = "30";
							alert("Due to a credit issue on your account, we cannot provide a due date for this order.  You can continue and submit your order and a credit representative will contact you by email.");
							return false; // we need to continue order so return false
						}
					}
				}
			}
		}
	}
	return false;
}

// This function is specif to FTTP, LINEHUNT pages 
// dinakar Oct 30 2005 
// CID - 392000.5 
function isDeniedProduct(phc_id)
{
	var vBasicInd = document.mainForm.hdnBasicInd.value;
	var vNonBasicInd = document.mainForm.hdnNonBasicInd.value;
	var vTollInd = document.mainForm.hdnTollInd.value;

	vBasicInd = vBasicInd.toUpperCase();
	vNonBasicInd = vNonBasicInd.toUpperCase();
	vTollInd = vTollInd.toUpperCase();

	var page_hc_id = phc_id;
	var retValue = checkTreatmentStatus(page_hc_id, vBasicInd, vNonBasicInd, vTollInd);
	if (retValue == "DENIED") 
	{
		document.mainForm.hdnDueDays.value = "";
		alert("Due to a credit issue on your account, we cannot continue your order at this time. \nWe suggest that you either pay your bill online https://www20.verizon.com/secure/pages/paybill/ \n(or)\n pay your bill by phone call at 1-800-345-6563.");
		return true;
	}
	else if (retValue == "TERMINATED") 
	{
		document.mainForm.hdnDueDays.value = "30";
		alert("Due to a credit issue on your account, we cannot provide a due date for this order.  You can continue and submit your order and a credit representative will contact you by email.");
		return false; // we need to continue order so return false
	}
	return false;
}


// This function is specif to FeatureCalatog page and Other Feature Additions pages 
// dinakar Oct 30 2005 
// CID - 392000.5 
function checkTreatmentStatus(page_hc_id, vBasicInd, vNonBasicInd, vTollInd)
{
	//case1: basic product denied and terminated then user cannot proceed 
	if (vBasicInd == "DENIED" || vBasicInd == "TERMINATED")
	{
		return "DENIED";
	}

	//case2: user cannot order nonbasic products 
	if (vNonBasicInd == "DENIED")
	{
		var denied_hc_id = document.mainForm.hdnNonBasic.value;
		var denied_hc_ids = denied_hc_id.split(",");
		for(j=0; j<=denied_hc_ids.length; j++) 
		{
			if (page_hc_id == denied_hc_ids[j])
			{
				return "DENIED";
			}
		}
	}

	//case3: user cannot order toll products 
	if (vTollInd == "DENIED")
	{
		var denied_hc_id = document.mainForm.hdnToll.value;
		var denied_hc_ids = denied_hc_id.split(",");
		for(j=0; j<=denied_hc_ids.length; j++) 
		{
			if (page_hc_id == denied_hc_ids[j])
			{
				return "DENIED";
			}
		}
	}

	//case4: user can order nonbasic products but duedate will be 30 days 
	if (vNonBasicInd == "TERMINATED")
	{
		var denied_hc_id = document.mainForm.hdnNonBasic.value;
		var denied_hc_ids = denied_hc_id.split(",");
		for(j=0; j<=denied_hc_ids.length; j++) 
		{
			if (page_hc_id == denied_hc_ids[j])
			{
				return "TERMINATED";
			}
		}
	}

	//case5: user can order toll products but duedate will be 30 days 
	if (vTollInd == "TERMINATED")
	{
		if (page_hc_id == "25151") 
			return "TERMINATED";
		var denied_hc_id = document.mainForm.hdnToll.value;
		var denied_hc_ids = denied_hc_id.split(",");
		for(j=0; j<=denied_hc_ids.length; j++) 
		{
			if (page_hc_id == denied_hc_ids[j])
			{
				return "TERMINATED";
			}
		}
	}

}