// source from http://developer.netscape.com/viewsource/goodman_modal/goodman_modal.html
//var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
// browser version  4 and up
var is_major = parseInt(navigator.appVersion) >=4;
var isIE = (navigator.appName == "Microsoft Internet Explorer");

var jmpcnt=1;

// showOS & hideOS are used by the searchMenu.jsp
//function showOS() {
//	showMenu('osmenu','visible');
//}

//function hideOS() {
//	showMenu('osmenu','hidden');
//}
//function showMenu(id, v) {
//	if (isIE) {
//		document.all[id].style.visibility = v;
//	}
	//add Netscape later
	//document.layers[id].visibility = v;
//}

// whitespace characters
var whitespace = " \t\n\r";
var msg = "one or more";

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function checkQuery (theField) {
	if (isWhitespace(theField.value)) {
		theField.focus();
		theField.select();
		
		alert("Please type in one or more key words before searching. ");
		return false;
	} else {
		return true;
	}
}

function doSubmit(obj)
{

	return checkQuery(document.search.query);
   
}

function doSubmitDBKeywd(obj,fld)
{

	return checkDBKeywd(fld);
   
}

function checkDBKeywd (theField) {
	if (isWhitespace(theField.value)) {
		theField.focus();
		theField.select();
		
		alert("You must type in one or more words to search. ");
		return false;
	} else {
		return true;
	}
}

function countjumps() 
{
	jmpcnt++;
        //alert used for debugging.
	//var msg = "you jump " + jmpcnt + " times";
	//alert(msg);
}
function goback()
{
	// To go back to previous page, subtract the internal links
        // the user click on.
	history.go(-jmpcnt); 
}

function popup(url, url2)
{
	// centered popup on screen, originate from Eric King, http://redrival.com/eak/
	// This script and many more are available free online at  
	// The JavaScript Source!! http://javascript.internet.com 

	//alert("version " + parseInt(navigator.appVersion));
	
	var w =500;
	var h= 100;
	var winl= 260;
	var wint= 400;
	

	if (is_major) {
	   winl = (screen.width - w) / 2;
	   wint = (screen.height - h) / 2;
	   //alert("width " + screen.width + " height " + screen.height);

	}

	var wdim;


	// do not do this, because a redirect will be done first.
	// iw.darcknet.com for dev, support.worldnet.att.net for prod

	//if (location.hostname != "iw.darcknet.com" &&
	//    location.hostname != "support.worldnet.att.net")

	if (location.hostname != "support.worldnet.att.net")
	{
		// do the expanded search
		if (is_major) {
			//wdim='height='+h+',width='+w+',top='+wint+',left='+winl+
		         //    ',scrollbars='+scroll+',resizable';
			wdim='height='+h+',width='+w+',top='+wint+',left='+winl;
			//wdim='height='+h+',width='+w;
			//alert("Trying to open window");
			win = window.open(url, "popup",wdim);
		 	win.window.focus(); 
			location.replace(url2);
		} else {
			// no longer supporting NS3
			//wdim='height='+h+',width='+w+
		        //     ',scrollbars='+scroll+',resizable';
			//win = window.open(url, "iwpop",wdim);
			//location.href = url2;
		}
	}
	return true;


}

function popdown()
{
	//close window after n secs
	n = 5000;    // 5 secs
	setTimeout('window.close()',n);
	return true;

}


// ********** Begin PPHS return cookie code
var wnargs      = 'WN-ARGS';
var pphs        = 'PPHS';
var ppcode      = '0C';
var cooky       = '';
// .net for prod
//var pphs_domain = '.att.net';      // leading dot may be important!
// .com for lab
//var pphs_domain = '.att.com';

function NV_GetValue(str,name,delim) {
        var s  = delim+str+delim;
        var nm = delim+name+'=';
        var i  = s.indexOf(nm);
        if (i == -1) { return ""; }
        i += nm.length;
        var j = s.indexOf(delim, i);
        return s.substring(i,j);
}

function Cookie_Get(nm) {
        return NV_GetValue(document.cookie,nm,'; ');
}

function Crumb_Get(str,nm) {
        return NV_GetValue(str,nm,'&');
}

function Cookie_Set(nm,val) {
    document.cookie = nm + "=" + val + "; path=/" +
                "; domain=" + pphs_domain +
                "; expires=Sun, 29-Dec-2002 00:00:01 GMT";
}
// ********** End of PPHS cookie code


//redirect if the user still using old url - support.worldnet.att.net.
function redirect() 
{
	//if (location.hostname == "iw.darcknet.com" ||
	//    location.hostname == "support.worldnet.att.net")

	if (location.hostname == "support.worldnet.att.net")
	{
	   var href = "http://help.att.net" + location.pathname+ location.search
	   //alert("matched " + href);
	   location.replace(href);
	} 
	//for testing
	//else {
        //	 alert("does not match " + location.hostname)
	//}


	// ********** Read DSL partner cookie
//      if (location.host != "mtviw07.ccc.worldnet.att.net:7778") {
//	cooky = Cookie_Get(wnargs);
//	if (cooky != "") {
//        	var crumb = Crumb_Get(cooky, pphs);
//        	if (crumb == "0C" || crumb == "0c") {
//			// DSL site homepage
//			//window.location="http://www.attworldnetdsl.com/common/0,,pageId%3Dhelp%252Findex,00.html";
//			//window.location="http://localhelp.att.net/dsl/help/index.html";
//			window.location="http://dslhelp.att.net/";
//        	}
//        	else if (crumb == "0F" || crumb == "0f") {
//			// Covad DSL site homepage
//			window.location="http://atthelpdsl.att.net/";
//        	}
//		//for testing
//		//else {
//        	// 	alert("no cookie crumb")
//		//}
//	}
//	//for testing
//	//else {
//      //  	 alert("no cookie")
//	//}
//      }
}


	// LUPA - ACCESS NUMBER script functions
 function examine(v,f){

                number = "";

                for(i=0;i<v.length;i++){

                temp = v.substring(i,i+1);

                  if(temp == "(" || temp == ")" ||temp == "-" ||temp == " " || temp == "."){}

                  else {
                   if (temp<"0" || temp>"9") {
                        return false;}
                   else {number+=temp;}
                   }

                  }
                  if (number.length==10) {
                        f.lupa_phone_number.value = number.substring(0,3)+"-"+number.substring(3,6)+"-"+number.substring(6,10);
                        return true;}
		 else {return false;}
                  }
         function phlookup(v,f,vpath){
                if(examine(v,f)){
                        f.action=vpath + "phoneLookup.jsp";
                }
                else{
                        alert("You have not entered a 10-Digit telephone Number.  Please enter your telephone number with area code.");
                        f.action=document.location;
                        return false;}
                        return true;
                }

         function agentphlookup(v,f,vpath){
                if(examine(v,f)){
                        f.action=vpath + "phoneLookup.jsp";
                }
                else{
                        alert("You have not entered a 10-Digit telephone Number.");
                        f.action=document.location;
                        return false;}
                        return true;
                }

	// SPOCSURVEY page functions
function update_spoc() {
  //defaults to iwreport
  var spoc_url = 'http://iwreport.ccc.worldnet.att.com/cgi-bin/mailer_back.cgi';
  if (location.host.indexOf("att.net") > -1) {
        spoc_url = 'http://mtviw08.ccc.worldnet.att.net:90/cgi-bin/mailer_back.cgi';
  }
        document.survey.action = spoc_url;
}

function formCheck() {
 var errStr = ""
 var choice = document.survey.User_location.selectedIndex;
 if (document.survey.Problem_category.selectedIndex==0) {
  errStr += "\n\t- Problem Category";
 }
 if (document.survey.PROBLEM.value == "") {
  errStr += "\n\t- Problem Description";
 }
 if (choice == 0) {
  errStr += "\n\t- User Location";
 }
//if (document.survey.NAME.value == "" ) {
 // errStr += "\n\t- Full Name";
 //}
if (errStr != "") {
  errStr = "Please enter the following required field(s):\n" + errStr
+ "\n";
  alert(errStr);
 }
 else {
  update_spoc();
  document.survey.submit();
 }
}

function tech_check(){
 if (document.survey.Problem_category[document.survey.Problem_category.selectedIndex].value == "Technical"){
  alert ("Please contact your SPOC to submit Technical Fixes/Corrections.");
     document.survey.Problem_category.selectedIndex=0;
 }
}
function StartTutorial() 
{
window.open
("/care/ccforums/newusers/email/send-receive.html","NewAgentLogin","width=700,height=500,toolbar=1,location=1,directories=0,status=0,resizable=yes,scrollbars=yes,menubar=yes");
}

function StartBulletins() 
{
window.open("http://care.att.net/bulletins/index.html","NewAgentLogin","width=700,height=500,toolbar=1,location=1,directories=0,status=0,resizable=yes,scrollbars=yes,menubar=yes");
}

function StartResource()                                                        
{                                                                               
window.open("http://help.att.net/care/ccforums/browsers/tcpip-dun.html?platform=none","NewAgentLogin","width=700,height=500,toolbar=1,location=1,directories=0,status=0,resizable=yes,scrollbars=yes,menubar=yes");
}                                                                               

function StartNewWindow() 
{
window.open("http://helpchat.att.net/wnindex.html", "NewAgentLogin","width=640,height=480,toolbar=0,location=0,directories=0,status=0,resizable=yes,scrollbars=yes,menubar=no");
}

function StartAccessInfo() 
{
window.open("/iw/ci/access_info.jsp", "NewAgentLogin","width=800,height=600,toolbar=1,location=1,directories=1,status=1,resizable=yes,scrollbars=yes,menubar=yes");
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else
		countfield.value = maxlimit - field.value.length;
}

function formsurveyCheck() {

 var errStr = ""

 var choice = document.survey.User_location.selectedIndex;

 if (document.survey.location.selectedIndex==0) {

  errStr += "\n\t- Location";

 }

 if (document.survey.segment.value == "") {

  errStr += "\n\t- Segment";

 }

 if (choice == 0) {

  errStr += "\n\t- User Location";

 }

 //if (document.survey.NAME.value == "" ) {

 // errStr += "\n\t- Full Name";

 //}

 if (errStr != "") {

  errStr = "Please enter the following required field(s):\n" + errStr + "\n";

  alert(errStr);

 }

 else {

  document.survey.submit(); 

 }

}






