//run onload
self.focus();

//added 3/31/09 - membership promo...
var xmlhttp;
var membershipPromoAppealCode;
var membershipPromoCodeID;
var membershipPromoLastName;

function validateMemberPromoEntries(ObjectForm){
	var codeID = ObjectForm.codeid.value;
	var lastName = ObjectForm.lastname.value;
	var appealCode = ObjectForm.appealcode.value;
	var url = "/ecomv2/membership/activatespoffer.asp?codeid=" + codeID + "&lastname=" + lastName + "&appealcode=" + appealCode;
	
	membershipPromoAppealCode = appealCode;
	membershipPromoCodeID = codeID;
	membershipPromoLastName = lastName;
	
	validateMemberPromoEntries_loadXMLDoc(url);
}


function validateMemberPromoEntries_loadXMLDoc(URL)
{
	xmlhttp=null;
	if (window.XMLHttpRequest)
	{// code for Firefox, Opera, IE7, etc.
	xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null)
	{
	xmlhttp.onreadystatechange=validateMemberPromoEntries_StateChange;
	xmlhttp.open("GET",URL,true);
	xmlhttp.send(null);
	}
	else
	{
	alert("Your browser does not support XMLHTTP.");
	}
}

function validateMemberPromoEntries_StateChange()
{
	if (xmlhttp.readyState==4)
	{// 4 = "loaded"
	if (xmlhttp.status==200)
		{// 200 = "OK"
			if (xmlhttp.responseText=="OK"){
				//redirect to captcha...
				//self.location = "/ecomv2/membership/spmembf01.asp?appealcode=" + membershipPromoAppealCode + "&prospectid=" + membershipPromoCodeID;	
				self.location = "/security/process_prioritycode.aspx?codeid=" + membershipPromoCodeID +  "&lastname=" + membershipPromoLastName + "&appeal_code=" + membershipPromoAppealCode;
				
			}
			else{
				//alert("Retry, maybe?");
				self.location = "/security/process_prioritycode.aspx?codeid=" + membershipPromoCodeID +  "&lastname=" + membershipPromoLastName + "&appeal_code=" + membershipPromoAppealCode;
			}
		}
	else
		{
			alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
}


//added 3/13/08 by zaldy for custom membership appeal codes handler 
function proceedMembershipPurchase(){
    self.location = "/ecomv2/membership/membf01.asp?appeal_code=" + getQueryVariable("appeal_code");
}

//generic function that parses query string from the URL
function getQueryVariable(variable) { 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) 
    { 
        var pair = vars[i].split("="); 
        if (pair[0] == variable) 
        { 
            return pair[1]; 
        } 
    } 
    return ''; 
} 


//added 2/7/08 by zaldy for best offer page
function nextStep(objForm){
    var appeal_Code = "**Web-Best_Offer";
    var priority_value = objForm.codeid.value;
    var priority_length = priority_value.length;
    var priority_isNaN = isNaN(priority_value);
    var lastname = objForm.lastname.value;
    
    //validate priority code...
    if (priority_length==0){
        alert("Please enter your priority code");
        objForm.codeid.value = "";
        objForm.codeid.focus();
        return;
    }else if(priority_length<=6){
        if(priority_isNaN){
            alert("Please enter valid priority code");
            objForm.codeid.value = "";
            objForm.codeid.focus();
            return;
        }
    }else if(priority_length<=9 && priority_length>7){
        var priority_7 = priority_value.substring(0,7);//alert(priority_7 );
        var priority_7_isNaN = isNaN(priority_7);
        var priority_8 = priority_value.substring(0,8);
        var priority_8_isNaN = isNaN(priority_8);
        var priority_9 = priority_value.substring(8);
        var priority_9_isNaN = isNaN(priority_9);
        
        
        if (priority_9_isNaN){
	    if (priority_8_isNaN){
	         if (priority_7_isNaN){
            	      alert("Please enter valid priority code");
            	      objForm.codeid.value = "";
            	      objForm.codeid.focus();
            	      return;
		 }
	    }
        }
    }else{
        alert("Please enter valid priority code");
        objForm.codeid.value = "";
        objForm.codeid.focus();
        return;
    }
      
   self.location='/security/process_prioritycode.aspx?codeid=' + priority_value  + '&lastname=' +  lastname +  '&appeal_code=' + appeal_Code;
}

//added 2/6/09 by zaldy - modified next step...
//this can handle different appeal codes pass in to the function...
function sumbitMembershipPromoOffer(objForm, appealCode){
    var appeal_Code = appealCode;
    var priority_value = objForm.codeid.value;
    var priority_length = priority_value.length;
    var priority_isNaN = isNaN(priority_value);
    var lastname = objForm.lastname.value;
    
    //validate priority code...
    if (priority_length==0){
        alert("Please enter your priority code");
        objForm.codeid.value = "";
        objForm.codeid.focus();
        return;
    }else if(priority_length<=6){
        if(priority_isNaN){
            alert("Please enter valid priority code");
            objForm.codeid.value = "";
            objForm.codeid.focus();
            return;
        }
    }else if(priority_length<=9 && priority_length>7){
        var priority_7 = priority_value.substring(0,7);
        var priority_7_isNaN = isNaN(priority_7);
        var priority_8 = priority_value.substring(0,8);
        var priority_8_isNaN = isNaN(priority_8);
        var priority_9 = priority_value.substring(8);
        var priority_9_isNaN = isNaN(priority_9);
        
        
        if (priority_9_isNaN){
	    if (priority_8_isNaN){
	         if (priority_7_isNaN){
            	      alert("Please enter valid priority code");
            	      objForm.codeid.value = "";
            	      objForm.codeid.focus();
            	      return;
		 }
	    }
        }
    }else{
        alert("Please enter valid priority code");
        objForm.codeid.value = "";
        objForm.codeid.focus();
        return;
    }
      
   self.location='/security/process_prioritycode.aspx?codeid=' + priority_value  + '&lastname=' +  lastname +  '&appeal_code=' + appeal_Code;
}

function goFieldGuide(sAnimal){
	if (sAnimal != "#") {
		var frameWindow	=  window.open("/pagegen/htm/fix/fg/guide00.asp?sAnimal=" + escape(sAnimal),"Fieldguide","toolbar=no,width=484,height=350,scrollbars=no,resize=yes");}
}

function openNewWindow(Width, Height,URL,Name) {
		if (document.all)
			var xMax = screen.width, yMax = screen.height;
		else
			if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 640, yMax=480;


	    var xOffset = (xMax - Width)/2, yOffset = (yMax - Height)/2;

		newWin=window.open(URL,Name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=' + Width + ',height=' + Height + ',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset);
		newWin.focus();
		newWin.name = Name;
	}


/*
ecommerce use only...
added: 11/23/04 - za
*/
function openProductImage(Width, Height,URL,Name) {
		if (document.all)
			var xMax = screen.width, yMax = screen.height;
		else
			if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 640, yMax=480;


	    var xOffset = (xMax - Width)/2, yOffset = (yMax - Height)/2;

		newWin=window.open(URL,Name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + Width + ',height=' + Height + ',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset);
		newWin.focus();
		newWin.name = Name;
	}


function switcher(mystring,stringfind,swithwith){
		var strValue = mystring;
		var intLength = strValue.length;
		var charValue = strValue.substr(intLength-1,1)
		var strReturnValue = "";

		for (var i=0;i<intLength;i++){
			charValue = strValue.substr(i,1);
			if(charValue == stringfind){
				charValue = swithwith;
			}
			
			strReturnValue = strReturnValue + charValue;			
		}
		return strReturnValue;
	}
	
function trimString(strText){
	//trim leading spaces
	while(''+strText.charAt(0)==' ')
		strText=strText.substring(1,strText.length);

	//trim trailing spaces
	while(''+strText.charAt(strText.length-1)==' ')
		strText=strText.substring(0,strText.length-1);

	return strText;
}

<!-- Original:  Bill Dortch, Idaho Design (bdortch@netw.com)

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; 
}
return null;
}  

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function show_count() {
var expdate = new Date();
var num;
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 31)); 
if(!(num = GetCookie("jtotwcount"))) 
num = 0;
num++;
SetCookie ("jtotwcount", num, expdate);
if (num == 1) document.write("Since this is the first time you have been here, please take a moment to look around.");
else document.write("You have been here " + num + " times."); 
}
function auto_show_name() {
if(GetCookie("jtotwname") != null)
document.write("Welcome back to this week\'s tip " + GetCookie('jtotwname') + ". ");
else {
document.write("<FORM>Please enter your name: <INPUT TYPE = \"text\" NAME = \"nameinput\">" + "<BR><BR><INPUT TYPE = \"button\" VALUE = \"Save to Cookie\" onClick = \"set_name(this.form)\"></FORM>");
document.write("Please enter your first name in the input" + " box and press the \"Save to Cookie\" button, then the page will automatically reload. ");
   }
}
function set_name(form) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
var username = form.nameinput.value
if (username != "") {
if (confirm("Are you sure you want this saved as your name?")) {
SetCookie ("jtotwname", username, expdate);
window.history.go(0);
   }
}
else alert("Geez, at least enter something, entering nothing will cause an error.");
}
// End -->


//CET Specific....
function overrideCETSearch(StartDate,EndDate,Topic){
	var strURLSearch;
	if(!isDate(StartDate) || !isDate(EndDate)){ 
		alert("Invalid Date Range.  Date format must be MM/DD/YYYY");
		return;
	}
	strURLSearch = "/ecommerce/regsearch.aspx?startdate=" + StartDate + "&enddate=" + EndDate + "&topic=" + Topic;
	//if (StartDate=='1/1/08') alert(strURLSearch);
	self.location = strURLSearch;
}



//Date Validator.....

function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function




function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function


