 // This function will display the priview of geadline in admin blog pages
 function ShowPrivew(source, destination, container)
        {
        var y=document.getElementById(source);
        var dest =document.getElementById(destination);
        var destCont =document.getElementById(container);
        
            if (destCont.style.display =="none")
            {
                destCont.style.display="block";
            }
            dest.innerHTML= y.value;
        }
        
 
 function ClosePrivew(source)
 {
    document.getElementById(source).style.display="none";
 }
 
 
 function ShowDiv(source)
 {
    document.getElementById(source).style.display="block";
 }

//********** for admin blog text count ***************
    function CountWords(srsCtrl,displayCtrlID)
    {  
        var plainText = removeHTMLTags(srsCtrl.value);
        //alert(WordCount(plainText));
        document.getElementById(displayCtrlID).innerHTML=WordCount(plainText);
    
    }

   //function will remove HTML tags
     function removeHTMLTags(htmlString)
     {
        var plainText;
        
        if(htmlString)
        {
          var mydiv = document.createElement("div");
           mydiv.innerHTML = htmlString;
 
            if (document.all) // for IE
            {
                plainText= mydiv.innerHTML;
            }   
            else // for Mozilla 
            {
                plainText=mydiv.textContent;
            } 
        }
        return plainText;
    } 
    
    // function will count no of words
    function WordCount(strText)
    {
        var wordCount=0;
        if (strText)
        {
            strText= jQuery.trim(strText); 
            var formcontent=strText.split(" ");
            wordCount=formcontent.length;
            //alert(wordCount);
        }
        return wordCount;
    }
    
   
// ******** end admin blog text count ****************
 
 function detectBrowser()
 {
    var browser=navigator.appName;
    if (browser=="Microsoft Internet Explorer")
    {
        document.getElementById("searchButton").className="GoogleTextBoxMargin";
        return false;
     }
 }
 
 function adjustDiv()
 {
    if (document.getElementById("imagesourcelink")!=null)
    {
        if (document.getElementById("imagesourcelink").innerText !="")
        {
            var as = document.getElementById("PostImage");
            var bs = document.getElementById("ImageSourceDIV");
            bs.style.width=as.offsetWidth +"px";
        }
        else
        {
            document.getElementById("ImageSourceDIV").style.display="none";
        }
    }
    return false;
}

function HideDivContents()
{
    if (document.getElementById("RelatedLinksDIV")!=null)
    {
        document.getElementById("RelatedLinksDIV").style.display="none";
    }
    if (document.getElementById("rightNavPhotoGallery")!=null)
    {
        document.getElementById("rightNavPhotoGallery").style.display="none";
    }
    return false;
}
           
 
 function validateEmail(controlToValidate,error)
 {    
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if (emailPattern.test(document.getElementById(controlToValidate).value))
        {
            document.getElementById(error).innerText="";
            validate(controlToValidate) ;
            }
        else
        {
            alert("Invalid email address");
            document.getElementById(error).innerText="Invalid email address";
            document.getElementById(error).value="Invalid email address";
            
        }
    return emailPattern.test(document.getElementById(controlToValidate).value) ; 
 } 
 
 // this function will use in right navigation 
 function ShowAlertBoxDiv(source, sourceBox)
 {
        ShowDiv(source);
        var viewportwidth, viewportheight;
    if (typeof window.innerWidth != 'undefined')
     {
          viewportwidth = window.innerWidth,
          viewportheight = window.innerHeight
     }
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
     else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0)
     {
           viewportwidth = document.documentElement.clientWidth,
           viewportheight = document.documentElement.clientHeight
     }
     // older versions of IE
     else
     {
           viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
           viewportheight = document.getElementsByTagName('body')[0].clientHeight
     }

    document.getElementById(source).style.width= viewportwidth +"px";
    document.getElementById(source).style.height= viewportheight +"px";
    
    var topBox, leftBox;
    topBox = (viewportheight - document.getElementById(sourceBox).offsetHeight) /2;
    leftBox = (viewportwidth- document.getElementById(sourceBox).offsetWidth) /2;
    document.getElementById(sourceBox).style.top= topBox +"px";
    document.getElementById(sourceBox).style.left= leftBox +"px";
   if (document.getElementById("RightNavi3_SignUpTextBox")!=null)
   {
        document.getElementById('RightNavi3_SignUpTextBox').className='rightNav_emailtext'; 
        document.getElementById('RightNavi3_SignUpTextBox').value="";
    }
 }
 
 
// masking text box
 function MaskEmailBox(controlToValidate)
 { 
    controlToValidate.className='singupinputBox';
 }
 function MaskEmailBoxOnLost(controlToValidate)
 {
    
    var txVal=controlToValidate.value.trim();
    if (txVal != "")
    {
       controlToValidate.className='singupinputBox'; 
    }
    else
    {
         controlToValidate.className='rightNav_emailtext'; 
    }
 }
 
 //************************* Ajax functions **************************************
 
 
var req;
function validate(ctrl) 
{ 
    var idField = document.getElementById(ctrl);
    var url = "http://www.hollyscoop.com/AjaxRequest.aspx?id=" + encodeURIComponent(idField.value) +"&rnd=" + Math.random()*1000;
    if (idField.value!='')
    {
       if (typeof XMLHttpRequest != "undefined")
        {
            req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.open("GET", url, true);
        req.onreadystatechange = callback;
        req.send(null);
    }
}

function callback() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            // update the HTML DOM based on whether or not message is valid
            parseMessage(req.responseText);
        }
    }
}

function parseMessage(responseText) 
{
    var Response= req.responseText.trim();
     if (Response == 1) 
     {
        var msg = "You have already registered for Hollyscoop!";
         alert(msg);
         document.getElementById("alertBoxBG").style.display="none";
     }
     else if (Response == 2) 
     {
        var msg = "Thank you for registering with Hollyscoop!";
         alert(msg);
         document.getElementById("alertBoxBG").style.display="none";
     }
     else if (Response == 3) 
     {
        var msg = "Thank you for registering with Hollyscoop!";
         alert(msg);
         document.getElementById("alertBoxBG").style.display="none";
     }
     else if (Response == 4) 
     {
        var msg = "Thank you for registering with Hollyscoop!";
         alert(msg);
         document.getElementById("alertBoxBG").style.display="none";
     }
     else
     {
         var msg = "Invalid response!" + Response;
         alert(msg);
     }
   
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
// for post details more cat image border //
function ShowPostMoreCatBorder(imgCat, container)
{
    if (document.getElementById(imgCat)!= null)
    {
         var imgCtrl= document.getElementById(imgCat);
         var cont= document.getElementById(container);
         //alert(imgCtrl.offsetWidth +":"+ imgCtrl.offsetHeight) 
         if ((imgCtrl.offsetWidth < 130) || (imgCtrl.offsetHeight < 172))
         {
             cont.className="post-MoreArticleRow2-imgBox-inner";
         }
         else
         {
             cont.className="";
         }
    }
}

