var $j = jQuery.noConflict();

function checkRegFormFields()
{
  var formObj = document.regForm;
   
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
  var fieldsArr = eval('({"first_name":"first name", "last_name":"last name", "email":"email address", "username":"username", "password":"password", "country":"country"})');
	
  with(formObj)
  {
     for(var ind in fieldsArr)
     {
               
       if(eval(ind).value == '')
       {
     	   alert('Please enter ' + fieldsArr[ind]);      	   
     	   eval(ind).focus();
     	   return false;
       }
       else if(ind == 'email')
       {
          if(filter.test(eval(ind).value))
          {
             ;	
          }
          else
          {
             alert('Please enter a valid email address');		
     	     eval(ind).focus();
     	     return false;
          }   		
       }
       else if(ind == 'username')
       {
          if(username.value.length < 6)
          {
             alert('Username should be atleast 6 characters long');		
     	     username.focus();
     	     return false;
          }        
       }
       else if(ind == 'password')
       {
          if(password.value.length < 6)
          {
             alert('Password should be atleast 6 characters long');		
     	     password.focus();
     	     return false;
          }
           
          if(eval(ind).value == password2.value)
          {
             ;	
          }
          else
          {
             alert('Both password and confirm password should be equal');		
     	     password2.focus();
     	     return false;
          }   		
       }
       
     }
  }
  
  return true;		
    
}

function checkContactFormFields()
{
    var formObj = document.contactForm;

    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    var fieldsArr = eval('({"first_name":"first name", "last_name":"last name", "email":"email address", "comments":"comments"})');

    with(formObj)
    {
        for(var ind in fieldsArr)
        {
            if(eval(ind).value == '')
            {
                alert('Please enter ' + fieldsArr[ind]);
                eval(ind).focus();
                return false;
            }
            else if(ind == 'email')
            {
                if(filter.test(eval(ind).value))
                {
                    ;
                }
                else
                {
                    alert('Please enter a valid email address');
                    eval(ind).focus();
                    return false;
                }
            }
        }
    }

    return true;

}
function checkAccountFormFields()
{
  var formObj = document.accountForm;
   	
  var fieldsArr = eval('({"first_name":"first name", "last_name":"last name", "country":"country"})');
	
  with(formObj)
  {
     for(var ind in fieldsArr)
     {            
       if(eval(ind).value == '')
       {
     	   alert('Please enter ' + fieldsArr[ind]);      	   
     	   eval(ind).focus();
     	   return false;
       }       
     }
  }
  
  return true;		
    
}

function checkSearchField()
{
  if(document.searchForm.q.value.length < 3)
  {
     alert('Search keyword must be of 3 characters long');
     document.searchForm.q.focus();
     return false;
  }
  else
  {
     return true;
  }
      
}

function checkSearchField2()
{
  if(document.searchForm2.q.value.length < 3)
  {
     alert('Search keyword must be of 3 characters long');
     document.searchForm2.q.focus();
     return false;
  }
  else
  {
     return true;
  }
      
}

function addToFavList(media_id)
{

   $j.get('/Pages/ajax/add2fav?media_id=' + media_id, function(data){
     $j('#fav_block').html(data);
     $j('#fav_block').show(500);
     $j('#fav_block').hide(3000);
   });

}

function addToPlayList(media_id)
{

   $j.get('/Pages/ajax/add2list?media_id=' + media_id, function(data){
     $j('#fav_block').html(data);
     $j('#fav_block').show(500);
     $j('#fav_block').hide(3000);
   });

}
var embedon = false;
function getEmbeded(data) {
    if(embedon) { hideEmbeded(); } else {
        $j('#player-description').hide(300);
        data2 = '&lt;embed width=&quot;456&quot; height=&quot;295&quot; allowscriptaccess=&quot;always&quot; wmode=&quot;opaque&quot; allowfullscreen=&quot;true&quot; quality=&quot;high&quot; bgcolor=&quot;#000000&quot; name=&quot;ply&quot; id=&quot;ply&quot; style=&quot;&quot; src=&quot;'+ data +'&quot; type=&quot;application/x-shockwave-flash&quot;&gt;'
        $j('#embed_block').html(data2);
        $j('#embed_block').fadeIn(300);
        embedon = true;
    }
}
function hideEmbeded() {
    $j('#embed_block').slideUp(3000);
    setTimeout("$j('#player-description').fadeIn(1000)", 3100);
    embedon = false;
}

function reportMedia(media_id)
{

   $j.get('/Pages/ajax/reportmedia?media_id=' + media_id, function(data){
     $j('#fav_block').html(data);
     $j('#fav_block').show(500);
     $j('#fav_block').hide(3000);
   });

}

function swapImage(i, img_name)
{
   if(rated)
   {
      return false; 
   }
   
   var jstr = '';
   
   for(var j = 1; j<=i; j++)
   {
      jstr += j + ',';
      $j('#img_' + j).attr('src', statics + 'images/' + img_name + '.gif');      		        
   }
   
   if(img_name == 'red')
   {
      var msgs = new Array('Poor', 'Nothing special', 'Worth watching', 'Pretty cool', 'Awesome!');      
      $j('#rate_msg').html(msgs[i-1]);
      $j('#total_ratings').hide();
      $j('#rate_msg').show();      
   }
   else
   {
      $j('#rate_msg').hide();      
      $j('#total_ratings').show(); 
   }
}

function putRating(rv, media_id)
{
   $j.get('/Pages/ajax/ratevideo?media_id=' + media_id + '&rv=' + rv, function(data){
     if(data.indexOf('Thanks')!=-1) rated = true;     
     $j('#rate_msg').html(data);
   });       
}
function jumpToPage(page) {
    $j('#pagination_wrapper').load("/Ajax/feedback/?page="+page);
}


