﻿// JScript File
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}; 
function unescapeHTML (str)
{
    var div = document.createElement('div');
    div.innerHTML = this.stripTags();
    return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
  }
function UpdateAdsAndCounters()
{

    //For now we are going to log the Ajax calls in DB as well as OneStat
    if(typeof('OneStat_PageviewUpdate') != 'undefined')
        OneStat_PageviewUpdate();
    
    if(window.frames && window.frames["ad250x250"])
    {
        if(typeof(window.frames["ad250x250"].location.replace) != 'undefined')
            window.frames["ad250x250"].location.replace('http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=17&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime());
        else
            window.frames["ad250x250"].location.href='http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=17&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime();    
    }
    if(window.frames && window.frames["ad728x90"])
    {
        if(typeof(window.frames["ad728x90"].location.replace) != 'undefined')
            window.frames["ad728x90"].location.replace('http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=16&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime());
        else
            window.frames["ad728x90"].location.href='http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=16&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime();
    }
}

function UpdateAdsAndCountersStaticOnly()
{
     //For now we are going to log the Ajax calls in DB as well as OneStat
    if(typeof('OneStat_PageviewUpdate') != 'undefined')
        OneStat_PageviewUpdate();
        
    if(typeof('GA_PageviewUpdate') != 'undefined')
        GA_PageviewUpdate();
    
    if(window.frames && window.frames["ad250x250"])
    {
        if(typeof(window.frames["ad250x250"].location.replace) != 'undefined')
            window.frames["ad250x250"].location.replace('http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=17&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime());
        else
            window.frames["ad250x250"].location.href='http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=17&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime();    
    }
    if(window.frames && window.frames["ad728x90"])
    {
        if(typeof(window.frames["ad728x90"].location.replace) != 'undefined')
            window.frames["ad728x90"].location.replace('http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=16&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime());
        else
            window.frames["ad728x90"].location.href='http://iklipz.advertserve.com/advertpro/servlet/view/banner/url/zone?zid=16&pid=0&random='+Math.floor(89999999*Math.random()+10000000)+'&millis='+new Date().getTime();
    }
}


var OneStatUpdateImage;
function OneStat_PageviewUpdate()
{
    var d=document;
    var sid="297808";
    var CONTENTSECTION="";
    var osp_URL=d.URL;
    var osp_Title=d.title;
    var t=new Date();
    var p="http"+(d.URL.indexOf('https:')==0?'s':'')+"://stat.onestat.com/stat.aspx?tagver=2&sid="+sid;

    p+="&url="+escape(osp_URL);
    p+="&ti="+escape(osp_Title);
    p+="&section="+escape(CONTENTSECTION);
    p+="&rf="+escape(parent==self?document.referrer:top.document.referrer);
    p+="&tz="+escape(t.getTimezoneOffset());
    p+="&ch="+escape(t.getHours());
    p+="&js=1";
    p+="&ul="+escape(navigator.appName=="Netscape"?navigator.language:navigator.userLanguage);
    if(osp_URL!=d.URL) p+="&ol="+escape(d.URL);
    if(typeof(screen)=="object"){
       p+="&sr="+screen.width+"x"+screen.height;p+="&cd="+screen.colorDepth;
       p+="&jo="+(navigator.javaEnabled()?"Yes":"No");
    }
    if(!OneStatUpdateImage)
        OneStatUpdateImage= new Image(1,1);
    OneStatUpdateImage.src = p + '&random='+Math.floor(89999999*Math.random()+10000000)+'&millis1='+new Date().getTime();  

}

function GA_PageviewUpdate()
{
    var pageTracker = _gat._getTracker("UA-3803658-1");
    pageTracker._initData();
    pageTracker._trackPageview();
}

function EvalScriptTag(str, name)
{
    var s = str;
    var embedStart = "//#EMBED-"+ name + "-START#";
    var embedEnd = "//#EMBED-"+ name + "-END#";
    var pos1= s.indexOf(embedStart);
    if(pos1 >-1)
    {
        var scr= s.substr(pos1 + embedStart.length);
        var pos2= scr.indexOf(embedEnd);
        if(pos2 > -1)
        {
            var scr= scr.substr(1,pos2-1);
            try {
            eval(scr);
            }
            catch(e){}
        }
    }
}

function ClickGo2(evt, id) {
    //LoginButtonID
    if (evt.keyCode == 13) {
        try {
            document.getElementById(id).click();
            document.getElementById(id).scroll;
            evt.cancelBubble = true;
            evt.returnValue = false;
            return false;
        }
        catch (e) {
            var clickevent = document.createEvent("MouseEvents")
            clickevent.initEvent("click", true, true)
            document.getElementById(id).dispatchEvent(clickevent);
            evt.cancelBubble = true;
            evt.returnValue = false;
            return false;
        }
    }
    return true;
}
function ClickElm(id) 
{
    try 
    {
        document.getElementById(id).click();
        document.getElementById(id).scroll;
    }
    catch (e) 
    {
        var clickevent = document.createEvent("MouseEvents")
        clickevent.initEvent("click", true, true)
        document.getElementById(id).dispatchEvent(clickevent);
    }
}


//function ClickGo2(evt, id )
//{
//    if( evt.keyCode == 13 )
//    {   
//        var fireOnThis = document.getElementById(id);
//        if( document.createEvent ) 
//        {
//            var evObj = document.createEvent('MouseEvents');
//            evObj.initEvent( 'click', true, false );
//            fireOnThis.dispatchEvent(evObj);
//        } 
//        else if( document.createEventObject ) 
//        {
//            fireOnThis.fireEvent('click');
//        }
//        /*
//        try
//        {            
//            document.getElementById(id).click();          
//            document.getElementById(id).scroll;
//            evt.cancelBubble = true;
//            evt.returnValue = false; 
//            return false;
//        }
//        catch(e)
//        {
//            var clickevent = document.createEvent('MouseEvents');  
//            clickevent.initMouseEvent('click', true, true, this, 1, 0, 0, 0, 0, false, false, false, false, 0, null);  
//            fireOnThis.dispatchEvent(clickevent) ;
//            
////            var clickevent=document.createEvent("MouseEvents")
////            clickevent.initEvent("click", true, true)
////            document.getElementById(id).dispatchEvent(clickevent) ;
//            evt.cancelBubble = true;
//            evt.returnValue = false; 
//            return false;
//        }  
//        */
//    } 
//    return true;      
//}


//CHECK FOR SAFARI
var agt=navigator.userAgent.toLowerCase();
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;


/************************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
    var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40;
    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
        edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset);
}
else{
    var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)    
        edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight;
    
    
}
return edgeoffset;
}



function getPos( el, sProp) 
{
    var iPos = 0;
    while (el!=null)
    {
        iPos+=eval("el.offset" + sProp);
        el = el.offsetParent;
    }
    return iPos;
}
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}



function showRestrictedMoviePopup(menucontents, plaincontents, obj, e, tipwidth)
{
    tipwidth = "350px"
      
        dropmenuobj=document.getElementById("infobox");
        dropmenuobj.innerHTML=menucontents;
        var playerBottom =0;
        if (tipwidth!=""){
            dropmenuobj.widthobj=dropmenuobj.style;
            dropmenuobj.widthobj.width=tipwidth;
        }
        if ( document.getElementById('FLVPlayer') ) {        
            playerBottom = 50;
        }
                
        var scrollTop =(ns6)? document.documentElement.scrollTop : ietruebody().scrollTop;
        scrollTop = scrollTop+180
        var scrollLeft=(ns6)? document.documentElement.scrollLeft : ietruebody().scrollLeft;
        
        var itop = 130;
        if ( (document.getElementById('FLVPlayer') && pageHeight() > 475) || !document.getElementById('FLVPlayer') )
        {  
               
            if (document.getElementById('FLVPlayer'))
            {
            document.getElementById('FLVPlayer').style.display = "none";
            }
            if ( (playerBottom - scrollTop) > 125 )
                itop = playerBottom + 10;
            else
                itop = (scrollTop + pageHeight()/2);           
                
            
                ileft = scrollLeft + 350
            
                    
            dropmenuobj.style.left= ileft+"px";
            dropmenuobj.style.top= "200px";
            dropmenuobj.style.visibility="visible";
            //hideInfoBox();
        }
        else
        {
            alert(plaincontents);        
        }
    
}


function showInfoBox(menucontents, plaincontents, obj, e, tipwidth)
{
    tipwidth = "310px"
    if ((ie||ns6) && document.getElementById("infobox"))
    {    
        dropmenuobj=document.getElementById("infobox");
        dropmenuobj.innerHTML=menucontents;
        var playerBottom =0;
        if (tipwidth!=""){
            dropmenuobj.widthobj=dropmenuobj.style;
            dropmenuobj.widthobj.width=tipwidth;
        }
        
        var scrollTop =(ns6)? document.documentElement.scrollTop : ietruebody().scrollTop;
        var scrollLeft=(ns6)? document.documentElement.scrollLeft : ietruebody().scrollLeft;
        
       
        var itop = 300;
       
        itop = (scrollTop + pageHeight()/2)-100;   
        var ileft = (pageWidth() /2 ) - (113) + scrollLeft;  
   
        itop = (scrollTop + pageHeight()/2)-100;   
        dropmenuobj.style.left= ileft+"px";
        dropmenuobj.style.top= itop+"px";
        dropmenuobj.style.visibility="visible";
        
        hideInfoBoxDelay();
   
    }
    else
    {
        alert(plaincontents);
    }
}
function mjalert(msg) {
    alert(msg.gsub('&#13;', '\n'));
}

function hideInfoBoxNow(){
    dropmenuobj.style.visibility='hidden';    
}
var infoboxtimeout;
function resethibto() {
    clearTimeout(infoboxtimeout);
}
function hideInfoBoxDelay() {
    resethibto();
    infoboxtimeout = setTimeout("dropmenuobj.style.visibility='hidden';", 4000);    
}

function createinfobox(){
var divblock=document.createElement("div");
divblock.setAttribute("id", "infobox");
document.body.appendChild(divblock);
}

if (window.addEventListener){
window.addEventListener("load", createinfobox, false);
}
else if (window.attachEvent){
window.attachEvent("onload", createinfobox);
}
else if (document.getElementById)
{
}

function ImportAddressBook(source, accountType)
{  
    switch(source)
     {
        case "1" :
           document.getElementById('spanMailAccountType').innerHTML = "Import from Yahoo" ; 
           break ;
        case "2" :
           document.getElementById('spanMailAccountType').innerHTML = "Import from Hotmail" ; 
           break ;
        case "3" :
           document.getElementById('spanMailAccountType').innerHTML = "Import from Gmail" ; 
           break ;
     }
    document.getElementById('divSecondBlock').style.display = "block";     
     var ouser = document.getElementById('ctl00_cph_txtUserName') ; 
    if(ouser != null) ouser.focus() ;     
    var hdField = document.getElementById("ctl00_cph_hdMailClient");
    hdField.value = source ;
} 
function serializeInputData(elmID, restrainTo)
{
    var o = $(elmID).getElementsByTagName('input');
    var p = $(elmID).getElementsByTagName('textarea');
    var s = $(elmID).getElementsByTagName('select');
    var qss = "";
    
    for(i=0; i<o.length; i++)
    {
        if(typeof(restrainTo) != 'undefined' && restrainTo.indexOf(o[i].name) == -1)
            continue;

        v = Form.Element.serialize(o[i]);
        if(typeof(v) != 'undefined')
        {
            if(qss!="")
                qss += "&";
            qss +=  v ;
        }
    }
    for(i=0; i<p.length; i++)
    {
        if(typeof(restrainTo) != 'undefined' && restrainTo.indexOf(p[i].name) == -1)
            continue;

        v = Form.Element.serialize(p[i]);
        if(typeof(v) != 'undefined')
        {
            if(qss!="")
                qss += "&";
            qss +=  v ;
        }
    }
    for(i=0; i<s.length; i++)
    {
        if(typeof(restrainTo) != 'undefined' && restrainTo.indexOf(s[i].name) == -1)
            continue;

        v = Form.Element.serialize(s[i]);
        if(typeof(v) != 'undefined')
        {
            if(qss!="")
                qss += "&";
            qss +=  v ;
        }
    }
    return qss;
}

getPosition = function(elm) 
{
    var x = 0;
    var y = 0;
    obj = elm;
    if ( obj.offsetParent ) 
    {
        x = obj.offsetLeft;
        y = obj.offsetTop;
        while ( obj = obj.offsetParent ) 
        {
            x += obj.offsetLeft;
            y += obj.offsetTop;
        }
    }
    return { x:x, y:y };
}

getArea = function(elm) 
{
    var position = getPosition(elm);
    var area = new Object();
    area.topLeftX = position.x;
    area.topLeftY = position.y;
    area.bottomRightX = position.x + this.offsetWidth;
    area.bottomRightY = position.y + this.offsetHeight;
    return area;
}
geth = function(elm)
{
    var a = getArea(elm);
    return a.topLeftY - a.bottomRightY;
}
function deleteRecipe(recipeID)
{
    if(confirm("Do you really want to delete this Recipe?"))
        window.location.href= g_FieldflyApplicationPath + "/Member/MyRecipes.aspx?Mode=Delete&RecipeID=" + recipeID;
}
function deleteBlog(blogID)
{
    if(confirm("Do you really want to delete this Blog?"))
        window.location.href= g_FieldflyApplicationPath + "/Member/MyBlog.aspx?Mode=Delete&BlogEntryIDID=" + blogID;
}

function AddMovieView(movieID, setPrerollViewedCookie){
    prmPreRollViewed = "0"; //default to NO
    if (typeof setPrerollViewedCookie != "undefined") 
        prmPreRollViewed = setPrerollViewedCookie;
    CallServerAjaxAddMovieView("AddMovieView|"  + movieID +"|" + prmPreRollViewed);    
}
function AjaxAddMovieViewResponse(args, context){
}
function WriteWidth(elm) {
    var dimensions = $(elm).getDimensions();
    $(elm).innerHTML=dimensions.width;
}
function ShowWidth() {

    var sss = 'ss'+Math.floor(89999999 * Math.random() + 10000000);
    document.write('<div id="' + sss + '"></div>');
    setTimeout('WriteWidth("'+sss+'");',2000);
}
function SearchAllForums() {
    var pagevarnames = ["p", "q", "mode"];
    if ($("q").value.strip().length == 0) {
        $("SearchError").show();
        $("SearchError").style.backgroundColor = '#ffcccc';
        $("SearchError").style.color = "#000000";
        $("SearchError").style.position = "absolute";
        $("SearchError").style.float = "left";
        $("q").focus();
        return false;
    }
    $("p").value = 1;
    $("mode").value = "search";
    window.location.href = g_MJApplicationPath + "ForumTopics.aspx?" + serializeInputData("ForumSearchForm", pagevarnames);
    return false;
}


