 var $j = jQuery.noConflict();	
 var isIE = 0;
 if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null) {
   isIE = 1;
   document.writeln("<link href=\"/css/style_ie.css\" type=\"text/css\" rel=\"stylesheet\" />");
 }
 
$j(document).ready(function(){
   
   $j("#TopicImage").focus(function(){
	if ($j("#TopicImage").val() == "http://") {
	   $j("#TopicImage").val("");
	}
   });
});

function checkForm()
 {
    var $j = jQuery.noConflict();		

    $j("#newlist_message").html('');
	clearForm();
    var toReturn = true;
    
    var TopicTitle = document.NewTopicForm.TopicTitle.value;
    var TopicIsGrowable = document.NewTopicForm.TopicIsGrowable.value;
    var TopicType = document.NewTopicForm.TopicType.value;
    var TopicNswf = document.NewTopicForm.TopicNsfw.value;
    var TopicCategory = document.NewTopicForm.TopicCategory.value;
    var TopicDescription = document.NewTopicForm.TopicDescription.value;
    var TopicImage = document.NewTopicForm.TopicImage.value;
    
    toReturn &=  flagForm(TopicTitle=="", 'TopicTitle', 'List name cannot be blank');
    toReturn &=  flagForm(TopicIsGrowable=="", 'TopicIsGrowable', 'You must choose to write or not write the list');
    toReturn &=  flagForm(TopicType=="", 'TopicType', 'You must choose a list type');
    toReturn &=  flagForm(TopicNsfw=="", 'TopicNsfw', 'You must select SFW/NSFW');
    toReturn &=  flagForm(TopicCategory=="", 'TopicCategory', 'You must select a category');
    toReturn &=  flagForm(TopicDescription=="", 'TopicDescription', 'Description cannot be blank');
    toReturn &=  flagForm(TopicImage=="", 'TopicImage', 'Image cannot be blank');
    
    toReturn &=  flagForm(TopicDescription.length>3000, 'TopicDescription', 'Description must be less than 3000 characters');
    toReturn &=  flagForm(TopicTitle.length>45, 'TopicTitle', 'List name must be less than 45 characters');
    
    $j(".txt_item").each(function(){
       var val = $j(this).val();
       if (val=="")
       {
         $j("#newlist_message").html("All items must have text and cannot be blank");
         toReturn = false;
       }
    });
    
    $j(".txt_text").each(function(){
       var val = $j(this).val();
       if (val=="")
       {
         $j("#newlist_message").html("All text descriptions must have text and cannot be blank");
         toReturn = false;
       }
    });
    
    $j(".txt_video").each(function(){
       var val = $j(this).val();
       if (val=="")
       {
         $j("#newlist_message").html("All video links must have text and cannot be blank");
         toReturn = false;
       }
       else if (val.indexOf("http://")==-1 || val.indexOf("youtube")==-1)
       {
         $j("#newlist_message").html("All video links must be to YouTube at this time");
         toReturn = false;
       }
    });
    
    $j(".txt_image").each(function(){
       var val = $j(this).val();
       var ext = val.substr(val.lastIndexOf('.') + 1);
       if (val=="")
       {
         $j("#newlist_message").html("All image links must have text and cannot be blank");
         toReturn = false;
       }
       else if (val.indexOf("http://")==-1)
       {
         $j("#newlist_message").html("All image links must be to an external web site at this time");
         toReturn = false;
       }
       else if ("|gif|jpg|png|jpeg|JPG|GIF|PNG|JPEG|".indexOf('|' + ext + '|')==-1)
       {
         $j("#newlist_message").html("Please enter a valid image file format of GIF, JPG, or PNG format");
         toReturn = false;
       }
    });
    
    if (!toReturn)
      return false;
      
    return true;
    
 }
 
 function populateTableHead()
 {
   var $j = jQuery.noConflict();		
   var type = $j("#TopicType").val();
   if (type == "1")
   {
       $j("#listHead").html("<tr><th>Rank</th><th>Item Name</th><th>Text Description</th><th>Image Link</th></tr>");
   }
   else if (type == "2")
   {
       $j("#listHead").html("<tr><th>Rank</th><th>Item Name</th><th>Text Description</th><th>Video Link</th></tr>");
   }
   else
   {
       $j("#listHead").html("<tr><th>Rank</th><th>Item Name</th><th>Text Description</th></tr>");
   }
   populateTableBody();
 }
 
 function populateTableBody()
 {      
      var $j = jQuery.noConflict();		
      var num = $j("#numitems").val();
      var newBody = "";
      for (var i=0; i<num; i++)
      {
         newBody += "<tr><td class=newlistrow>"+(i+1)+"</td><td class=newlistrow><input type=text name=item-"+(i+1)+" id=item-"+(i+1)+" class=\"newlisttext txt_item\"></td><td class=newlistrow><textarea class=txt_text cols=30 rows=3 name=text-"+(i+1)+" id=text-"+(i+1)+"></textarea></td>";
         if ($j("#TopicType").val()=="2")
         {
            newBody += "<td class=newlistrow><input value=\"http://\" class=\"newlisttext txt_video\" type=text name=video-"+(i+1)+" id=video-"+(i+1)+"></td>";
         }
         else if ($j("#TopicType").val()=="1")
         {
            newBody += "<td class=newlistrow><input value=\"http://\" class=\"newlisttext txt_image\" type=text name=image-"+(i+1)+" id=image-"+(i+1)+"></td>";
         }
         newBody += "</tr>";
      }
      $j("#listBody").html(newBody);
 }

   
