
var advisorSelectMessage = "You must select a client before importing from Albridge";


function importAction(linkName, menuItem, params) {

    var mode = "";

    if (linkName.toLowerCase() == "albridge_web_services") {

        if (menuItem.toLowerCase() == "search" && params.indexOf("AisIsLogin=true") < 0 && params.indexOf("AdvisorId=All") > 0) {
            alert(advisorSelectMessage);
            return;
        }
        mode = "webservice";
    }
    else if (linkName.toLowerCase() == "albridge_csv") {
        if (menuItem.toLowerCase() == "search" && params.indexOf("AdvisorId=All") > 0 && params.indexOf("AisIsLogin=false") > 0) {
            alert(advisorSelectMessage);
            return;
        }
        mode = "csv";
    }
    else if (linkName.toLowerCase() == "advisoryworld_report") {
        mode = "report";
    }

    var wnd = window.open('../AlbridgeApp/View/Index.aspx' + params + "&menuItem=" + menuItem + "&mode=" + mode, '_blank', '');
    wnd.moveTo(0, 0);
    wnd.resizeTo(screen.width, screen.height);
}




function ValueOfChange(tag, event) {
    if (event.keyCode == 13) {
        if (dateValid(tag.value, tag.name)) {
            document.getElementById('dateValueOf').value = tag.value;
            portfolioForm.submit();
        }
        else {
            alert("Please input the right format of date(mm/dd/yyyy) and 2200>year>2000");
        }
    }
}

function ChangePortfolioLastUpdate(thisobj) {
    document.location.replace("editPopupWindow.asp?command=edit&name=Portfolio&policy=" + thisobj.options[thisobj.selectedIndex].attributes["appid"].value.toString());
}

String.prototype.trimNbsp = function () {
    return (this.replace(/&nbsp;&nbsp;$/, ''));
}

String.prototype.trim = function () {
    return (this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/, '$1'));
}
function timerchk() {

    alert(' Testing ');

}
var setmins
var setsecs;

function getcd() {
    
 	setmins = 1 * getmin("45"); // change minutes here
 	setsecs = 0 + getsec(":01"); // change seconds here (always add an additional second to your total)
 	getredo();
}

function getreset() {
	setmins = 1 * getmin("45");
	setsecs = 0 + getsec(":01");
}

function getmin(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(0, i));
}

function getsec(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(i + 1, obj.length));
}

function getdis(setmins,setsecs) {
 	var disp;
 	if(setmins <= 9) {
  		disp = " 0";
 	} else {
  		disp = " ";
 	}
 	disp += setmins + ":";
 	if(setsecs <= 9) {
  		disp += "0" + setsecs;
 	} else {
  		disp += setsecs;
 	}
 	return(disp);
}

function getredo() {
 	
 	if (isObject("ct")) {
 		document.timerform.ct.value = getdis(setmins,setsecs); // setup additional displays here.
 	}
 	if((setmins > 0)&&((setsecs == 10)||(setsecs == 20)||(setsecs == 30)||(setsecs == 40)||(setsecs == 50))) {
 		 var getcnum = getTimerCookie('ZukOpsMain');
 		if (getcnum == "C"){
alert('closing1');
			if (isObject('Winstatus')){document.location.replace('test.asp?menuName=LogOff');}
			else {WindowClose();}
		}
		getcd = setTimeout("getredo()",1000);
 	} 		
 	else if((setmins > 1)&&(setsecs == 0)) {
 		if (getcnum == "N"){
			//alert(" window testing "+setmins+" " +setsecs);
alert('closing2');
			if (isObject('Winstatus')){document.location.replace('test.asp?menuName=LogOff');}
			else {WindowClose();}
		}
		getcd = setTimeout("getredo()",1000);
 	}
 	else if((setmins == 0) && (setsecs == 59)) {
 	    if (isObject("Winstatus"))	{ var MenuName=Winstatus.value;}
 	    else if (isObject("Mname"))	var MenuName=Mname.value;
 	    else var MenuName = "None";
 	    	    
 	    var getcnum = getTimerCookie('ZukOpsMain');
		if (getTimerCookie('ZukOpsMain') == "C"){
			if (isObject('Winstatus')){	document.location.replace('test.asp?menuName=LogOff');}
			else {WindowClose();}	  
		}
		else if (getcnum == "6"){
			//getcd = setTimeout("getredo()",1000);
		}
		else if ((getcnum == "0")||(getcnum == "1")||(getcnum == "2")||(getcnum == "3")||(getcnum == "4")||(getcnum == "7")){ 
 				if (isObject('Winstatus')){
 					deleteLoginCookie('ZukOpsMain');
 					GetTimerIn('R');
 				}
				getreset();
 			}	
 		else {
 			if (isObject("Winstatus")){	
 				GetTimerIn(6);
 				MenuName = Winstatus.value;
 				if (isObject("Mpolicy")){var mPolicy=Mpolicy.value;}
 				else {var mPolicy='View';}	
 				var msg1='Window Session will be timeout within a minute. Please, Click the OK button to keep the connection';
 				msg1 = 'mstr1=Main '+MenuName + ' ' + msg1 +'&name='+MenuName+'&policy='+mPolicy+'&type=idleCon';
				var winmsg = window.open('WinReturn.asp?'+msg1,'_blank','left=250,top=230,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=120,width=360');
			 }
 			else { 
 			    if (isObject("Mname")){
 						GetTimerIn(6);
 						MenuName=Mname.value;
 						if (isObject("Mpolicy")){var mPolicy=Mpolicy.value;}
 						else {var mPolicy='View';}	
 						if ((Mname.value=='Portfolio')&&(getcnum == '4')) {
 							deleteLoginCookie('ZukOpsMain');
 							GetTimerIn(2);
 							getreset();
 						}
 						else {	
 							GetTimerIn(6);
 							var msg1='Window Session will be timeout within a minute. Please, Click the OK button to keep the connection';
							if (MenuName==undefined) {MenuName='None';}
							msg1 = 'mstr1=' + msg1 +'&name='+MenuName+'&policy='+mPolicy+'&type=idleCon';
							var winmsg = window.open('WinReturn.asp?'+msg1,'_blank','left=250,top=230,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=120,width=360');
							}
					} 
			    }  
			}
		getcd = setTimeout("getredo()",1000);
  	  } 
 	 else if((setmins == 0) && (setsecs == 50)) {
 	   	if (getTimerCookie('ZukOpsMain') == "7"){
 				GetTimerIn(2);
 				getreset();
 				getcd = setTimeout("getredo()",1000);
 			}
 		else if (getTimerCookie('ZukOpsMain') == "C"){
			if (isObject('Winstatus')){alert('time3'); document.location.replace('test.asp?menuName=LogOff');}
			else {WindowClose();}	  
		}
 		else {getcd = setTimeout("getredo()",1000);}
  	 }		    
 	 else if((setmins == 0)&&((setsecs == 40)||(setsecs == 30)||(setsecs == 20))){
 		if (getTimerCookie('ZukOpsMain') == "C"){
			if (isObject('Winstatus')){alert('time4'); document.location.replace('test.asp?menuName=LogOff');}
			else {WindowClose();}	  
		}
 		else {getcd = setTimeout("getredo()",1000);}
  	
 	 }
 	 else if((setmins == 0) && (setsecs <= 10)) {
 			 var getcnum = getTimerCookie('ZukOpsMain');
 			if ((getcnum == "6")||(getcnum == "C")){
 				var subwin='subwin';
 				if (isObject('Winstatus')){	
 					var MenuName=Winstatus.value;
 					subwin="homewin";
 					}
 				else if (isObject("Mname"))	var MenuName=Mname.value;
 				else var MenuName = "None";
 				if (subwin=='subwin'){
 					deleteLoginCookie('ZukOpsMain');
 					GetTimerIn('C');
 					WindowClose();
 				}
 				else {
 					deleteLoginCookie('ZukOpsMain');
	 				GetTimerIn('C');
alert('time5'); 
	 				document.location.replace('test.asp?menuName=LogOff');
 				}	
 			}
 			else {
 				GetTimerIn(2);
 				getreset();
 				getcd = setTimeout("getredo()",1000);
  			}
 	 }
 	 else {
 		getcd = setTimeout("getredo()",1000);
 	}
}

function getinit() {
  getcd();
}
function GetTimerIn(num){
 	var tname = 'ZukOpsMain';
	var Lexp = new Date();
	var Lcontent, LContend;
    var num1=Math.floor(Math.random()*(999+1));
	Lexp.setTime(Lexp.getTime()+(1000*60*55));
	Lcontent=num;
	deleteLoginCookie(tname);
	setLoginCookie(tname,Lcontent,Lexp);
}
 
function getTimerCookie(name){
	var cookiename = name + "=";
	var dc = document.cookie;
	var begin, end;
	
	if (dc.length > 0){
		begin = dc.indexOf(cookiename);
		if (begin != -1) {
			begin += cookiename.length;
			end = dc.indexOf(";",begin);
			if (end == -1) {
				end = dc.length;
			}
			return unescape(dc.substring(begin, end));
		}
	}
	return "N";
}		 

function LoginCall(){
 	var tname = document.VbinForm.txtLoginName.value;
	//var tbin = document.VbinForm.txtBinCode.value;
	var Lexp = new Date();
	var Lcontent, LContend;
    var num=Math.floor(Math.random()*(99999999+1));
	var mtype='mtype=== erwdouli1239900-3werwe9090'+num
    Lexp.setTime(Lexp.getTime()+(1000*60));
	//alert('tests lib ' +tname);
	tname = tname.replace(" ",";;");
	if (tname.indexOf(";;") != -1){ tname=tname.substring(0,(tname.indexOf(";;")))}
	else {tname=tname.substring(0,(tname.length));} 	
	Lcontent=tname;
	setLoginCookie(tname,Lcontent,Lexp);
	var s='mtype='+mtype+'&tname='+tname;
	alert('s test '+s);
	//window.open('Zuktokenlogin.asp?'+s,'_blank','left=300,top=280,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=110,width=320');		
	window.open('Zuktokenlogin.asp?'+s,'_blank','left=300,top=280,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,height=410,width=420');		
	//	document.VbinForm.submit();
 }

function LoginOpen(tid) {
tid = tid.replace(" ","");
var getcontent = getLoginCookie(tid);
alert('LoginOpen' + tid);
if (getcontent == null) {
	alert("Data Invalid. Please, try again! ");
	window.close();
}
else{
//	deleteLoginCookie(tid);
//	location.href=tfile;
	}
}


function setLoginCookie(name,value,expires){
    document.cookie = escape(name) + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

function getLoginCookie(name){
	var cookiename = name + "=";
	var dc = document.cookie;
	var begin, end;
	
	if (dc.length > 0){
		begin = dc.indexOf(cookiename);
		if (begin != -1) {
			begin += cookiename.length;
			end = dc.indexOf(";",begin);
			if (end == -1) {
				end = dc.length;
			}
			return unescape(dc.substring(begin, end));
		}
	}
	return null;
}		

function deleteLoginCookie(name){
	document.cookie = name + "=; expires=thu,01-jan-70 00:00:01 GMT"+"; path=/";
}

function ReportAll(rid, rtype) {

    var exp = new Date();
    exp.setTime(exp.getTime() + (1000 * 60));
    /*rid = rid +";
    'alert(rtype+ " test " + rid);
    */
    rtype = rtype.replace(" ", ";;");
    if (rtype.indexOf(";;") != -1) { rtype = rtype.substring(0, (rtype.indexOf(";;"))) }
    else { rtype = rtype.substring(0, (rtype.length)); }
    setCookie("CRreport", rid, exp);
    window.setTimeout("ReportGo1('" + rid + "&id=2021','twin1','left=10,top=10,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,height=510,width=820')", 5);
    window.setTimeout("ReportGo1('" + rid + "&id=200','twin2','left=30,top=30,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,height=510,width=820')", 8000);
    window.setTimeout("ReportGo1('" + rid + "&id=201','twin3','left=50,top=50,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,height=510,width=820')", 16000);
    window.setTimeout("ReportGo1('" + rid + "&id=20101','twin4','left=70,top=70,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,height=510,width=820')", 32000);

}
function ReportGo1(wpath, wname, wset) {
    var twin = window.open(wpath, wname, wset);
    /*twin.focus();
    /* window.open('a.asp?'+t,'_blank','location=1,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,left=40,top=80,height=110,width=320');
    */
}

function WindowClose() {
    window.setTimeout(windowGo, 2000);
}
function WindowlaClose() {
    window.setTimeout(windowGo, 9000);
}
function WindowidleClose() {
    window.setTimeout(windowGo, 30000);
}
function WindowDelClose() {
    window.setTimeout(windowGo, 8000);
}
function WindowPopClose() {
    window.setTimeout(windowGo, 40000);
}
function windowGo() {
    window.close();
}

function WindowLAOpen(tid) {
    var getcontent = getCookie(tid);
    var temstr = document.getElementById("fullpath").value;
    var tfile = "laserapplaunch.asp?" + temstr;
    if (getcontent == null) {
        alert("System cannot be launched if over a period," + "\n" + "Please, go back Client information screen and try again! ");
    }
    else {
        deleteCookie(tid);
        location.href = tfile;
        /* var tfile = "launch_laserApp.aspx?"+temstr
        */
    }
}

function setCookie(name, value, expires) {
    document.cookie = escape(name) + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}
function getCookie(name) {
    var cookiename = name + "=";
    var dc = document.cookie;
    var begin, end;

    if (dc.length > 0) {
        begin = dc.indexOf(cookiename);
        if (begin != -1) {
            begin += cookiename.length;
            end = dc.indexOf(";", begin);
            if (end == -1) {
                end = dc.length;
            }
            return unescape(dc.substring(begin, end));
        }
    }
    return null;
}

function deleteCookie(name) {
    document.cookie = name + "=; expires=thu,01-jan-20 00:00:01 GMT" + "; path=/";
}

function afterPrintAction() {
    var Myitem = document.getElementsByTagName("OBJECT");
    for (i = 0; i < Myitem.length; i++) {
        Myitem(i).style.display = ""
        //			Myitem(i).replaceAdjacentText("afterEnd","");
        var c = document.getElementById("gqgTT" + i.toString());
        c.removeNode(true);
    }

}
function beforePrintAction() {
    //			Email.insertAdjacentText("beforeBegin","<!--TempGQG ");
    //			Email.insertAdjacentText("afterEnd"," TempGQG-->");
    //		var tempObj=document.all("t");
    var Myitem = document.getElementsByTagName("OBJECT");
    for (i = 0; i < Myitem.length; i++) {
        Myitem(i).style.display = "None"
        var d = document.createElement("input");
        d.id = "gqgTT" + i.toString();
        //			alert('hi');
        //			Email.className="InformationText"
        //			Email.style.height  
        d.className = "InformationText";
        d.style.width = Myitem.item(i).width;
        d.style.height = Myitem.item(i).height;
        d.value = Myitem.item(i).value;
        Myitem(i).insertAdjacentElement("afterEnd", d);

    }
}
function window.onbeforeprint() {
    beforePrintAction();
}
function window.onafterprint() {
    afterPrintAction();
}
var myStr = "";
function isBlank(mValue) {
    if (mValue == "") return true;
    var mBlank = " ";
    for (var i = 0; i < mValue.length; i++) {
        if (mBlank == mValue) return true;
        else mBlank += " ";
    }
    return false;
}
function isObject(cName) {
    var obj = document.getElementsByName(cName);
    return (obj.length > 0);
}
function Mprint(Name) {
    //	if (Name=="Basic") 
    //		window.open("printPopupWindow.asp?command=print&name="+Name,"_blank","toolbar=1,location=0,directories=0,status=1,menubar=0,width=350,height=450,scrollbars=0,resizable")
    //	if (Name=="Portfolio") 
    //		window.open("printPopupWindow.asp?command=print&name="+Name,"_blank","toolbar=1,location=0,directories=0,status=1,menubar=0,width=780,height=650,scrollbars=0,resizable")
    //	if (Name=="Products")
    Name = Mname.value;
    //	if (Name=="Portfolio") 
    //		window.open("printPopupWindow.asp?command=print&name="+Name,"_blank","toolbar=1,location=0,directories=0,status=1,menubar=0,width=780,height=650,scrollbars=1,resizable")
    //	else
    GetTimerIn(1);
    getreset();
    var tabName = Mname.value;
    if (tabName == "Associate") print();
    else
        window.open("printPopupWindow.asp?command=print&name=" + Name + "&tabName=" + tabName, "_blank", "toolbar=1,location=0,directories=0,status=1,menubar=0,width=780,height=650,scrollbars=1,resizable")
}
//common function for all the menuName and tabName
function del(CheckboxName, ActionPage) {
    var select = ""
    select = getItemsSelect(CheckboxName);
    if ((select == "") || (select.indexOf(";;") != -1)) {
        alert("Please select one item each time. Thank you!");
        //		return false;
    }
    else {
        select = ";;" + select + ";;"
        alert("Sorry,under construction...");
        //		window.open(ActionPage+"?action=Delete&items="+select,"_self")
    }
}
function directEdit(CheckboxName, myValue) {
    //special relate action
    if (CheckboxName == "PortfolioKeeper") {
        window.open("PortfolioSpouse.asp?policy=" + myValue, "_blank", "toolbar=1,location=0,directories=0,status=1,menubar=0,width=400,height=200,scrollbars=1,resizable");
    }
    else
        if ((CheckboxName == "Prior_Seminars_In_This_District") || (CheckboxName == "Prior_Seminars_At_This_School") || (CheckboxName == "Prior_Event_For_This_Organization")) {
            document.location.replace("test.asp?command=edit&menuName=Marketing&tabName=Seminar&flag=new" + "&name=" + CheckboxName + "&policy=" + myValue);
        }
        else if (CheckboxName == "Seminar_Contact") {
            document.location.replace("test.asp?command=edit&menuName=Marketing&tabName=Contact&flag=new" + "&name=" + CheckboxName + "&policy=" + myValue);
        }
        else if (CheckboxName == "Children") {
            var name = Mname.value;
            var policy = Mpolicy.value;
            document.location.replace("test.asp?command=edit&menuName=Client&name=" + CheckboxName + "&policy=" + myValue);
        }
        //nomal action	
        else {
            var name = "";
            if (CheckboxName == "Sub_Accounts") {
                GetTimerIn(4);
                getreset();
            }
            else {
                GetTimerIn(1);
                getreset();
            }
            if (isObject("Mname")) { var name = Mname.value; }
            window.open("editPopupWindow.asp?menuName=" + name + "&firstOpen=true&command=edit&name=" + CheckboxName + "&policy=" + myValue, "_blank", "toolbar=1,location=0,directories=0,status=1,menubar=0,width=600,height=400,scrollbars=1,resizable");
        }
}
function edit(CheckboxName) {
    var select = ""
    select = getItemsSelect(CheckboxName);
    //	alert(select);
    if ((select == "") || (select.indexOf(";;") != -1)) {
        alert("Please select one item each time. Thank you!");
    }
    else {
        if (select.indexOf(";;") != -1) select = select.substr(0, select.indexOf(";;"));
        //		alert(select);
        window.open("editPopupWindow.asp?firstOpen=true&command=edit&name=" + CheckboxName + "&policy=" + select, "_blank", "toolbar=1,location=0,directories=0,status=1,menubar=0,width=600,height=400,scrollbars=1,resizable")
    }
}
function add(CheckboxName) {
    if (CheckboxName == "Sub_Accounts") {
        GetTimerIn(4);
        getreset();
    }
    else {
        GetTimerIn(1);
        getreset();
    }
    window.open("editPopupWindow.asp?firstOpen=true&name=" + CheckboxName + "&policy=add", CheckboxName, "toolbar=1,location=0,directories=0,status=1,menubar=0,width=600,height=400,scrollbars=1,resizable")
}
function getItemsSelect(CheckboxName) {
    var Myitem = document.all;
    var select = "";
    var count = 0;
    for (var i = 0; i < Myitem.length; i++) if ((Myitem.item(i).tagName == "INPUT") && (Myitem.item(i).name.indexOf(CheckboxName) != -1)) {
        if (Myitem.item(i).checked) {
            count = count + 1;
            if (select == "") select = Myitem.item(i).name.substr(CheckboxName.length);
            else select = select + ";;" + Myitem.item(i).name.substr(CheckboxName.length);
        }
    }
    return (select)
}
function getItemsSelect_Pos(CheckboxName) {
    var Myitem = document.all;
    var select = "";
    var count = 0;
    for (var i = 0; i < Myitem.length; i++) if ((Myitem.item(i).tagName == "INPUT") && (Myitem.item(i).name.indexOf(CheckboxName) != -1)) {
        count = count + 1;
        //			alert(count);
        if (Myitem.item(i).checked) {
            if (select == "") select = count.toString();
            else select = select + ";;" + count.toString();
        }
    }
    return (select)
}
function getItemsCount(CheckboxName) {
    var tempObj = document.all(CheckboxName + "Content");
    var Myitem = tempObj.getElementsByTagName("INPUT");
    return (Myitem.length);
}
//--------------------------addition function for something
function checkDate(myDate) {
    if (myDate.value == "") return true;
    if (myDate.value == "  /  /    ") return true;
    var temp = myDate.value;
    var d = temp.split("/");
    flag = false;
    if (d.length == 3) {
        if ((!(isNaN(d[0]))) && (!(isNaN(d[1]))) && (!(isNaN(d[2])))) {
            if (isDate(d[0], d[1], d[2])) flag = true;
        }
    }
    if (!flag) myDate.focus();
    if (!flag) alert("Please input the right format of date(mm/dd/yyyy) and 2200>year>2000");
    return flag
}
function year2k(d) {
    return (d < 1000) ? d + 1900 : d;
}

function isDate(month, day, year) {
    if ((year < 1900) || (year > 2200)) return false;
    // month argument must be in the range 1 - 12
    month = month - 1;  // javascript month range : 0- 11
    var tempDate = new Date(year, month, day);

    if ((year2k(tempDate.getYear()) == year) &&
      (month == tempDate.getMonth()) &&
      (day == tempDate.getDate())) {
        return true;
    }
    else {
        return false;
    }
}

function getDropDownBoxDescription(thisobj) {

    alert(thisobj.name);

    alert(thisobj.selectedIndex);

    if ((thisobj == null) || (thisobj.selectedIndex == -1))
        return "";

    else
        return (thisobj.options(thisobj.selectedIndex).text);

}



function autoCaculate(thisobj, choice, destination, thirdParam) {

    var secondChoice = "";
    if (choice.indexOf("*") != -1) {  //for one element have some parameters,but just one call autoCaculate,others are use in server VB ASP
        var len = 1;
        var temp = choice.split("*");
        choice = temp[0];
        len = temp.length;
        secondChoice = temp[1];
        //	alert(len);
    }
    if (choice == "BooleanInverse") {
        var destinationObj = document.all(destination);
        if (thisobj.value == "1") destinationObj.value = "0";
        else destinationObj.value = "1";
    }
    if (choice == "SeminarTitle") {
        var temp = "";
        var destinationObj = document.all(destination);
        //IsSchool School_ School ___  :isOrgan Organization_ Organize ____
        //			var IsSchoolObj=document.all("School_");
        //			var IsOrganObj=document.all("Organization_");
        //			var ScoolObj=document.all("TSCHOOL");
        //			var OrganizeObj=document.all("T____");
        //			var TopicObj=document.all("Topic");
        //			alert(destinationObj.name);
        //			alert(destinationObj.value);
        if ((School_.value == "1") && (TSCHOOL.selectedIndex != -1)) temp = TSCHOOL.options(TSCHOOL.selectedIndex).text;
        else if ((Organization_.value == "1") && (T____.selectedIndex != -1)) temp = T____.options(T____.selectedIndex).text;
        var Topic1 = "";
        if (Topic.selectedIndex != -1) Topic1 = Topic.options(Topic.selectedIndex).text;
        destinationObj.value = temp + " " + Topic1;
        //			destinationObj.value="454";
    }
    if (choice == "WeekDay") {
        if (checkDate(thisobj)) {
            var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
            var destinationObj = document.all(destination);
            var c = new Date(thisobj.value);
            var dayOfWeek = c.getDay();
            //			alert(days[dayOfWeek]);
            destinationObj.value = days[dayOfWeek];
        }
    }
    if (choice == "ShowConstant") {
        var constantObj = document.all(thirdParam);
        thisobj.value = constantObj.value;
    }
    if (choice == "RefreshScreen") {
        var destinationObj = document.all(thisobj.name);
        var hrefStr = document.location.href;
        if (hrefStr.indexOf("policy") == -1) {
            var t = hrefStr + "&policy=" + thisobj.value;
            document.location.replace(t);
        }
        else {
            var t = hrefStr.substr(0, hrefStr.indexOf("policy") - 1);
            t = t + "&policy=" + thisobj.value;
            document.location.replace(t);
        }
    }

    if (choice == "Visibility") {  //thisobj.value=1?"*,1,*,2?$,1,$,2"
        var visibleFlag = 0;
        if (secondChoice != "") {
            var sParam = thisobj.value.toString();
            var sOperation = temp[1];
            var sValue = temp[2];
            switch (sOperation) {
                case ">":
                    if (sParam > sValue) visibleFlag = 1;
                    break;
                case "=":
                    if (sParam == sValue) visibleFlag = 1;
                    break;
                case "<>":
                    if (sParam != sValue) visibleFlag = 1;
                    break;
                case "<":
                    if (sParam < sValue) visibleFlag = 1;
                    break;
            }
        }
        else {
            if (thisobj.value.toString() == "1") visibleFlag = 1;
        }

        if (visibleFlag == 1) {
            var firstVisibility = "";
            var secondVisibility = "hidden";
        }
        else {
            var firstVisibility = "hidden";
            var secondVisibility = "";
        }


        var firstGroup = destination.split("?")[0];
        var secondGroup = destination.split("?")[1];

        if (firstGroup.indexOf(";") != -1) {
            var firstGroupSplit = firstGroup.split(";");
            for (var i = 0; i < firstGroupSplit.length; i++) {
                var destinationObj = document.getElementsByName(firstGroupSplit[i]);
                //				if (destinationObj.length!=null) alert(destinationObj.length); else alert(destinationObj.length);
                if (isNaN(firstGroupSplit[i + 1])) var mIndex = 0;
                else var mIndex = firstGroupSplit[i + 1];
                if (destinationObj[mIndex] != null) {
                    destinationObj[mIndex].style.visibility = firstVisibility;
                    if (firstVisibility != "") destinationObj[mIndex].style.width = 0;
                    else {
                        if (thirdParam.indexOf(";") != -1) {
                            var thirdParamSplit = thirdParam.split(";");
                            destinationObj[mIndex].style.width = thirdParamSplit[i / 2];
                        } else destinationObj[mIndex].style.width = thirdParam;
                    }
                }
                i += 1;
            }
        }
        if (secondGroup.indexOf(";") != -1) {
            var secondGroupSplit = secondGroup.split(";");
            for (var i = 0; i < secondGroupSplit.length; i++) {
                var destinationObj = document.getElementsByName(secondGroupSplit[i]);
                if (isNaN(secondGroupSplit[i + 1])) var mIndex = 0;
                else var mIndex = secondGroupSplit[i + 1];
                if (destinationObj[mIndex] != null) {
                    destinationObj[mIndex].style.visibility = secondVisibility;
                    if (secondVisibility != "") destinationObj[mIndex].style.width = 0;
                    else {
                        if (thirdParam.indexOf(";") != -1) {
                            var thirdParamSplit = thirdParam.split(";");
                            destinationObj[mIndex].style.width = thirdParamSplit[i / 2];
                        } else destinationObj[mIndex].style.width = thirdParam;
                    }
                }

                i += 1;
            }
        }
    }

    if ((choice == "Append") && (secondChoice == "Option")) {
        var destinationObj = document.all(destination);
        var OptionValue = thisobj.options(thisobj.selectedIndex).text;
        if (thirdParam == "") {
            destinationObj.value = destinationObj.value + " " + OptionValue;
        }
        else {
            var a = thirdParam + ",1";
            var b = a.split(",");
            destinationObj[b[0]].value = destinationObj[b[0]].value + " " + OptionValue;
        }
    }
    if (choice == "Display") {
        var mValue = thisobj.value;
        var destinationObj = document.all(destination);
        if (secondChoice == "Role") {
            var displayStr = "Block";
            if (mValue == "Admin") displayStr = "None";
            if (thirdParam == "") {
                destinationObj.style.display = displayStr;
            }
            else {
                var a = thirdParam + ",1";
                var b = a.split(",");
                destinationObj[b[0]].style.display = displayStr;
            }
        }
    }
    if (choice == "ConstantInsert") {
        var InsertObj = document.all(thirdParam);
        thisobj.value = InsertObj.value + "\n" + thisobj.value;
        setSelectionRange(thisobj, InsertObj.value.length, InsertObj.value.length);
    }

    if (choice == "Same") {
        var destinationObj = document.all(thisobj.name);
        if (thirdParam == "") destinationObj.value = thisobj.value;
        else {
            var a = thirdParam + ",1";
            var b = a.split(",");
            destinationObj[b[0]].value = thisobj.value;
        }
    }
    if (choice == "Copy") {
        var destinationObj = document.all(destination);
        if (thirdParam == "") destinationObj.value = thisobj.value;
        else {
            var a = thirdParam + ",1";
            var b = a.split(",");
            destinationObj[b[0]].value = thisobj.value;
        }
    }
    //	alert("here0");
    if (choice == "SetValue") {
        //		alert("here");
        var destinationSplit = destination.split("!");
        var destinationValueSplit = thirdParam.split("!");
        var mv;
        for (var i = 0; i < destinationSplit.length; i++) {
            if (destinationValueSplit[i] != "this*") mv = destinationValueSplit[i];
            else mv = thisobj.value.trim();
            //			alert(destinationSplit[i]);
            if (destinationSplit[i].indexOf("*Select") == -1)
                document.all(destinationSplit[i]).value = mv;
            else {//select text match
                //				alert(mv);
                if (mv != "") {
                    var destSplit = destinationSplit[i].split("*");
                    var dest = destSplit[0];
                    var pos;
                    //					alert(destinationSplit[i]);
                    //					alert(dest);
                    var destObj = document.all(dest);
                    if (destObj.innerText.toLowerCase().indexOf(mv.toLowerCase()) != -1) {
                        for (pos = 0; pos < destObj.options.length; pos++)
                            if (destObj.options(pos).text.trim().toLowerCase() == mv.trim().toLowerCase()) break;
                        if (pos < destObj.options.length)
                            destObj.value = destObj.options(pos).value;
                        else { alert("can not find seminar"); thisobj.focus(); }
                    }
                    else { alert("can not find seminar"); thisobj.focus(); }
                }
            }
        }
        //		var destinationObj=document.all(destination);
        //		destinationObj.value=thirdParam;
    }
    if (choice == "Premium") {
        //check if NaN
        if (isNaN(thisobj.value)) {
            alert("Error! Wrong numeric value:'" + thisobj.value + "'");
            thisobj.focus();
        }
        else {
            var operaterObj = document.all(thirdParam);
            var firstValue = 0;
            var secondValue = 0;
            var firstMulti = 1;
            var secondMulti = 1;
            var firstPremiumValue = 0;
            var secondPremiumValue = 0;
            var firstMObj = document.all("Payments#");
            var secondMObj = document.all("Payments#_");
            var firstPremium = document.all("Premium");
            var secondPremium = document.all("Premium_");
            if (!isNaN(firstMObj.value)) firstMulti = firstMObj.value * 1;
            if (!isNaN(secondMObj.value)) secondMulti = secondMObj.value * 1;
            if (!isNaN(firstPremium.value)) firstPremiumValue = firstPremium.value * 1;
            if (!isNaN(secondPremium.value)) secondPremiumValue = secondPremium.value * 1;
            firstValue = firstPremiumValue * firstMulti;
            secondValue = secondMulti * secondPremiumValue;
            /*//			alert(firstMObj.value);			if(thirdParam.indexOf("_")!=-1)			{				if (!isNaN(firstMObj.value)) firstMulti=firstMObj.value*1;				if (!isNaN(secondMObj.value)) secondMulti=secondMObj.value*1;			}			else			{				if (!isNaN(firstMObj.value)) secondMulti=firstMObj.value*1;				if (!isNaN(secondMObj.value)) firstMulti=secondMObj.value*1;			}			if ((!isNaN(thisobj.value)) && (thisobj.value!="")) firstValue=thisobj.value*firstMulti;			if ((!isNaN(operaterObj.value)) && (operaterObj.value!="")) secondValue=operaterObj.value*secondMulti;*/
            var destinationObj = document.all(destination);
            destinationObj.value = firstValue * 1 + secondValue * 1;
        }
    }

    if (choice == "SeminarCostTotal") {
        //check if NaN
        if (isNaN(thisobj.value)) {
            alert("Error! Wrong numeric value:'" + thisobj.value + "'");
            thisobj.focus();
        }
        else {
            //DD26,DD28,DD30,DD32,DD109,DD34,DD36,DD209,DD38,DD40,DD42,DD142,DD44,DD46,DD146,DD246,DD346,DD50
            //DD52
            var s = "DD26,DD28,DD30,DD32,DD109,DD34,DD36,DD209,DD38,DD40,DD42,DD142,DD44,DD46,DD146,DD246,DD346,DD50";
            var ssplit = s.split(",");
            var st = 0;
            //			alert(ssplit.length);
            for (var i = 0; i < ssplit.length; i++) {
                var os = document.all(ssplit[i]);
                if (!isNaN(os.value)) st += os.value * 1;
            }
            var destinationObj = document.all(destination);
            destinationObj.value = st;
        }

    }
    if (choice == "SpeakerTotal") {
        //check if NaN
        if (isNaN(thisobj.value)) {
            alert("Error! Wrong numeric value:'" + thisobj.value + "'");
            thisobj.focus();
        }
        else {
            var description = thirdParam;
            var s, s1, s2, s3;
            var s1split, s2split, s3split, tP;
            var os1, os2, os3;
            s1 = "DDNN02,DDNN03,DDNN04,DDNNNew04,DDNNNew03";  //attP
            s2 = "DDN02,DDN12,DDNS22,DDNSNew22,DDNNew12";    //att
            s3 = "DDN01,DDN11,DDN21,DDNNew21,DDNNew11";      //lead
            s1split = s1.split(",")
            s2split = s2.split(",")
            s3split = s3.split(",")
            var thisName = thisobj.name;
            //			alert(thisName);
            switch (description) {
                case "AttendeeP":
                    s = s1;
                    break;
                case "AttendeeNO":
                    s = s2;
                    break;
                case "Leads":
                    s = s3;
                    break;
            }
            var ssplit = s.split(",");
            var st = 0;
            var pos = -1;
            var destinationObj = document.all(destination);
            //			if (description=="AttendeeP") destinationObj.value=100;
            document.all("DDNNN04").value = 100;   //total percent is always 100
            //			if (description!="AttendeeP") {
            if (description == "Leads") {
                for (var i = 0; i < ssplit.length; i++) {
                    var os = document.all(ssplit[i]);
                    if (thisName == ssplit[i]) pos = i;
                    if (!isNaN(os.value)) st += os.value * 1;
                    destinationObj.value = st;
                }
                document.all("Total_Leads").value = st;

                //			if (pos!=-1)  { //caculate percent (description!="AttendeeP")
                for (pos = 0; pos < s3split.length; pos++) {
                    tP = 0;
                    os1 = document.all(s1split[pos]);
                    //				os2=document.all(s2split[pos]);
                    os3 = document.all(s3split[pos]);
                    if ((!isNaN(os3.value)) && (st != 0) && (os3.value != "")) tP = Math.round(os3.value / st * 100);
                    os1.value = tP;
                }

            }
            //auto division according to leads
            if ((description == "AttendeeNO") || (description == "Leads")) {
                st = document.all("Total_Leads").value;
                if ((!isNaN(st)) || (st == "") || (st <= 0)) st = document.all("DDNN21").value;
                var Tatt;
                if (description == "AttendeeNO") {
                    Tatt = thisobj.value;   //total attendees
                    document.all("DDNN22").value = Tatt;
                    document.all("Total_Attendance").value = Tatt;
                }
                else {
                    Tatt = document.all("DDNN22").value;
                    if ((!isNaN(Tatt)) || (Tatt == "") || (Tatt <= 0)) Tatt = document.all("Total_Attendance").value;
                }

                var tSum = 0;
                for (pos = 0; pos < s3split.length; pos++) {
                    tP = 0;
                    os2 = document.all(s2split[pos]);
                    os3 = document.all(s3split[pos]);
                    if ((!isNaN(os2.value)) && (!isNaN(os3.value)) && (st >= 0) && (os3.value != "")) tP = Math.round(os3.value / st * Tatt);
                    if ((tSum + tP) > Tatt) tP--;
                    if (pos == s3split.length - 1) os2.value = Tatt - tSum;
                    else {
                        os2.value = tP;
                        tSum += tP;
                    }
                }

            }


        }
    }
    if ((choice == "Date") && (destination == "_Age")) {
        if ((thisobj.value != "") && (checkDate(thisobj))) {  //check if it is a valid date format
            var destinationObj = document.all(destination);
            var myYear = constantToday.value.split("/");
            var thisYear = thisobj.value.split("/");
            var today = new Date(constantToday.value);
            var birthday = new Date(thisobj.value);
            var ageYear = years_between(birthday, today);
            //			alert(ageYear);
            destinationObj.value = ageYear;
        }
    }
    if ((choice == "Date") && (destination == "Last_Updated")) {
        //var destinationObj=document.all(destination);
        //destinationObj.value=constantToday.value;
    }
    if (choice == "checkDate") checkDate(thisobj);
    if (choice == "isNaN") {  //check if it isNaN
        if (isNaN(thisobj.value)) {
            if ((thisobj.value == "  .  ") && (thisobj.tagName == "OBJECT")) { } else {
                alert("Error! Wrong numeric value:'" + thisobj.value + "'");
                thisobj.focus();
            }
        }
    }
    if (choice == "refreshHtmlSelect") { //destination
        var mDestination = "";
        var mName = destination;  //now for "Product","_Company*_Approved"
        var mValue = thisobj.value;
        if (destination.indexOf("*") == -1) {//just one object to refresh 
            if (thirdParam == "") mDestination = destination;
            else {
                mDestination = destination + "[" + thirdParam + "]";
            }
        }
        else {                             //more than one object to refresh
            if (thirdParam == "") mDestination = destination;
            else {
                //debug on 01/11/05
                //same name in one page process:"1*2*5" 
            }
        }
        //adjusted on 01/05/05
        //alert('refreshHtmlSelect.asp?name='+mName+'&value='+mValue+"&destination="+mDestination);
        window.open('refreshHtmlSelect.asp?name=' + mName + '&value=' + mValue + "&destination=" + mDestination, '_blank', 'scrollbars=1,left=1000,top=1000,location=1,height=500,width=600');
    }
    if (choice == "Fundsumuptmp") {
        var t1 = document.all('Percentage_1').value;
        var t2 = document.all('Percentage_2').value;
        var t3 = document.all('Percentage_3').value;
        var allfd = t1 + t2 + t3;
        alert('test' + allfd);
    }
}
function years_between(date1, date2) {

    // The number of milliseconds in one day
    var ONE_Year = 1000 * 60 * 60 * 24 * 365

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)

    // Convert back to days and return
    return Math.floor(difference_ms / ONE_Year)

}

function GetDelIn(num) {
    var tname = 'ZukOpsDel';
    var Lexp = new Date();
    var Lcontent, LContend;
    var num1 = Math.floor(Math.random() * (999 + 1));
    Lexp.setTime(Lexp.getTime() + (1000 * 10));
    Lcontent = num;
    deleteLoginCookie(tname);
    setLoginCookie(tname, Lcontent, Lexp);
}

function getDelCookie(name) {
    var cookiename = name + "=";
    var dc = document.cookie;
    var begin, end;

    if (dc.length > 0) {
        begin = dc.indexOf(cookiename);
        if (begin != -1) {
            begin += cookiename.length;
            end = dc.indexOf(";", begin);
            if (end == -1) {
                end = dc.length;
            }
            return unescape(dc.substring(begin, end));
        }
    }
    return "N";
}

function Confirmwin(Iname, Ipolicy) {
    var num = '0';
    if (isObject("Ramchker ")) { num = Ramchker.value; }
    var menuName = "Client";

    var retchk = getDelCookie('ZukOpsDel');
    var retchkall = retchk.split(",");
    var policy = retchkall[1];
    var name = retchkall[0];
    if (name == "School") menuName = "Employer";
    if (Iname == name) {
        switch (name) {
            case "clientBasic":
                window.opener.location.replace("test.asp?menuName=Client&tabName=Information&Command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "spouseBasic":
                window.opener.location.replace("test.asp?menuName=Client&tabName=Information&Command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Tracker":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Tickler":
                window.opener.location.replace("test.asp?Command=Delete&menuName=" + menuName + "&tabName=" + name + "&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Contact":
                window.opener.location.replace("test.asp?Command=Delete&menuName=" + menuName + "&tabName=" + name + "&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Portfolio":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Children":
                window.opener.location.replace("test.asp?Command=Delete&menuName=" + menuName + "&tabName=" + name + "&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "School":
                window.opener.location.replace("test.asp?Command=Delete&menuName=" + menuName + "&tabName=" + name + "&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Vendor_Contact":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Product":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Employer":
                window.opener.location.replace("test.asp?menuName=Admin&tabName=Employer&command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
            case "User":
                window.opener.location.replace("test.asp?menuName=Admin&tabName=User&command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Associate":
                window.opener.location.replace("test.asp?menuName=Admin&tabName=Associate&command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Vendor":
                window.opener.location.replace("test.asp?menuName=Admin&tabName=Vendor&command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "License":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Marketing_Contact":
                window.opener.location.replace("test.asp?menuName=Marketing&tabName=Contact&command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Seminar":
                window.opener.location.replace("test.asp?menuName=Marketing&tabName=Seminar&command=Delete&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Contact_Log":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Sub_Accounts":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Fund_Distribution":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "Varible_Sub_Account":
                window.opener.location.replace("editPopupWindow.asp?command=delete&name=" + name + "&policy=" + policy);
                deleteLoginCookie('ZukOpsDel');
                break;
            case "New_Lead":
                break;

            default:
        }
    }
}
function ClientPopupDelete(intext) {
    var policy = Mpolicy.value;
    var contall = intext + "," + policy
    var num1 = Math.floor(Math.random() * (9 + 1));
    var msg1 = "Are you sure to delete the record ";
    var retchk = getDelCookie('ZukOpsDel');
    if (retchk == 1) {
        deleteLoginCookie('ZukOpsDel');
        GetDelIn(contall);
        //window.setTimeout(Confirmwin, 4000);
        window.open('PopupDelturn.asp?ramnum=' + num1 + '&Funname=' + intext, '_blank', 'left=250,top=230,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=80,width=350');
    }
}

function savePopupWindow(mType, subName) {
    var mName = Mname.value;  //hidden value 
    if (mType == "save") {
        getreset();
        if (isObject("Winstatus")) { GetTimerIn(0); }
        else if (mName == "Sub_Accounts") { GetTimerIn(4); }
        else { GetTimerIn(1); }
    }
    else if (mType == "Autosave") {
        mType = "save";
        deleteLoginCookie('ZukOpsMain');
        if (mName == "Sub_Accounts") { GetTimerIn(3); }
        else { GetTimerIn(3); }
    }
    var ppolicy = Mpolicy.value; //hidden value 
    var partition = Mypartition.value;
    var outLname = "";
    var outFname = "";
    var outSchEmpl = "";
    var outEmpl = "";
    var outSeminar = "";
    //special process for the special aspect
    if (subName == "Staff_Development_Dates") { //in the zuk user

        var tempObj = document.all(subName + "Content");
        var Myitem = tempObj.all;
        var s = "";
        var itemValue = "";
        //		alert(Myitem.length);
        for (i = 0; i < Myitem.length; i++) {
            if ((Myitem.item(i).tagName == "INPUT") || (Myitem.item(i).tagName == "SELECT") || (Myitem.item(i).tagName == "OBJECT") || (Myitem.item(i).tagName == "TEXTAREA")) {
                if (Myitem.item(i).value != "  /  /    ") itemValue = Myitem.item(i).value;
                else itemValue = "";
                //				alert(Myitem.item(i).value);
                if (s == "") s = itemValue;
                else s += "{{" + itemValue;
            }
        }
        //		alert(s);
        window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + s + '&Name=' + subName + '&policy=' + ppolicy, '_blank', 'left=420,top=320,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
    }

    else if (subName == "Staff_Development_Dates_old") { //in the zuk user
        var tempObj = document.all(subName + "Content");
        var Myitem = tempObj.getElementsByTagName("OBJECT");
        var Myitem2 = tempObj.getElementsByTagName("SELECT");
        var s = "";
        var itemValue = "";
        alert(Myitem.length);
        for (i = 0; i < Myitem.length; i++) {
            if (Myitem.item(i).value != "  /  /    ") itemValue = Myitem.item(i).value;
            else itemValue = "";
            if (s == "") s = itemValue + "{{" + Myitem2.item(i).value;
            else s += "{{" + itemValue + "{{" + Myitem2.item(i).value;
        }
        //		alert(s);
        window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + s + '&Name=' + subName + '&policy=' + ppolicy, '_blank', 'left=420,top=320,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
    }
    else if (subName == "Role_Specific") { //in the zuk user
        var tempObj = document.all(subName + "Content");
        var Myitem = tempObj.getElementsByTagName("INPUT");
        var s = "";
        var itemValue = "";
        for (i = 0; i < Myitem.length; i++)
            if (Myitem.item(i).name.indexOf("_CB") == 0) {
                if (Myitem.item(i).checked) itemValue = "1";
                else itemValue = "0";
                if (s == "") s = itemValue;
                else s += "{{" + itemValue;
            }
        //	alert(s);
        window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + s + '&Name=' + subName + '&policy=' + ppolicy, '_blank', 'left=420,top=320,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
    }
    else if ((subName == "Fund_Distribution") || (subName == "Sub_Accounts")) { //in the single portfolio information,to instant edit and save for the _table list information
        var tempObj = document.all(subName + "Content");
        var Myitem = tempObj.getElementsByTagName("INPUT");
        var s = "";
        var preID = "";
        for (i = 0; i < Myitem.length; i++) {
            var mName = Myitem.item(i).name;
            if (Myitem.item(i).style.visibility.toLowerCase() != "hidden")
                if ((mName != "Mypartition") && (mName != "Mname") && (mName != "Mpolicy")) {  // leave behind the common variable
                    var mPos = Myitem.item(i).name.indexOf("____");
                    var mID = Myitem.item(i).name.substr(mPos + 4);
                    if (s == "") { s = mID + "{{" + Myitem.item(i).value; preID = mID; }
                    else {
                        if (preID == mID) s += "{{" + Myitem.item(i).value;
                        else {
                            preID = mID;
                            s += "{{" + mID + "{{" + Myitem.item(i).value;
                        }
                    }

                }
        }
        var re = /&/g;             //Create regular expression pattern.
        s = s.replace(re, "(amp)");
        var re = /%/g;             //Create regular expression pattern.
        s = s.replace(re, "(pct)");
        var re = /#/g;             //Create regular expression pattern.
        s = s.replace(re, "(pound)");

        //		alert('savePopupWindow_Special.asp?type='+mType+'&value='+s+'&Name='+subName+'&policy='+ppolicy);
        window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + s + '&Name=' + subName + '&policy=' + ppolicy, '_blank', 'left=420,top=320,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
    }
    else if (subName == "Seminar_Contact") { //in the Seminar screen/Contact 
        var contactID = "";
        if (mType == "Link") {
            contactID = Mcontact.value;
            if (contactID == "")
                alert("Sorry. Please select Contact in the Contact Tab first. Thank you.");
            else {
                var contactCount = getItemsCount(subName);
                //		alert(contactCount.toString());
                window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + contactID + '&Name=' + subName + '&parameter=' + contactCount.toString() + '&policy=' + ppolicy, '_blank', 'left=400,top=350,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
            }
        }
        else if (mType == "Unlink") {
            var select = ""
            select = getItemsSelect(subName);
            if ((select == "") || (select.indexOf(";;") != -1)) {
                alert("Sorry. Please select one item each time. Thank you!");
            }
            else {
                contactID = select;
                window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + contactID + '&Name=' + subName + '&policy=' + ppolicy, '_blank', 'scrollbars=1,left=1000,top=1000,location=1,height=500,width=600');
            }
        }
    }
    else if (subName == "Amend") {  //in the Employer Screen to process the Amend Information
        var mvalue = "";  //the company to selected into the related amend Type
        var nNumber = _Approved.length;
        //alert(nNumber);
        for (var i = 0; i < nNumber; i++) {
            var svalue = _Approved.options(i).value.toString();
            //if (i>38)	alert(svalue);
            if (svalue == "") svalue = _Approved.options(i).Value.toString();
            //if (i>38)	alert(svalue);
            if (mvalue == "") mvalue = svalue; else mvalue = mvalue + "|" + svalue;
            //if (i>38)	alert(_Approved.options(i).text.toString());
        }
        var AmendType = _TypeList.value;  //amend type that is selected
        window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + mvalue + '&Name=' + mName + '&parameter=' + AmendType + '&policy=' + ppolicy, '_blank', 'left=420,top=320,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
    }
    else if (subName == "Specific_Associate") {  //in the Employer Screen to process the Amend Information
        var mvalue = "";  //the associate to selected into the related amend Type
        var nNumber = _Approved.length;
        for (var i = 0; i < nNumber; i++) {
            if (mvalue == "") mvalue = _Approved.options(i).value.toString(); else mvalue = mvalue + "|" + _Approved.options(i).value.toString();
            //			alert(mvalue);
        }
        //		alert(mvalue);
        var parameter = _OfficeList.value;  //amend type that is selected
        //		alert("this function has a bug and will re-open until next version. Sorry about that. Guan");
        //alert('savePopupWindow_Special.asp?type='+mType+'&value='+mvalue+'&Name='+mName+'&parameter='+parameter+'&policy='+ppolicy);		
        window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + mvalue + '&Name=' + mName + '&parameter=' + parameter + '&policy=' + ppolicy, '_blank', 'left=420,top=320,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
    }
    else if (subName.indexOf("_Code") != -1) { //in the Admin Code Screen 
        var tempObj = document.all(subName + "Content");
        var Myitem = tempObj.getElementsByTagName("SELECT");
        //		alert(Myitem.item(0).name);
        //		alert(Myitem.item(1).name);
        var mvalue = "";  //the code to selected into the related code Type
        var mtext = "";
        var nNumber = Myitem.item(1).length;
        for (var i = 0; i < nNumber; i++) {
            if (mtext == "") mtext = Myitem.item(1).options(i).text; else mtext = mtext + "|" + Myitem.item(1).options(i).text;
            if (mvalue == "") mvalue = Myitem.item(1).options(i).value; else mvalue = mvalue + "|" + Myitem.item(1).options(i).value;
            //			alert(mvalue);
        }
        //		alert(mtext);
        var parameter = Myitem.item(0).value;  //code type that is selected
        //			alert(parameter);
        var temp = false;
        temp = window.confirm("Be Careful to remove any Code Item unless you are sure that it is no use in your Database. It will affect previous relative data, such as client information.Would you like to save changes now?");
        if (temp) {
            if (parameter == "SemOrgan") {
                var allStr = mvalue + "}}}" + mtext;
                var re = /&/g;             //Create regular expression pattern.
                allStr = allStr.replace(re, "(amp)");
                var re = /%/g;             //Create regular expression pattern.
                allStr = allStr.replace(re, "(pct)");
                var re = /#/g;             //Create regular expression pattern.
                allStr = allStr.replace(re, "(pound)");
                form_whole.mAllStr.value = allStr;
                //alert('inputsave_special.asp?type='+mType+'&Name='+mName+'&parameter='+parameter);				
                window.open('inputsave_special.asp?type=' + mType + '&Name=' + mName + '&parameter=' + parameter, '_blank', 'scrollbars=1,left=1000,top=1000,location=1,height=500,width=600');
            }
            else {
                window.open('savePopupWindow_Special.asp?type=' + mType + '&value=' + mvalue + '&mtext=' + mtext + '&Name=' + mName + '&parameter=' + parameter + '&policy=' + ppolicy, '_blank', 'left=1,top=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=5,width=5');
            }
        }
    }

    else {
        //normal process			
        if ((subName != "school") && (subName != "children") && (subName != "clientsingleTicklerInformation") && (subName != "singleticklerInformation") && (subName != "Contact") && (mType == "new") && !((ppolicy == "add") || (ppolicy == "new"))) {
            //alert("editPopupWindow");
            var mName = Mname.value;  //hidden value 
            LocationStr = "editPopupWindow.asp?command=new&name=" + mName + "&policy=add"
            document.location.replace(LocationStr);
        }
        else if (((mType == "new") && ((ppolicy == "add") || (ppolicy == "new"))) || (mType == "save")) {

            //	alert(partition);

            var MenuName = Mname.value;
            var count = 1;
            if (partition.indexOf(",") != -1) {  //split at least two partition;"xxxContent"
                partitionSplit = partition.split(",");
                count = partitionSplit.length;
            }
            else {     //one whole page,no split
                var temp = partition + ","
                partitionSplit = temp.split(",");
            }

            var allStr = "";
            var fBlank = false;
            var s = "";
            //		alert(allStr);
            for (var j = 0; j < count; j++) {
                //alert(s);
                //alert(allStr);
                s = "";
                if (count > 1) var tempObj = document.all(partitionSplit[j] + "Content");
                else var tempObj = document.all(partitionSplit[j]);

                //special process with the value start
                //			alert(partitionSplit[j]);
                var mName = Mname.value;  //hidden value 
                if (mName == "New_Lead") {
                    var oFirstName = tempObj.all("First_Name");
                    //	alert(oFirstName.value);
                    if (isBlank(oFirstName.value)) fBlank = true;
                }
                //special process with the value end
                if (!fBlank) {
                    var Myitem = tempObj.getElementsByTagName("SELECT");
                    for (var i = 0; i < Myitem.length; i++) {

                        switch (Myitem.item(i).name) {
                            case "School_Employer":
                                if (j == 0) outSchEmpl = Myitem.item(i).value;
                                break;
                            case "Employer":
                                if (j == 0) outEmpl = Myitem.item(i).value;
                                break;
                        }
                        if (Myitem.item(i).style.visibility.toLowerCase() != "hidden")
                            if (s == "") s = Myitem.item(i).name + "{{" + Myitem.item(i).value;
                            else s += "{{" + Myitem.item(i).name + "{{" + Myitem.item(i).value;
                    }
                    //			alert("select");
                    //			alert(s);
                    var Myitem = tempObj.getElementsByTagName("OBJECT");
                    for (var i = 0; i < Myitem.length; i++)
                        if (Myitem.item(i).style.visibility.toLowerCase() != "hidden")
                            if ((Myitem.item(i).value != "  .  ") && (Myitem.item(i).value != "  /  /    ") && (Myitem.item(i).value != "  .  .    ")) {
                                var tempobjStr = Myitem.item(i).value;
                                //if (!((Myitem.item(i).value.indexOf(".")!=-1) && (isNaN(Myitem.item(i).value))))
                                if (s == "") s = Myitem.item(i).name + "{{" + tempobjStr;
                                else s += "{{" + Myitem.item(i).name + "{{" + tempobjStr;
                            }
                            else {
                                tempobjStr = "";
                                if (s == "") s = Myitem.item(i).name + "{{" + tempobjStr;
                                else s += "{{" + Myitem.item(i).name + "{{" + tempobjStr;
                            }
                    //			alert("object");
                    //			alert(s);

                    Myitem = tempObj.getElementsByTagName("INPUT");
                    for (i = 0; i < Myitem.length; i++) {
                        var mName = Myitem.item(i).name;
                        if (Myitem.item(i).style.visibility.toLowerCase() != "hidden")
                            if ((mName != "") && (mName != "mAllStr") && (mName != "Mypartition") && (mName != "Mname") && (mName != "Mpolicy")) {  // leave behind the common variable
                                //						alert(Myitem.item(i).id);
                                //						alert(mName);
                                //					alert(Myitem.item(i).name+"{{"+Myitem.item(i).value);
                                switch (Myitem.item(i).name) {
                                    case "Last_Name":
                                        outLname = Myitem.item(i).value;
                                        break;
                                    case "First_Name":
                                        outFname = Myitem.item(i).value;
                                        break;
                                    case "Seminar_ID":
                                        outSeminar = Myitem.item(i).value;
                                        break;
                                    case "Employer":
                                        if (j == 0) outEmpl = Myitem.item(i).value;
                                        break;
                                }

                                var tempobjStr = Myitem.item(i).value;
                                if ((tempobjStr == "__/__/____") || (tempobjStr == "___-__-____") || (tempobjStr == "___-___-____")) {
                                    tempobjStr = "";
                                }
                                if (s == "") s = Myitem.item(i).name + "{{" + tempobjStr;
                                else s += "{{" + Myitem.item(i).name + "{{" + tempobjStr;
                            }
                    }

                    //			alert("input");
                    //    		alert(s);

                    Myitem = tempObj.getElementsByTagName("TEXTAREA");
                    for (i = 0; i < Myitem.length; i++) {
                        if (Myitem.item(i).style.visibility.toLowerCase() != "hidden")
                            if (s == "") s = Myitem.item(i).name + "{{" + Myitem.item(i).value;
                            else s += "{{" + Myitem.item(i).name + "{{" + Myitem.item(i).value;
                        //alert(Myitem.item(i).value);
                    }
                } //if it is blank key field
                allStr += s;
                if ((count > 1) && (count != (j + 1))) allStr += "|||";
                //alert(allStr); 
            }
            var re = /&/g;             //Create regular expression pattern.
            allStr = allStr.replace(re, "(amp)");
            var re = /%/g;             //Create regular expression pattern.
            allStr = allStr.replace(re, "(pct)");
            var re = /#/g;             //Create regular expression pattern.
            allStr = allStr.replace(re, "(pound)");
            //			var re = /\r/g;             //Create regular expression pattern.
            //			allStr = allStr.replace(re, "(return)")
            //			allStr=escape(allStr);
            form_whole.mAllStr.value = allStr;

            if (_Mmodified != null) //exist this object
                _Mmodified.value = "true";  //hidden value 
            var mName = Mname.value;  //hidden value 
            var ppolicy = Mpolicy.value; //hidden value 

            window.open('inputsave.asp?type=' + mType + '&Name=' + mName + '&policy=' + ppolicy + '&funName=' + MenuName + '&LName=' + outLname + '&FName=' + outFname + '&Seminar=' + outSeminar + '&SchEmp=' + outSchEmpl + '&Employer=' + outEmpl, '_blank', 'left=300,top=400,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=210,width=370');

        } //if current is new to save
        var mName = Mname.value;  //hidden value 
        var ppolicy = Mpolicy.value; //hidden value 

        if ((mName != "clientBasic") && (mName != "spouseBasic")) { //not from ClientBasicInformation and SpouseBasicInformation in main cient window
            if (mType == 'new') ppolicy = "add";
            else if (mType == 'save')
                if ((ppolicy == "add") || (ppolicy == "new")) ppolicy = "first";
            var objIframe = document.getElementById("IFrame_list");
            if (objIframe != null) {
                if ((mName == "Tickler") && (mType != 'new')) ppolicy = "first";
                if (objIframe.src.indexOf("frameLoadFrom=sub") != -1) {//maybe click from the main client window
                    if (mName == "School")
                        var LocationStr = "test.asp?command=edit&menuName=Employer&tabName=" + mName + "&name=" + mName + "&policy=" + ppolicy
                    else
                        var LocationStr = "test.asp?command=edit&menuName=Client&tabName=" + mName + "&name=" + mName + "&policy=" + ppolicy
                }
                else if (objIframe.src.indexOf("frameLoadFrom=asp") != -1) {//maybe click from the popup window
                    var LocationStr = "editPopupWindow.asp?command=new&name=" + mName + "&policy=" + ppolicy
                }
                //setTimeout("document.location.replace('"+LocationStr+"');",1000);
                //		var LocationStr="test.asp";
                //		alert(LocationStr);
                myStr = LocationStr;
                setTimeout("doNull();", 1000);

                //document.location.replace(LocationStr);
            }
        }
        //	if (mName=="New_Lead") {
        //		var LocationStr="editPopupWindow.asp?command=new&name="+mName+"&policy=add"
        //		document.location.replace(LocationStr);
        //	}

    } //for the nomal process 

}
function doNull() {

    document.location.replace(myStr);
}
function setSelectionRange(thisobj, selectionStart, selectionEnd) {
    if (thisobj.setSelectionRange) {
        thisobj.focus();
        thisobj.setSelectionRange(selectionStart, selectionEnd);
    }
    else if (thisobj.createTextRange) {
        var range = thisobj.createTextRange();
        range.collapse(true);
        range.moveEnd('character', selectionEnd);
        range.moveStart('character', selectionStart);
        range.select();
    }
}

function refreshHtml(name) {
    var opernerHref = window.opener.document.location.href;
    if (opernerHref.indexOf('savePopuowindow.asp') == -1) {
        switch (name) {
            case "sub_accounts", "fund_distribution", "varible_sub_account":
                var policyStr = '';
                var re = /NoNeedtoDo/g;
        }
        opernerHref = opernerHref.replace(re, policyStr);
        var re = /firstOpen/g;
        opernerHref = opernerHref.replace(re, 'firstOpen1');
    }
}
function ChkChar(Ich) {
    if ((Ich.indexOf("'") == -1) && (Ich.indexOf("&") == -1) && (Ich.indexOf("%") == -1) && (Ich.indexOf("@") == -1) && (Ich.indexOf("!") == -1) && (Ich.indexOf("*") == -1) && (Ich.indexOf("#") == -1)) {
        return (true);
    }
    else {
        alert("Invalid login String : " + Ich);
        document.getElementById('TxtLoginID').value = "";
        return (false);
    }
}

function ChkDec(Ich) {
    if ((Ich.indexOf("'") == -1) && (Ich.indexOf("&") == -1) && (Ich.indexOf("%") == -1) && (Ich.indexOf("@") == -1) && (Ich.indexOf("!") == -1) && (Ich.indexOf("*") == -1) && (Ich.indexOf("#") == -1)) {
        return (true);
    }
    else {
        alert("Invalid Password String : ");
        document.getElementById('TxtPassword').value = "";
        return (false);
    }
}


//function PopulateData(vDateName, vDateValue, e, dateCheck, dateType){
//	alert('test populate ' +vDateValue +' : '); 
//	if (vDateValue.length < 1){
//		if (vDateName.name=="Marketing_Assistant_Follow_Up_Date"){
//		document.all('Marketing_Assistant_Follow_Up_Date_').value = vDateValue;
//		
//		}
//	}
//	if (!dateValid(vDateValue,vDateName.name)) {
//		alert("Invalid Date\nPlease Re-Enter ");
//		vDateType = vDateTypeTemp;
//		vDateName.value = "";
//		vDateName.focus();
//		return true;
//	}
//	
//	
//}

var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
var vDateType = 3; // 1 = mm/dd/yyyy  3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
    vDateType = dateType;

    if (vDateValue == "__/__/____") {
        vDateName.value = "";
        return true;
    }
    var whichCode = (window.Event) ? e.which : e.keyCode;
    // Check to see if a seperator is already present.
    //alert(" test " +vDateValue + "; " + vDateName.name);
    if (vDateValue.length > 8 && isNav4) {
        if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
            return true;
    }
    var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
    if (alphaCheck.indexOf(vDateValue) >= 1) {
        if (isNav4) {
            vDateName.value = "";
            vDateName.focus();
            vDateName.select();
            return false;
        }
        else {
            vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
            return false;
        }
    }
    if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
        return false;
    else {
        //numeric string values for 0123456789/
        var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
        if (strCheck.indexOf(whichCode) != -1) {
            if (isNav4) {
                if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >= 1)) {
                    alert("Invalid Date\nPlease Re-Enter ");
                    vDateName.value = "";
                    vDateName.focus();
                    vDateName.select();
                    return false;
                }
                if (vDateValue.length == 6 && dateCheck) {
                    var mDay = vDateName.value.substr(2, 2);
                    var mMonth = vDateName.value.substr(0, 2);
                    var mYear = vDateName.value.substr(4, 4)
                    //Turn a two digit year into a 4 digit year
                    if (mYear.length == 2 && vYearType == 4) {
                        var mToday = new Date();
                        //If the year is greater than 30 years from now use 19, otherwise use 20
                        var checkYear = mToday.getFullYear() + 30;
                        var mCheckYear = '20' + mYear;
                        if (mCheckYear >= checkYear)
                            mYear = '19' + mYear;
                        else
                            mYear = '20' + mYear;
                    }
                    var vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                    if (!dateValid(vDateValueCheck)) {
                        alert("Invalid Date\nPlease Re-Enter ");
                        vDateName.value = "";
                        vDateName.focus();
                        vDateName.select();
                        return false;
                    }
                    return true;
                }
                else {
                    // Reformat the date for validation and set date type to a 1

                    if (vDateValue.length >= 8 && dateCheck) {
                        if (vDateType == 1) // mmddyyyy
                        {
                            var mDay = vDateName.value.substr(2, 2);
                            var mMonth = vDateName.value.substr(0, 2);
                            var mYear = vDateName.value.substr(4, 4)
                            vDateName.value = mMonth + strSeperator + mDay + strSeperator + mYear;
                        }
                        if (vDateType == 2) // yyyymmdd
                        {
                            var mYear = vDateName.value.substr(0, 4)
                            var mMonth = vDateName.value.substr(4, 2);
                            var mDay = vDateName.value.substr(6, 2);
                            vDateName.value = mYear + strSeperator + mMonth + strSeperator + mDay;
                        }
                        if (vDateType == 3) // ddmmyyyy
                        {
                            var mMonth = vDateName.value.substr(2, 2);
                            var mDay = vDateName.value.substr(0, 2);
                            var mYear = vDateName.value.substr(4, 4)
                            vDateName.value = mDay + strSeperator + mMonth + strSeperator + mYear;
                        }
                        //Create a temporary variable for storing the DateType and change
                        //the DateType to a 1 for validation.
                        var vDateTypeTemp = vDateType;
                        vDateType = 1;
                        var vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                        //alert(" date value "+vDateValueCheck);

                        if (!dateValid(vDateValueCheck)) {
                            vDateType = vDateTypeTemp;
                            vDateName.value = "";
                            vDateName.focus();
                            vDateName.select();
                            return false;
                        }
                        vDateType = vDateTypeTemp;
                        return true;
                    }
                    else {
                        //if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
                        if ((vDateValue.length < 8 && dateCheck) && (vDateValue.length >= 1)) {
                            alert("Invalid Date\nPlease Re-Enter ");
                            vDateName.value = "";
                            vDateName.focus();
                            vDateName.select();
                            return false;
                        }
                    }
                }
            }
            else {
                // Non isNav Check
                //if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {

                if ((vDateValue.length < 8 && dateCheck) && (vDateValue.length >= 1)) {
                    alert("Invalid Date\nPlease Re-Enter ");
                    vDateName.value = "";
                    vDateName.focus();
                    return true;
                }
                // Reformat date to format that can be validated. mm/dd/yyyy
                if (vDateValue.length >= 8 && dateCheck) {
                    // Additional date formats can be entered here and parsed out to
                    // a valid date format that the validation routine will recognize.
                    if (vDateType == 1) // mm/dd/yyyy
                    {
                        var mMonth = vDateName.value.substr(0, 2);
                        var mlen = 3;
                        var mfix = 6;
                        if (mMonth.indexOf("/") > 0) {
                            mlen = mMonth.indexOf("/") + 1;
                            mMonth = '0' + vDateName.value.substr(0, 1);
                            mfix = mfix - 1;
                            //mMonth = mMth;
                        }
                        var mDay = vDateName.value.substr(mlen, 2);
                        if (mDay.indexOf("/") > 0) {
                            mDay = '0' + vDateName.value.substr(mlen, 1);
                            mfix = mfix - 1;
                        }
                        var mYear = vDateName.value.substr(mfix, 4)
                    }
                    if (vDateType == 2) // yyyy/mm/dd
                    {
                        var mYear = vDateName.value.substr(0, 4)
                        var mMonth = vDateName.value.substr(5, 2);
                        var mDay = vDateName.value.substr(8, 2);
                    }
                    if (vDateType == 3) // dd/mm/yyyy
                    {
                        var mDay = vDateName.value.substr(0, 2);
                        var mMonth = vDateName.value.substr(3, 2);
                        var mYear = vDateName.value.substr(6, 4)
                    }
                    if (vYearLength == 4) {
                        if (mYear.length < 4) {
                            alert("Invalid Date\nPlease Re-Enter ");
                            vDateName.value = "";
                            vDateName.focus();
                            return true;
                        }
                    }
                    // Create temp. variable for storing the current vDateType
                    var vDateTypeTemp = vDateType;
                    // Change vDateType to a 1 for standard date format for validation
                    // Type will be changed back when validation is completed.
                    vDateType = 1;
                    // Store reformatted date to new variable for validation.

                    var vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                    //alert(" test " + vDateValueCheck);
                    if (mYear.length == 2 && vYearType == 4 && dateCheck) {
                        //Turn a two digit year into a 4 digit year
                        var mToday = new Date();
                        //If the year is greater than 30 years from now use 19, otherwise use 20
                        var checkYear = mToday.getFullYear() + 30;
                        var mCheckYear = '20' + mYear;
                        if (mCheckYear >= checkYear)
                            mYear = '19' + mYear;
                        else
                            mYear = '20' + mYear;
                        vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                        // Store the new value back to the field.  This function will
                        // not work with date type of 2 since the year is entered first.
                        if (vDateTypeTemp == 1) // mm/dd/yyyy
                            vDateName.value = mMonth + strSeperator + mDay + strSeperator + mYear;
                        if (vDateTypeTemp == 3) // dd/mm/yyyy
                            vDateName.value = mDay + strSeperator + mMonth + strSeperator + mYear;
                    }

                    if (!dateValid(vDateValueCheck, vDateName.name)) {
                        alert("Invalid Date\nPlease Re-Enter ");
                        vDateType = vDateTypeTemp;
                        vDateName.value = "";
                        vDateName.focus();
                        return true;
                    }
                    vDateType = vDateTypeTemp;
                    return true;
                }
                else {

                    if (vDateType == 1) {
                        if (vDateValue.length == 2) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                        if (vDateValue.length == 5) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                    }
                    if (vDateType == 2) {
                        if (vDateValue.length == 4) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                        if (vDateValue.length == 7) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                    }
                    if (vDateType == 3) {
                        if (vDateValue.length == 2) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                        if (vDateValue.length == 5) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                    }
                    if (vDateValue.length < 1) {
                        if (vDateName.name == "Marketing_Assistant_Follow_Up_Date") {
                            document.all('Marketing_Assistant_Follow_Up_Date_').value = vDateValue;

                        }
                    }
                    return true;
                }
            }
            if (vDateValue.length == 10 && dateCheck) {
                if (!dateValid(vDateName, vDateName.name)) {
                    // Un-comment the next line of code for debugging the dateValid() function error messages
                    //alert(err);  
                    alert("Invalid Date\nPlease Re-Enter ");
                    vDateName.focus();
                    vDateName.select();
                }
            }
            return false;
        }
        else {
            // If the value is not in the string return the string minus the last
            // key entered.
            if (isNav4) {
                vDateName.value = "";
                vDateName.focus();
                vDateName.select();
                return false;
            }
            else {
                vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
                return false;
            }
        }
    }
}
function dateValid(objName, fdName) {

    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparatorArray = new Array("-", "/", ".");
    var intElementNr;
    // var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    //strDate = datefield.value;
    strDate = objName;
    if (fdName == "Marketing_Assistant_Follow_Up_Date") {
        document.all('Marketing_Assistant_Follow_Up_Date_').value = objName;
        //alert('test ' +fdName +' : '); 
    }
    if (strDate.length < 1) {
        return true;
    }
    for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
        if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
            strDateArray = strDate.split(strSeparatorArray[intElementNr]);
            if (strDateArray.length != 3) {
                err = 1;
                return false;
            }
            else {
                strDay = strDateArray[0];
                strMonth = strDateArray[1];
                strYear = strDateArray[2];
            }
            booFound = true;
        }
    }
    if (booFound == false) {
        if (strDate.length > 5) {
            strDay = strDate.substr(0, 2);
            strMonth = strDate.substr(2, 2);
            strYear = strDate.substr(4);
        }
    }
    //Adjustment for short years entered
    if (strYear.length == 2) {
        strYear = '20' + strYear;
    }
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
    intday = parseInt(strDay, 10);
    if (isNaN(intday)) {
        err = 2;
        return false;
    }
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth)) {
        for (i = 0; i < 12; i++) {
            if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
                intMonth = i + 1;
                strMonth = strMonthArray[i];
                i = 12;
            }
        }
        if (isNaN(intMonth)) {
            err = 3;
            return false;
        }
    }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
        err = 4;
        return false;
    }
    if (intMonth > 12 || intMonth < 1) {
        err = 5;
        return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
        err = 6;
        return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
        err = 7;
        return false;
    }
    if (intMonth == 2) {
        if (intday < 1) {
            err = 8;
            return false;
        }
        if (LeapYear(intYear) == true) {
            if (intday > 29) {
                err = 9;
                return false;
            }
        }
        else {
            if (intday > 28) {
                err = 10;
                return false;
            }
        }
    }
    //var tempObj=document.all("Seminar_NotesContent");
    //var Myitem= tempObj.all;
    //Myitem= tempObj.getElementsByTagName("INPUT");
    //for ( i=0; i<Myitem.length; i++) {
    //		var mName=Myitem.item(i).name;
    if (fdName == "Marketing_Assistant_Follow_Up_Date") {
        document.all('Marketing_Assistant_Follow_Up_Date_').value = objName;
        //alert('test ' +fdName +' : '); 
    }
    return true;
}
function LeapYear(intYear) {
    if (intYear % 100 == 0) {
        if (intYear % 400 == 0) { return true; }
    }
    else {
        if ((intYear % 4) == 0) { return true; }
    }
    return false;
}
function Datechkclear(vDateName, vDateValue) {
    //alert(" T1 " +vDateValue);
    //if (vDateValue == "__/__/____"){
    //	vDateName.value = "";
    //}
}
function doDate() {
    var box = document.insert.item_date
    var now = new Date();
    var theDay = now.getDate();
    var theMonth = now.getMonth() + 1;
    var theYear = now.getFullYear();
    if (theDay < 10) theDay = "0" + theDay;
    if (theMonth < 10) theMonth = "0" + theMonth
    var theDate = theDay + "/" + theMonth + "/" + theYear;
    box.value = theDate;
}
function Fundsumup() {
    var allfd = document.all('Percentage_1').value * 1 + document.all('Percentage_2').value * 1 + document.all('Percentage_3').value * 1
    if (allfd != 100) alert('Message: The Sum of Percentage(%) is ' + allfd + '\n\nThat is not equal to 100%, please check. ');

}
function AskAll(o) {
    var tstr = o.name.replace('_', ' ');
    if ((o.value != 'Yes') && (o.value != 'YES') && (o.value != 'yes')) {
        var iget = window.confirm('Click OK to list all client information that "' + tstr + '" posted, or  \n\nClick Cancel button and input a string into "' + tstr + '" box for searching ');
        if (iget == true) document.all(o.name).value = 'Yes';
    }
}
function AskCalendar(o) {
    var tselect = "test.asp?menuName=Calendar&tabName=Calendar&Search=" + o.value + "&flag=" + o.name + "&date=" + o.value
    window.open(tselect, "Get_Calender", "left=800,top=220,toolbar=0,location=0,directories=0,status=0,menubar=0,width=190,height=420,scrollbars=0");
    //window.open(tselect,"Get_Calender","left=700,top=220,width=600,height=620");
}
function PopCalendar(o) {
    var fd = document.getElementById(o).value;
    var tselect = "test.asp?menuName=Calendar&tabName=Calendar&Search=" + fd + "&flag=" + o + "&date=" + fd
    window.open(tselect, "Get_Calender", "left=700,top=220,toolbar=0,location=0,directories=0,status=0,menubar=0,width=190,height=420,scrollbars=0");
    //window.open(tselect,"Get_Calender","left=700,top=220,width=600,height=620");
}

function UpCurDate(o, type) {
    var fd = document.getElementById("DateFd").value;
    var yearSet = 0;
    //alert("test " +o.value);
    switch (type) {
        case "0":
            var ad = document.getElementById("AllDate").value;
            var yr = document.getElementById("YearText").value;
            var date1 = o.value + "/01/" + yr;
            if (isNaN(yr)) {
                yearSet = 1;
            }
            else {
                document.getElementById("AllDate").value = date1;
                var tstr = "test.asp?menuName=Calendar&tabName=Calendar&date=" + date1 + "&flag=" + fd;
                if ((yr <= 1900) || (yr >= 2300)) yearSet = 1;
                else yearSet = 0;
            }
            break;
        case "1":
            var ad = document.getElementById("AllDate").value;
            var Mn = document.getElementById("GetMonth").value;
            if (isNaN(o.value)) {
                type = "0";
                yearSet = 1;
            }
            else {
                var yr = o.value;
                var date1 = Mn + "/01/" + o.value;
                document.getElementById("AllDate").value = date1;
                var tstr = "test.asp?menuName=Calendar&tabName=Calendar&date=" + date1 + "&flag=" + fd;
                if ((yr <= 1900) || (yr >= 2300)) yearSet = 1;
                else yearSet = 0;
            }
            break;
        case "2":
            var ad = document.getElementById("AllDate").value;
            var Mn = document.getElementById("GetMonth").value - 1;
            var yr = document.getElementById("YearText").value;
            if (isNaN(yr)) {
                yearSet = 1;
            }
            else {
                if (Mn < 1) {
                    Mn = 12;
                    yr = yr - 1;
                    var date1 = Mn + "/01/" + yr;
                }
                else {
                    var date1 = Mn + "/01/" + yr;
                }
                document.getElementById("AllDate").value = date1;
                var tstr = "test.asp?menuName=Calendar&tabName=Calendar&date=" + date1 + "&flag=" + fd;
                if ((yr <= 1900) || (yr >= 2300)) yearSet = 1;
                else yearSet = 0;
            }
            break;
        case "3":
            var ad = document.getElementById("AllDate").value;
            var Mn = document.getElementById("GetMonth").value;
            Mn++;
            var yr = document.getElementById("YearText").value;
            if (isNaN(yr)) {
                yearSet = 1;
            }
            else {
                if (Mn > 12) {
                    Mn = 1;
                    yr++;
                    var date1 = Mn + "/01/" + yr;
                }
                else {
                    var date1 = Mn + "/01/" + yr;
                }
                document.getElementById("AllDate").value = date1;
                var tstr = "test.asp?menuName=Calendar&tabName=Calendar&date=" + date1 + "&flag=" + fd;
                if ((yr <= 1900) || (yr >= 2300)) yearSet = 1;
                else yearSet = 0;
            }
            break;
    }
    if ((yearSet == 1) && (type != "1")) {
        alert('Invalid data in year field, pls chcek!');
    }
    else {
        if (yearSet == "0") {
            document.location.replace(tstr);
        }
    }
}
function AskStatus(o) {
    var tselect = o.value;
    window.open("AdhocStatus.asp?vsel=" + tselect, "Adhoc_Client_Status", "toolbar=0,location=0,directories=0,status=0,menubar=0,width=380,height=450,scrollbars=0");
    //window.open("Authuser.asp?vsel="+tselect,"Adhoc_Client_Status","toolbar=0,location=0,directories=0,status=0,menubar=0,width=380,height=450,scrollbars=0");

}
function AskEmail(o) {
    var tselect = o.value;
    window.open("AdhocEmail.asp?vsel=" + tselect, "Adhoc_Email_Address", "toolbar=0,location=0,directories=0,status=0,menubar=0,width=380,height=230,scrollbars=0");
}
function AskContact(o) {
    var tselect = o.value;
    window.open("AdhocContact.asp?vsel=" + tselect, "Adhoc_Contact_Note", "toolbar=0,location=0,directories=0,status=0,menubar=0,width=380,height=400,scrollbars=0");
}
function CallPDF(o) {
    if (o == 'Finance') {

        var tempObj = document.all("BasicContent");
        if (tempObj !== null) {
            var exp = new Date();
            var content, Contend;
            exp.setTime(exp.getTime() + (1000 * 60));
            var tid = document.getElementById("Mpolicy").value;
            var a = document.getElementById("Last_Name").value;
            var b = document.getElementById("First_Name").value;
            var c = document.getElementById("SSN").value;
            var d = document.getElementById("Address").value;
            var e = document.getElementById("City").value;
            var f = document.getElementById("State").value;
            var g = document.getElementById("Zip").value;
            var h = document.getElementById("Home_Phone").value;
            var i = document.getElementById("Sex").value;
            var j = document.getElementById("Date_Of_Birth").value;
            var k = document.getElementById("MI").value;
            /*	var rflag=window.confirm("\n"+"Client Id: " + tid +"\n" + "Client Name: " + b + "," + a + "\n\n" +"Such client information will fill in LaserApp Form ")
            if (rflag){
            }*/

            tid = tid.replace(" ", ";;");
            if (tid.indexOf(";;") != -1) { tid = tid.substring(0, (tid.indexOf(";;"))) }
            else { tid = tid.substring(0, (tid.length)); }
            content = b + ", " + a;
            setCookie(tid, content, exp);
            var s = 'tid=' + tid + '+&a=' + a + '&b=' + b + '&c=' + c + '&d=' + d + '&e=' + e + '&f=' + f + '&g=' + g + '&h=' + h + '&i=' + i + '&j=' + j + '&k=' + k;
            /*window.showModalDialog('nlaform.asp?'+s);
            */
            //window.open('http:\www.zukplan.com\secure\webform\nlaform.asp?'+s,'_blank','left=300,top=280,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=110,width=320');		
            window.open('nlaform.asp?' + s, '_blank', 'left=300,top=280,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=110,width=320');
            //	window.open('http://www.zukplan.com/webform/nlaform.asp?'+s,'_blank','left=10,top=20,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,height=600,width=820');		
        }
        else {
            /*window.open('a-form.asp','_blank','left=10,top=20,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,height=700,width=900');		
            */
        }
    }
    else {
        window.open('ZschF.asp', '_blank', 'left=10,top=20,location=1,menubar=1,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,height=700,width=900');
    }
}

function NumFormat(vDateName, vDateValue, e, dateCheck, dateType) {
    vDateType = dateType;
    var dSeperator = "-";
    if ((vDateValue == "___-__-____") || (vDateValue == "___-___-____")) {
        vDateName.value = "";
        return true;
    }
    var whichCode = (window.Event) ? e.which : e.keyCode;
    // Check to see if a seperator is already present.
    //alert(" test " +vDateValue + "; " + vDateName.name);
    if (vDateValue.length > 8 && isNav4) {
        if (vDateValue.indexOf("-") >= 1)
            return true;
    }
    var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/";
    if (alphaCheck.indexOf(vDateValue) >= 1) {
        if (isNav4) {
            vDateName.value = "";
            vDateName.focus();
            vDateName.select();
            return false;
        }
        else {
            vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
            return false;
        }
    }
    if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
        return false;
    else {
        //numeric string values for 0123456789/
        var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
        if (strCheck.indexOf(whichCode) != -1) {
            if (isNav4) {

            }
            else {
                // Non isNav Check
                // Reformat date to format that can be validated. mm/dd/yyyy
                if (vDateValue.length > 7) {
                    //alert(" In " +vDateValue);
                    //vDateValue=vDateValue.replace(" -","");
                    vDateValue = vDateValue.replace(" ", "");
                }
                if ((vDateValue.length < 4 && dateCheck) && (vDateValue.length >= 1)) {
                    for (i = vDateValue.length; i < 3; i++) {
                        vDateValue = vDateValue + "  ";
                    }
                    vDateName.value = vDateValue + "" + dSeperator + "    -  ";
                    return true;
                }
                if (vDateType == 1) {
                    if (vDateValue.length == 3) {
                        vDateName.value = vDateValue + dSeperator;
                        return true;
                    }
                    if (vDateValue.length == 6) {
                        vDateName.value = vDateValue + dSeperator;
                        return true;
                    }
                    if ((vDateValue.length < 7 && dateCheck) && (vDateValue.length >= 1)) {
                        for (i = vDateValue.length; i < 6; i++) {
                            vDateValue = vDateValue + "  ";
                        }
                        vDateName.value = vDateValue + "" + dSeperator + "  ";
                        return true;
                    }
                }
                if (vDateType == 2) {
                    if (vDateValue.length == 3) {
                        vDateName.value = vDateValue + dSeperator;
                        return true;
                    }
                    if (vDateValue.length == 7) {
                        vDateName.value = vDateValue + dSeperator;
                        return true;
                    }
                    if ((vDateValue.length < 8 && dateCheck) && (vDateValue.length >= 1)) {
                        for (i = vDateValue.length; i < 7; i++) {
                            vDateValue = vDateValue + "  ";
                        }
                        vDateName.value = vDateValue + "" + dSeperator + "  ";
                        return true;
                    }
                }
                else {
                    if (vDateType == 1) {
                        if (vDateValue.length == 3) {
                            vDateName.value = vDateValue + dSeperator;
                        }
                        if (vDateValue.length == 6) {
                            vDateName.value = vDateValue + dSeperator;
                        }
                    }
                    if (vDateType == 2) {
                        if (vDateValue.length == 3) {
                            vDateName.value = vDateValue + dSeperator;
                        }
                        if (vDateValue.length == 7) {
                            vDateName.value = vDateValue + dSeperator;
                        }
                    }
                    return true;
                }
            }

            return false;
        }
        else {
            // If the value is not in the string return the string minus the last
            // key entered.
            if (isNav4) {
                vDateName.value = "";
                vDateName.focus();
                vDateName.select();
                return false;
            }
            else {
                vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
                return false;
            }
        }
    }
}
