// JavaScript Document
// All JavaScript Functions for jsp/common folder
/* latestnews_edit.jsp */
var siteSecEleNames = "siteSectionValues,exceptionSiteSection";
var taxEleNames = "primary_taxonomy,taxonomy_element,exceptionTaxonomyElement";
/* latestnewssection_edit.jsp */
var elementNames = "";  // represents the element names of categories or textual representation
var taxonomyElementIDs = ""; // represents the ids of categories
/* articledisplay_view.jsp */
var votes_counter=0;


/* articledisplay_view.jsp */
function bodyPagination(num , size){
    for(var i=1; i <=size;i++)
   {
        var div_ele = document.getElementById("body_div_"+i);
        var sty_div_ele = div_ele.style;
        var divElementNameTop = "pagenationDivTop"+i;
        
        if(num==i) { 
            sty_div_ele.display='block';
            document.getElementById(divElementNameTop).className = "articleselectedPage";
            
            }
        else {
            sty_div_ele.display='none';
            document.getElementById(divElementNameTop).className = "articledefault";
            
            }
    }
}
function IncrementCounter()
{
    votes_counter++;
    document.getElementById( 'votes_counter_value' ).innerHTML=votes_counter;
}
function activate_postCommentsDiv_articledisplay(){
        document.getElementById("message").value="";
        var div_ele, vis;
        div_ele = document.getElementById("post_comments_div");
        vis = div_ele.style;
        vis.display = (vis.display=='none')?'block':'none';
        if( vis.display == 'block' ){
            document.getElementById("message").focus();
        }        
}
function activate_postReplyDiv(num){
        document.getElementById("replymessage"+num).value="";
        var post_ele, postvis;
        post_ele = document.getElementById("post_reply_div_"+num);
        postvis = post_ele.style;
        postvis.display = (postvis.display=='none')?'block':'none';
        if( postvis.display == 'block' ){
            document.getElementById("replymessage"+num).focus();
        }
}
function showHide(num){
        var showall_ele = document.getElementById("show_all_"+num);
        var showall_vis = showall_ele.style;
        var s_ele = document.getElementById("show_"+num);
        var s_vis = s_ele.style;
        var h_ele = document.getElementById("hide_"+num);
        var h_vis = h_ele.style;
        if(s_vis.display=='block'){
            s_vis.display='none';
            h_vis.display='block';
            showall_vis.display='block';
        }
        else {
            s_vis.display='block';
            h_vis.display='none';
            showall_vis.display='none';
        }
}

/* PLACE IN JSP */


function prepareForSubmit(){
    flag = true;
    if(document.getElementById("subject").value == ""){
    alert(" Please enter subject");
    flag = false;
    }
    else{
    var mes_val = trim(document.getElementById("message").value);
    if(mes_val == ""){
    alert("Please enter your comment");
    document.getElementById("message").value="";
    flag = false;
    document.getElementById("message").focus();
    }
    }
    return flag;
}
function validateAndSubmit()
    {
    var isValid=prepareForSubmit();
    if(isValid)
    {     
        document.postthread.submit();
    }
    
    }
function validate()
    {
    var isValid=prepareForSubmit();
    if(isValid)
    {     
        document.postThread.submit();
    }
    }
function validatePostMessage(num,msgID){
    var formName = "postmessage"+num;
    var mes_val = trim(document.getElementById("replymessage"+num).value);
    if(mes_val == ""){
        alert("Please Enter your Reply");
        document.getElementById("replymessage"+num).value="";
        flag = false;
        document.getElementById("replymessage"+num).focus();
    }
        else{

            document.getElementById("messageID").value=msgID;
            document.getElementById(formName).submit();
        }
    }
function renderPage(){
     var Line1 = document.getElementById("headLine_p");
     var Line2 = document.getElementById("authorsName_p");
     var Line3 = document.getElementById("siteName_p");
     var Line4 = document.getElementById("pubDate_p");
     var Line5 = document.getElementById("body_p");
     var Line6 = document.getElementById("image_p");
     var Line7 = document.getElementById("description_p");
     var Line8 = document.getElementById("printURL_p");
     var printUrl = window.location.href;
     myWindow = window.open(printUrl,'','');
     myWindow.document.write("<table><tr><td>"+Line6.innerHTML+"</td></tr></table>"+"<br /><span style='font-family:Times New Roman, Times, serif; font-size:24px; '>"+Line1.innerHTML+"</span><br /><br /><span style='font-family:Times New Roman, Times, serif; font-size:18px; '>"+Line7.innerHTML+"</span><br /><br /><span style='font-family:Arial, Helvetica, sans-serif; font-size:13px; '> By "+Line2.innerHTML+"</span><span style='font-family:Times New Roman, Times, serif; font-size:13px; '>&nbsp;<a href='/home'><font color='blue'>"+Line3.innerHTML+"</font></a></span><br /><span style='font-family:Times New Roman, Times, serif; font-size:13px; '>"+Line4.innerHTML+"</span><br><span style='font-family:Times New Roman, Times, serif; font-size:14px; '> URL: <a href='"+Line8.innerHTML+"'>"+Line8.innerHTML+"</a></span></br><span style='font:Times New Roman; font-size:15px; '><p>"+Line5.innerHTML+"</p></span>");
     myWindow.focus();
     myWindow.document.close();
}    
function ltrim(str) { 
    for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
    return str.substring(k, str.length);
}
function rtrim(str) {
    for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
    return str.substring(0,j+1);
}
function trim(str) {
    return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
    var whitespaceChars = " \t\n\r\f";
    return (whitespaceChars.indexOf(charToCheck) != -1);
}

/* email_story_popup.jsp */

function checkemail(){
      var mailFrom =document.getElementById('mailFrom').value;
      var mailTo =document.getElementById('mailTo').value;
      var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
      if (filter.test(mailFrom) && filter.test(mailTo))
            testresults=true
      else{
            alert("Please input a valid email address!")
            testresults=false
      }
      return (testresults)
}
function emailValidateAndSubmit()
{
  var isValid=true;
  var mailFrom =document.getElementById('mailFrom').value;
  var mailTo =document.getElementById('mailTo').value;

  if(mailFrom=='' && mailTo=='')
  {
      alert('Destination e-mail & Your e-mail address are mandatory fields.');
    isValid=false
  }else if(mailFrom=='')
  {
      alert('Your e-mail address is mandatory field.');
    isValid=false
  }else if(mailTo=='')
  {
      alert('Destination e-mail address is mandatory field.');
    isValid=false
  }
  isValid =isValid && checkemail();
  if(isValid)
  {
    document.getElementById('actionKey').value='sendMail';
    document.forms['emailstorypopup'].submit();
   }
}
function openFeedbackHelp()
{
   var w =window.open('/','','width=325,height=350');
   w.document.write('<html><head><title>Why do I need to type characters from a picture to send your message?</title><link rel=\"stylesheet\" type=\"text/css\" href=\"chrome://firebug/content/highlighter.css\"/></head><body><h4>Why do I need to type characters from a picture to send your message?</h4><p>Typing the characters from a picture helps ensure that a person&#151;not an automated program&#151;is completing the form. </p><p>This is important because attackers use harmful programs to try to utilize these pages to cause problems for other users, by sending junk e-mail messages or slowing down the service by repeatedly performing bogus requests.</p><p>In most cases, an automated program cannot recognize the characters in the picture.</p></body></html>');
   w.document.close();
}

/* email_story_popup.jsp */


/*  blogentrycomments_view.jsp */


function activate_postCommentsDiv_blogentrycomments(){
        document.getElementById("message").value = "";
        var div_ele, vis;
        div_ele = document.getElementById("post_comments_div");
        vis = div_ele.style;
        vis.display = (vis.display=='none')?'block':'none';
        if( vis.display == 'block' ){
            document.getElementById("message").focus();
        }
}

function prepareForSubmit_blogentrycomments(){
    flag = true;
    var mes_val = trim(document.getElementById("message").value);
    document.getElementById("subject").value=entryTitle;
    if(mes_val == ""){
        alert("Please enter your comment");
        document.getElementById("message").value="";
        flag = false;
        document.getElementById("message").focus();
    }
    return flag;
    }
function validateAndSubmit_blogentrycomments()
    {
    var isValid=prepareForSubmit_blogentrycomments();
    if(isValid)
    {     
        document.postThread.submit();
    }
    
    }


/* categorynews_edit.jsp */

 function prepareForSubmit_categorynews(){
     flag = true;
     if(document.getElementById("siteSectionNames").value==null || document.getElementById("siteSectionNames").value=='')
            {
                alert("Please select atleast One Category");
                flag = false;
            }
    if(document.getElementById("siteId").value==null || document.getElementById("siteId").value=='')
    {
        alert("Please enter site id");
        flag = false;
    }
        return flag;
    }

 function showCategories_categorynews_edit(siteId)
    {
        var name = document.getElementById("siteSectionValues");
        var site_id_val = document.getElementById("siteId").value;
        window.open(applicationContextPath+'/siteSectionLookupController.do?siteId='+site_id_val+"&siteSectionValues="+name.value ,"ShowCategories",'','height=500,width=400,status=yes,toolbar=no,scrollbars=yes');
    }






/* forumdescription_view.jsp */

function stopwatchForum(){
     document.postthread2.submit();
}

/* forumdiscussionlisting_edit.jsp */

function selectdata(elementName,elementValue){
    for( j=0;j<document.getElementById(elementName).length;j++){
        if( document.getElementById(elementName)[j].value==elementValue ){
            document.getElementById(elementName)[j].selected = true;
        }
    }
}


/* forumdiscussionlisting_view.jsp */


function activate_postCommentsDiv_forumdiscussionlisting(){
        document.getElementById("message").value="";
        document.getElementById("subject").value="";
        var div_ele, vis;
        div_ele = document.getElementById("post_comments_div");
        vis = div_ele.style;
        vis.display = (vis.display=='none')?'block':'none';
        if( vis.display == 'block' ){
            document.getElementById("subject").focus();
        }
}
function trim_forumdiscussionlisting(text_value){
    while(text_value.substring(0,1) == ' ')
    {
    text_value = text_value.substring(1, text_value.length);
    }
    while (text_value.substring(text_value.length-1, text_value.length) == ' ')
    {
    text_value = text_value.substring(0,text_value.length-1);
    }
    return text_value;
}

function prepareForSubmit_forumdiscussionlisting(){
    flag = true;
    if(trim_forumdiscussionlisting(document.getElementById("subject").value) == ""){
    alert("enter subject");
    flag = false;
    document.getElementById("subject").focus();
    }
    else{
    if(trim_forumdiscussionlisting(document.getElementById("message").value) == ""){
    alert("enter message");
    flag = false;
    document.getElementById("message").focus();
    }
    }
    return flag;
}
function validateAndSubmit_forumdiscussionlisting()
    {
    var isValid=prepareForSubmit_forumdiscussionlisting();
    if(isValid)
    {     
        document.postthread.submit();
    }
    
    }


/* forumdiscussions_edit.jsp */




/* forumdisplaycomments_view.jsp */

function activate_postReplyDiv_forumdisplaycomments(num,flag){
var post_div, post_vis;
        document.getElementById("replymessage"+num).value=""; 
        post_div = document.getElementById("post_reply_div"+num);
        post_vis = post_div.style; 
        if(flag==1)
        post_vis.display ='block';
         else
        post_vis.display ='none';
}

function activate_postCommentsDiv_forumdisplaycomments(flag){
        var div_ele, vis;
        document.getElementById("message").value="";
        div_ele = document.getElementById("post_comments_div");
        vis = div_ele.style;
      if(flag==1)
        vis.display ='block';
         else
        vis.display ='none';
}

function trim_forumdisplaycomments(text_value){
    while(text_value.substring(0,1) == ' ')
    {
    text_value = text_value.substring(1, text_value.length);
    }
    while (text_value.substring(text_value.length-1, text_value.length) == ' ')
    {
    text_value = text_value.substring(0,text_value.length-1);
    }
    return text_value;
}

function prepareForSubmit_forumdisplaycomments(){
    flag = true;
  if(trim_forumdisplaycomments(document.getElementById("message").value) == ""){
    alert("enter message");
    flag = false;
    document.getElementById("message").focus();
    }else
    return flag;

    
}

function validateAndSubmit_forumdisplaycomments()
    {
    var isValid=prepareForSubmit_forumdisplaycomments();
    if(isValid)
    {     
        document.postcomment.submit();
    }
    }

function submitReply(num) {
       formName="postReplyForm"+num;
     if(trim(document.getElementById("replymessage"+num).value)==""){
      alert("Please enter the reply message.");
      document.getElementById("replymessage"+num).focus();
      }
    else{
      var postReplyForm = document.getElementById("postReplyForm"+num);
      postReplyForm.submit();
    }
}

function showHide_forumdisplaycomments(num){
        var showall_ele = document.getElementById("show_all_"+num);
        if(showall_ele){
            var showall_vis = showall_ele.style;
            var s_ele = document.getElementById("show_"+num);
            var s_vis = s_ele.style;
            var h_ele = document.getElementById("hide_"+num);
            var h_vis = h_ele.style;
            if(s_vis.display=='block'){
                s_vis.display='none';
                h_vis.display='block';
                showall_vis.display='block';
            }
            else {
                s_vis.display='block';
                h_vis.display='none';
                showall_vis.display='none';
            }
        }
}

function hideReplies()
{
    if(document.getElementById("replydisable").style.display=="none")
        document.getElementById("replydisable").style.display="";
    else
        document.getElementById("replydisable").style.display="none"
}

function watchDiscussion(){
    document.discussionform1.submit();
}

function stopwatchDiscussion(){
    document.discussionform2.submit();
}

function watchForum(){
     document.postthread1.submit();
}


/* latestnews_edit.jsp */
    function trimStartAndTrailSpaces( val ){
        if( val.length>0 && val.charAt(0)==" "){
            val = val.substring( 1, val.length);
        }
        if( val.charAt( val.length-1 )==" " ){
            val = val.substring( 0, val.length-1);
        }
    return val;
    }

    function actualValidation( fldName ){
        var fldValue = fldName.value;
        var newValue="";
        if(fldValue.length>0) {      
            for( var count=0; count<fldValue.length; count++ ){
                    if(fldValue.charAt(count)==0 || fldValue.charAt(count)==1 || fldValue.charAt(count)==2 || fldValue.charAt(count)==3 || fldValue.charAt(count)==4 || fldValue.charAt(count)==5 || fldValue.charAt(count)==6 || fldValue.charAt(count)==7 || fldValue.charAt(count)==8 || fldValue.charAt(count)==9 || fldValue.charAt(count)=="," ){
                          newValue = newValue + fldValue.charAt(count);
                    } else {
                    alert("Field sholudn't contain text");
                    fldName.focus();
                      return false;
                      }
                    }
          }
          return true;
    }

    function checkForBlankValuesBtwIDs( IDs ){
        var valuesAfterTrimming = trimStartAndTrailSpaces( IDs );
        var IDsArray = valuesAfterTrimming.split(" ");
        if( IDsArray.length>1 ){
            alert("Blank space is not allowed between ids. Should be seperated by comma");
            return false;
        }else{
            return true;
        }
    }

    function validateTextInFields(){
        var elementNames;
        if(lookupType == "SiteSection"){
            elementNames= "article_ids,company_ids,author_ids,copydesk_id,article_type_ids,site_article_type,parent_art,exceptionArticleId,exceptionSiteArticleType,exceptionSiteSection";
        }else{
            elementNames= "article_ids,company_ids,author_ids,copydesk_id,article_type_ids,site_article_type,primary_taxonomy,taxonomy_element,parent_art,exceptionArticleId,exceptionSiteArticleType,exceptionTaxonomyElement";
        }
        var elementArray = elementNames.split(",");
        for( taxEleIndex=0; taxEleIndex<elementArray.length; taxEleIndex++ ){
            if(!actualValidation( document.getElementById( elementArray[ taxEleIndex ] ) )){return false;}
        }
        return true;    
    }

    function nullifyElementValues( elementNames ){    
        var elementArray = elementNames.split(",");
        for( eleIndex=0; eleIndex<elementArray.length; eleIndex++ ){
            document.getElementById( elementArray[ eleIndex ] ).value = "";
        }    
    }


    function prepareForSubmit_latestnews_edit(currentdate){
        flag = true;        
        
        /* if(document.getElementById("viewAllURL").value==null || document.getElementById("viewAllURL").value==''){
            alert("Please enter url");
            flag = false;
        }*/
        
        if(document.getElementById("siteId").value==null || document.getElementById("siteId").value==0)
        {
            alert("Please Select atleast One Site Name");
            return false;
        }
        if(document.getElementById("start_at").value==null || document.getElementById("start_at").value=='')
        {
            alert("Please enter start at");
            flag = false;
        }
        if(document.getElementById("create_site_id").value==null || document.getElementById("create_site_id").value=='')
        {
            alert("Please enter create site id");
            flag = false;
        }
        var elementNames;
        if(lookupType == "SiteSection"){
            elementNames= "article_ids,company_ids,author_ids,copydesk_id,article_type_ids,site_article_type,parent_art,exceptionArticleId,exceptionSiteArticleType,exceptionSiteSection";
        }else{
            elementNames= "article_ids,company_ids,author_ids,copydesk_id,article_type_ids,site_article_type,primary_taxonomy,taxonomy_element,parent_art,exceptionArticleId,exceptionSiteArticleType,exceptionTaxonomyElement";
        }
        var elementArray = elementNames.split(",");
        for (var index = 0;index<elementArray.length;index++){
            if( !checkForBlankValuesBtwIDs( document.getElementById(elementArray[index] ).value ) ){
            document.getElementById(elementArray[index]).focus();
            return false;
            }
        }
        if(flag)
            flag = validateTextInFields();
        if( flag ){
            if( document.getElementById("article_ids").value != "" || document.getElementById("company_ids").value != "" || document.getElementById("author_ids").value != "" || document.getElementById("copydesk_id").value != "" || document.getElementById("article_type_ids").value != "" || document.getElementById("site_article_type").value != "" || document.getElementById("parent_art").value != "" || document.getElementById("issue_number").value != ""  ){

            if( document.getElementById("lookup_type").value=="TaxonomyElement" )
                nullifyElementValues("taxonomy_element");
            else
                nullifyElementValues("siteSectionValues");
            }
        }
        if(!(site_windowHandle_closed || site_windowHandle.closed) ){
               alert("The Site Lookup Screen is Open")    ;
            return false;
        }
        if( !(site_lookup_windowHandle_closed || site_lookup_windowHandle.closed) ){
               alert("The Site Taxononmy Lookup Screen is Open")    ;
         return false;
        }
        if( !(site_section_windowHandle_closed || site_section_windowHandle.closed) )
        {
               alert("The Site Section Lookup Screen is Open")    ;
            return false;

        }    
        if((winCal!=null)&& !(winCal.closed)){
            alert("The Date Window is Open");
            return false;
        }    
        
        if(document.getElementById("dateCriteria").value == "dateRange"){
            var from=document.getElementById("fromDateCalendar").value;
            var to=document.getElementById("toDateCalendar").value;
            if(from == '' && to == '' ){
                    document.getElementById('fromDateCalendar').value= currentdate;
                    document.getElementById('toDateCalendar').value= currentdate;
                    alert("Date range is updated to current date as it is not modified.");
            }
            
            if(from==""&& to!=""){        
                var d=new Date(to);                
                d.setDate(d.getDate()-89);
                var newfromdate=(d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear();
                document.getElementById("fromDateCalendar").value=newfromdate;    
                 alert("From date is updated as it is not modified.");
            }
            
            if(from!="" && to==""){
                var fromdate=new Date(from);                
                var curdate=new Date();
                var currentMonth = parseInt(curdate.getMonth()+1);
                var currentDay = parseInt(curdate.getDate());
                var month=0;
                fromdate.setDate(fromdate.getDate()+89);
                var current = currentMonth+"/"+currentDay+"/"+curdate.getFullYear();
                var newtodate=(fromdate.getMonth()+1)+"/"+fromdate.getDate()+"/"+fromdate.getFullYear();
                document.getElementById("toDateCalendar").value=newtodate;                        
                if(fromdate>=curdate){
                    document.getElementById("toDateCalendar").value=current;        
                    alert("To date is updated to current date as it is not modified.");
                }
                else{
                    document.getElementById("toDateCalendar").value=newtodate;
                    alert("To date is updated as it is not modified.");
                }
            }                    
        }            
        var from=document.getElementById("fromDateCalendar").value;
        var to=document.getElementById("toDateCalendar").value;
        if(from == '' && to == '' ){
                document.getElementById('fromDateCalendar').value= currentdate;
                document.getElementById('toDateCalendar').value= currentdate;
                alert("Date range is updated to current date as it is not modified.");
        }
        return flag;
    }



    function chkNum(obj){

    obj.value = obj.value.replace(/[^0-9]/g,'') // numbers only

    }

    function enableFields( name ){
        if ( name == 'dateRange' ){
            document.getElementById("date_range_div1").style.display = 'block';
            document.getElementById("date_range_div2").style.display = 'block';
        }else{
            document.getElementById("date_range_div1").style.display = 'none';
            document.getElementById("date_range_div2").style.display = 'none';

        }
    }

    function showSiteSectionCategories(siteId)
    {
        var name = document.getElementById("siteSectionValues");
        var site_id_val = document.getElementById("siteId").value;
        if ( site_section_windowHandle_closed || site_section_windowHandle.closed) {
        site_section_windowHandle_closed =false;
        site_section_windowHandle = window.open(applicationContextPath+"/siteSectionLookupController.do?siteId="+site_id_val+"&siteSectionValues="+name.value ,"ShowCategories", "height=500,width=400,status=yes,toolbar=no,scrollbars=yes");
        }
        else{
        site_section_windowHandle.moveTo(0,0);
        site_section_windowHandle.focus();
        }
    }

    function showTaxonomyCategories(siteId)
    {
        var name = document.getElementById("taxonomy_element");
        var site_id_val = document.getElementById("SiteNameId").value;
        var site_name_val = document.getElementById("SiteNameList").value;
        var selected_site_val = document.getElementById("selectedSiteIds").value;
        if ( site_lookup_windowHandle_closed || site_lookup_windowHandle.closed) {
        site_lookup_windowHandle_closed =false;
        site_lookup_windowHandle = window.open(applicationContextPath+"/taxonomyLookupController.do?siteId="+site_id_val+"&taxonomy_element="+name.value +"&selectedSiteIds="+selected_site_val,"ShowCategories", "height=500,width=400,status=yes,toolbar=no,scrollbars=yes");
        }
        else{
        site_lookup_windowHandle.moveTo(0,0);
        site_lookup_windowHandle.focus();
        }
    }

    function enableAdvanced( name ){
        lookupType = document.getElementById("lookup_type").value;
        if (name=="TaxonomyElement")
        {
            document.getElementById("block_div").innerHTML='<table width="100%"><tr><td width="50%" class="eetimesTable" align="left"><b>Taxonomy</b></td>          <td width="50%"  ><input type="text" name="taxonomyNames" id="taxonomyNames" readonly value="'+taxName+'" style="width:300px"/>            <a href="javascript:void(0)" class="lookup" onclick="showTaxonomyCategories(0)">lookup</a>          </td>              </tr>    <tr>        <td width="50%" class="eetimesTable"   align="left">        <b>Primary Taxonomy Element ID</b></td>        <td width="50%"><input type="text" id="primary_taxonomy" name="primary_taxonomy" value="'+primTaxValue+'"></td>    </tr>    <tr>        <td width="50%" class="eetimesTable"   align="left">        <b>Taxonomy Element ID</b></td>        <td width="50%"><input type="text" id="taxonomy_element" name="taxonomy_element" value="'+taxValue+'" readonly></td>    </tr>    <tr>        <td width="50%" class="eetimesTable"   align="left">        <b>Exception Taxonomy Element ID</b></td>        <td width="50%"><input type="text" id="exceptionTaxonomyElement" name="exceptionTaxonomyElement" value="'+exTaxId+'"></td>    </tr></table>';
        }else{
            document.getElementById("block_div").innerHTML='<table width="100%"><tr><td width="50%" class="eetimesTable" align="left"><b>Site Section</b></td><td width="50%"  >             <input type="text" name="siteSectionNames"  id="siteSectionNames" value="'+siteSecName+'" readonly style="width:300px"/>        <a href="javascript:void(0)" class="lookup" onclick="showSiteSectionCategories(0)">lookup</a>        </td>      </tr>    <tr>        <td width="50%"   class="eetimesTable" align="left"><b>Site Section ID</b></td>        <td width="50%"  ><input type="text" id="siteSectionValues" name="siteSectionValues" value="'+siteSecValue+'" readonly></td>    </tr>    <tr>        <td width="50%"   class="eetimesTable" align="left"><b>Exception Site Section ID</b></td>        <td width="50%"><input type="text" id="exceptionSiteSection" name="exceptionSiteSection" value="'+exSiteSecId+'"></td>    </tr></table>';
        }
    }

/* latestnewssection_edit.jsp */
    function prepareForSubmit_latestnewssection_edit(){
        flag = false;
        if(document.getElementById("siteSectionNames").value==null || document.getElementById("siteSectionNames").value=='')
        {
            alert("Please select atleast One Category");
            return false;
        }
        return true;
    }
    function showCategories(siteId)
    {
        var name = document.getElementById("siteSectionValues");
        siteSection=window.open(applicationContextPath+"/siteSectionLookupController.do?siteId="+siteId+"&siteSectionValues="+name.value ,"ShowCategories", "height=500,width=400,status=yes,toolbar=no,scrollbars=yes");
        siteSection.moveTo(0,0);
        siteSection.focus();
    }




function todaya()
{
document.getElementById("cella").innerHTML = document.getElementById("div1a").innerHTML;
document.getElementById("td2a").className="butClassWithBottomBorder";
document.getElementById("td1a").className="butClassWithoutBottomBorder";
document.getElementById("td3a").className="butClassWithBottomBorder";
}
function lastWeeka(){
document.getElementById("cella").innerHTML = document.getElementById("div2a").innerHTML;
    document.getElementById("td1a").className="butClassWithBottomBorder";
    document.getElementById("td2a").className="butClassWithoutBottomBorder";
    document.getElementById("td3a").className="butClassWithBottomBorder";
}

function lastMontha(){
document.getElementById("cella").innerHTML = document.getElementById("div3a").innerHTML;
    document.getElementById("td1a").className="butClassWithBottomBorder";
    document.getElementById("td2a").className="butClassWithBottomBorder";
    document.getElementById("td3a").className="butClassWithoutBottomBorder";
}


/* login.jsp */

function emailvalidation(emailvali) {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailvali.emailaddress.value)){
        return (true)
        }
        alert("Invalid E-mail Address! Please Re-Enter.")
        return (false)
    }

/* lookup_site_section.jsp */

function targetopener(mylink, closeme, closeonly)
{
if (! (window.focus && window.opener))return true;
window.opener.focus();
if (closeme)window.close();
return false;
}




/* lookup_taxonomy.jsp */


/* manageprofile.jsp */

function MM_jumpMenu(value){ //v3.0
              var newslettereetimes=document.getElementById("newslettereetimes");
              var newslettertechonline=document.getElementById("newslettertechonline");

              newslettereetimes.style.display="none";
                newslettertechonline.style.display="none";

              if    (value=="eetimes")
              {
               newslettereetimes.style.display="inline";
              }
               else if (value=="techonline")
               {
                   newslettertechonline.style.display="inline";
               }
               else
               {
               }
            }


function selectPrimaryIndustry(thisObj)
        {


            if(thisObj.value!='other')
            {
                document.getElementById("primaryIndustryOther").value="";
                document.getElementById('primaryIndustryOtherID').style.display='none';
            }
            else if(thisObj.value=='other')
            {
                 document.getElementById('primaryIndustryOtherID').style.display='block';
                 document.getElementById("primaryIndustryOther").value="Other(Please specify)";
            }

        }
        function selectJobFunction(thisObj)
        {
            if(thisObj.value!='Other')
            {
                 document.getElementById("jobFunOther").value="";
                document.getElementById('jobFunctionOtherID').style.display='none'

            }
            else if(thisObj.value =='Other')
            {
                document.getElementById('jobFunctionOtherID').style.display='block'
                 document.getElementById("jobFunOther").value="Other(Please specify)";
            }

        }
        function selectState(thisObj)
        {
            if(thisObj.value=='other')
            {
              document.getElementById('stateOther').style.display="block";
               document.getElementById('stOth').value="";
            }
            else
            { document.getElementById('stOth').value="";
              document.getElementById('stateOther').style.display="none";
            }


        }


/**
        * Generic  function to set selected options.
        */
        function setSelectedOption(optionsObj, selectedVal)
        {
            
                    if(selectedVal!=null && selectedVal!='')
                    {
                        for(var i=0;i<optionsObj.options.length;i++)
                        {

                          if(optionsObj.options[i].value==selectedVal)
                          {
                             optionsObj.options[i].selected=true
                          }

                        }
                    }

        }
        /**
        * Generic function to set check boxes
        */
        function setCheckBoxes(checkBoxesObj, selectedCheckBoxes)
        {
                if(selectedCheckBoxes!=null)
                    {

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

                        if(checkBoxesObj[i].type=='checkbox')
                        {

                         for(var j=0;j<selectedCheckBoxes.length;j++)
                         {

                            if(checkBoxesObj[i].value==selectedCheckBoxes[j])
                              {
                                 checkBoxesObj[i].checked=true
                              }

                          }
                         }

                        }
                    }
        }

            //Ajax Functions to Pickup state Code

            //To get XML Http Object
            function GetXmlHttpObject()
            {
              var xmlHttp=null;
              try  {// Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
               }
              catch (e){
                try {   // Internet Explorer
                  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                  }
                catch (e){
                  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                }
              return xmlHttp;
            }

            //It Returns Postal Code Details
            function pickStates(countryID)
            {
                
                   var countryObj = document.getElementById(countryID)
                var countryVal= countryObj.value
                
                if(countryVal==" -"){
                document.getElementById(countryID).value="";
                document.getElementById('stOth').value="";
                document.getElementById("stateID").value="";
                document.getElementById('stateOther').style.display="none"
                document.getElementById('stateID').style.display="inline"
                 var browserName= navigator.appName
                                if('Microsoft Internet Explorer' == browserName)
                                {
                                  document.getElementById("stateID").outerHTML= '<select id="stateID" name="state" onChange="selectState(this);" style="width:205px; "><option value="" selected>- Select -</option></select>';
                                 }
                                else
                                {
                                 document.getElementById("stateID").innerHTML= '<option value="" selected>- Select -</option>';
                                 }
            
                return;
                }
                if(countryVal == '')
                {
                document.getElementById('stOth').value="";
                document.getElementById("stateID").value="";
                document.getElementById('stOth').value="";
                document.getElementById('stateOther').style.display="none"
                document.getElementById('stateID').style.display="inline"
                 var browserName= navigator.appName
                                if('Microsoft Internet Explorer' == browserName)
                                {
                                  document.getElementById("stateID").outerHTML= '<select id="stateID" name="state" onChange="selectState(this);" style="width:205px; "><option value="" selected>- Select -</option></select>';
                                 }
                                else
                                {
                                 document.getElementById("stateID").innerHTML= '<option value="" selected>- Select -</option>';
                                 }
                
                ////////////////////////////////////////////////////
                  return;
                }
                else if(countryVal!='US' && countryVal!='Canada')
                {
                  document.getElementById('stateOther').style.display="block";
                    document.getElementById("stateID").value="";
                  document.getElementById("backupState").value="";
                  document.getElementById("stateID").style.display= "none";

                  return;
                }
                else
                {  
                      document.getElementById("stateID").style.display= "block";
                       if(document.getElementById("backupState").value!="other"){
                    document.getElementById('stOth').value="";
                    document.getElementById('stateOther').style.display="none"
                    }
                    
                }
                //load states for US or canada
             try{
                 if(document.getElementById(countryID)){
                    var countryCode=document.getElementById(countryID).value;

                    if(countryCode==null || countryCode=='') //if countryCode is empty nothing to do
                        return;

                    xmlHttp=GetXmlHttpObject();

                    if (xmlHttp==null)     {
                      alert ("Your browser does not support AJAX!");
                      return;
                    }

                    var url="";
                    var state=document.getElementById('backupState').value;
                    url=applicationContextPath+'/lookupStates.do?countryCode='+countryCode+'&prvState='+state;

                    xmlHttp.onreadystatechange=function(){
                        if (xmlHttp.readyState==4)
                        {
                            var respText=xmlHttp.responseText;

                            if(document.getElementById("stateID")!=null)
                            {

                               var browserName= navigator.appName
                                if('Microsoft Internet Explorer' == browserName)
                                {
                                  document.getElementById("stateID").outerHTML= '<select id="stateID" name="state" onChange="selectState(this);" class="" style="width:205px; ">'+respText+'</select>';
                                 }
                                else
                                {
                                 document.getElementById("stateID").innerHTML= respText;
                                 }
                            }
                        }
                    };
                    xmlHttp.open("GET",url,true);
                    xmlHttp.send(null);
                  }
             }catch(e){
             alert(e);
             }
            }



/* recentinforums_edit.jsp */

/* registration.jsp */
            //It Returns Postal Code Details
            function pickStates_registration(countryID)
            {
                var countryObj = document.getElementById(countryID)                    
                var countryVal= countryObj.value
                var isLeftMenuVisble=document.getElementById('leftMenuVisble').value;
                if(isLeftMenuVisble=='true'){
                    document.getElementById('co').value=countryObj.options[countryObj.selectedIndex].value;
                     document.getElementById('st').value="";
                 
                }
                
                if(countryVal==" -"){
                document.getElementById(countryID).value="";
                document.getElementById('stOth').value="";
                document.getElementById("stateID").value="";
                document.getElementById('stateOther').style.display="none"
                document.getElementById('stateID').style.display="inline"

                 var browserName= navigator.appName
                                if('Microsoft Internet Explorer' == browserName)
                                {
                                  document.getElementById("stateID").outerHTML= '<select id="stateID" name="state" onChange="selectState(this);" style="width:205px; "><option value="" selected>- Select -</option></select>';
                                 }
                                else
                                {
                                 document.getElementById("stateID").innerHTML= '<option value="" selected>- Select -</option>';
                                 }
                

                return;
                }
                if(countryVal == '')
                {
                document.getElementById("stateID").value="";
                document.getElementById('stOth').value="";
                document.getElementById('stateOther').style.display="none"
                document.getElementById('stateID').style.display="inline"

                 var browserName= navigator.appName
                                if('Microsoft Internet Explorer' == browserName)
                                {
                                  document.getElementById("stateID").outerHTML= '<select id="stateID" name="state" onChange="selectState(this);" style="width:205px; "><option value="" selected>- Select -</option></select>';
                                 }
                                else
                                {
                                 document.getElementById("stateID").innerHTML= '<option value="" selected>- Select -</option>';
                                 }
                
                ////////////////////////////////////////////////////
                  return;
                }
                else if(countryVal!='US' && countryVal!='Canada')
                {
                      document.getElementById('stateOther').style.display="block"
                      document.getElementById("stateID").style.display= "none";
                  return;
                }
                
                else 
                {   
                    document.getElementById("stateID").style.display= "block";
                    if(document.getElementById("backupState").value!="other"){
                  document.getElementById('stOth').value="";                    
                  document.getElementById('stateOther').style.display="none"
                  }
                }
                //load states for US or canada
             try{
                 if(document.getElementById(countryID)){
                    var countryCode=document.getElementById(countryID).value;
                    
                    if(countryCode==null || countryCode=='') //if countryCode is empty nothing to do
                        return;
                        
                    xmlHttp=GetXmlHttpObject();
                    
                    if (xmlHttp==null)     {
                      alert ("Your browser does not support AJAX!");
                      return;
                    }         
            
                    var url="";
                    var state=document.getElementById('backupState').value;
                    
                    url=applicationContextPath+'/lookupStates.do?countryCode='+countryCode+'&prvState='+state;
            
                    xmlHttp.onreadystatechange=function(){
                        if (xmlHttp.readyState==4)
                        {                         
                            var respText=xmlHttp.responseText;
                            
                            if(document.getElementById("stateID")!=null)
                            {
                            
                               var browserName= navigator.appName
                                if('Microsoft Internet Explorer' == browserName)
                                {
                                  document.getElementById("stateID").outerHTML= '<select id="stateID" name="state" onChange="selectState(this);" style="width:205px; ">'+respText+'</select>';
                                 }
                                else
                                {
                                 document.getElementById("stateID").innerHTML= respText;
                                 }
                            }
                                
                        }
                    };
                    xmlHttp.open("GET",url,true);
                    xmlHttp.send(null);
                  }
             }catch(e){ 
             alert(e);
             }
            }

        function selectPrimaryIndustry_registration(thisObj)
        {
            if(thisObj.value!='other')
            {
                //document.getElementById('pi').value=(thisObj.options[thisObj.selectedIndex].text);
                   document.getElementById("primaryIndustryOther").value="";
                document.getElementById('primaryIndustryOtherID').style.display='none';
            }
            else if(thisObj.value=='other')
            {
                document.getElementById('primaryIndustryOtherID').style.display='block';
                   document.getElementById("primaryIndustryOther").value="Other(Please specify)";
            }
            
        }
        function selectJobFunction_registration(thisObj)
        {
         var isLeftMenuVisble=document.getElementById('leftMenuVisble').value;
            if(thisObj.value!='Other')
            {
             document.getElementById('jobFunOther').value="";
              if(isLeftMenuVisble=='true'){
                document.getElementById('jf').value=(thisObj.options[thisObj.selectedIndex].value);
                }
                document.getElementById('jobFunctionOtherID').style.display='none'
            }
            else if(thisObj.value =='Other')
            {
                document.getElementById('jobFunctionOtherID').style.display='block'
                document.getElementById('jobFunOther').value="Other(Please specify)";
            }
            
        }
        function selectState_registration(thisObj)
        {            
        var isLeftMenuVisble=document.getElementById('leftMenuVisble').value;
        
            if(thisObj.value=='other')
            {
              document.getElementById('stateOther').style.display="block";
              document.getElementById('stOth').value="";
              if(isLeftMenuVisble=='true'){
              document.getElementById('st').value="";
              document.getElementById('st').value=(thisObj.options[thisObj.selectedIndex].value);
              }
            }
            else
            {
            if(isLeftMenuVisble=='true'){
              document.getElementById('st').value=(thisObj.options[thisObj.selectedIndex].value);
              }
                document.getElementById('stOth').value="";
              document.getElementById('stateOther').style.display="none";
            }
            
            
        }
        function selectTab()
        {
            var tabKey = document.getElementById("tabKey").value
            
            var divName='div1'
            
                document.getElementById("td2").className="regClassWithBottomBorder";
                document.getElementById("td3").className="regClassWithBottomBorder";            
                document.getElementById("td1").className="regClassWithoutBottomBorder";
            
            if(tabKey=='tab2')
            {            
                divName='div2';
                document.getElementById("td1").className="regClassWithBottomBorder";
                document.getElementById("td3").className="regClassWithBottomBorder";
                document.getElementById("td2").className="regClassWithoutBottomBorder";                
            }
            else if(tabKey=='tab3')
            {
                divName='div3';
                document.getElementById("td1").className="regClassWithBottomBorder";
                document.getElementById("td2").className="regClassWithBottomBorder";
                document.getElementById("td3").className="regClassWithoutBottomBorder";                
            }

            document.getElementById("cell").innerHTML = document.getElementById(divName).innerHTML;
        
        }

    /*function registerUser()
        {
              
              //document.getElementById('seletdNewsLetters').value=document.getElementById('sletdNews').value;
              //News Letters
              for(i=0;i<10;i++){
              
              }//FOR END
              
              document.getElementById('frname').value=document.getElementById('forumNickName').value;
              document.getElementById('frmTitle').value=document.getElementById('forumTitle').value;
              document.getElementById('wphone').value=document.getElementById('workPhone').value;
              document.getElementById('clphone').value=document.getElementById('cellPhone').value;
              document.getElementById('instmsg').value=document.getElementById('instantMessanger').value;
              document.getElementById('instmsgId').value=document.getElementById('instantMessengerID').value;
               var urlObj=document.getElementById('urlMap').value;
                var tabKey = document.getElementById("tabKey").value;
                var registrationType=document.getElementById("registrationType").value;
                document.forms['register'].action=urlObj+"&switchedTabKey=tabMain&tabKey="+ tabKey+"&registrationType="+registrationType;
                document.forms['register'].submit();
        }*/

        /*function tab1()
        {
            var tabKey = document.getElementById("tabKey").value
                var urlObj=document.getElementById('urlMap').value;
                var registrationType=document.getElementById("registrationType").value;
            if(tabKey=='tab2')
            {            
                document.getElementById('form2').action=urlObj+"&switchedTabKey=tab1&tabKey=tab2"+"&registrationType="+registrationType;
                document.getElementById('form2').submit();
            }
            else if(tabKey=='tab3')
            {

                document.getElementById('form3').action=urlObj+"&switchedTabKey=tab1&tabKey=tab3"+"&registrationType="+registrationType;
                document.getElementById('form3').submit();
            }
                        
            document.getElementById("cell").innerHTML = document.getElementById("div1").innerHTML;
            document.getElementById("td2").className="regClassWithBottomBorder";
            document.getElementById("td3").className="regClassWithBottomBorder";            
            document.getElementById("td1").className="regClassWithoutBottomBorder";
        }

        function tab2(){
            var tabKey = document.getElementById("tabKey").value;
            var urlObj=document.getElementById('urlMap').value;
            var registrationType=document.getElementById("registrationType").value;
            if(tabKey=='tab1' || tabKey=='tabMain')
            {  
                //document.getElementById('switchedTabKey').value="tab2";
                document.getElementById('form1').action=urlObj+"&switchedTabKey=tab2&tabKey=tab1"+"&registrationType="+registrationType;
                document.getElementById('form1').submit();
            }
            else if(tabKey=='tab3')
            {
            
                //document.getElementById('switchedTabKey').value="tab2";
                document.getElementById('form3').action=urlObj+"&switchedTabKey=tab2&tabKey=tab3"+"&registrationType="+registrationType;
                document.getElementById('form3').submit();
            }
                        
            document.getElementById("cell").innerHTML = document.getElementById("div2").innerHTML;
            document.getElementById("td1").className="regClassWithBottomBorder";
            document.getElementById("td3").className="regClassWithBottomBorder";
            document.getElementById("td2").className="regClassWithoutBottomBorder";
        }
        function tab3(){
            var urlObj=document.getElementById('urlMap').value;
            var tabKey = document.getElementById("tabKey").value;
            var registrationType=document.getElementById("registrationType").value;
            if(tabKey=='tab1' || tabKey=='tabMain')
            {    
                document.getElementById('form1').action=urlObj+"&switchedTabKey=tab3&tabKey=tab1"+"&registrationType="+registrationType;;
                document.getElementById('form1').submit();
            }
            else if(tabKey=='tab2')
            {
                document.getElementById('form2').action=urlObj+"&switchedTabKey=tab3&tabKey=tab2"+"&registrationType="+registrationType;;
                
                document.getElementById('form2').submit();
            }
                
            document.getElementById("cell").innerHTML = document.getElementById("div3").innerHTML;
            document.getElementById("td1").className="regClassWithBottomBorder";
            document.getElementById("td2").className="regClassWithBottomBorder";
            document.getElementById("td3").className="regClassWithoutBottomBorder";
        }*/


/* relatedblogs_edit.jsp */

function validateCollection(){
var flag = false;
    if(document.getElementById("collection").value==null || document.getElementById("collection").value=='')
        {
            alert("Please enter collection type");
            flag = false;
        }else
    flag = true;
    return flag;
}


/* Blog Entry Comments Page scroll down logic START*/

    function elementPosition(obj) {
        var curleft = 0, curtop = 0;

        if (obj.offsetParent) {
            curleft = obj.offsetLeft;
            curtop = obj.offsetTop;

            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            }
        }

        return { x: curleft, y: curtop };
    }
    
    
    
/* Blog Entry Comments Page scroll down logic END */    

/* registration javascript for post a comment start*/

function registerOrLog(){
    document.getElementById('regist').style.display="inline";
    document.getElementById("regist").scrollIntoView(); 
}
/* registration javascript for post a comment end*/

 function escapeChars(obj) {
 var imagePath=obj.src;
 imagePath = imagePath.replace( /[ \f\n\r\t]|\%0D\%0A|\%0D|\%0A/g,'' );
 obj.src=imagePath;
}


/* Best of TechWeb */
function prepareForSubmit_bestofTechweb_edit(){

        flag = true;
        //alert(document.getElementById("siteNameList").value);
        if(document.getElementById('siteNameList').value!=""){
        var cleartemp1 = document.getElementById('siteNameList').value.split(",");
        finalValue=cleartemp1.length;
        }
    
        if(finalValue<minSiteValue){
            alert("Please Select atleast "+minSiteValue+" Site Names");
            return false;
        }
        if(finalValue>maxSiteValue){
            alert("Please Don't Select more than "+maxSiteValue+" Site Names");
            return false;
        }
        //alert(document.getElementById("siteNameList").value);
        if((bestoftechweb!=null) && !(bestoftechweb.closed)){
            alert("The Site Lookup Screen is Open");
            return false;
        }
    
        return flag;
}
