//COMMON
function createCookie(name,value,days)
{
  if(days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while(c.charAt(0)==' ')
      c = c.substring(1,c.length);
    if(c.indexOf(nameEQ) == 0)
      return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//IMAGE CHANGER
var element1;
var element1OGsrc;
var imgFolder;
var picNum1 = 1;
var RUNNING = false;
var timer;

function timerCall(delay, useFade, count)
{
  if(RUNNING)
  {
    if(++picNum1 > count)
      picNum1 = 1;
    element1.src = imgFolder + picNum1 +".jpg";
    if(useFade)
      opacity(element1.id, 100, 0, delay);
    timer = setTimeout("timerCall("+ delay +", "+ useFade +", "+ count +")",delay);
  }
  else
  {
    element1.src = element1OGsrc;
    clearTimeout(timer);
  }
}
function startImageSwap(element, delay, useFade, count)
{
  RUNNING = true;
  picNum1 = 0;
  element1 = element;  //alert(element1.src);
  element1OGsrc = element1.src;
  imgFolder = element1.src.substring(0, element1.src.lastIndexOf("/") + 1);
  clearTimeout(timer);
  if(!delay)
    delay = 500;
  if(!count)
    count = 4;
  timer = setTimeout("timerCall("+ delay +", "+ useFade +", "+ count +")",delay);
}
function stopImageSwap()
{
  element1.src = element1OGsrc;
  RUNNING = false;
  picNum1 = 0;
  clearTimeout(timer);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function expand(id)
{
  var element = document.getElementById(id);
  if(element.style.display == "inline")
    element.style.display = "none"
  else
    element.style.display = "inline"
}

function showStars(id,count,imgSrc)
{
  //if(rated == false)
  {
    i=1;  //alert(id+"_"+i);
    while(i < count+1)
    {
      document.getElementById(id+"_"+i).src = imgSrc;
      i=i+1;
    }
  }
}
function clearStars(id,count,imgSrc)
{
  //if(rated == false)
  {
    i=1;  //alert(id+"_"+i);
    while(i < 6)
    {
      document.getElementById(id+"_"+i).src = imgSrc;
      i=i+1;
    }
  }
}

function opacity(id, opacStart, opacEnd, millisec)
{
  //speed for each frame
  var speed = Math.round(millisec / 100);
  var timer = 0;

  //determine the direction for the blending, if start and end are the same nothing happens
  if(opacStart > opacEnd)
  {
    for(i = opacStart; i >= opacEnd; i--)
    {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
  else if(opacStart < opacEnd)
  {
    for(i = opacStart; i <= opacEnd; i++)
    {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
      timer++;
    }
  }
}
//change the opacity for different browsers
function changeOpac(opacity, id)
{
  var object = document.getElementById(id).style;
  if(object)
  {
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
  }
}
function formCheck(form)
{
  for(var i = 0; i < form.elements.length; i++)
  {
    var formField = form.elements[i];
    if(formField.name.charAt(0) != '*')
    {
      try
      {
        if(formField.value == '')
        {
          highLight(formField.name, false);
          return false;
        }
        else
          unHighLight(formField.name);
      }
      catch(ex){}
    }
  }
  return true;
}

function validEmail(str)
{
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
  return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
  return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
  return false
  }
  if (str.indexOf(at,(lat+1))!=-1){
  return false
  }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
  return false
  }
  if (str.indexOf(dot,(lat+2))==-1){
  return false
  }
  if (str.indexOf(" ")!=-1){
  return false
  }
  return true
}

function ajaxRate(wid, cid, value)
{ //alert(readCookie(cid));
  if(readCookie(cid) == "Y")
  {
    document.getElementById("RATE_"+ cid).innerHTML = '<b>You have already voted for this scene today!</b>';
  }
  else
  {
    value = (value * 2); //times by 2 cuz there is only 5 stars, ie 1-5 numbers
    ajaxRequest('process/content_actions.jsp?Action=Rate&CID='+ cid +'&WID='+ wid +'&V='+ value, AJAXRATE_myCallback, cid, 'POST');
    createCookie(cid, "Y", 1);
  }
}
function AJAXRATE_myCallback(response, id)
{
  document.getElementById("RATE_"+ id).innerHTML = '<b>Ranking Score: '+ response +' Thanks for voting!</b>';
}

function ajaxFavs(action, cid, wid, callbackFuntion)
{ //alert(readCookie(cid));
  if(!callbackFuntion)
  {
    callbackFuntion = AJAXFAVS_myCallback;
  }
  ajaxRequest('process/content_actions.jsp?Action='+ action +'&CID='+ cid +'&WID='+ wid, callbackFuntion, cid, 'POST');
}
function AJAXFAVS_myCallback(response, id)
{
  var text = "";
  if(response == 1)
    text = '<br />Added to your favorites.<br /><a href="favs.jsp">go to favorites</a>';
  else
    text = '<br /><b>There was an error adding to favorites!</b><br /><a href="favs.jsp">go to favorites</a>';
  document.getElementById("FAVS_"+ id).innerHTML = text;
}

function highLight(id, useTimeout)
{
  var element = document.getElementById(id);
  if(!element)
    return;
  element.focus();
  element.parentNode.style.backgroundImage = "url(/specific/smash/images/bar_search2.gif)";
  if(useTimeout)
    setTimeout("unHighLight('"+ id +"')", 500);
}
function unHighLight(id)
{
  var element = document.getElementById(id);
  if(!element)
    return;
  element.parentNode.style.backgroundImage = "url(/specific/smash/images/bar_search.gif)";
}

function goNewWin()
{
  var value = readCookie("MORE");
  if(!value || value != "YES")
  {
    var newWin = window.open('http://getmoreporno.com/popadd.jsp','MORE','width=720,height=660,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1');
    newWin.blur();
    createCookie("MORE","YES",1);
  }
}




