﻿/* JScript File
Global String*/
var IntErr = "Lo sentimos pero ocurrio un error interno, intente de nuevo mas tarde";

/* Search Scripts */
var bx;
var by;
var bty;
/*Gallery Player*/

var curpic = 1 ;
var treg = 0;
var t;
var galleryplaying = false;
var imgctl;
var imgcaption;
var galBigPicsVisible = false;
var galBigPicsImg;
var galBigPicsCaption;
function changepic(wo) {
/*galleryimg is the img ctl in the main control for the gallery*/
imgctl = getctl('galleryimg');
var tmpcaption = '';
    if (imgctl) {
        if (wo  == 'n') {
            if (curpic  == imgarray[0]) {
            curpic = 1;
            } else {
            curpic = curpic + 1;
            }
        }
        if (wo  == 'p') {
            if (curpic  == 1) {
            curpic = imgarray[0];
            } else {
            curpic = curpic - 1;
            }
        }
        if (document.all) {
        imgctl.style.filter = 'blendTrans(duration=1)';
        imgctl.filters.blendTrans.Apply();
        }
        if (treg  == 4 || treg==2) {
           tmpcaption = imgcaptionsarray[curpic];
        }
    checkifpicready(imgarray[curpic],imgctl.id, tmpcaption);
    }
}

/*This guy will do severals things needed when the page loads.*/
/*the mh value, will hold the value of the loaded maincontent*/

function CNYInit() {
showDate();SetHeightOnMain();updateSM('1');checkadholder();
var tm = getctl('maincontent');
        
/*Check if it's IE, if it is, then add the CSS file to fix some stuff*/
    if (Browser.Version() < 7) {
      var fileref=document.createElement("link");
      fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", "plugins/ie6.css");
    }
}

var divloadingvisible = false;
tmpimg = new Image();
function checkifpicready(tmpimgpath, targetctl, caption) {
if (!divloadingvisible) {
tmpimg.src = tmpimgpath;
}
var tmptgtctl = getctl(targetctl);
    if (tmpimg && tmptgtctl) {
        if (!tmpimg.complete) {
        /*Here, do the logic to show the loading in either the maincontent or the big gallery*/
            if (galBigPicsVisible) {
            showdiv('galBigPicsLoadDiv');
            } else {
            showdiv('divloading');            
            }

        divloadingvisible = true;
        clearTimeout(t);
        setTimeout('checkifpicready("'+tmpimgpath+'", "'+targetctl+'", "' +caption+'")', 100);
        } else {
        if (divloadingvisible) {
            /*check if the big gallery load is being shown*/
            if(galBigPicsVisible) {
            hidediv('galBigPicsLoadDiv');
            } else {
            hidediv('divloading');
            }
            
        
        divloadingvisible = false;
        }
        tmptgtctl.src = tmpimg.src;
        if (galBigPicsVisible) {
            galBigPicsImg = getctl('imgBigPics');
            if (galBigPicsImg) {
                galBigPicsImg.src = tmpimg.src;
            }
        }
            if (treg  == 4 || treg==2) {
            var dch = getctl('imgcaption');
                if (galBigPicsVisible) {
                galBigPicsCaption = getctl('divImgCaption');
                }
                if (caption != '') {
                    if (dch) {
                    dch.style.display = '';
                    dch.innerHTML = caption;
                    }
                    if (galBigPicsCaption) {
                    dch.style.display = '';
                    galBigPicsCaption.innerHTML = caption;                    
                    }
                } else {
                    if (dch) {
                    dch.style.display = 'none';
                    }
                    if (galBigPicsCaption) {
                    galBigPicsCaption.style.display = 'none';
                    }                    
                }
            }
            if (document.all) {
            tmptgtctl.filters.blendTrans.Play();
            }
        if (galleryplaying) {t = setTimeout("changepic('n')", 5000);}                        
        }
    }

    if (galBigPicsVisible) {
                var tctl = getctl('galBigPics');
                centerdiv(tctl,true);
    }   
}

/*Simple Load Image*/

function simpleLoadPic (divtoshow, imgctlname, imgtoload, divload, working) {
var loading;
    /*Check if a value is being passed to the working param*/
    if (typeof(working) == 'undefined') {
        loading = false;
    } else if (working == true) {
        loading = true;
    } else {
        loading = false;
    }

    if (loading) {
    
    } else {
    var divtoshowctl = getctl(divtoshow);
    var imgctl = getctl(imgctlname);
    var divloadctl = getctl(divload);
    }
    
}

/*This will check if a pic is loaded completely, if not, then it will return false*/
function simplePicCheck(ctl) {
    if (ctl) {
        if (ctl.complete) {
        return true;
        } else {
        return false;
        simplePicCheck(ctl)
        }
    }
} 



function showGalBigPics() {
    setGalBigPicsPicture(curpic);
}

function hideGalBigPics() {
Hidedimdiv('galBigPics');
galBigPicsVisible = false;
}

function setGalBigPicsCaptionSize() {
var cctl = getctl('divImgCaption');
var ictl = getctl('imgBigPics');
    if (ictl && cctl) {
       cctl.style.maxWidth = ictl.clientWidth - 40;
    }
}

function setGalBigPicsPicture(picID) {
var ibp = getctl('imgBigPics');
var irp = getctl('galleryimg');
    if (ibp) {
    
    ibp.src = imgarray[picID];
        if (typeof(imgcaptionsarray) != 'undefined') {
            var icaption = imgcaptionsarray[picID];
                if (icaption != '') {
                    var icctl = getctl('divImgCaption');
                    icctl.innerHTML = icaption;
                    //setGalBigPicsCaptionSize(ibp,icctl);
                }
            
         }
         
         if (typeof(imgtitlesarray) != 'undefined') {
            var ititle = imgtitlesarray[picID];
                if (ititle != '') {
                    var icctl = getctl('divImgTitle');
                    icctl.innerHTML = ititle;
                    
                }
            
         }
    DimBkg('galBigPics', true);
    galBigPicsVisible = true;
    }
}

function turngallery(what) {
    if (what  == 'on') {
    galleryplaying = true;
    t = setTimeout("changepic('n')", 5000);
    }
    if (what  == 'off') {
    galleryplaying = false;
    clearTimeout(t);
    }
}

function updateppbutton() {
var ppctl = getctl("ppanchor");
    if (!galleryplaying) {
        if (ppctl) {
        ppctl.style.backgroundImage = "url('images/gallery player/playbutton.gif')";
        }
    } else {
    if (ppctl) {
        ppctl.style.backgroundImage = "url('images/gallery player/pausebutton.gif')";
        }
    }

}
function togglerotator(what) {
    if (typeof(what) == 'undefined') {
        if (!galleryplaying) {
        t = setTimeout("changepic('n')", 5000);
        galleryplaying = true;
        } else {
        clearTimeout(t);
        galleryplaying = false;
        }
    } else {
        if (what == 'on') {
         t = setTimeout("changepic('n')", 5000);
         galleryplaying = true;       
        } else if (what == 'off') {
        clearTimeout(t);
        galleryplaying = false;        
        }
    }
    updateppbutton();
}   
/*gallery functions end here */

/*Sidebar premium divlist */
var divlist = new Array();
var totaldivlist;
function showgroup(groupname) {
var ctl; 
var smit = getctl('divsminfo');
    for (i = 0; i<totaldivlist; i++) {
    ctl = getctl(divlist[i]);
        if (ctl) {
        ctl.style.display = 'none';
        }
    }
    if (groupname  == 'divgeneral') {
        if (smit) {
        smit.style.display = 'none';
        }
    } else {
        if (smit) {
        smit.style.display = '';
        }
    }
    if (groupname  == 'all') {
        for (i = 0; i<totaldivlist; i++) {
        ctl = getctl(divlist[i]);
            if (ctl) {
            ctl.style.display = '';
            }
        }
        if (smit) {
        smit.style.display = 'none';
        }
    } else {
    ctl = getctl(groupname);
        if (ctl) {
        ctl.style.display = '';
        }
    }
}

function togglemenu(name) {
var allmenu = getctl('divallmenu'); 
var gmenu = getctl('divgroupmenu');
var divad = getctl('adholder');

if (name  == 'all') {
    if (allmenu && gmenu) {
    allmenu.style.display = '';
    gmenu.style.display = 'none';
    toggletop('on');
                if (divad) {
                divad.style.display = '';
                }
    }
}
if (name  == 'group') {
    if (allmenu && gmenu) {
    allmenu.style.display = 'none';
    gmenu.style.display = '';
    toggletop('off');
                if (divad) {
                divad.style.display = 'none';
                }
    }
}
}

function toggletop(onoff) {
var topctl;
    if (onoff  == 'on') {
        for (i=0;i<20;i++) {
        topctl = getctl('span-top' + i);
            if (topctl) {
            topctl.style.display = '';
            }
        }
    } else if (onoff  == 'off') {
        for (i=0;i<20;i++) {
        topctl = getctl('span-top' + i);
            if (topctl) {
            topctl.style.display = 'none';
            }
        }
    }
}
/*Functions for Premium end here*/

/*Searchresults*/
function OptionsDropdown(valuestr) {
var tmpstr = new String (valuestr);
var i = tmpstr.indexOf('popitup',0);
if (i >=0) {
eval(valuestr);
}else{
window.location=valuestr;
}
}

function refreshcatpage(){
var tmptxtbox = document.getElementById('searchcattxbox');
    if (tmptxtbox) {
    window.location = "showcat.aspx?cat=" + tmptxtbox.value + "#SC";
    }
}

function refreshsearchcitypage(){
var tmptxtbox = document.getElementById('searchcattxbox');
    if (tmptxtbox) {
    window.location = "searchcity.aspx?query=" + tmptxtbox.value;
    }
}

/*The following function will open the popups*/
function popitup(url, type) {
var settings;
var infosettings = 'height=400,width=300,scrollbars=yes';
var comparisonsettings = 'height=400,width=700,scrollbars=yes';
var mailsettings = 'height=400,width=380,scrollbars=yes,resizable=no';
var formsettings = 'scrollbars=1,width=460,height=600';
var fullsettings = 'height:600,width=800,addressbar=yes,scrollbars=1,menubar=yes,toolbar=yes';
	if (type  == 'full') {
	window.open(url);
	} else {
	if (type  == 'form')	{settings = formsettings;}
    if (type  == 'comparison')	{settings = comparisonsettings;}
	if (type  == 'info') {settings = infosettings;}


	newwindow=window.open(url,'', settings);
	    if (window.focus) {
	        try {
    	    newwindow.focus();
	        } catch (ex) {
	        }
    	    
	    }
	
	}

	/* return false;*/
}

function showcitysearchcat(countystr, citystr, zcstr) {
var inputtxtbox = document.getElementById('SCBTxtBox');
    if (inputtxtbox) {
    var inputstr = inputtxtbox.value;
    if (inputstr  == '') {
    inputstr = '_NS';
    }
    window.location ='showcity.aspx?county=' + countystr + '&ZC=' + zcstr + '&city=' + citystr + '&CSC=' + inputstr + '#SC';
    }
}

function UpdateResList(str) {
var _nearbylist = document.getElementById('nearbycities');
var _citylist = document.getElementById('citylist');
var _ziplist = document.getElementById('ziplist');
    if (_nearbylist && _citylist && _ziplist) {
        if (str== 'nearbylist') {
        _nearbylist.style.display = 'block';
        _citylist.style.display = 'none';
        _ziplist.style.display = 'none';
        }
        if (str== 'citylist') {
        _nearbylist.style.display = 'none';
        _citylist.style.display = 'block';
        _ziplist.style.display = 'none';
        }
        if (str== 'ziplist') {
        _nearbylist.style.display = 'none';
        _citylist.style.display = 'none';
        _ziplist.style.display = 'block';
        }
    }
    /*Stting the height on Main, after the change*/
    SetHeightOnMain();
}
/*This will clic the told btn.*/
function cbc (name){
var tmpctl = getctl(name);
    if (tmpctl) {
        tmpctl.click();
        event.keyCode = 0;

    }
}

/*Master functions 
The following function will execute jscript when enter is pressed*/
function ifenterpressed(Exec, e) {
EnterPressed(e);
if (Enterkeypressed  == 'Yes') {
eval(Exec);
e.keyCode = 0;
return false;
}
}
/*The following is used by showcity.aspx*/
function scifenterpressed(countystr, citystr, zcstr, event) {
EnterPressed(event);
if (Enterkeypressed  == 'Yes') {
var inputtxtbox = document.getElementById('SCBTxtBox');
    if (inputtxtbox) {
    var inputstr = inputtxtbox.value;
    if (inputstr  == '') {
    inputstr = '_NS';
    }
    window.location ='showcity.aspx?county=' + countystr + '&ZC=' + zcstr + '&city=' + citystr + '&CSC=' + inputstr + '#SC';
    event.KeyCode = 0;
    }
}
}
/*This is the function that checks if enter was pressed.*/
function EnterPressed(e) {
/* Code adapted from Jennifer Madden
 http:jennifermadden.com/162/examples/stringEnterKeyDetector.html */

  var characterCode;
  characterCode =e.keyCode? e.keyCode : e.charCode;


  if (characterCode  == 13) {
  Enterkeypressed = 'Yes';  
  /* Enter key is 13 */
  }
  else {
  Enterkeypressed = 'No';
}
}

/*selSM will set the current Search Method*/
var curSM = '1';
function selSM(whichtype) {
    if (whichtype  == '2' || whichtype  == '3') {
        curSM = whichtype;
    } else { 
        curSM = '1';
    }
}
function updateSM (whichone) {
var tmpctl;
    if (whichone < 4 || whichone >= 1) {
    var mmon = getctl('mMon');
    if (mmon) {
    mmon.value = whichone;
    }
    curSM = whichone;
        for (var i=0;i<4;i++) {
        tmpctl = getctl('tb' + (i + 1));
            if (tmpctl) {
                tmpctl.style.backgroundPosition = '0px 0px';
                
            }
        }
        tmpctl = getctl('tb' + curSM);
        if (tmpctl) {
            tmpctl.style.backgroundPosition = '-155px 0px';
        }
    swapnumberdivs(curSM, 3, 'SM');
    }
}

/*showResults will check which search method is selected and will 
show results based on that.*/
function showResults() {
    /*If method selected is Phone*/
    if (curSM  == 2) {
        var acode = getctl('AreaCode');
        var adigits = getctl('ADigits');
        var bdigits = getctl('BDigits');
        if (acode && adigits && bdigits) {
        window.location = 'resultsbyphone.aspx?pa=' + acode.value + '&pb=' + adigits.value + '&pc=' + bdigits.value;
        /*return true;*/
        } else {
        alert(IntErr);
        }
    }
    /*If method selected is Person*/
    if (curSM  == 3) {

    /*create a point counter, remember that at least two spaces has to be filled.*/
        var pcounter = 0;
        var fname = getctl('PName');
        var lname = getctl('PLastName');
        var cat = getctl('PCat');
        if (fname && lname && cat) {
            if (fname.value != '')  {
            pcounter = pcounter +1;
            }
            if (lname.value != '') {
            pcounter = pcounter +1;
            }
            if (cat.value != '') {
            pcounter = pcounter +1;
            }

            /*check if pcounter total is more than 1*/

            if (pcounter > 1) {
               window.location = "pplresults.aspx?fn=" + fname.value + "&ln=" + lname.value + "&cat=" + cat.value;
                return true; 
            }
        }
    }
    if (curSM !=2 || curSM !=3) {
    SearchByCat();
    }
}

/*the following functin will update which type of search is active
function UpdateButtonOn() {
        if (SearchSelected  == 'divsearchcat') {
            document['CatSearch'].src = 'images/master/Search Buttons/catsearchon.jpg';
            document['PhoneSearch'].src = 'images/master/Search Buttons/phonesearch.jpg';
            document['PersonSearch'].src = 'images/master/Search Buttons/Personsearch.jpg';
            document['BSSCode'].src = 'images/master/Search Buttons/BSSCodesearch.jpg';
        }
        if (SearchSelected  == 'divsearchphone') {
            document['CatSearch'].src = 'images/master/Search Buttons/catsearch.jpg';
            document['PhoneSearch'].src = 'images/master/Search Buttons/phonesearchon.jpg';
            document['PersonSearch'].src = 'images/master/Search Buttons/Personsearch.jpg';
            document['BSSCode'].src = 'images/master/Search Buttons/BSSCodesearch.jpg';
        }
        if (SearchSelected  == 'divsearchperson') {
            document['CatSearch'].src = 'images/master/Search Buttons/catsearch.jpg';
            document['PhoneSearch'].src = 'images/master/Search Buttons/phonesearch.jpg';
            document['PersonSearch'].src = 'images/master/Search Buttons/Personsearchon.jpg';
            document['BSSCode'].src = 'images/master/Search Buttons/BSSCodesearch.jpg';
        }
        if (SearchSelected  == 'divsearchbbcode') {
            document['CatSearch'].src = 'images/master/Search Buttons/catsearch.jpg';
            document['PhoneSearch'].src = 'images/master/Search Buttons/phonesearch.jpg';
            document['PersonSearch'].src = 'images/master/Search Buttons/Personsearch.jpg';
            document['BSSCode'].src = 'images/master/Search Buttons/BSSCodesearchon.jpg';
        }        
}
*/
/*The following makes the div containing the controls to search visible, base on selection.
When extra time is available, fix and reduce code.*/
/*function MakeDivVisible(Divname) {
    var div1 = document.getElementById('divsearchphone');
    var div2 = document.getElementById('divsearchcat');
    var div3 = document.getElementById('divsearchperson');
    var div4 = document.getElementById('divsearchbbcode');
if (Divname  == 'divsearchphone') {
div1.style.visibility = "visible";
div2.style.visibility = "hidden";
div3.style.visibility = "hidden";
div4.style.visibility = "hidden";
}
if (Divname  == 'divsearchcat') {
div1.style.visibility = "hidden";
div2.style.visibility = "visible";
div3.style.visibility = "hidden";
div4.style.visibility = "hidden";
}if (Divname  == 'divsearchperson') {
div1.style.visibility = "hidden";
div2.style.visibility = "hidden";
div3.style.visibility = "visible";
div4.style.visibility = "hidden";
}if (Divname  == 'divsearchbbcode') {
div1.style.visibility = "hidden";
div2.style.visibility = "hidden";
div3.style.visibility = "hidden";
div4.style.visibility = "visible";
}
}*/
/*Function that updates and change the search method (Top Bar)*/
function ChangeSearchMethod(SMethod) {
        SearchSelected = SMethod;
        UpdateButtonOn();
        MakeDivVisible(SMethod);
}

/*Functions that start the searches
To search cats and names within a city.*/
function SearchByCat(){
var _catstr = getctl('CatTxtBox');
var _where = getctl('CityTxtBox');
if (_catstr && _where)
{
window.location="searchresults.aspx?what=" + _catstr.value + "&where=" + _where.value;
}
}
/*To search by name*/
function SearchByName() {
var pfn = getctl('PName');
var pln = getctl('PLastName');
var pcat = getctl('PCat');
    if (pfn && pln && pcat)  {
    window.location="pplresults.aspx?fn=" + pfn.value + "&ln=" + pln.value + "&cat=" + pcat.value ;
    }
}

/*Focus controller Most used in number search.*/
function ControlFocus(ctlSource, LenToJump, ctlTarget){
var cs = getctl(ctlSource);
var ct = getctl(ctlTarget);
if (cs && ct) {
    var ts = cs.value;
    /*var ti = ts.length;*/
    if (ts.length  == LenToJump) {
        ct.focus();
    }
}
}

/*Function to control numbers entered in phone number boxes
If the character entered is not a number then it will not be written*/

      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode ;
         if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            if (charCode  == 13) {
            return false;
            } else {
            event.keyCode = 0;
            return event;
            }
         } else {
         return true;
         }
      }
      
function valkey(what, evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
/*Lines below will validate characters for CNYURL, so only valid and simple characters are entered
which are A-Z, a-z, 0-9, -, _*/
    if (what  == 'cnyurl') {
            if ((charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode > 44 && charCode < 47) || charCode  == 95 || charCode  == 126) {
            return true;
            } else {
            return false;
            }
    }
    /*this detects if the ctl btn is pressed.
    if (what  == 'noctl') {
        if (charCode  == 17 || charCode  == 24) {
        alert('CTRL presionado');
        }
    }*/
}

function chktxtboxlimit(totalallowed, ctltocheck, spanprefix) {
var tmpctl = getctl(ctltocheck);
var tmpspan;
    if (tmpctl) {
    var tmpstr = new String(tmpctl.value);
        if (tmpstr.length >= totalallowed) {
            tmpctl.value = tmpstr.slice(0, totalallowed);

                    if (spanprefix != "") {
            tmpspan = getctl(ctltocheck + spanprefix);
                if (tmpspan) {
                tmpspan.innerHTML = '0';
                }
            }
        } else {
            if (spanprefix != "") {
            tmpspan = getctl(ctltocheck + spanprefix);
                if (tmpspan) {
                tmpspan.innerHTML = totalallowed - (tmpstr.length);
                }
            }
        }

    }
}


/* Date Script*/
var today = new Date();
var DayW = today.getDay();
var DateW = today.getDate();
var MonthW = today.getMonth();
var YearW = today.getYear();
var DayString = "Missing day";
var MonthString = "";

try {
if (DayW >= 0 && DayW < 7) {
DayString = daysStr[DayW];
}
MonthString = monthsStr[MonthW];
} catch (err) {
}

var DateString = "";
   DateString = "" + ((DateW < 10) ? "0" : "") + DateW;
var YearString = "Don't know year";
YearW = YearW + 0000;
YearString = "" + YearW;
try {
    if (timeLng == 'SP') {
    DateString = DayString + " " + DateString + " de " + MonthString + " - ";/* + " de " + YearString + " - "; */
    } else {
    DateString = DayString + ", " + MonthString + "/" + DateString + "/" + YearString + " - ";
    }
} catch(err) {

}

function showDate(){
/*	if (!document.layers&&!document.all)
		return;*/

	var Digital=new Date();
	var hours=Digital.getHours();
	var minutes=Digital.getMinutes();
	var seconds=Digital.getSeconds();
	var dn="AM";
	if (hours>12){
		dn="PM";
		hours=hours-12;
	}
	if (hours ==0) {
	hours=12;}
	if (minutes<=9)
	 {minutes="0"+minutes;}
	if (seconds<=9) 
	{seconds="0"+seconds;}
	myclock=hours+":"+minutes+":"+seconds+" "+dn;

var clockctl = getctl('liveclock');
		if (clockctl) {
	    clockctl.innerHTML=DateString + myclock;
		setTimeout("showDate()",1000);
		}
}

/*++++++++++++Height Checkers ++++++++++++
/*create a var to hold the current main height*/
var minMainHeight;

/*function to save the minimun main height*/
function setMinMainHeight(){
  var d = getctl('maincontent');
  if (d) {
    minMainHeight = d.clientHeight;
  }
}


/*For Main, it will check if sidebar is higher than main
UPDATED, it will set the minHeight on the maincontent based on the height of the sidebar.
so if height of sidebar, is a lot less than maincontent, this will not be reduced too much, since the 
minheight only was set and not the actual height.
*/
function SetHeightOnMain() {
  var swHeight;
  var sw = getctl('sidebarwrapper');
  if (sw) {
  swHeight = sw.clientHeight;
  } else {
  sw = getctl('ctl00_CNYContent_sidebarwrapper');
      if (sw) {
      swHeight = sw.clientHeight;
      }
  }
  var d = getctl('maincontent');
  if (d) {
    /*if (d.clientHeight < swHeight) { */
    if (d && sw) {
    d.style.minHeight = swHeight + 'px';
    }
  }
}    

/*The SetHeightOnSW works similar to the onMain, difference is, instead of 
fixing height based on sidewrapper height, checks if sidewrapper height is 
lower than the original height on main, this is used on search results, where
user chooses list of zipcodes and height on main increases, but when he comes back
to cities around, height on main used to keep the increased height, this function
will check if sidewrapper height is lower than the original height on main, if so, it 
will set the height on main to the original one.
*/
function SetHeightOnSW() {
    var swHeight;
    var sw = getctl('sidebarwrapper');
      var d = getctl('maincontent');
    if (sw && d) {
        if (sw.clientHeight < minMainHeight) {
        d.style.minHeight = minMainHeight + 'px';
        }
        /*alert(sw.clientHeight);*/
    }
}  
  
  /*This was added because of a problem with Firefox in the main searchbox.*/
  var browser = GetBrowser();
  if (browser  == "Firefox") {
    var tmpctl1 = getctl('divCatBlock1');
    var tmpctl2 = getctl('divCatBlock2');
    if (tmpctl1 && tmpctl2) {
    tmpctl1.style.marginTop = '0px';
    tmpctl2.style.marginTop = '0px';
    }
  }  

        /*Justa test*/
        try 
        {
        var flash = CheckFlash();
        /*alert("String found is" + flash); */
        }
        catch (err)
        {
        /*alert("An error ocurred"); */
        var hctl = getctl('divFlashIntro');
            if (hctl) {
            hctl.innerHTML += 'Your browser does not have Flash Installed, <a href="http://www.macromedia.com/go/getflashplayer">Click here</a> to download it.';
            }
        }
 
/* Following will check if adholder is bigger than main, if so, adholder will be hidden.*/
function checkadholder() {
  var swHeight;
  var sw = getctl('adholder');
  var d = getctl('maincontent');
  var rc = getctl ('divrpagecontrols');
  if (typeof adheight  == 'undefined') {
  adheight = 600;
  }
  if (d) {
  swHeight = d.clientHeight;
  }
  if (d && sw && rc) {
    if (swHeight < adheight + rc.clientHeight) {
    sw.style.display = 'none';
    } else {
    sw.style.display = '';
    }
  }
}



/*/AJAX Functions*/
var ajaxtdiv = '';
/*/checkcnyurl will check if the cnyurl entered at UI is available.*/
function checkcnyurl() {
var txtholder = getctl('txtboxcnyurl');
var pta = "../ajax helpers/searchfunctions.aspx";
var _q = txtholder.value;
ajaxtdiv = 'divcnyurlmessage';
runAJAX (pta,_q, 'cnyurl');

}

/*The Actual AJAX Code*/
var xmlHttp;
function runAJAX(pta, pq, qt) 
/*function getviaAJAX(ftr, pta, pq)

PTA -> PagetoAsk
PG -> PageQuery
QT -> QueryType
tdiv -> TargetDiv*/

{ 
xmlHttp=GetXmlHttpObject();
    if (xmlHttp ==null)
      {
      alert ("Lo sentimos pero su navegador o es compatible con AJAX.\nLe recomendamos actualizarlo.\nNuestro equipo fue notificado sobre este error.");
      return;
      } 
var url=pta;
url=url+"?q="+ pq;
url=url+"&sid="+Math.random();
url=url+"&t="+qt;
xmlHttp.onreadystatechange=fillDiv;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function fillDiv() 
{ 
    if (xmlHttp.readyState==4)
    { 
    var tmpres = getctl(ajaxtdiv);
        if (tmpres) {
        tmpres.innerHTML=xmlHttp.responseText;
        ajaxtdiv = null;
        }
    }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  /* Firefox, Opera 8.0+, Safari*/
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  /* Internet Explorer*/
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


var sb = document.getElementsByTagName('HTML');

function DimBkg (divtoshow, keepmainbar) {
var db = getctl('dimdiv');
var ds = getctl(divtoshow);
var kmb;
if (typeof(keepmainbar) == 'undefined') {
kmb = false;
} else if (keepmainbar == true) {
kmb = true;
} else {
kmb = false;
}
    if (db && ds) {
    db.style.display = '';
    ds.style.display = '';
    centerdiv(ds, kmb);
        if (sb && kmb == false) {
        sb[0].style.overflow = 'hidden';
        }
    }
}

function Hidedimdiv (divtohide) {
var db = getctl('dimdiv');
    if (db) {
    db.style.display = 'none';
            if (sb) {
                    sb[0].style.overflow = 'auto';
                        
                            var dh = getctl(divtohide);
                            if (dh) {
                            dh.style.display = 'none';
                            }
                        
                    }
    }
}
/*The following function will hide the div specified.*/
function invisiblediv(name) {
var tmpctl = getctl(name);
    if (tmpctl) {
    tmpctl.style.visibility = 'hidden';
    }
}

function getbxy()
/*the byt is getting the position of the page, it might be scrolled, if it is not retrieved then 
div can be centered on top*/
{
 if (typeof window.innerWidth != 'undefined')
 {
   bx = window.innerWidth - 10;
   by = window.innerHeight;
   bty = window.pageYOffset;

 }
 else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
 {
  bx = document.documentElement.clientWidth;
  by = document.documentElement.clientHeight;
  bty = document.documentElement.scrollTop;
 }
 else
 {
   bx = document.getElementsByTagName('body')[0].clientWidth;
   by = document.getElementsByTagName('body')[0].clientHeight;
   bty = document.getElementsByTagName('body')[0].scrollTop;
 }
}

function centerdiv (d, isAbsolute) {
getbxy();

/*The is absolute will check is position is fixed or absolute, if it's the last, then some extra math will be done.
if no value was provided, then this will be bypassed and taken as false*/
var isAb;
if (typeof(isAbsolute) == 'undefined') {
isAb = false;
} else {
isAb = isAbsolute;
}

    if (d) {
    var tmpy;
    if (isAb == true) {
    /*div position is absolute, so fix the position to be centered adding up the scrolled space.*/
    if (d.clientHeight > by) {
    tmpy = bty
    } else {
    tmpy = ((by /2) + bty) - (d.clientHeight / 2);
    }
    
    } else {
    tmpy = by / 2 - d.clientHeight /2;
    }
    var tmpx = bx /2 - d.clientWidth / 2 ;
    if (tmpx < 0) {tmpx = 0;}
    if (tmpy < 0) {tmpy = 0;}
    d.style.top = tmpy + 'px';
    d.style.left = tmpx + 'px';
    }
}


/*_____________________________________*/

function getctl(dname) {
var e = document.getElementById(dname);
if (e) {
return e;
} else {
e = document.getElementById('ctl00_CNYContent_' + dname);
    if (e) { 
    return e;
    } else {
    e = document.getElementById('ctl00_' + dname);
        if (e) {
        return e;
        }  else {
        e = document.getElementById('ctl00$CNYContent$' + dname);
            if (e) {
            return e;
            } else {
                e = document.getElementById('ctl00$' + dname);
                if (e) {
                return e;
                }      
            }
        }
    }
}
}

/*Directions*/
var pointb = '';
var Alreadyvisible=false;
var pointbalertstr = '' ;

function showdirections() {
    var divctl = getctl('pointa');
    if (pointb  == '') {
    DimBkg('pointa');
    }

}
function hidediv(divname) {
var dn = getctl(divname);
    if (dn) {
    dn.style.display = 'none';
    }
}

function showdiv(divname) {
var s_div = getctl(divname);
    if (s_div) {
    s_div.style.display = '';
    }
}

/*Change directions language*/
var viewingaltdirectionslink = false;
function detailchangedirectionslanguage(lng) {
/*lastlanguage = curlng;*/
curlng = lng;
updatepointbspan();
var altlinkctl = getctl('spanaltdirectionslink');
var locallinkctl = getctl('spanlocaldirectionslink');
    if (altlinkctl && locallinkctl) {
        if (viewingaltdirectionslink) {
        viewingaltdirectionslink = false;
        altlinkctl.style.display = '';
        locallinkctl.style.display = 'none';
        } else {
        viewingaltdirectionslink = true;
        altlinkctl.style.display = 'none';
        locallinkctl.style.display = '';
        }
    
    }
}

/*function to avoid showing several instructions on href*/
function bdGetDir(whichone) {
    if (whichone == '3') {
    DimBkg('pointa');dstxt('dst');spt();
    } else if (whichone == '2') {
    DimBkg('pointa');dstxt('dst');dmode="w";
    } else {
    DimBkg('pointa');
    dstxt('r');
    dmode="d";
    }
    
}

var dmode;
/*spt simple sets dmode to pt*/
function spt() {
dmode="pt";
}

/*dstxt function will disable the state txtbox*/
function dstxt(wtd) {
var dst1 = getctl('divst1');
var dst2 = getctl('divst2');
var sttxt = getctl('state');
    if (dst1 && dst2 && sttxt) {
        if (wtd == 'dst') {
        dst1.style.display = 'none';
        dst2.style.display = '';
        /*dmode = 'w';*/
        sttxt.value = "NY";
        } else {
        dst1.style.display = '';
        dst2.style.display = 'none';
        /*mode = 'd';*/
        }

    }
}

/*The function below is of BSSDetail and Pdetail only*/
            var lng;
            var pointa = '';
            var ptlng;
            
           function setLngs() {
                            if (curlng  == 'SP') {
                            lng = 'es_ES';
                            ptlng = 'es';
                            } else {
                            lng = 'en_US';
                            ptlng = 'en';
                            }
           }
           
function updatepointbspan() {
var addr = getctl('address');
var city = getctl('city');
var state = getctl('state');
var zc = getctl('zipcode');

pointa = '';
        var divdm = getctl('divdm');
        var divdt = getctl('divdt');
if (addr.value != '') {pointa = addr.value;}    
if (city.value != '') {pointa = pointa + ' ' + city.value;}
   if (state.value != '') {
        if (pointa != '') {
        pointa = pointa + ', ' + state.value;
        } else {
        pointa = state.value;
        }
    }
    
    if (zc.value != '') {pointa = pointa + ' ' + zc.value;}       
    if (!addr.value  == '' || !city.value  == '' || !zc.value  == '') {
        if (dmode == 'pt' || dmode=='w') {
        setLngs();
        var url;
            if (dmode == 'pt') {
            turl = 'http://maps.google.com/maps?f=d&source=s_d&saddr=' + pointa + '&daddr=' + pointb + '&hl=' + ptlng + '&mra=ls&dirflg=r';
            }
            if (dmode == 'w') {
            turl = 'http://maps.google.com/maps?f=d&source=s_d&saddr=' + pointa + '&daddr=' + pointb + '&hl=' + ptlng + '&mra=ls&dirflg=w&ie=UTF8';
            
            }
                if (confirm(ptmessage)) {
                popitup(turl, 'full');        
                }
        Hidedimdiv('pointa');
        } else {
                    var divdir = getctl('divdirections');
                    if (divdir) {
                    divdir.style.display = '';
                    }
                    window.location.hash = '#directions';
                     
                var pointbspan = getctl('spanpointa');
                    if (pointbspan) {
                    pointbspan.innerText = pointa; /*addr.value + ' ' + city.value + ', ' + state.value + ' ' + zc.value;
                    here will be set on hold, until API key is assigned from google.*/
                        if (divdm && divdt) {
                        divdm.style.display = '';
                        divdt.style.display = '';
                        sddivs('divdm', 'divdt');
                        
                        setLngs();                            
                            setDirections(pointa, pointb, lng, dmode);
                            
                        
                        }
                    }
                    Hidedimdiv('pointa');
        }
    } else {
    alert(pointaalertstr);
    }
}

/*Code to create directions on PrintDirections Page.*/
function builddirectionsmap(divmap, divtext, pointa, pointb, lang, dm) {
var divdm = getctl(divmap);
var divdt = getctl(divtext);
var lng = '';
    if (divdm && divdt) {
            sddivs(divmap, divtext);
                if (lang  == 'SP') {
                lng = 'es_ES';
                } else {
                lng = 'en_US';
                }
            setDirections(pointa, pointb, lng, dm);
            }
}            

/*This line will check the checkbox on printdirections*/
function pdcheckchkbox() {
var chkctl = getctl('pdchkbox');
var pdmap = getctl('divdirmap');
    if (chkctl) {
        if (chkctl.checked ==true) {
            if (pdmap) {
            pdmap.style.display='';
            }
        } else {
            if (pdmap) {
            pdmap.style.display='none';
            }
        }
    }
}

/*This will build the Senddirections, printdirections URLtaskmg
But we need a helper variable that will tell language of directions.*/
function sdirections(tgturl, bopid, type, putype) {
var addr = getctl('address');
var city = getctl('city');
var state = getctl('state');
var zc = getctl('zipcode');
var dirlanguage;
    if (addr && city && zc && state) {
    var tmpurl = tgturl + '?addr=' + addr.value + '&city=' + city.value + '&zc=' + zc.value + '&st=' + state.value + '&t=' + type + '&i=' + bopid + '&dl=' + curlng + '&dm=' + dmode ;
    popitup(tmpurl, putype);
    }
}


/*BSSDetail Menus*/
var divslist = new Array(1);


/*Add to Favorites*/
function addtofav(URL, Title) { 
if (window.external) { 
window.external.AddFavorite(URL, Title); 
} else if (window.sidebar) { 
window.sidebar.addPanel(URL, Title,""); 
}
}

function addbookmark() {
  if (document.all)
  {
    window.external.AddFavorite(document.location.href, document.title);
  } else {
  alert(alertffoxstr);
  }
}

/*Cookie Handling*/
function createCookie(name,value,days) {
var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else {
	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;
}
/* The line below will set the cookie expiration date to a past day
Once the browser detects that, the cookie will be inmediately deleted.*/
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*Default.aspx*/
var dscalert;
function defsearchcat () {
    var ctlname = getctl('dsctb');
    if (ctlname) {
        if (ctlname.value != "") {
        window.location = "showcat.aspx?cat=" + ctlname.value;
        } else {
        alert(dscalert);
        }
    }

}

/*Home Page scripts
Last Regged items rotator*/
var homeregtimer ;
var homeregcurrent = 0;
function tooglelastregrotator(onoff) {
var holderdiv = getctl('lastregs');
    if (holderdiv) {
        if (onoff  == 'on') {
            if (homeregcurrent  == 5) {
            homeregcurrent = 1 ;
            } else {
            homeregcurrent++;
            }
            if (document.all) {
            holderdiv.filters[0].Apply();
            }
            swapnumberdivs(homeregcurrent, 5, 'divitem');
            if (document.all) {
            holderdiv.filters[0].Play();
            }
        homeregtimer = setTimeout("tooglelastregrotator('"+ 'on' + "')" , 8000);       
        } else {
        clearTimeout(homeregtimer);
        }
    }
}

function swapnumberdivs (show, total, divsname) {
/*Basically which this does is hide total divs, and show the specified one.
Show = Div to be shown
Total = Total number of divs
Divsname = what the group of divs are named.
for example if item1 has to be shown, then divsname should be item, plus the show, equals item1 (divsname + show)*/
var divtoshow = getctl(divsname + show);
    for (i=0;i<total;i++) {
    var curdiv = getctl(divsname + (i + 1));
        if (curdiv && divtoshow) {
            curdiv.style.display = 'none';
        }
    }
    if (divtoshow) {
    divtoshow.style.display = '';  
    } 
}
function swaparraydivs (show, total, arrayname) {
var divtoshow = getctl(show);

}

/*++++++++++UI-ManageReg Functions++++++++++++++++++++
uicurimg will hold the number of the current uicurimg
uidbkg -> UI Dimmed BacKGround, a boolean that checks if the page is dimmed.*/
var uicurimg;
var uidbkg = false;

/*vars used in the span detail on each images
 
var ui_sd_fn ; -> UI_SpanDetail_FileName
var ui_sd_ic ; -> UI_SpanDetail_ImageCaption
var ui_sd_it ; -> UI_SpanDetail_ImageTitle
var ui_sd_ifn ; -> UI_SpanDetail_InvalidFileName
var ui_sd_nonesel ; -> UI-SpanDetail-NoneSelection
*/
var ui_sd_fn ;
var ui_sd_ic ;
var ui_sd_it ;
var ui_sd_ifn ;
var ui_sd_nonesel;
function modifyimg(imgnumber) {
   swapnumberdivs(imgnumber, 15, 'himgctls');
    DimBkg('himgctls');
    uicurimg = imgnumber;
    uidbkg = true;
}

function uiupdateimg () {
var tgspan = getctl('spanimgdetail' + uicurimg);
var txtimgfn = getctl('himgctlsFU' + uicurimg);
var txtimgtitle = getctl('himgctlsIT' + uicurimg);
var txtimgcaption = getctl('himgctlsIC' + uicurimg);
/*tmpcheckbox will exist if we are updating.*/
var tmpcheckbox = getctl('himgctlsCB' + uicurimg);
/*Get the image if available*/
var tmpimgprev = getctl('GImgPrev' + uicurimg);
var tmptxt = '';
var txthelper = getctl('txtimgu' + uicurimg);
    if (tgspan) {
        if (txtimgfn) {
        var tmpfilename = new String(txtimgfn.value);
        var ltmpfilename = tmpfilename.toLowerCase();
                if (tmpfilename  == '') {
                /*LEFT HERE, apparently the this part of the working with the images is done, we have to add the 
                new controls to every image now.
                This function has to be tested against every possible scenario.
                If no filename, then user didn't chose any, check if we are updating or creating by checking the checkbox*/
                             txthelper.value = '0';
                             if (tmpcheckbox) {
                                 if (tmpcheckbox.checked  == 1) {
                                 /*Must select replacement image text*/
                                 alert(mustselectimgrep);
                                 tmptxt = '';
                                 } else {
                                    if (tmpimgprev) {
                                    tmptxt = ui_sd_imglabel + '<br><img src="' + tmpimgprev.src + '" class="ui-gimg-thumb">';
                                    }
                                 }
                             } else {
                             /*Must select image text*/
                             alert (mustselectimgrep);
                             tmptxt = '';
                             }
                } else {
                    if (ltmpfilename.indexOf('.jpg',0) > 5 || ltmpfilename.indexOf('.gif',0) > 5) {
                    tmptxt = ui_sd_fn + '<BR>' + getNameFromPath(tmpfilename);
                        if (txthelper) {
                             txthelper.value = '1';
                             if (tmpcheckbox) {
                                 if (tmpcheckbox.checked  == 1) {
                                 tmptxt = ui_sd_fn + '<BR>(' + getNameFromPath(tmpfilename) + ')';
                                 txthelper.value = '1';
                                 } else {
                                    if (tmpimgprev) {
                                    tmptxt = ui_sd_imglabel & '<br><img src="' + tmpimgprev.src + '" class="ui-gimg-thumb">';
                                    txthelper.value = '0';
                                    }
                                 }
                             } else {
                             /*If we get to this point then the tmpcheckbox for update is not visible, therefor e
                             wasn't found*/
                                tmptxt = ui_sd_fn + '<BR>(' + getNameFromPath(tmpfilename) + ')';
                                txthelper.value = '1';
                             }
                        }
                    } else {
                        if (txthelper) {
                            txthelper.value = '0';
                             if (tmpcheckbox) {
                                 if (tmpcheckbox.checked  == 1) {
                                 /*REPLACE*/
                                 tmptxt = mustselectrepimg;
                                 } else {
                                    if (tmpimgprev) {
                                    tmptxt = ui_sd_imglabel + '<BR><img src="' + tmpimgprev.src + '">';
                                    }
                                 }
                             } else {
                             /*Invalid filename*/
                              tmptxt = ui_sd_ifn + '<BR>(' + getNameFromPath(tmpfilename) + ')';
                             }
                        }
                    }
                }
        }
        if (tmptxt != '') {
            if (txtimgtitle) {
            tmptxt += '<BR><br>' + ui_sd_it + '<BR>' + txtimgtitle.value;
            }
            if (txtimgcaption) {
            tmptxt += '<BR><br>' + ui_sd_ic + '<BR>' + txtimgcaption.value;
            }
            tgspan.innerHTML = tmptxt + "<BR>";
            var disimgctl = getctl('spanimgdel'+ uicurimg);
            if (disimgctl) {
            disimgctl.style.display = 'block';
            }
        }
    }
    Hidedimdiv('himgctls');
    uidbkg=false;
}

function disableimg(whichone) {
cfuctl('himgctlsFU' + whichone)
var disimgctl = getctl('spanimgdetail' + whichone);
    if (disimgctl) {
    disimgctl.innerHTML = ui_sd_nonesel; 
/*TODO, on server code assign the No seleccionada o no editada.*/
    }
    /*The following line will hide the link.*/
    disimgctl = getctl('spanimgdel'+ uicurimg);
    if (disimgctl) {
    disimgctl.style.display = 'none';
    }
                 var txthelper = getctl('txtimgu' + whichone);
                if (txthelper) {
                     txthelper.value = '0';
                }
}

/*This uiaddimgs function adds 5 extra images to the current creation.*/


function  uiaddimgs(total) {
var tgtxtbox = getctl('himgctlsICount');
var spaddimg = getctl('spanaimg' + total);
var gdivs;
var confirmdialog;
    if (total  == 10) {
    gdivs = getctl('TImg10');
        if (tgtxtbox && gdivs && spaddimg) {
        confirmdialog = confirm(strconfirm);
            if (confirmdialog) {
            gdivs.style.display = '';
            tgtxtbox.value = 'HICYB';
            spaddimg.style.display = 'none';
            }
        }
    }
    if (total  == 15) {
    gdivs = getctl('TImg15');
        if (tgtxtbox && gdivs && spaddimg) {
        confirmdialog = confirm(strconfirm);
            if (confirmdialog) {
            gdivs.style.display = '';
            tgtxtbox.value = 'HICZC';
            spaddimg.style.display = 'none';
            }
        }
    }
}

/*Create or Update*/
function uiucbtn(){
    var obtn = getctl('btnUpCreate');
    var dw = getctl('divw');
    if (obtn && dw) {
    DimBkg('divw');
    obtn.click();
    }
}

/*+++++++++++++++++SearchResults+++++++++++++++++++++++*/
function srchangeview(whichone) {
var sbmenus = getctl('sidebarreg');
var sbregs = getctl('sidebarmap');
var mres = getctl('regresults');
var mmap = getctl('mapformain');

var vm1 = getctl('viewmode1');
var vm2 = getctl('viewmode2');
var ads = getctl('adholder');

    if (sbmenus && sbregs && mres && mmap && vm1 && vm2) {
        if (whichone == 2) {
            sbmenus.style.display = '';
            sbregs.style.display = 'none';
            mres.style.display = '';
            mmap.style.display = 'none';
            vm1.style.display = '';
            vm2.style.display = 'none';

            checkadholder();

        } else {
            sbmenus.style.display = 'none';
            sbregs.style.display = '';
            mres.style.display = 'none';
            mmap.style.display = '';
            vm1.style.display = 'none';
            vm2.style.display = '';
            if (ads) {ads.style.display = 'none';}
            SetHeightOnMain();
        }
    }
}

function GetBrowser() {
    if (navigator.userAgent.indexOf("Firefox")!=-1) {
    return "Firefox";
    }

    if (navigator.userAgent.indexOf("MSIE")!=-1){
    return "IE";
    }
    
    if (navigator.userAgent.indexOf("Chrome")!=-1){
    return "Chrome";
    }
}

/* CreateUser*/

function updateLabel(ddname, lblname) {
var ddctl= getctl(ddname);
var lblctl = getctl(lblname);
    if (ddctl && lblctl) {
       lblctl.innerHTML = ddctl.options[ddctl.selectedIndex].value;
    }
}

function CheckFlash() {
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
return version;
}

/*Check Browser*/
var Browser = {  Version: function() {    var version = 999; /* we assume a sane browser */ if (navigator.appVersion.indexOf("MSIE") != -1)     /* bah, IE again, lets downgrade version number */      version = parseFloat(navigator.appVersion.split("MSIE")[1]);    return version;  }}


/*fdtt -> Fill date to textbox*/
function fdtt(ctlname) {
    var ctl = getctl(ctlname);
    if (ctl) {
    ctl.value = new Date();
    }
}

/*Check HasPic CB*/
function chpcb () {
var cb = getctl('cbHaspic');
var divfi = getctl('divFrontImgUF');
    if (cb && divfi) {
        if (cb.checked == true) {
        divfi.style.display='';
        chkcbs();
        } else {
        divfi.style.display='none';
        cfuctl('frontimg');
        chkcbs();
        }
    }
}

/*Show Hidden Div With CheckBox*/

function shdivwcb (cbname, divname) {
var tmpcb = getctl(cbname);
var tmpdiv = getctl(divname);

    if (tmpcb && tmpdiv) {
        if (tmpcb.checked == true) {
        tmpdiv.style.display = '';
        } else {
        tmpdiv.style.display = 'none';
        }
    }
}


function cbannercb () {
var cb = getctl('cbBanner');
var divfi = getctl('divbannerUC');
    if (cb && divfi) {
        if (cb.checked == true) {
        divfi.style.display='';
        chkcbs();
        } else {
        divfi.style.display='none';
        chkcbs();
        cfuctl('banner');
        }
    }
}

/*Check if Tos checkbox is needed*/

function chkcbs() {
var cbhp = getctl('cbHaspic');
var cbb = getctl('cbBanner');
var cbg = getctl('cbGallery');
var divpt = getctl('divpt');

if (cbhp && divpt) {
    if (cbg && cbb) {
        if (cbg.checked == false && cbb.checked == false && cbhp.checked == false) {
        divpt.style.display = 'none';
        } else if (cbg.checked == true || cbb.checked == true || cbhp.checked == true) {
        divpt.style.display = '';
        }
    } else if (cbg) {
        if (cbg.checked == false && cbhp.checked == false) {
        divpt.style.display = 'none';
        } else if (cbg.checked == true || cbhp.checked == true) {
        divpt.style.display = '';
        }
    } else if (cbhp.checked == true) {
    divpt.style.display = '';
    } else {
    divpt.style.display = 'none';
    }
    
    
}

}



/*Function to clear Fileupload control to avoid sending extra data*/
function cfuctl(name) {
var ctl = getctl(name);
    if (ctl) {
        ctl.value = '';
        var ctl2 = ctl.cloneNode(false);
        ctl2.onchange= ctl.onchange;
        ctl.parentNode.replaceChild(ctl2,ctl);
    }
}

function getNameFromPath(strFilepath) {
    var objRE = new RegExp(/([^\/\\]+)$/);
    var strName = objRE.exec(strFilepath);

    if (strName == null) {
        return null;
    }
    else {
        return strName[0];
    }
}

/*Following function will be used to get height and width, used sometimes to fix stuff*/
function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    /*Non-IE*/
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    /*IE 6+ in 'standards compliant mode'*/
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    /*IE 4 compatible*/
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}


/*Checking the city on main*/
var curl;
function fcity() {
var proceed;
var pa = curl + "cny/ajax helpers/checkcity.ashx";
var q;
var tc;

    if (geoip_city() !=null) {
    q = geoip_city();
    tc = geoip_country_code();
        if (tc=='US') {
        proceed=true;        
        } else {
        proceed=false;       
        }

    } else {
    proceed=false;
    }

xmlHttp=GetXmlHttpObject();

	if (proceed==true) {
		if (xmlHttp!=null) {
		var url=pa + '?cn=' + q + '&sid=' +Math.random();
			xmlHttp.onreadystatechange=function () {
				if (xmlHttp.readyState==4) {
					if (xmlHttp.responseText=='true') {
				    window.location='default.aspx?where=' + q + '&cc=1';
					}
				}
			}
			xmlHttp.open('GET', url, true);
			xmlHttp.send(null);
		}	
	}

}


