var guestuser='admin@emmyonline.tv';
var guestpass='Da3TE5';
function scrapURL(url){
    var remProto = url.substring(url.indexOf("://")+3,url.length);
    var protocal = url.substring(0,url.indexOf("://")+3); 
    var elimateStr = remProto.substring(0,remProto.indexOf("/")+1);
    var newURL = "";
    
    
    // Comment this block for port
   /* if(protocal == "http://"){
         newURL = "https://" + remProto;  
         window.location.href = newURL;
    }else{
         newURL = protocal + elimateStr;  
    }*/
    
    
    // Comment this if it is for 80 port and http to httpsl
    newURL = protocal + elimateStr;    
    newURL = newURL.substring(0, newURL.length-1)      
    return newURL;
}
function showProgress(status){
   // alert(status);
    if(status==true){
        $("divProgress").style.display="";
        $("loadImg").style.left=(document.body.clientWidth)/2;
        if(state.currentPage=="JudgePanels.html"){
            $("loadImg").style.top=((document.body.clientHeight)/2)+30;
        }else{
            $("loadImg").style.top=(document.body.clientHeight)/2;
        }
        $("loadImg").style.display="";
    }else{
        $("divProgress").style.display="none";
        $("loadImg").style.display="none";
    }
}
function firefoxFocus(){
    window.frames["GateWay"].document.getElementById("anchorEmmy").focus();
    window.frames["GateWay"].document.getElementById("anchorEmmy").blur();
}
function getdata(name){
    var temp = settingsjson;    
    for(i=0;i<temp.length;i++){
        if(temp[i].name == name){        
          //  alert(temp[i].name +"==="+ name);
            this.name = temp[i].name;
            this.ConstraintMaximum = temp[i].ConstraintMaximum;
            this.ConstraintMinimum = temp[i].ConstraintMinimum;
            this.DataType = temp[i].DataType;
            this.SettingType = temp[i].SettingType;
            this.ValueDateTime = temp[i].ValueDateTime; 
            this.ValueMultilineText = temp[i].ValueMultilineText;
            this.ValueText = temp[i].ValueText;
        }
    }
}

function getCookieDetails(){
    parent.showProgress(true);
    state.loginName=getCookie("Remail");
    state.currentPage=getCookie("fileName");
    if(state.loginName != "" && !isNull(state.loginName)){
        state.isRemember=true;
        state.loginName=getCookie("Remail");
        state.password=getCookie("Rpassword");
        state.currentPage=getCookie("fileName");
    }
    state.userID=getCookie("userID");
}
function getTheme(){
    var obj = new sendRequest(state.SERVER_URL+"/servlet/theme?hash="+Math.random(), null, '', true, afterTheme);
}
function afterTheme(jsonData){
    state.folderID = jsonData.folderID;
    if(state.userID != "" && !isNull(state.userID)){
        state.loginName=getCookie("email");
        state.password=getCookie("password");
        var json="["+state.userID+", \""+state.userID+"\", []]";
        afterLogin(JSON.parse(json));
    }else{
        window.frames["GateWay"].location.href = "Daytime.html";
    }
}
function displayDummy(){
    state.currentPage="";    
    showProgress(true);
    var loginUrl = state.SERVER_URL +"/servlet/me/session?userName="+state.loginName+"&userPWD="+state.password+"&hash="+Math.random();
    var Obj = new sendRequest(loginUrl,null,'POST',true,afterLogin);
}
function GuestDummy(g){
    state.currentPage="";
    showProgress(true);
    var loginUrl = state.SERVER_URL +"/servlet/me/session?userName="+state.loginName+"&userPWD="+state.password+"&hash="+Math.random();
    if(g=='cal'){
    var Obj = new sendRequest(loginUrl,null,'POST',true,GuestLogincal); 
    }else{
    var Obj = new sendRequest(loginUrl,null,'POST',true,GuestLogincer);    
    }
}
function GuestLogincal(jsonData){
    var json="[0,\"Default\", [\"field_11\", \"field_12\", \"field_14\"],[],[[\"field_11\",\"ASC-1\"]],[[\"field_11\",\"LEFT\"],[\"field_12\",\"LEFT\"],[\"field_14\",\"LEFT\"]],[[],[]]]";
    var resourceURL = "jsonText="+encodeURIComponent(json);//=RESOURCELIST["field_11","DESC-1"]
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.calServiceID+"/resources?@RestURLType=GET&count="+100;
    var Obj = new sendRequest(params,resourceURL,'POST',true,guestcalResource);   
    }
function GuestLogincer(jsonData){
    var url = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.ruleServiceID+"/resources?@RestURLType=GET&count="+100+"&hash="+Math.random();
    var params="jsonText=[0, \"Default\", [\"RecordedBy\", \"RecordedDate\", \"ModifiedBy\", \"ModifiedDate\", \"RevertMessage\", \"field_11\", \"field_12\", \"field_13\", \"field_16\"],[],[],[],[[],[]]]";
    var Obj = new sendRequest(url, params,'POST',true,guestruleResource);   
    }
function afterLogin(jsonData){
    if(jsonData[0] >0){
        setCookie("email",state.loginName,0);
        setCookie("password",state.password,0);
        setCookie("userID",jsonData[1],0);
        if(state.isRemember){
            setCookie("Remail",state.loginName);
            setCookie("Rpassword",state.password);
        }else {
            setCookie("Remail","");
            setCookie("Rpassword","");
        }
     //   alert(jsonData);
      //  alert(jsonData[1]);
        state.userID=jsonData[1];
        var loginUrl = state.SERVER_URL +"/servlet/folder/"+state.folderID+"/me/preference?userID="+jsonData[1]+"&hash="+Math.random(); //=PREFERENCE
        var Obj = new sendRequest(loginUrl,null,'',true,userloginInfo);
    }else{
        showProgress(false);
        if(jsonData[1]=="User session Expired"){
            alert("User session expired. Please click OK for the page to refresh automatically.");
            parent.location.reload();
        }else{
            var stText=window.frames[0].document.getElementById("statText");
            stText.innerHTML="Wrong Email/Password";
        }
    }
}
function userloginInfo(jsonData){

    state.profileID = jsonData[0][0];    
    state.userName = decodeNonHTML(jsonData[0][1]+" "+jsonData[0][3]);    
    state.entryProfileID = state.profileID;
    state.entryUserName = state.userName;
    changeustime();
} 
function changeustime(){           
    var urlValue = state.SERVER_URL+"/servlet/getTime?@RestURLType=GET";
    var Obj = new parent.sendRequest(urlValue, null,'POST', true, serverDate);
}
function serverDate(jsonData){
    state.US_Date = new Date(jsonData[0]);
    state.us_long = jsonData[0]
    setInterval("runTimer()",1000);
    var url = state.SERVER_URL+"/servlet/service/"+state.serviceID+"/resource/"+state.profileID+"?hash="+Math.random();//=RESOURCE
    var obj = new sendRequest(url, null, '' ,true , checkUserProfile);
}
function checkUserProfile(jsonData){
    if(jsonData != "failure"){
        state.resFieldValues = jsonData;
        state.userData=jsonData;
        state.entryUserData=jsonData;
        state.loginName = state.userData[10];
        if(jsonData[14]==2){
            state.userName="Mr. "+state.userName;
        }else if(jsonData[14]==3){
            state.userName="Ms. "+state.userName;
        }else if(jsonData[14]==4){
            state.userName="Mrs. "+state.userName;
        }else if(jsonData[14]==5){
            state.userName="Dr. "+state.userName;
        }        
        var url = state.SERVER_URL +"/servlet/folder/"+state.folderID+"?hash="+Math.random();  //FOLDER DETAIL
        var obj = new sendRequest(url, null, 'GET' ,true , getAdminStatus);
    }else{
        window.frames["GateWay"].location.href = "Daytime.html";
    }
}

function getAdminStatus(jsonData){
        var temp=jsonData[15].toUpperCase();
        if((temp=="USER")){
            state.userStatus="User"; 
        }else if(temp=="HEIRARCHYADMIN" || temp=="PRIMADMIN"|| temp=="SECADMIN"){
            state.userStatus="Admin"; 
             state.filters=[["field_12","(@field_12 ~=~ '1|:::end:::|') AND"],["field_28","(@field_28 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND"]];
        }
        var status = userProfileValidate();
        if(status && state.userStatus!="Admin" ){
            state.currentAction="PROFILE_EDIT";
            state.isProfileLogin = true;
            window.frames["GateWay"].location.href = "Registration.html";
        }else{
            getFolderDetails(jsonData);
        }
}

function userProfileValidate(){
    var val=unescape(state.resFieldValues[25]);
    val=val.replace(/&#10;/g,"\n");
    val=val.replace(/&#61;/g,"=");
    val=val.replace(/&amp;/g,"&");      
    val=val.replace(/&quot;/g,"\"");
    val=val.replace(/&lt;/g,"<");  
    val=val.replace(/&gt;/g,">");
    var phone = val;    
    if(stringTrim(phone) == ""){
        return true;
    }
    return false;
}
var amt="";
function getFolderDetails(jsonData){
    var temp=jsonData[15].toUpperCase();
    if((temp=="USER")){
        state.userStatus="User"; 
    }else if(temp=="HEIRARCHYADMIN" || temp=="PRIMADMIN"|| temp=="SECADMIN"){
        state.userStatus="Admin"; 
    }
    state.currentResID=getCookie("entantResID");  
    if(state.currentResID>0 && location.href.indexOf("payId=")>-1){
        var idStr=location.href.substring(location.href.indexOf("payId=")+6);
        if(idStr.indexOf("&")>-1){
            amt=idStr.substring(idStr.indexOf("payamt=")+7);
            idStr=idStr.substring(0,idStr.indexOf("&"));
            if(amt.indexOf("&")>-1){
                amt=amt.substring(0,amt.indexOf("&"));
            }
        }
        var url = state.SERVER_URL+"/servlet/paycheck?payId="+idStr+"&hash="+Math.random();
        var urlParams="folder="+state.folderID+"&service="+state.entrantServiceID;
        var Obj = new sendRequest(url ,urlParams,'POST',true, checkId);
    }else{
        pageRetain();
    }
}
var t_mem_count;
var incr=0;
function checkId(jsonData){
    if(jsonData[0]==1){
           var t_mem_count1=getCookie("t_mem_count");
           t_mem_count=new Number(t_mem_count1);
           if(t_mem_count>0){
                updateTeamMem_of_paypal();
           }          
    }else{
        alert("Transaction declained");     
        window.frames["GateWay"].location.href = "Daytime.html";
    }
}
function next_ceck(){
    var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.entrantServiceID+"/resource/"+state.currentResID+"?hash="+Math.random();
    var Obj = new sendRequest(resourcelistURL, null, '',true, entrantGet);
}
function updateTeamMem_of_paypal(){    
        var urlParam="";
        var params =""; 
        params=getCookie("t_mem_params_"+incr+"");
        urlParam=getCookie("t_mem_urlparam_"+incr+"");
        var Obj = new parent.sendRequest(params,urlParam,'POST',true,teamMemSave1);
        setCookie("t_mem_params_"+incr+"","");
        setCookie("t_mem_urlparam_"+incr+"","");
        incr++;
}
function teamMemSave1(jsonData){
   if(incr!=t_mem_count){
        updateTeamMem_of_paypal();        
   }else{
        setCookie("t_mem_count",0);
        next_ceck();
   }
}
function entrantGet(jsonData){
 //   alert("fine");
    var currDate=new Date();
    var datStr=(currDate.getMonth()+1)+"/"+currDate.getDate()+"/"+currDate.getFullYear();
    var onlineAir="";
    parent.paypalData = jsonData;
 
    if(jsonData[32].length>0){
        onlineAir=jsonData[32][0];
    }
    var urlParams="field_11="+jsonData[8]+"&field_12="+jsonData[9]+"&field_13="+jsonData[10]+"&field_14="+encodeURIComponent(decodeHTML(jsonData[11])).replace(/\'/g,encodeURIComponent("&apos;"))+"&field_15="+jsonData[12];
    urlParams+="&field_16="+jsonData[13]+"&field_17="+encodeURIComponent(decodeHTML(jsonData[14]))+"&field_18="+jsonData[15]+"&field_19="+jsonData[16]+"&field_20="+jsonData[17]+"&field_21="+jsonData[18];
    urlParams+="&field_22="+jsonData[19]+"&field_23="+jsonData[20]+"&field_24="+jsonData[21]+"&field_25="+encodeURIComponent(jsonData[22])+"&field_26="+jsonData[23]+"&field_27=3";
    urlParams+="&field_28="+jsonData[25]+"&field_29="+jsonData[26]+"&field_30=4&field_32="+jsonData[28]+"&field_33="+encodeURIComponent(decodeHTML(jsonData[29]))+"&field_34="+jsonData[30];
    urlParams+="&field_35="+jsonData[31]+"&field_36="+onlineAir+"&field_37="+encodeURIComponent(decodeHTML(jsonData[33]))+"&field_38="+encodeURIComponent(decodeHTML(jsonData[34]))+"&field_39="+datStr+"&field_40="+amt+"&field_41="+jsonData[37]; //+(jsonData[38]==1?"&field_42="+jsonData[38]:"") for Broadband checkbox field
    var dateVal="";
    var hrEpi="";
    var minEpi="00";
    var sesEpi="AM";
    if(jsonData[38] != null && jsonData[38] != "" ){
            dateVal=jsonData[38][0];
            var hrEpisode = jsonData[38][1];
            if(hrEpisode.substring(0,1) != 0){
                hrEpi = "0"+hrEpisode;
            }
            var minEpisode = jsonData[38][2];
          //  if(minEpisode.substring(0,1) != 0){
                minEpi = minEpisode;
           // }
            sesEpi = jsonData[38][3];
            
    }
    urlParams += "&field_42="+dateVal; // mm/dd/yyyy
    urlParams += "&hfield_42="+hrEpi;  // 2 digit integer  <=12
    urlParams += "&mfield_42="+minEpi;  //2 digit integer
    urlParams += "&am_pmfield_42="+sesEpi; //AM
    dateVal="";
    var hrPass="";
    var minPass="00";
    var sesPass="AM";
    if(jsonData[39] != null && jsonData[39] != "" ){
            dateVal=jsonData[39][0];
            var hrBPass = jsonData[39][1];
            if(hrBPass.substring(0,1) != 0){
                hrPass = "0"+hrBPass;
            }
            var minBPass = jsonData[39][2];
            if(minBPass.substring(0,1) != 0){
                minPass = "0"+minBPass;
            }
            sesPass = jsonData[39][3];
            
    }
    urlParams += "&field_43="+dateVal; // mm/dd/yyyy
    urlParams += "&hfield_43="+hrPass;  // 2 digit integer  <=12
    urlParams += "&mfield_43="+minPass;  //2 digit integer
    urlParams += "&am_pmfield_43="+sesPass; //AM
  //  alert(jsonData[41]+jsonData[42]+jsonData[43]+jsonData[44]+jsonData[45]);
    urlParams += "&field_45="+jsonData[41];// following 5 files new chnage fro emmy our's ,adv agn
    urlParams += "&field_46="+jsonData[42];
    urlParams += "&field_47="+jsonData[43];
    urlParams += "&field_48="+encodeURIComponent(decodeHTML(jsonData[44]));
    urlParams += "&field_49="+encodeURIComponent(decodeHTML(jsonData[45]));
    /*var data="";
    for(var i=8,j=11;j<41;i++,j++){
        var val;
        if(j==27){
            val=3;
        }else if(j==30){
            val=4;
        }else if(j==31){
            i--;
            continue;
        }else if(j==39){
            val=datStr;
        }else if(j==40){
            val=amt;
        }else{
            val=jsonData[i];
        }
        if(data!=""){
            data+="&";
        }
        data+='field_'+j+'='+val;
    }*/
    
    var url = state.SERVER_URL+"/servlet/service/"+state.entrantServiceID+"/resource/"+jsonData[0]+"?form=0&editaccess="+0+"&viewaccess="+0+"&isNotifyChecked="+0+"&notifyUsers="+0+"&notifyGroups="+0+"&groupviewaccess="+0+"&groupeditaccess="+0+"&@RestURLType=PUT&hash="+Math.random();
    logdetails("User-Paypal-Payment-Success",state.entrantServiceID,jsonData[0],urlParams);
    var Obj = new  sendRequest(url ,urlParams,'POST',true, entrantSuccess);
}
function logdetails(paytype,serviceid,id,params){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/Nataslog?logName="+paytype+"&sid="+serviceid+"&id="+id+"&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL,params,'POST',true,logsuccess);  
}
function logsuccess(jsonData){
    if(jsonData[0]==1){
    }else{
    return false;
    }
}
function entrantSuccess(jsonData){
    if(jsonData[0]==1){
        for(var m=0;m<Categorylistjson.length;m++){
            if(Categorylistjson[m][0] == parent.paypalData[10]){
                sendAutoPayPalInvoice(Categorylistjson[m][1][0].replace(/&nbsp;/g," "));
                break;
            }
        }
        //getCategoryName();
        //sendAutoPayPalInvoice(jsonData);
        /*alert("Your payments successfully paid. Thank you for your payments.");
        setCookie("entantResID",0,0);
        setCookie("fileName","Entrant.html",0);
        alert(state.NATASURL);
        location.href=state.NATASURL;*/
    }else{
        alert("Error in Resource Updation");
        location.href=state.NATASURL;

    }
}
/*function getCategoryName(){
        var resourceURL = state.SERVER_URL+"/servlet/service/"+state.catServiceID+"/resource/"+parent.paypalData[10]+"?hash="+Math.random();
        var Obj = new sendRequest(resourceURL, null, 'GET',true, getCatRes);
}
function getCatRes(jsonData){
    sendAutoPayPalInvoice(jsonData[8]);
}*/
function sendAutoPayPalInvoice(cname){
    var dd=new Date();
    var mon=MONTHS[dd.getMonth()].substring(0,3);
    var day=dd.getDate();
    var yr=dd.getFullYear();
    var payType="PayPal";
    /*var USState = new Array("AL","AK","AS","AZ","AR","CA","CO","CT","DE","DC","FM","FL","GA","GU","HI","ID","IL","IN","IA","KS","KY",
    "LA","ME","MH","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","MP","OH","OK","OR","PW",
    "PA","PR","RI","SC","SD","TN","TX","UT","VT","VI","VA","WA","WV","WI","WY");
    USState.sort();
    var canadaState = new Array("AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE" ,"QC", "SK", "YT");
    canadaState.sort();*/
    var add="&nbsp;"+state.userData[18]+"<BR>&nbsp;"+state.userData[19]+"<BR>&nbsp;"+state.userData[20];
    if(state.userData[21]!=""){
        if(state.userData[23]=="United States"){
            add+="<BR>&nbsp;"+USState[state.userData[21][0]-2];
        }else if(state.userData[23]=="Canada"){
            add+="<BR>&nbsp;"+canadaState[state.userData[21][0]-61];
        }
    }
    var cid = parent.paypalData[9];    
    cname=cname.replace(/&nbsp;/g," ");
    if(state.userData[22]!=""){
        add+=" - "+state.userData[22];
    }
    add+="<BR>&nbsp;"+state.userData[23];
    add=add.replace(/&amp;/g,"&");
    add=add.replace(/&#47;/g,"/");
    add=add.replace(/&quot;/g,"\"");
    add=add.replace(/&#61;/g,"=");
    add=add.replace(/&#39;/g,"'");
    var nam = state.entryUserName;
    nam=nam.replace(/&amp;/g,"&");
    nam=nam.replace(/&#47;/g,"/");
    nam=nam.replace(/&quot;/g,"\"");
    nam=nam.replace(/&#61;/g,"=");
    nam=nam.replace(/&#39;/g,"'");
    var tit = state.entryUserData[15];
    tit=tit.replace(/&amp;/g,"&");
    tit=tit.replace(/&#47;/g,"/");
    tit=tit.replace(/&quot;/g,"\"");
    tit=tit.replace(/&#61;/g,"=");
    tit=tit.replace(/&#39;/g,"'");
    var data='<TABLE CELLPADDING="4" CELLSPACING="0" WIDTH="600px" STYLE="border:1px solid #cccccc"><TR><TD STYLE="padding:10px;padding-top:20px;" VALIGN="top" WIDTH="50%">';
    data+='<TABLE CELLPADDING="2" CELLSPACING="0" STYLE="border:1px solid #cccccc;" WIDTH="100%"><TR><TD style="font-weight:bold;padding-left:10px;padding-top:10px;padding-right:10px;">Name: <SPAN style="font-weight:normal;" id="tdName">'+nam+'</SPAN>';
    data+='</TD></TR><TR><TD style="padding-left:10px;padding-right:10px"> <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0"><TR><TD WIDTH="1%" NOWRAP STYLE="font-weight:bold;">Title:&nbsp;</TD><TD id="tdTitle" CLASS="judgePara">'+tit+'</TD></TR></TABLE></TD></TR><TR><TD style="font-weight:bold;padding-left:10px;padding-right:10px;padding-bottom:0px;">';
    data+='Address:</TD></TR><TR><TD id="tdAddress" CLASS="judgePara" style="padding-left:20px;padding-right:10px;padding-bottom:10px;">'+add;
    data+='</TD></TR></TABLE></TD><TD ALIGN="center" VALIGN="top" STYLE="padding-top:20px;"><TABLE CELLPADDING="0" CELLSPACING="0" WIDTH="90%"><TR><TD STYLE="padding-top:0px;color:#00478F;font-weight:bold;" ALIGN="center">';
    data+='Emmy Entry Invoice</TD></TR><TR><TD STYLE="padding-top:20px;"><TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0"><TR STYLE="background-color:#C0D8EF;font-size:12px;font-weight:bold" ALIGN="center">';
    data+='<TD STYLE="border:1px solid white">Dated</TD><TD STYLE="border:1px solid white">Invoice No.</TD></TR><TR STYLE="background-color:#E0EFF0;font-size:12px;" ALIGN="center">';
    data+='<TD STYLE="border:1px solid white" ID="tdDate">'+mon+" "+day+", "+yr+'</TD><TD STYLE="border:1px solid white" ID="tdBillno">'+state.currentResID+'</TD></TR></TABLE></TD></TR><TR>';
    data+='<TD STYLE="padding-top:10px;font-weight:bold;">Payment Mode: <SPAN style="font-weight:normal" id="tdPayType">PayPal</SPAN></TD></TR></TABLE></TD></TR><TR><TD COLSPAN="2" style="font-weight:bold;">';
    data+='Purchase Details:</TD></TR><TR><TD STYLE="padding-top:10px;font-weight:bold;">Ref ID: <SPAN style="font-weight:normal" id="tdPayType">'+state.currentResID+'</SPAN></TD></TR><TR><TD COLSPAN="2" STYLE="padding-top:10px;"><TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" STYLE="border:1px solid #CCCCCC;"><TR STYLE="background-color:#E8E8E8">';
    data+='<TD ALIGN="center" STYLE="border:1px solid #CCCCCC;border-left:0;border-top:0;font-weight:bold;" nowrap>Item #</TD><TD STYLE="border:1px solid #CCCCCC;border-left:0;border-top:0;font-weight:bold;" nowrap>Payment For</TD>';
    data+='<TD ALIGN="center" STYLE="border-bottom:1px solid #CCCCCC;font-weight:bold;" nowrap>Price in <font color="red">USD</font></TD></TR><TR><TD CLASS="judgeTitle" ALIGN="center" STYLE="border:1px solid #CCCCCC;border-left:0;border-top:0;font-weight:bold;">1.</TD>';
    data+='<TD ID="tdItem" CLASS="judgePara" STYLE="border:1px solid #CCCCCC;border-left:0;border-top:0">'+cid+". "+cname+'</TD><TD ID="tdPrice" CLASS="judgePara" ALIGN="center" STYLE="border-bottom:1px solid #CCCCCC;">'+parent.paypalData[36]+'</TD>';
    data+='</TR><TR STYLE="background-color:#E8E8E8"><TD ALIGN="right" COLSPAN="2" STYLE="border-right:1px solid #CCCCCC;font-weight:bold;">Amount Paid:</TD><TD STYLE="font-weight:bold;" ALIGN="center" ID="tdTotal">'+parent.paypalData[36]+'</TD>';
    data+='</TR></TABLE></TD></TR></TABLE>';
    
    var urlParams="field_11="+state.userID+"&field_12="+encodeURIComponent(data);
    url = state.SERVER_URL+"/servlet/service/"+state.invoiceServiceID+"/resource?form=0&editaccess="+0+"&viewaccess="+0+"&isNotifyChecked="+0+"&notifyUsers="+0+"&notifyGroups="+0+"&groupviewaccess="+0+"&groupeditaccess="+0+"&hash="+Math.random();
    var Obj = new  parent.sendRequest(url ,urlParams,'POST',true, sendAutoInvoice);
}
function sendAutoInvoice(jsonData){
    alert("Your payments successfully paid. Thank you for your payments.");
    setCookie("entantResID",0,0);
    setCookie("fileName","Entrant.html",0);
    location.href=state.NATASURL;
}
function pageRetain(){
    ensureUploadScriptIsLoaded("Application Settings");
    refreshApplication();
}
function refreshApplication(){
    if(state.userStatus=="Admin"){
        if(state.currentPage=="Calendar.html"){
            calendarClick();
        }else if(state.currentPage=="Registration.html"){
            editProfilePage();
        }else if(state.currentPage=="AdminEntrant.html"){
            entrantPage();
        }else if(state.currentPage=="AdminJudge.html"){
            getJudgePage();
        }else if(state.currentPage=="AdminBallot.html"){
            getAdminballotPage();
        }else if(state.currentPage=="Rules.html"){
            rulesClick();
         }else if(state.currentPage=="Help.html"){
            helpClick();   
        }else if(state.currentPage=="Administration.html"){
            adminClick();   
        }else if(state.currentPage=="JudgePanels.html"){
            adminClick();   
        }else if(state.currentPage=="JudgePerformer.html"){
            adminClick();   
        }else{
            getcount();
         //   window.frames["GateWay"].location.href = "WelcomeAdmin.html";
        }
    }else if(state.userStatus=="User"){
        if(state.currentPage=="Calendar.html"){
            calendarClick();
        }else if(state.currentPage=="Registration.html"){
            editProfilePage(); 
        }else if(state.currentPage=="judge.html"){
            getJudgePage();
        }else if(state.currentPage=="Entrant.html"){
            parent.invoiceArr = new Array();
            entrantPage();
        }else if(state.currentPage=="Rules.html"){
            rulesClick();
        }else if(state.currentPage=="Help.html"){
            helpClick();    
        }else if(state.currentPage=="EntryCheckout.html"){
            window.frames["GateWay"].location.href = "EntryCheckout.html";     
        }else{
            getcount();
           // window.frames["GateWay"].location.href = "Welcome.html";
        }
    }     
}
function getcount(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportServlet?reportName=InboxCount&userID="+state.userID+"&date="+state.us_long+"&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL,"",'POST',true,displayhome);   
}
function displayhome(jsonData){        
    state.Mailcount = jsonData[2];
    var urlPath = state.NATASURL;
    if(state.userStatus == "Admin"){
        if(state.emmyclick == 1){           
            window.frames["GateWay"].location.href = urlPath+"/WelcomeAdmin.html";
            state.emmyclick = 0;
        }else{
            window.frames["GateWay"].location.href = "WelcomeAdmin.html";
        }
    }else{  
        if(state.emmyclick == 1){
            window.frames["GateWay"].location.href = urlPath+"/Welcome.html";
            state.emmyclick = 0;
        }else{
            window.frames["GateWay"].location.href = "Welcome.html";
        }
    }
}
function emmyHomeClick(){
    if(state.userStatus=="Admin"){
        state.emmyclick = 1;
        getcount();
    }else if(state.userStatus=="User"){
        state.emmyclick = 1;
        getcount();        
    }
}
function calendarClick(){
    parent.showProgress(true);
    state.isBallotApp = false;
    var json="[0,\"Default\", [\"field_11\", \"field_12\", \"field_14\"],[],[[\"field_11\",\"ASC-1\"]],[[\"field_11\",\"LEFT\"],[\"field_12\",\"LEFT\"],[\"field_14\",\"LEFT\"]],[[],[]]]";
    var resourceURL = "jsonText="+encodeURIComponent(json);//=RESOURCELIST["field_11","DESC-1"]
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.calServiceID+"/resources?@RestURLType=GET&count="+100;
    var Obj = new sendRequest(params,resourceURL,'POST',true,calResource);
}
function calResource(jsonData){
//alert("calResource");
    state.resourceList=new Resources(jsonData).resources;
    window.frames["GateWay"].location.href="Calendar.html";
}
function guestcalendarClick(){
    parent.showProgress(true);
    state.isBallotApp = false;
    state.isRemember=false;
    state.loginName=guestuser;
    state.password=guestpass;
    parent.GuestDummy('cal');
    
}
function guestcalResource(jsonData){
//alert("guestcalResource");
    state.resourceList=new Resources(jsonData).resources;
    window.frames["GateWay"].location.href="guestCalendar.html";
}
function signUp(){
    state.currentAction = "";
    window.frames["GateWay"].location.href = "Registration.html";
}



function redirect(stat){
    var flag = false;
    if(isUndefined(stat)){
        // all user and admin - logout process. - siva
        if(confirm("Are you sure you want to logout?")) {
            flag = true;
        }
    }else{
        // team member user- cancel registration process. - siva
        flag = true;
    }
    
    if(flag){
        state.isProfileLogin = false;
        state.categoryArray = new Array();
        state.programArray = new Array();
        var logoutUrl = state.SERVER_URL +"/servlet/me/session?hash="+Math.random();//=LOGOUT           
        var Obj = new sendRequest(logoutUrl,null,'DELETE',true, logoutPage);
    }
}
function logoutPage(){
    setCookie("userID","");
    setCookie("email","");
    setCookie("password","");
    state.userID="";
    state.currentPage="";
    state.filters="";
    getTheme();
}
function editProfilePage(){   
    state.currentAction="PROFILE_EDIT";
    state.isBallotApp = false;
    showProgress(true);
    var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.serviceID+"/resource/"+state.profileID+"?hash="+Math.random();
    var Obj = new sendRequest(resourcelistURL, null, '',true, getResourceDetails);
}
function getResourceDetails(resource){
    state.resFieldValues = resource;
    window.frames["GateWay"].location.href = "Registration.html";  
}
function rulesClick(){
    parent.showProgress(true);
   
    var url = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.ruleServiceID+"/resources?@RestURLType=GET&count="+100+"&hash="+Math.random();
    var params="jsonText=[0, \"Default\", [\"RecordedBy\", \"RecordedDate\", \"ModifiedBy\", \"ModifiedDate\", \"RevertMessage\", \"field_11\", \"field_12\", \"field_13\", \"field_16\"],[],[],[],[[],[]]]";
    var Obj = new sendRequest(url, params,'POST',true,ruleResource);
}
function ruleResource(jsonData){
//alert("ruleResource");
    state.resourceList=new Resources(jsonData).resources;
    window.frames["GateWay"].location.href="Rules.html";
}
function guestRules(){
    parent.showProgress(true);
    state.isRemember=false;
    state.loginName=guestuser;
    state.password=guestpass;
    parent.GuestDummy('cer');
}
function guestruleResource(jsonData){
//alert("guestruleResource");
    state.resourceList=new Resources(jsonData).resources;  
    window.frames["GateWay"].location.href="GuestRule.html";
}
function getAdminballotPage(){
// state.filters = "";
   state.page = "Ballot";
   state.ballotFilters = new Array();
   //var f =  "field_20,=, 2007";
   //var fil= "";
   var wholeBuffer="";
  // var cnd=f.toString().split(",")[1];
   //fil = "(emmyYear "+cnd+" "+parent.gCurrentEmmyYear+")";
   var fieldId = "field_20";
   var condval1 = "=, '"+parent.gCurrentEmmyYear+"'";
   state.ballotFilters[state.ballotFilters.length] = [fieldId,condval1];
   for(var i = 0; i<state.ballotFilters.length;i++){
            var condval = state.ballotFilters[i][1].split(",");
            //alert("cond value :::::::"+condval);
            var cond = condval[0];
            var vals = condval[1];
            var fieldname="";
            if(state.ballotFilters[i][0] == "field_20"){
                fieldname = "emmyYear";
            }else{
                fieldname = state.ballotFilters[i][0];
            }    
                
            if(wholeBuffer!=""){
                wholeBuffer +="AND ("+fieldname+" "+cond+" "+vals+") ";
            }else{
                wholeBuffer +=" ("+fieldname+" "+cond+" "+vals+") ";
            }    
   }
   state.stateArray = new Array();
   state.buffer = "("+fieldname+" "+cond+" "+vals+")";
   state.subsel = false;
   state.statusPrint=false;
   //field_20,=, '2008'   
   //alert(state.ballotFilters.length);
   parent.showProgress(true); 
   state.round = state.DefaultRoundType;
   state.status = "-1";
   state.pageNo = 1;
   state.totalRecords = 0;
   state.stateArray[state.stateArray.length] = "Open";
   var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
   var resURL = reportURL+"/reportServlet?reportName=AdminballotListing&round="+state.DefaultRoundType+"&status="+state.status+"&filter="+wholeBuffer+"&pageNo=1&hash="+Math.random();
   var Obj = new parent.sendRequest(resURL, "", 'POST',true,adminBallotListing);
}
function RedirectgetAdminballotPage(){
   parent.showProgress(true); 
   var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
   var resURL = reportURL+"/reportServlet?reportName=AdminballotListing&round="+state.round+"&status="+state.status+"&filter="+state.buffer+"&pageNo="+state.pageNo+"&hash="+Math.random();
   var Obj = new parent.sendRequest(resURL, "", 'POST',true,adminBallotListing);
}
function adminBallotListing(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, "", 'POST',true, adminList);
}
function adminList(jsonData){
    var obj = jsonData;
    if(obj.toString() == 'start'){
        setTimeout('adminBallotListing()',2000);
    }else{
       // var json = obj.toString().substring(8,obj.toString().length);        
        showAdminBallots(jsonData);
    }    
}      
function showAdminBallots(jsonData){
//alert("showAdminBallots");
    state.resourceList = jsonData[0];    
    state.totalRecords = jsonData[1];
    if(state.ballotfieldlist == "")
        DrawResource();
    else
        window.frames["GateWay"].location.href = "AdminBallot.html";
}
function DrawResource1(){
   // state.judresources = new Resources(jsonData).resources; 
    var listURL = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/users";    
    var Obj = new parent.sendRequest(listURL,null,'POST',true,getBallotJudgeList);
}
function DrawResource(){
   var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
  // var resURL = reportURL+"/reportServlet?reportName=BallotJudgeListing&hash="+Math.random();
  resURL = reportURL+"/reportServlet?reportName=UserListing&service=91&field=25&emmyyear="+parent.gCurrentEmmyYear+"&hash="+Math.random();

   var Obj = new parent.sendRequest(resURL, "", 'POST',true,ballotUserListing);
}
function ballotUserListing(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
   
    var Obj = new parent.sendRequest(resURL, "", 'GET',true, bUserListing);
}
function bUserListing(jsonData){  
//alert("bUserListing");
    var obj = jsonData;
    
    if(obj.toString() == 'start'){
        setTimeout('ballotUserListing()',2000);
    }else{
       // var json = obj.toString().substring(8,obj.toString().length);      
        getBallotJudgeList(jsonData);
    }    
}
function formatSelect(Json){
   var selJson = new Array();
    //selJson[selJson.length] = "Select=0";
    for(var i=0;i<Json.length;i++){
        if(Json[i][1] == "" || Json[i][1] == null){
            continue;
        }else{
            selJson[selJson.length] = Json[i][1].replace(/&quot;/g,"\"")+"="+Json[i][0];
        }
    }
    selJson.sort(sortCaseInsensitive);
    var selJsonNew = new Array();
    selJsonNew[selJsonNew.length] = "Select=0";
    for(var i=0;i<selJson.length;i++){
        selJsonNew[selJsonNew.length] = selJson[i];
    }
    return selJsonNew;
}
function getBallotJudgeList(jsonData){    
    
    var jdata = jsonData;
    if(jdata.toString()!="failure"){//if there is coming filure, we no need to make any format.
    
    state.memberList = parent.formatSelect(jsonData);
    }
    if(state.ballotfieldlist == "")
        getballotfields();
    else
        window.frames["GateWay"].location.href = "AdminBallot.html";
}
function getballotfields(){
    var serviceURL= state.SERVER_URL+"/servlet/service/"+state.ballotServiceID+"/fields?pin="+state.userID+"&hash="+Math.random(); 
    var Obj = new sendRequest(serviceURL, null,'', true, getBallotFieldList);
}
function getBallotFieldList(jsonData){
    var fields = new parent.FieldList(jsonData).fields;
    var field = new Array();
    state.ballotfieldlist = new parent.FieldList(jsonData).fields;
    for(var i=0;i<fields.length;i++){
        if(fields[i].id != "field_14" && fields[i].id != "field_18" && fields[i].id != "field_19")
            field[field.length] = fields[i];
    }
    state.ballotfieldlist = field;
    window.frames["GateWay"].location.href = "AdminBallot.html";
}
function getPanelList(jsonData){
//alert("getPanelList");
    state.resourceList = new Resources(jsonData).resources;
    var res = new Resources(jsonData);
    state.totalRecords = res.totalRecords;
    var temp = new Array();
    if(state.stateArray.length > 1){
        for(var i=0;i<state.resourceList.length;i++){
            for(var j=0;j<state.stateArray.length;j++){
                if(state.stateArray[j] == state.resourceList[i].fieldsValue[7]){                    
                    temp[temp.length] = state.resourceList[i];
                }
            }
        }
        state.resourceList = temp ;
        temp = new Array();
    }
    var json="[0,\"Filter View\",[\"field_11\",\"field_12\",\"field_13\",\"field_14\",\"field_15\",\"field_16\",\"field_18\",\"field_21\",\"field_20\"],[";
    var tempJson="";
    //alert(state.resourceList[0].fieldsValue);
    tempJson += "[\"field_22\",\"(@field_22 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]";
    for(var i=0;i<state.resourceList.length;i++){
        if(tempJson != ""){
            tempJson += ",";
        }
    //  alert("state.ballotFilters :::: "+state.ballotFilters);
        if(state.ballotFilters != ""){
            //alert("if");
            tempJson += "[\"ID\",\"(@ID ~=~ '"+state.resourceList[i].fieldsValue[2]+"|:::end:::|') OR\"]";            
        }else{
            //alert("else");
            tempJson += "[\"ID\",\"(@ID ~=~ '"+state.resourceList[i].fieldsValue[2]+"|:::end:::|') OR\"]";            
            //tempJson += "[\"ID\",\"(@ID ~=~ '"+state.resourceList[i].fieldsValue[7]+"|:::end:::|') OR\"]";
        }
    }
    json += tempJson;
    json +="],[[\"field_13\",\"ASC-1\"],[\"field_12\",\"ASC-2\"]],[],[[],[]]]";
    //alert("json :::::::::;; "+json);
    var jsonURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.panelServiceID+"/resources?@RestURLType=GET&count="+1000+"&hash="+Math.random();
    var Obj = new parent.sendRequest(params,jsonURL,'POST',true,getJudgeList);
}
function getJudgeList(jsonData){
    //alert("hai1");
    //state.PanelResources = "";
    state.PanelResources = new Resources(jsonData).resources;
    //alert("panels ::::: "+state.PanelResources.length);
    //alert("state.PanelResources :::::: "+state.PanelResources[0].fieldsValue);    
    var json="[0,\"Filter View\",[\"field_23\",\"field_26\",\"field_27\",\"field_28\",\"field_29\"],[";
    var tempJson="";
    for(var i=0;i<state.resourceList.length;i++){
        if(tempJson != ""){
            tempJson += ",";
        }
        if(state.ballotFilters != ""){
            tempJson += "[\"ID\",\"(@ID ~=~ '"+state.resourceList[i].fieldsValue[1]+"|:::end:::|') OR\"]";
        }else{
            tempJson += "[\"ID\",\"(@ID ~=~ '"+state.resourceList[i].fieldsValue[1]+"|:::end:::|') OR\"]";
            //tempJson += "[\"ID\",\"(@ID ~=~ '"+state.resourceList[i].fieldsValue[6]+"|:::end:::|') OR\"]";
        }        
    }
    json += tempJson
    json+="],[],[],[[],[]]]";
    var jsonURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.judgeServiceID+"/resources?@RestURLType=GET&count="+1000+"&hash="+Math.random();
    var Obj = new parent.sendRequest(params,jsonURL,'POST',true,DrawResource);
}
function getAdminjudgePage123(){

    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/AutoJudgeStatus?hash="+Math.random();
    var Obj = new parent.sendRequest(resURL,"",'POST',true,get123);   	    
}
function get123(){
}

function getAdminjudgePage(){

    state.isBallotApp = false;
    state.pageNo = 1;
    parent.showProgress(true);
    getAdminjudgePage123();
    if(state.judgeFieldList==""){ 
        var serviceURL= state.SERVER_URL+"/servlet/service/"+state.judgeServiceID+"/fields?pin="+state.userID+"&hash="+Math.random(); 
       
        var Obj = new sendRequest(serviceURL, null,'', true, getJudgeFieldList);
    }else{
        state.memberList = state.judgememberList;
        var json="[0,\"Filter View\",[\"field_11\",\"field_12\",\"field_13\",\"field_14\",\"field_15\",\"field_16\",\"field_17\",\"field_18\",\"field_19\",\"field_20\",\"field_21\",\"field_22\",\"field_23\",\"field_24\",\"field_25\",\"field_26\",\"field_27\",\"field_28\"],";
        if(state.judgeFilters==""){           
            json+="[]";
        }else{
            json+=JSON.stringify(state.judgeFilters);
        }
        json+=",[],[],[[],[]]]";
        var resURL = "jsonText="+encodeURIComponent(json);
          if(getCookie("last_page_judge")!=null && getCookie("last_page_judge")!=""){
        var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.judgeServiceID+"/resources?@RestURLType=GET&pageNo="+getCookie("last_page_judge")+"&count=100&hash="+Math.random();
          }else
        var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.judgeServiceID+"/resources?@RestURLType=GET&count=100&hash="+Math.random();
       
        var Obj = new sendRequest(params,resURL,'POST',true,showJudgeRecords);
    }
}
function getJudgeFieldList(jsonData){
    state.judgeFieldList= new parent.FieldList(jsonData).fields;
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportServlet?reportName=UserListing&service=91&field=25&emmyyear="+parent.gCurrentEmmyYear+"&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, "", 'POST',true,judgeUserListing);
}
function showJudgeRecords(jsonData){
   state.judgeFieldList= new parent.FieldList(jsonData).fields;
   var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
   var resURL = reportURL+"/reportServlet?reportName=UserListing&service=91&field=25&emmyyear="+parent.gCurrentEmmyYear+"&hash="+Math.random();
   var Obj = new parent.sendRequest(resURL, "", 'POST',true,judgeUserListing);
}
function judgeUserListing(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, '', 'GET',true, jUserListing);
}
function jUserListing(jsonData){    
    var obj = jsonData;
    if(obj.toString() == 'start'){
        setTimeout('judgeUserListing()',2000);
    }else{
       // var json = obj.toString().substring(8,obj.toString().length); 
        getJudgeMemberList(jsonData);
    }    
}
function getJudgeMemberList(jsonData){ // ok
        
    state.memberList = formatSelect(jsonData);
    state.judgememberList = state.memberList;
    var json="[0,\"Filter View\",[\"field_11\",\"field_12\",\"field_13\",\"field_14\",\"field_15\",\"field_16\",\"field_17\",\"field_18\",\"field_19\",\"field_20\",\"field_21\",\"field_22\",\"field_23\",\"field_24\",\"field_25\",\"field_26\",\"field_27\",\"field_28\"],";
    if(state.judgeFilters==""){
        json+="[[\"field_24\",\"(@field_24 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]]";
    }else{
        json+=JSON.stringify(state.judgeFilters);
    }
    json+=",[],[],[[],[]]]";
    var resURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.judgeServiceID+"/resources?@RestURLType=GET&count="+100+"&hash="+Math.random();
    var Obj = new sendRequest(params,resURL,'POST',true,showJudgeRecords);
}

/*
function showJudgeRecords(jsonData){
//alert("showJudgeRecords");
     var totalRec = new Resources(jsonData);
     state.resourceList = new Resources(jsonData).resources;
     //alert("showJudgeRecords");
     //state.judgeLength = jsonData[1][0][0];
     state.totalRecords = totalRec.totalRecords;
     window.frames["GateWay"].location.href = "AdminJudge.html";
}   
*/

function getJudgePage(){
    parent.showProgress(true);
    if(state.userStatus=="Admin"){
        getAdminjudgePage();
    }  
    else{
        getAdminjudgePage123(); // For judge status change based on panel
    var json="[0,\"Default\",[\"field_11\",\"field_12\",\"field_13\",\"field_14\",\"field_15\",\"field_16\",\"field_17\",\"field_18\",\"field_19\",\"field_20\",\"field_21\",\"field_22\",\"field_23\",\"field_24\",\"field_25\",\"field_26\",\"field_27\",\"field_28\",\"field_29\"],";
    json+="[[\"field_23\",\"(@field_23.@ID ~=~ '"+state.userID+"|:::end:::|') AND\"],[\"field_24\",\"(@field_24 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]],[],[],[[],[]]]";
    var resURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.judgeServiceID+"/resources?@RestURLType=GET";
    
    var Obj = new sendRequest(params,resURL,'POST',true,editJudgeRecord);
    }
}
function editJudgeRecord(jsonData){
    state.resourceList = new Resources(jsonData).resources;
   
    if(state.resourceList.length>0){

        state.currentResID=state.resourceList[0].id;
        state.resIDforMemStat = state.currentResID;
        var resourceURL = state.SERVER_URL+"/servlet/service/"+state.judgeServiceID+"/resource/"+state.currentResID+"?hash="+Math.random();
        var Obj = new sendRequest(resourceURL, null, 'GET',true, editJudgeResource);
    }else{   
        window.frames["GateWay"].location.href = "Judge.html";
    }
    
}
function editJudgeResource(jsonData){
    state.resFieldValues=jsonData;
    window.frames["GateWay"].location.href = "Judge.html";
}
function editAdminJudge(resID,status){
    state.resIDforMemStat=resID;
     parent.rc = resID;
     var resourceURL = state.SERVER_URL+"/servlet/service/"+state.judgeServiceID+"/resource/"+resID+"?hash="+Math.random();
     //alert("resourceURL  "+resourceURL);
     var Obj = new sendRequest(resourceURL, null, 'GET',true, editJudgeResource1);
}
function editJudgeResource1(jsonData){

    state.resFieldValues=jsonData;
    parent.showProgress(true);
    state.currentAction="JUDGE_EDIT";
    if(state.userStatus=="Admin"){
        state.currentAction="JUDGE_EDIT";
        var indx=0,flag=false;
        for(var i=0;i<state.resourceList.length;i++){
            if(state.resourceList[i].id == parent.rc){
                indx = i;
                flag = true;
            }
            if(flag){
                break;
            }
        }
        var loginUrl = state.SERVER_URL +"/servlet/folder/"+state.folderID+"/me/preference?userID="+state.resourceList[indx].fieldsValue[12][1]+"&hash="+Math.random(); //=PREFERENCE
	//alert("editJudgeResource1 loginUrl  "+loginUrl);
	var Obj = new sendRequest(loginUrl,null,'',true,JudgeUserProfileInfo);
        //state.userName = state.resourceList[z].fieldsValue[12][0];
    }else{
    
        getJudgeUserDetails(state.resFieldValues);
    }
}
   
function judgePage(){
    parent.showProgress(true);
    state.currentAction="JUDGE_ADD";
    showProgress(true);
    var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.serviceID+"/resource/"+state.profileID+"?hash="+Math.random();
    
    var Obj = new sendRequest(resourcelistURL, null, '',true, getJudgeUserDetails);
}
function editJudgePage(){
    parent.showProgress(true);
    state.currentAction="JUDGE_EDIT";
   
    getJudgeUserDetails(state.resFieldValues);
}
var type='default';
function sortentrant(type){
    this.type=type;
    entrantPage();
}
function entrantPage(){   
    state.isBallotApp = false;
    state.currentAction="";
    state.pageNo = 1;
    showProgress(true);
    var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.serviceID+"/resource/"+state.profileID+"?hash="+Math.random();   
    var Obj = new sendRequest(resourcelistURL, null, '',true, getJudgeUserDetails);
}
function getJudgeUserDetails(resourceList){
    //alert(state.currentAction.indexOf("JUDGE_"));

    state.resFieldValues = resourceList;
    if(state.currentAction.indexOf("JUDGE_")>-1){
   
        getGenreNamesList();
    }else{
        if(state.userStatus!="Admin"){
            var json="[0,\"Default\", [\"field_14\",\"field_12\",\"field_13\",\"field_27\",\"field_30\",\"field_40\",\"field_11\",\"field_43\"],";
            if(type=='default'){
                json+="[[\"field_11\",\"(@field_11.@ID ~=~ '"+state.userID+"|:::end:::|') AND\"],[\"field_28\",\"(@field_28 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]],[[\"field_12\",\"ASC-1\"],[\"field_27\",\"ASC-2\"]],[],[[],[]]]";
            }else{
                json+="[[\"field_11\",\"(@field_11.@ID ~=~ '"+state.userID+"|:::end:::|') AND\"],[\"field_28\",\"(@field_28 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]],[[\"field_14\",\"ASC-1\"],[\"field_27\",\"ASC-2\"]],[],[[],[]]]";
            }              
            var resURL = "jsonText="+encodeURIComponent(json);
          
            var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.entrantServiceID+"/resources?@RestURLType=GET&count=100&hash="+Math.random();
            

            var Obj = new sendRequest(params,resURL,'POST',true,getEntryResList);
        }else{

            state.currentAction="ADMINENTRANT";
          
            if(state.entrantFieldList==""){            
                var serviceURL= state.SERVER_URL+"/servlet/service/"+state.entrantServiceID+"/fields?pin="+state.userID+"&hash="+Math.random(); 
		
                var Obj = new sendRequest(serviceURL, null,'', true, getFieldList);
            }else{     
                 state.memberList = state.entrymemberList;
                var json="[0,\"Default\", [\"field_14\",\"field_12\",\"field_13\",\"field_27\",\"field_30\",\"field_40\",\"field_11\"],";
                         
                if(state.filters==""){
                     json+="[]";
                }else{
                    json+=JSON.stringify(state.filters);
                }
                json+=",[[\"field_14\",\"ASC-1\"],[\"field_12\",\"ASC-2\"]],[],[[],[]]]";
                var resURL = "jsonText="+encodeURIComponent(json);
               
                if(getCookie("last_page")!=null){
                    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.entrantServiceID+"/resources?@RestURLType=GET&pageNo="+getCookie("last_page")+"&count=100&hash="+Math.random();
                }else
                var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.entrantServiceID+"/resources?@RestURLType=GET&count=100&hash="+Math.random();
              
              
	        var Obj = new sendRequest(params,resURL,'POST',true,getEntryResList);
            }
        }
    }
}
function getFieldList(jsonData){
 // alert();
    state.entrantFieldList= new parent.FieldList(jsonData).fields;
   /* var listURL = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/users?hash="+Math.random();
    var Obj = new parent.sendRequest(listURL,null,'GET',true,getMemberList);*/
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportServlet?reportName=UserListing&service=99&field=27&emmyyear="+parent.gCurrentEmmyYear+"&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, "", 'POST',true,entryUserListing);
}
function entryUserListing(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, '', 'GET',true, eUserListing);
}
function eUserListing(jsonData){
    var obj = jsonData;
    if(obj.toString() == 'start'){
        setTimeout('entryUserListing()',2000);
    }else{
        getMemberList(jsonData);
    }    
}
function getMemberList(jsonData){
    state.memberList = formatSelect(jsonData);
    state.entrymemberList = state.memberList;
    var json="[0,\"Default\", [\"field_14\",\"field_12\",\"field_13\",\"field_27\",\"field_30\",\"field_40\",\"field_11\"],";
    //alert(state.filters);
    if(state.filters==""){
        json+="[[\"field_12\",\"(@field_12 ~=~ '1|:::end:::|') AND\"],[\"field_28\",\"(@field_28 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]]";
    }else{
        //alert("prs ::: "+state.filters);
        json+=JSON.stringify(state.filters);
    }
    json+=",[[\"field_14\",\"ASC-1\"],[\"field_12\",\"ASC-2\"]],[],[[],[]]]";
    var resURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.entrantServiceID+"/resources?@RestURLType=GET&count=100&hash="+Math.random();
    var Obj = new sendRequest(params,resURL,'POST',true,getEntryResList);
}


function getPanelResources(){
    state.currentAction="Admin_panel";
    getJudgeCount();
}

function getJudgeCount(){
    var json = "[0,\"Filter View\",[\"field_11\"],";
    json += "[[\"field_31\",\"(@field_31 ~=~ '6|:::end:::|') AND\"]";
    json += ",[\"field_24\",\"(@field_24 ~=~ '"+parent.gCurrentEmmyYear+"|:::end:::|') AND\"]]";
    json += ",[[\"field_29\",\"ASC-1\"]],[],[[],[]]]";
    var resURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.judgeServiceID+"/resources?@RestURLType=GET&count=1&pageNo=1&hash="+Math.random();
    var Obj = new parent.sendRequest(params,resURL,'POST',true,judgeCount);
}
function judgeCount(jsonData){  
    state.judgeCount = jsonData[1][0];
    getGenreNamesList();
}
function getBlueRibbonResources(){
    state.currentAction = "blue_ribbonPanel";
    getJudgeCount();
    //getGenreNamesList();
}
function getPerformerResources(){
    state.currentAction="Admin_performer";
    getJudgeCount();
    //getGenreNamesList();
}

var currPageNo=1;
function getGenreNamesList(){
    currPageNo=1;  

    if(parent.genreResources==""){
    
   
        var json="[0,\"Default\", [\"field_11\", \"field_13\"],[],[[\"field_11\",\"ASC-1\"]],[],[[],[]]]";
        var resURL = "jsonText="+encodeURIComponent(json);
    
        var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.genreServiceID+"/resources?@RestURLType=GET&count=100&hash="+Math.random();
        var Obj = new sendRequest(params,resURL,'POST',true,genListResource);
    
    }else{
        
           
        if(state.currentAction=="ADMINENTRANT"){
            if(state.userStatus!="Admin"){
                window.frames["GateWay"].location.href = "Entrant.html";
            }else{
                window.frames["GateWay"].location.href = "AdminEntrant.html";
            }
        }else if(state.currentAction.indexOf("ENTRANT")>-1){
            
            window.frames["GateWay"].location.href = "EntrantApplication.html";
        }else if(state.currentAction=="Admin_panel"){
           window.frames["GateWay"].location.href = "JudgePanels.html";
        }else if(state.currentAction=="Admin_performer"){
            window.frames["GateWay"].location.href = "JudgePerformer.html";
        }else if(state.currentAction=="blue_ribbonPanel"){
            window.frames["GateWay"].location.href = "BlueRibbon.html";
        }else{
           // window.frames["GateWay"].location.href = "JudgeApplication.html";  
           var judgeidformem = state.resIDforMemStat;
        //As per change of req from client here another server call to get membership status for judge
        var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
        var resURL = reportURL+"/reportServlet?reportName=MembershipStatusForJudge&judgesid="+judgeidformem+"&status="+state.status+"&hash="+Math.random();
        var Obj = new parent.sendRequest(resURL, "", 'POST',true,membershipStatusforSingleJudge); 
        }
    }
}

function genListResource(jsonData){

    genreResources = new Resources(jsonData).resources;
    //startCategoryList();

    if(state.currentAction=="ADMINENTRANT"){
            if(state.userStatus!="Admin"){
                window.frames["GateWay"].location.href = "Entrant.html";
            }else{
                
                window.frames["GateWay"].location.href = "AdminEntrant.html";
            }
        }else if(state.currentAction.indexOf("ENTRANT")>-1){
           
           window.frames["GateWay"].location.href = "EntrantApplication.html";
        }else if(state.currentAction=="Admin_panel"){
            window.frames["GateWay"].location.href = "JudgePanels.html";
        }else if(state.currentAction=="Admin_performer"){
            window.frames["GateWay"].location.href = "JudgePerformer.html";
        }else if(state.currentAction=="blue_ribbonPanel"){
            window.frames["GateWay"].location.href = "BlueRibbon.html";
        }else{
        
        var judgeidformem = state.resIDforMemStat;
        //As per change of req from client here another server call to get membership status for judge
        var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
        var resURL = reportURL+"/reportServlet?reportName=MembershipStatusForJudge&judgesid="+judgeidformem+"&status="+state.status+"&hash="+Math.random();
        var Obj = new parent.sendRequest(resURL, "", 'POST',true,membershipStatusforSingleJudge);         
        }
}


function membershipStatusforSingleJudge(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, "", 'POST',true, memStatusforsingleJudge);
}
function memStatusforsingleJudge(jsonData){
   var obj = jsonData;
    if(obj.toString() == 'start'){
        setTimeout('membershipStatusforSingleJudge()',2000);
    }else{
        showMembershipforsingleJudge(jsonData);
    }    
}  
function showMembershipforsingleJudge(jsonData){

state.singlememshipval =jsonData;    
 
window.frames["GateWay"].location.href = "JudgeApplication.html"; 

}

function getEntryResList(jsonData){ 
   // alert("ok");
    var resList = new Resources(jsonData);
    state.resourceList = resList.resources;
    //alert("getEntryResList  "+state.resourceList.toString());
    state.totalRecords = resList.totalRecords;
    state.categoryArray = new Array();
    state.programArray = new Array();
    state.userArray = new Array();
    for(var cCnt = 0; cCnt < state.resourceList.length; cCnt++){
            state.categoryArray[cCnt] = state.resourceList[cCnt].fieldsValue[2][1];
            state.programArray[cCnt] = state.resourceList[cCnt].fieldsValue[2][1] +"|~|"+state.resourceList[cCnt].fieldsValue[0] +"|~|"+state.resourceList[cCnt].id;            
    }
    parent.invoiceArr = new Array();
    if(state.userStatus!="Admin"){
        window.frames["GateWay"].location.href = "Entrant.html";
    }else{
        window.frames["GateWay"].location.href = "AdminEntrant.html";
        
    }
}
function startNetwork(){
    var json="[0,\"Default\", [\"field_12\",\"field_13\"],[],[],[],[[],[]]]";
    var resURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.networkServiceID+"/resources?@RestURLType=GET&pageNo="+currPageNo+"&hash="+Math.random();
    var Obj = new sendRequest(params,resURL,'POST',true,getNetworkList);
}
function getNetworkList(jsonData){
    var tempResources="";
    if(jsonData!=""){
        tempResources=new Resources(jsonData);
    }
    if(tempResources.totalRecords>100){
        if(currPageNo==1){
            networkResources=tempResources.resources;
            currPageNo++;
            startNetwork();
        }else{
            var len=networkResources.length
            for(var i=0;i<tempResources.resources.length;i++){
                networkResources[len+i]=tempResources.resources[i];
            }
            currPageNo=1;
            startProgram();
        }
    }else{
        networkResources=tempResources.resources;
        currPageNo=1
        startProgram();
    }
}
function startProgram(){
    var json="[0,\"Default\", [\"field_11\"],[],[],[],[[],[]]]";
    var resURL = "jsonText="+encodeURIComponent(json);
    var params = state.SERVER_URL+"/servlet/folder/"+state.folderID+"/service/"+state.programServiceID+"/resources?@RestURLType=GET&pageNo="+currPageNo+"&hash="+Math.random();
    var Obj = new sendRequest(params,resURL,'POST',true,getProgramList);
}
function getProgramList(jsonData){
    var tempResources="";
    if(jsonData!=""){
        tempResources=new Resources(jsonData);
    }
    if(tempResources.totalRecords>100){
        if(currPageNo==1){
            programResources=tempResources.resources;
            currPageNo++;
            startProgram();
        }else{
            var len=programResources.length
            for(var i=0;i<tempResources.resources.length;i++){
                programResources[len+i]=tempResources.resources[i];
            }
            currPageNo=1;
            getGenreNamesList();
        }
    }else{
        networkResources=tempResources.resources;
        currPageNo=1
        getGenreNamesList();
    }
}
function makeAnEntry(){
    var tradition = new parent.getdata("Traditional program applications");
    var broad = new parent.getdata("Broadband and mobile applications");
    var drama = new parent.getdata("Traditional Drama program applications");
    var tradDate = new Date(tradition.ValueDateTime);
    var broadDate = new Date(broad.ValueDateTime);
    var dramaDate = new Date(drama.ValueDateTime);    
    var tdiff = DateDiff(tradDate,state.US_Date);
    var bdiff = DateDiff(broadDate,state.US_Date);
    var ddiff = DateDiff(dramaDate,state.US_Date);
    if(tdiff > -1 || bdiff > -1 || ddiff > -1){
        state.currentAction="ENTRANT";        
        showProgress(true);
        getGenreNamesList();
    }else{
        alert("Deadline date has been expired for Entry Form.");
    }
}
function editEntrant(resID,status,catid,appStatus,backPassStatus){
  //  alert(catid);
    var tradition = new parent.getdata("Traditional program applications");
    var broad = new parent.getdata("Broadband and mobile applications");
    var drama = new parent.getdata("Traditional Drama program applications");
    var tradMulti = tradition.ValueMultilineText;
    var broadMulti = broad.ValueMultilineText;
    var dramaMulti = drama.ValueMultilineText;
    var tradArray = tradMulti.split(", ");
    var broadArray = broadMulti.split(", ");
    var dramaArray = dramaMulti.split(", ");
    var tradDate = new Date(tradition.ValueDateTime);
    var broadDate = new Date(broad.ValueDateTime);
    var dramaDate = new Date(drama.ValueDateTime);    
    var catAllow = false;
    state.backPassEntry = backPassStatus;
  //  alert(state.backPassEntry);
   if(parent.gCurrentEmmyYear==2007){
    if((catid < 30 || catid > 35) && catid < 64 && DateDiff(tradDate,state.US_Date)>-1){
            catAllow = true;
    }else{
        if(catid > 63 && DateDiff(broadDate,state.US_Date)>-1){
             for(kCnt = 0; kCnt < broadArray.length; kCnt++){
                if(broadArray[kCnt] == catid){ 
                    catAllow = true;
                }   
             }
         }else{
            if(DateDiff(dramaDate,state.US_Date)>-1){
                for(jCnt = 0; jCnt < dramaArray.length; jCnt++){
                    if(dramaArray[jCnt] == catid){
                        catAllow = true;
                    }   
                }
                for(kCnt = 0; kCnt < broadArray.length; kCnt++){
                    if(broadArray[kCnt] == catid){
                        catAllow = true;
                    }   
                 }   
            }
         }          
     }
    }
    if(parent.gCurrentEmmyYear>=2008){ //alert(tradArray);    
        if(catid==0){
            catAllow = true;
        }
        if(DateDiff(tradDate,state.US_Date)>-1){
             for(kCnt = 0; kCnt < tradArray.length; kCnt++){
                 if(tradArray[kCnt].replace(/<br>/g,"") == catid){ 
                    catAllow = true;
                 }   
             }
        }
        if(DateDiff(broadDate,state.US_Date)>-1){
           for(kCnt = 0; kCnt < broadArray.length; kCnt++){
               if(broadArray[kCnt].replace(/<br>/g,"") == catid){ 
                   catAllow = true;
                }   
           }
        }
        if(DateDiff(dramaDate,state.US_Date)>-1){
           for(jCnt = 0; jCnt < dramaArray.length; jCnt++){
               if(dramaArray[jCnt].replace(/<br>/g,"") == catid){
                   catAllow = true;
               }   
           }                
        }
    }
    if(state.userStatus == "Admin"){
      catAllow = true;      
    }else{ 
        if(appStatus == "Payment Unconfirmed" || appStatus == "Incomplete"){
            if(backPassStatus != null){
                if(!(backPassStatus.indexOf("Back_Pass") >= 0)){
                    state.mailAdminAction = false;
                }else if((backPassStatus.indexOf("Back_Pass") >= 0)){
                    state.mailAdminAction = true;            
                }
            }
        }else if(appStatus.indexOf("Submitted") >= 0 || appStatus == "Approved" ){
            catAllow = true;
        }
    }
    if(catAllow || state.mailAdminAction){
        state.currentAction=status;
        state.currentResID=resID;
        showProgress(true);
        var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.entrantServiceID+"/resource/"+state.currentResID+"?hash="+Math.random();
      
        var Obj = new sendRequest(resourcelistURL, null, '',true, getEntrantResource);
    }else{
        alert("Sorry, you cannot make Entry form submission since \ndeadline date to submit was expired.");
     }    
}
function deleteEntrant(resID,status){
    var conf=confirm("Are you sure you want to delete?");
    if(conf){
        var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.entrantServiceID+"/resource/"+resID+"?hash="+Math.random();
        var Obj = new sendRequest(resourcelistURL, null, 'DELETE',true, deleteEntrantResource);
    }
}
/*function getDeletedIDs(){
    var ids = "";
    for (var i = 0; i<parent.deletedArr.length; i++){
        ids += parent.deletedArr[i]+",";
    }
    return ids.substring(0,ids.length-1);
}*/
function deleteEntrantResource(jsonData){
      state.categoryArray = new Array();
      state.programArray = new Array();
      entrantPage();   
}
function getEntrantResource(jsonData){
    state.entryResource = jsonData;    
    if(state.currentAction.indexOf("ENTRANT")>-1){
       var loginUrl = state.SERVER_URL +"/servlet/folder/"+state.folderID+"/me/preference?userID="+state.entryResource[2]+"&hash="+Math.random(); //=PREFERENCE
       var Obj = new sendRequest(loginUrl,null,'',true,entryUserLoginInfo);
    }else{
    getGenreNamesList();
    } 
}
function setTitle(title){
    window.document.title = title;
}
function adminClick(){
    state.isBallotApp = false;
    window.frames["GateWay"].location.href="Administration.html";
}
function Panelclick(){
    window.frames["GateWay"].location.href="JudgePanels.html";
}
function helpClick(){
    parent.showProgress(true);
    state.isBallotApp = false;
    window.frames["GateWay"].location.href="Help.html";
}
 //For Getting the Entry user Login details ,Its used for Admin Entrant home page --vetrivel
function entryUserLoginInfo(jsonData){
    state.entryProfileID = jsonData[0][0];
    state.entryUserName = jsonData[0][1]+" "+jsonData[0][3];
    var url = state.SERVER_URL+"/servlet/service/"+state.serviceID+"/resource/"+state.entryProfileID+"?hash="+Math.random();//=RESOURCE    
    var obj = new sendRequest(url, null, '' ,true , checkEntryUserProfile);
}
//For Getting the Entry user Profile details ,Its used for Admin Entrant Application page --vetrivel
function checkEntryUserProfile(jsonData){    
     if(!(state.currentAction.indexOf("ENTRANT_EDIT1")>-1)){
        //Admin View the Entry 
        state.entryProfileList=jsonData;
        getGenreNamesList();
    }else{
        // Admin view Invoice    
        state.entryUserData=jsonData;
        if(state.invoiceAction.indexOf("Incomplete") >= 0){
            var resourcelistURL = state.SERVER_URL+"/servlet/service/"+state.entrantServiceID+"/resource/"+state.entryCatid+"?hash="+Math.random();
            var Obj = new sendRequest(resourcelistURL, null, '',true, window.frames["GateWay"].getEntrantResource1);
        }else{
            var data = "";
            data += '<DIV ID="divPrint" STYLE="position:absolute;top:200px;left:260px;background-color:#A0B3C5;z-index:1000;">';
            data += '<TABLE CELLPADDING="5" CELLSPACING="0"><TR><TD valign="middle" ALIGN="center" CLASS="judgeTitle">Invoice Receipt</TD></TR><TR>';
            data += '<TD><IFRAME ID="frmPrint" name="frmPrint" SRC="Invoice.html" WIDTH="605" HEIGHT="310" FRAMEBORDER="0"></IFRAME></TD>';
            data += '</TR><TR><TD ALIGN="right">';
            data += '<input id="chPrint" type="button" class="button" value="Print Invoice" ONCLICK="printDoc();"> &nbsp;';
            data += '<input id="chMail" type="button" class="button" value="Email Invoice" ONCLICK="mailInvoice();"> &nbsp;';
            data += '<INPUT TYPE="button" VALUE="Cancel" style="width: 70px;" class="button" ONCLICK="cancelPrintDiv();">';
            data += '</TD></TR></TABLE></DIV>';       
            window.frames["GateWay"].document.getElementById("printDiv").innerHTML = data;
            var obj=window.frames["GateWay"].document.getElementById("divPrint");
            obj.style.top = window.frames["GateWay"].document.body.scrollTop+50+"px";
            window.frames["GateWay"].document.getElementById("printDiv").style.display=""; 
            parent.showLocalProgress(true);           
            parent.showProgress(false);            
            parent.resizeProgress();
        }
    }    
}
function JudgeUserProfileInfo(jsonData){

	    state.judgeProfileID = jsonData[0][0];
        state.JudgeUserName = jsonData[0][1]+" "+jsonData[0][3];
	    var url = state.SERVER_URL+"/servlet/service/"+state.serviceID+"/resource/"+state.judgeProfileID+"?hash="+Math.random();//=RESOURCE    
	    //alert("url in JudgeUserProfileInfo "+url);
	    var obj = new sendRequest(url, null, '' ,true , GetJudgeUserProfile);
}
function GetJudgeUserProfile(jsonData){
	//alert("GetJudgeUserProfile jsonData "+jsonData);
	//alert("Member status "+ jsonData[19]);
	//alert("Member status [0] "+ jsonData[0]);
        //alert("Member status [13] "+ jsonData[13]);//Membership stastus
        
    state.membershipstatus = jsonData[13];
	state.judgeProfileID1 = jsonData[0][20];
	state.judgeUserData = jsonData;
	getJudgeUserDetails(state.resFieldValues);
}
function showLocalProgress(status){
    if(status==true){
        window.frames["GateWay"].document.getElementById("divProgress").style.display="";
        window.frames["GateWay"].document.getElementById("loadImg").style.left=(document.body.clientWidth)/2+document.body.scrollLeft;
        window.frames["GateWay"].document.getElementById("loadImg").style.top=(document.body.clientHeight)/2+(document.body.scrollTop);
        //$("loadImg").style.display="";
    }else{
        window.frames["GateWay"].document.getElementById("loadImg").style.display="none";
        window.frames["GateWay"].document.getElementById("divProgress").style.display="none";
    }
}
function resizeProgress(){
    //alert("AA:::"+document.body.offsetWidth+"=="+document.body.clientWidth);
    window.frames["GateWay"].document.getElementById("divProgress").style.width=window.frames["GateWay"].document.body.scrollWidth+"px";
    window.frames["GateWay"].document.getElementById("divProgress").style.height=window.frames["GateWay"].document.body.scrollHeight+"px";
}
function runTimer(){
    state.US_Date.setSeconds(state.US_Date.getSeconds()+1);
}
function returnToPanel(){
    window.frames["GateWay"].location.href="JudgePanels.html";
}
function inbox(){
    if(state.userStatus == "Admin"){
        state.screenID = 77;
        generateMessage();
    }else{    
        state.screenID = 87;
        generateMessage();
    }
}
function sent(){
   if(state.userStatus == "Admin"){
        state.snappPage = "AdminSent";
        state.screenID = 88;
        generateMessage();
    }else{
        state.screenID = 96;
        generateMessage();
    }
}
function schedule(){
   if(state.userStatus == "Admin"){
        state.screenID = 114;
        generateMessage();
    }else{
        /*state.screenID = 115;
        generateMessage();*/
    }
}
function trash(){
   if(state.userStatus == "Admin"){       
        state.screenID = 95;
        generateMessage();
    }else{
        state.screenID = 99;
        generateMessage();
    }
}
function draft(){
   if(state.userStatus == "Admin"){       
        state.screenID = 103;
        generateMessage();
    }else{
        state.screenID = 106;
        generateMessage();
    }
}
function compose(){
    //window.frames["GateWay"].location.href="Email Compose.html";
}
function mailView(){
    //window.frames["GateWay"].location.href = "SnappMXUserIntegration.html";
}

function displaylink(){
        if(state.userStatus!="Admin"){
            /*window.frames["GateWay"].document.getElementById("inbox").style.display = "";
            window.frames["GateWay"].document.getElementById("sent").style.display = "";
            window.frames["GateWay"].document.getElementById("trash").style.display = "";*/
            state.screenID = 87;
            generateMessage();
            
        }else{
            /*window.frames["GateWay"].document.getElementById("inbox").style.display = "";
            window.frames["GateWay"].document.getElementById("sent").style.display = "";
            window.frames["GateWay"].document.getElementById("Archies").style.display = "";
            window.frames["GateWay"].document.getElementById("trash").style.display = "";*/
            state.screenID = 77;
            generateMessage();
            //window.frames["GateWay"].location.href = "SnappMXIntegration.html";  
        }
}
function generateMessage(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=init&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, '', 'GET',true, onInitSuccess);
}      
function onInitSuccess(){
    var reportName = "loginID";
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
   // alert(state.userID);
    var resURL = reportURL+"/reportServlet?reportName="+reportName+"&loginID="+state.userID+"&screenID="+state.screenID+"&emmyYear="+state.emmyYear+"&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, '', 'GET',true, onRepSuccess);
}
function onRepSuccess(){
    getStatusID();
}
function getStatusID(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, '', 'GET',true, getStatusSuccess1);
}
function getStatusSuccess1(jsonData){
    var obj = jsonData;
    if(obj[0].toString() == 'start'){
        setTimeout('getStatusID()',2000);
    }else if(obj[0] == 'end'){
            state.snappPage = "UserInbox";
            if(state.userStatus == "Admin"){
                window.frames["GateWay"].location.href = "SnappMXIntegration.html";      
            }else{
                window.frames["GateWay"].location.href = "SnappMXUserIntegration.html";      
            }
    }
}


function showJudgeRecords(jsonData){
//alert("showJudgeRecords");
     var totalRec = new Resources(jsonData);
     state.resourceList = new Resources(jsonData).resources;
     //alert("showJudgeRecords");
     //state.judgeLength = jsonData[1][0][0];
     
var judgingid =0;
 for(var z= 0; z< state.resourceList.length; z++){
 if(judgingid!=0){
judgingid = judgingid+",";
}
judgingid = judgingid +  state.resourceList[z].id;
 }

state.totalRecords = totalRec.totalRecords;

//As per change of req from client here another server call to get membership status for judge
getMembershipStatusForJudge(judgingid);
   //  window.frames["GateWay"].location.href = "AdminJudge.html";
} 




function getMembershipStatusForJudge(judgesid)
{
 state.membershipstatusval ="";
   var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
 
  var resURL = reportURL+"/reportServlet?reportName=MembershipStatusForJudge&judgesid="+judgesid+"&status="+state.status+"&hash="+Math.random();
   var Obj = new parent.sendRequest(resURL, "", 'POST',true,membershipStatus);
}


function membershipStatus(){
    var reportURL=state.SERVER_URL.substring(0,state.SERVER_URL.lastIndexOf("/"))+"/report";
    var resURL = reportURL+"/reportSession?action=status&hash="+Math.random();
    var Obj = new parent.sendRequest(resURL, "", 'POST',true, memStatus);
}
function memStatus(jsonData){
   var obj = jsonData;
    if(obj.toString() == 'start'){
        setTimeout('membershipStatus()',2000);
    }else{
        showMembership(jsonData);
    }    
}  
function showMembership(jsonData){
//alert("showAdminBallots");

state.membershipstatusval =jsonData;    
window.frames["GateWay"].location.href = "AdminJudge.html";  

}
