function resizepage() {
// DEPRECATED this is called from the user pages (the ones generated from liquid templates)
}

var newwin;
function funautologin(frmaction)
{
    document.frmautologin.action=frmaction+"/index.html";
    document.frmautologin.submit();
}
function func()
{
    alert("This link will be active after your Web site is published.");
}
function blinkText()
{
    blinkdiv = document.getElementById('dashboard_promotion').style;
    (blinkdiv.visibility == 'hidden') ? blinkdiv.visibility = "visible" : blinkdiv.visibility = "hidden";
    setTimeout("blinkText()", 700);
}
function searchimg1() {
    var s1 =  "NoImage";

    page_id = document.getElementById("pageid").value;
    gg = document.getElementById('pageid').value;
    
    var page = document.getElementById("header_img").value;

    if(page.length <=0) {
        page_id = gg;
    } else {
        page_id = document.getElementById("header_img").value;
    }

    document.getElementById('dragframe').src = "/imgupload/index?searchimg="+s1+"&pageid="+page_id;
    parent.document.getElementById('frameid').src = "/designer/render_userdesignframe?pageid="+pageid;
}

function launchwin(winurl,winname,winfeatures)
{
    //This launches a new window and then
    //focuses it if window.focus() is supported.
    newwin = window.open(winurl,winname,winfeatures);
    if(javascript_version > 1.0)
    {
        //delay a bit here because IE4 encounters errors
        //when trying to focus a recently opened window
        setTimeout('newwin.focus();',250);
    }
}

function slideusemedia(url,id,type) {
    alert("Choosen slide show has been inserted sucessfully");
    window.frames.frameid.useslidechild(url,id,type);
}
function usemediachild(url,type) {
    document.frmcontent.type.value= type;
    document.frmcontent.usemedia.value= url;
    document.frmcontent.submit();

}
function setmediachild(url,page_id,type) {
    document.frmpagetop.usemedia.value= url;
    document.frmpagetop.pageid.value= page_id;
    document.frmpagetop.imgtype.value =type;
    alert("Page header has been changed successfully");
    document.frmpagetop.submit();

}
function usemediaheader(url,type) {
    page_id = window.frames['parent'].document.getElementById("pageid").value;
    gg = window.frames['parent'].document.getElementById('pageid').value;
    var page = document.getElementById("header_img").value;
    if(page.length <=0)
    {
        page_id = gg;
    }
    else
    {
        page_id = document.getElementById("header_img").value;
    }
    window.frames.frameid.setmediachild(url,page_id,type);
}
function usemedia(url,type) {
    window.frames.frameid.usemediachild(url,type);
    alert("Chosen file has been inserted successfully");
}

function fun(error)
{
    document.getElementById(error).focus();
}

function showimg(bigimg)
{
    document.getElementById('bigimg').innerHTML = "<img src='/images/layouts/"+bigimg+"' height='450' width='700' onclick=Element.hide('bigimg') onmouseout=Element.hide('bigimg') >";
    document.getElementById('bigimg').style.visibility = 'visible';
}

function clearText(txtbox) {
    document.frm_newpage.pagename.value="";
}
function clearIDX(){
    document.frm_idx.txt_idx.value="";
}
function getDocHeight(doc) {
    var docHt = 0, sh, oh;
    if (doc.height) {
        docHt = doc.height+ 50 + "px";
    }
    else if (doc.body) {
        if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
        if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
        if (sh && oh) docHt = Math.max(sh, oh);
        docHt = docHt + 70 + "px";
    }
    if (doc.height == "100%") {
        docHt = "50px";
    }
    return docHt;
}

function iframescroll() {
//window.moveTo(555,22);
}

function setIframeHeight(iframeName) {
    var iframeWin = window.frames[iframeName];
    var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
    if ( iframeEl && iframeWin ) {
        iframeEl.style.height = "auto";
        var docHt = getDocHeight(iframeWin.document || iframeEl);
        if (docHt) iframeEl.style.height = docHt;
    }
}

function hideMenu(divid)
{
    document.getElementById('src_child').style.visibility = 'hidden';
}

function concealEmail(e,n) {
    var s=e;
    var t=n
    var x = '<a href="&#109;a&#105;l&#116;&#111;:';
    var y = ''; for (i=0;i<s.length;i++) {
        y += '&#' +  s.charCodeAt(i) + ';';
    }
    var z = x+y+'">'+t+'<\/a>';
    return z
}

function searchresult(mode){
    var url = "/searchresult.html" +
    "?agent_id="         + document.getElementById("sales_id").value          +
    "&baths="            + document.getElementById("bathrooms").value         +
    "&beds="             + document.getElementById("bedrooms").value          +
    "&cid="              + document.getElementById("company_id").value        +
    "&office_id="        + document.getElementById("office_id").value         +
    "&price_max="        + document.getElementById("price_max_search").value  +
    "&price_min="        + document.getElementById("price_min_search").value  +
    "&qry="              + document.getElementById("txtMls_City_State").value
    "&wwsrch="           + "1"
    // document.getElementById("office_mailid").value
    // document.getElementById("agent_name").value
    if (mode == 2) {
        window.open(
            url + "&mode=office" + "&la=1",
            "preview",
            "height=620,width=555,top=40,left=40,scrollbars=auto,resizable=no,menubar=no,toolbar=no,location=no"
            );
    } else {
        window.open(
            url + "&mode=agents", // + "&la=0",
            "preview",
            "height=620,width=555,top=40,left=40,scrollbars=auto,addressbar=no,resizable=no,menubar=no,toolbar=no,location=no"
            );
    }
}

function contact_search(id,email) {
    window.open('http://c21wwcrest.idx.net/c21_email_associate.php?associate_email='+email, 'Contactdetails','width=550, height=477');
}

var HintClass = "hintTextbox";
var HintActiveClass = "hintTextboxActive";

// define a custom method on the string class to trim leading and training spaces
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
};


function initHintTextboxes() {
    var inputs = document.getElementsByTagName('input');
    for (i=0; i<inputs.length; i++) {
        var input = inputs[i];
        if (input.type!="text")
            continue;

        if (input.className.indexOf(HintClass)!=-1) {
            input.hintText = input.value;
            input.className = HintClass;
            input.onfocus = onHintTextboxFocus;
            input.onblur = onHintTextboxBlur;
        }
    }
}

function onHintTextboxFocus() {
    var input = this;
    if (input.value.trim()==input.hintText) {
        input.value = "";
        input.className = HintActiveClass;
    }
}

function onHintTextboxBlur() {
    var input = this;
    if (input.value.trim().length==0) {
        input.value = input.hintText;
        input.className = HintClass;
    }
}

function videoPlay(file_url){
    if (detectQuickTime()) {
        replace_div = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' width='220' height='200'><param name='src' value='"+file_url+"'/><param name='controller' value='true' /><PARAM name='autostart' value='true'><param name='loop' value='true'/><object type='video/quicktime' data='"+file_url+"' width='220' height='200' class='mov'><param name='controller' value='true' /></object></object>";
    }
    else if (detectWindowsMedia()) {
        replace_div = "<OBJECT id='media' style='LEFT: 2px; TOP: 100px' codeBase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=7,0,0,1954' type='application/x-oleobject' standby='Loading Microsoft Windows Media Playerco&#13;&#10;mponents...' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' VIEWASTEXT width='220' height='200'><PARAM NAME='BufferingTime' VALUE='5'><PARAM NAME='DisplayMode' VALUE='0'><PARAM NAME='EnableContextMenu' value='true'><PARAM NAME='PreBuffer' VALUE='True'><PARAM NAME='ShowStatusBar' VALUE='true'><PARAM NAME='Volume' VALUE='400'><PARAM NAME='Filename' VALUE='"+ file_url +"'><PARAM NAME='URL' VALUE='"+ file_url +"'><EMBED Type='video/x-ms-asf-plugin' pluginspage='http://www.microsoft.com/windows/mediaplayer/download/default.asp'  name='media' id='media' loop='True' AutoStart='True' ShowControls='1' width='220' height='50' src='"+ file_url + "'></OBJECT>"
    }
    else if (detectReal()) {
        replace_div = "<OBJECT ID=RVOCX CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='220' height='200'><PARAM name='src' value='"+ file_url +"'><PARAM name='autostart' value='true'><param name='loop' value='true'/><PARAM name='controls' value='imagewindow'><PARAM name='console' value='video'><EMBED TYPE='audio/x-pn-realaudio-plugin' SRC='"+ file_url +"' width='220' height='200' AUTOSTART='true' CONTROLS='imagewindow' CONSOLE='video'></EMBED></OBJECT>"
    }
    else {
        replace_div = " "
        alert ('Install QuickTime Plugin to play Media file.');
    }
    document.getElementById('movie_div').innerHTML = replace_div;
}

var detectableWithVB = false;
var pluginFound = false;

function detectQuickTime() {
    pluginFound = detectPlugin('QuickTime');
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectQuickTimeActiveXControl();
    }
    return pluginFound;
}

function detectReal() {
    pluginFound = detectPlugin('RealPlayer');
    if(!pluginFound && detectableWithVB) {
        pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
            detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
            detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
    return pluginFound;
}

function detectWindowsMedia() {
    pluginFound = detectPlugin('Windows Media');
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return pluginFound;
}



function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
        var pluginsArrayLength = navigator.plugins.length;
        // for each plugin...
        for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
            // loop through all desired names and check each against the current plugin name
            var numFound = 0;
            for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
                // if desired plugin name is found in either plugin name or description
                if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
                    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
                    // this name was found
                    numFound++;
                }
            }
            // now that we have checked all the required names against this one plugin,
            // if the number we found matches the total number provided then we were successful
            if(numFound == daPlugins.length) {
                pluginFound = true;
                // if we've found the plugin, we can stop looking through at the rest of the plugins
                break;
            }
        }
    }
    return pluginFound;
} // detectPlugin

var browserName = navigator.appName;
if (browserName == 'Microsoft Internet Explorer') {
    if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
        document.writeln('<script language="VBscript">');

        document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
        document.writeln('detectableWithVB = False');
        document.writeln('If ScriptEngineMajorVersion >= 2 then');
        document.writeln('  detectableWithVB = True');
        document.writeln('End If');

        document.writeln('\'this next function will detect most plugins');
        document.writeln('Function detectActiveXControl(activeXControlName)');
        document.writeln('  on error resume next');
        document.writeln('  detectActiveXControl = False');
        document.writeln('  If detectableWithVB Then');
        document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
        document.writeln('  End If');
        document.writeln('End Function');

        document.writeln('\'and the following function handles QuickTime');
        document.writeln('Function detectQuickTimeActiveXControl()');
        document.writeln('  on error resume next');
        document.writeln('  detectQuickTimeActiveXControl = False');
        document.writeln('  If detectableWithVB Then');
        document.writeln('    detectQuickTimeActiveXControl = False');
        document.writeln('    hasQuickTimeChecker = false');
        document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
        document.writeln('    If IsObject(hasQuickTimeChecker) Then');
        document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
        document.writeln('        detectQuickTimeActiveXControl = True');
        document.writeln('      End If');
        document.writeln('    End If');
        document.writeln('  End If');
        document.writeln('End Function');

        document.writeln('</scr' + 'ipt>');
    }
}

function radioButtonValidate(form) {
    var btn = valCheck(document.getElementsByName("page_layout[]") );
    if (btn == null) {
        alert('Please select a layout'); return false;
    }
    else {
        if (confirm("Warning: Selecting a page layout will remove all content you have on this page")) {
            jQuery.blockUI();
            return true;
        }
        else 
            return false
    }
}
function valCheck(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {
            cnt = i; i = -1;
        }
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
