<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michael Khalili &#187; Programming</title>
	<atom:link href="http://michaelapproved.com/articles/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://michaelapproved.com</link>
	<description>Tap my brain, drink it up.</description>
	<lastBuildDate>Wed, 26 Oct 2011 01:03:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>My New Site FollowZone.com Helps Get More Followers On Twitter</title>
		<link>http://michaelapproved.com/articles/my-new-site-followzone-com-helps-get-more-followers-on-twitter</link>
		<comments>http://michaelapproved.com/articles/my-new-site-followzone-com-helps-get-more-followers-on-twitter#comments</comments>
		<pubDate>Wed, 05 Jan 2011 10:27:02 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Follow Zone]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=52</guid>
		<description><![CDATA[I know what it’s like to try to build a following on Twitter. Each site I created came with a plea to “Follow me on Twitter.” The problem is, once the user clicks on my link, I have no control over what they saw and didn’t know if they even converted into a follower. Then, [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://michaelapproved.com/wp-content/uploads/2011/01/Follow-Zone-Logo-150x150.png"><img class="alignleft size-full wp-image-274" title="Follow Zone Logo" src="http://michaelapproved.com/wp-content/uploads/2011/01/Follow-Zone-Logo-150x150.png" alt="Follow Zone Logo" width="150" height="150" /></a>I know what it’s like to try to build a following on Twitter. Each site I created came with a plea to “Follow me on Twitter.” The problem is, once the user clicks on my link, I have no control over what they saw and didn’t know if they even converted into a follower. Then, once they clicked follow, there was nothing more I could ask the person to do. I was blind and at best I’d only get one follower, one conversion. There had to be a better way.</p>
<p><span id="more-52"></span></p>
<p>I created <a href="http://www.followzone.com">FollowZone.com</a> to try and solve these problems. The site gives you a customized way of presenting your Twitter profile and the ability to get more out of a new follower. When you send someone to your <a href="http://www.followzone.com">Follow Zone</a> profile, they see a custom list of tweets with little to distract them. After all, the main goal is to click the “Follow Me” button, most links and buttons beyond that are distracting from that goal. Then, once they follow you, they’re presented with a <strong>Suggested List</strong> of other people to follow.</p>
<p>Here’s the best part. For each new person they follow on that Suggested List, you earn 1 Follow Zone Credit. Those Credits can then be used to have your profile appear on the Suggested List of someone else’s profile. By being on the Suggested List you’re exposed to a new group of people who are encouraged to follow you. This makes one follower potentially several more.</p>
<p>My focus will be to help you get the most out of your potential followers. That means high conversion rates for people who view your profile page and making sure they follow people on the Suggested List. The combination of those two objectives means you’ll earn more Twitter followers by doing what you already do &#8211; Ask people to follow you.</p>
<p>See it in action. <a href="http://www.followzone.com/twitter/michaelapproved/">You should follow me on Twitter here.</a></p>
<p><strong>Update: </strong>Unfortunately, I had to stop running the site. I go into detail here <a href="http://www.followzone.com/blog/article/hiatus">http://www.followzone.com/blog/article/hiatus</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/my-new-site-followzone-com-helps-get-more-followers-on-twitter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Incremental Count Using Alphanumeric Values</title>
		<link>http://michaelapproved.com/articles/incremental-count-alphanumeric-values</link>
		<comments>http://michaelapproved.com/articles/incremental-count-alphanumeric-values#comments</comments>
		<pubDate>Wed, 14 Oct 2009 08:58:49 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Bit.ly]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=36</guid>
		<description><![CDATA[I&#8217;m currently working on a website that needs a URL shortener. In order to have a good shortened URL I must make the most of the path after the domain. The common way to do this, as Bit.ly and others already do, is to have a mix of alphanumeric characters that increment each time a [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;m currently working on a website that needs a URL shortener. In order to have a good shortened URL I must make the most of the path after the domain. The common way to do this, as Bit.ly and others already do, is to have a mix of alphanumeric characters that increment each time a new URL has been created. I&#8217;m using Asp.Net and since there&#8217;s no built in function or an already published one, I created my own.</p>
<p>This function works by accepting a list of characters to use in the counting process. Each time a new value is needed the function increments the count by going to the next character in the array. I hope to have a lot of traffic so it&#8217;s important to be efficient and fast. The resulting code can run thousands of times in just a fraction of a second.<br />
<span id="more-36"></span><br />
To use the function you need to pass in the current value (or empty string &#8220;&#8221; if it&#8217;s the first time) and a character array of values to use (include lowercase and uppercase values if you want to have case sensitivity). Including lowercase letters adds an enormous amount of extra values in a shorter character span. That&#8217;s very important when you&#8217;re working with short URLs.</p>
<pre class="brush: vb; title: ; notranslate">
Function CountWithCharacters(ByVal strValueCurrent As String, ByVal aryCharacter() As Char) As String
    Dim chrCharacterCurrent As Char
    Dim chrCharacterNew As Char
    Dim blnIncrementParent As Boolean
    Dim intCharacterCurrent As Integer = strValueCurrent.Length
    Dim strReturnValue As String

    strReturnValue = strValueCurrent

    Do
        'reset the IncrementParent switch
        blnIncrementParent = False

        'decrement the current character place so it moves up to the parent
        intCharacterCurrent -= 1

        'Are we still looking at characters that exist?
        If intCharacterCurrent &gt;= 0 Then
            chrCharacterCurrent = strReturnValue.Substring(intCharacterCurrent, 1)

            'If the current character is the same as the last value in the array we must increment the parent
            'and set its value to the first value in the array
            If chrCharacterCurrent = aryCharacter(aryCharacter.Length - 1) Then
                If intCharacterCurrent &gt;= 0 Then
                    blnIncrementParent = True
                    chrCharacterNew = aryCharacter(0)
                Else
                    chrCharacterNew = Nothing
                End If

            Else
                'take the next value
                chrCharacterNew = aryCharacter(Array.IndexOf(aryCharacter, chrCharacterCurrent) + 1)
            End If

            'Remove the current character and replace it with the new one
            strReturnValue = strReturnValue.Remove(intCharacterCurrent, 1).Insert(intCharacterCurrent, chrCharacterNew)
        Else
            'Trying to increment a value that doesn't exist. Instead append the first value in the character array
            strReturnValue = aryCharacter(0) &amp; strReturnValue
        End If

    Loop While blnIncrementParent

    Return strReturnValue

End Function
</pre>
<p><strong>Using the function</strong><br />
After calling the following example the result will be a value of 0 since it&#8217;s passing in an empty string and 0 is the first value in the character array. I&#8217;m creating the character array by using a string and converting it as I pass it into the function. This character array can include any set of characters in any order. I&#8217;m using numbers, lowercase letters, uppercase letters and finally _, &#8211; and ~. I&#8217;m using those three extra characters to give me more values in a smaller character span. It&#8217;s important that all these characters don&#8217;t have to be URL encoded which would actually make the URL longer.</p>
<pre class="brush: vb; title: ; notranslate">
strValue = CountWithCharacters(&quot;&quot;, &quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-~&quot;.ToCharArray)
</pre>
<p>As I continue to use the function, feeding it the previous result so it can increment it, I&#8217;ll get values like 1, 2, 3, &#8230; a, b, c, &#8230;A, B, C, &#8230; _, -, ~. After the ~ value the function will return 00, 01, 02 and so on. The following call will return 0Az to strValue.</p>
<pre class="brush: vb; title: ; notranslate">
strValue = CountWithCharacters(&quot;0Ay&quot;, &quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-~&quot;.ToCharArray)
</pre>
<p><strong>Profanity</strong><br />
As I worked on this function it crossed my mind that I would eventually run into some curse words. As the values increment, the letter combinations will spell words like ass, shit, fuck, etc. Users will probably not appreciate me giving them a URL that contains curse words. To prevent this I created another function that skips past any words I specify. This skipping process can take a tiny fraction of a second or much longer, depending on how many characters need to be skipped. Once I hit 5+ characters it can take over 1 second to execute. That&#8217;s a lot of time for a single function but given how infrequently it needs to skip past a word and now long it&#8217;ll take me to reach 5 character URL (&#8220;00000&#8243; is the equivalent of 17,850,626), I was willing to forgive it and move on.</p>
<pre class="brush: vb; title: ; notranslate">
Function CountWithCharacters(ByVal strValueCurrent As String, ByVal aryCharacter() As Char, ByVal arySkipWords() As String) As String
    Dim strReturnValue As String
    Dim blnSkip As Boolean
    Dim strSkipWord As String
    strReturnValue = strValueCurrent

    Do
        blnSkip = False
        strReturnValue = CountWithCharacters(strReturnValue, aryCharacter)
        For Each strSkipWord In arySkipWords
            If strReturnValue.ToLower.Contains(strSkipWord) Then
                blnSkip = True
                Exit For
            End If
        Next
    Loop While blnSkip

    Return strReturnValue

End Function
</pre>
<p>This new function will execute the previous one and then check it for a skip word. If it finds a skip word then it&#8217;ll keep looping until the counter incremented past it. This design probably isn&#8217;t the most efficient one but I didn&#8217;t want to spend any more time on something so simple. It&#8217;s better to move on and revisit it if the site gets popular enough for me to be concerned.</p>
<p>Here&#8217;s an example call to the function. It passes in the value &#8220;asr&#8221; which would normally return &#8220;ass&#8221; but instead, since &#8220;ass&#8221; is included in the skip word array, &#8220;ast&#8221; will be the return value.</p>
<pre class="brush: vb; title: ; notranslate">
strValue = CountWithCharacters(&quot;asr&quot;, &quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-~&quot;.ToCharArray, &quot;shit,piss,fuck,cunt,cock,dick,tit,ass&quot;.Split(&quot;,&quot;))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/incremental-count-alphanumeric-values/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove White Space in HTML Output</title>
		<link>http://michaelapproved.com/articles/remove-white-space-in-html-output</link>
		<comments>http://michaelapproved.com/articles/remove-white-space-in-html-output#comments</comments>
		<pubDate>Mon, 28 Sep 2009 07:02:43 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=21</guid>
		<description><![CDATA[If you&#8217;ve looked at the HTML source of an ASP.NET page you know there&#8217;s a ton of extra white space that isn&#8217;t necessary. If you&#8217;re concerned about page load speed and bandwidth you&#8217;ll want to remove all that extra space. Here&#8217;s some code you can use to reduce page size by an average of over [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>If you&#8217;ve looked at the HTML source of an ASP.NET page you know there&#8217;s a ton of extra white space that isn&#8217;t necessary. If you&#8217;re concerned about page load speed and bandwidth you&#8217;ll want to remove all that extra space. Here&#8217;s some code you can use to reduce page size by an average of over 10%. I put this in my MasterPage file.<span id="more-21"></span></p>
<pre class="brush: vb; title: ; notranslate">
Protected Overloads Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    Dim swHtmlText As New HtmlTextWriter(New System.IO.StringWriter)

    MyBase.Render(swHtmlText)

    Dim strHtml As String = swHtmlText.InnerWriter.ToString

    strHtml = Regex.Replace(strHtml, &quot;^\s+&lt;&quot;, &quot; &lt;&quot;, RegexOptions.Multiline)
    strHtml = Regex.Replace(strHtml, &quot;&gt;\s+&lt;&quot;, &quot;&gt; &lt;&quot;, RegexOptions.Multiline)

    writer.Write(strHtml.Trim)

End Sub
</pre>
<p>The replacements I make are very conservative. You can get even more extreme by replacing all spaces after &gt; and before &lt; with the regex SingleLine option.</p>
<pre class="brush: vb; title: ; notranslate">
strHtml = Regex.Replace(strHtml, &quot;\s+&lt;&quot;, &quot; &lt;&quot;, RegexOptions.Singleline)
strHtml = Regex.Replace(strHtml, &quot;&gt;\s+&quot;, &quot;&gt; &quot;, RegexOptions.Singleline)
</pre>
<p>That code could will break text in a Textfield so you have to make sure to test this more extreme version. You can also add a property in your code for the level of white space you want removed.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/remove-white-space-in-html-output/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Textbox and Dropdown combined</title>
		<link>http://michaelapproved.com/articles/textbox-and-dropdown-combined</link>
		<comments>http://michaelapproved.com/articles/textbox-and-dropdown-combined#comments</comments>
		<pubDate>Mon, 28 Sep 2009 06:51:38 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=18</guid>
		<description><![CDATA[While creating a form for a project I wanted to give the user the option of either creating a new entry or selecting from an existing one. The standard way to do it is to give the user a textbox on one line and a dropdown on another. As with most forms, I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>While creating a form for a project I wanted to give the user the option of either creating a new entry or selecting from an existing one. The standard way to do it is to give the user a textbox on one line and a dropdown on another. As with most forms, I wanted to limit the space used so the user wont get overwhelmed by the amount of data he needs to enter. My solution was to join the two objects as you can see in the following screen shot.</p>
<p style="text-align: center;"><a href="/articles/example/textbox-dropdown-combination.htm" target="_blank">Working Demo / Example</a></p>
<p><img class="size-full wp-image-72 aligncenter" title="Textbox-Dropdown-Combination-Screenshot" src="http://michaelapproved.com/wp-content/uploads/2009/09/Textbox-Dropdown-Combination-Screenshot.gif" alt="Textbox-Dropdown-Combination-Screenshot" width="288" height="90" /><span id="more-18"></span></p>
<p>The textbox is placed on top of the dropdown with enough room on the right to still display the down arrow of the dropdown. You can see that the user is either able to enter new text into the textbox or select an option from the dropdown.</p>
<p>To display the box properly I use HTML and CSS. When the user selects an option from the dropdown I use Javascript to load the value into the textbox. When the form is submitted ignore the dropdown and just pull the value from the textbox. The trickiest part of this was that IE 6 wasn&#8217;t able to display the textbox over the dropdown properly. Thanks to Hedger Wang and his <a rel="nofollow" href="http://www.hedgerwow.com/360/bugs/css-select-free.html" target="_blank">fix</a> I was able to make this work across browsers.</p>
<p>This style code is used to overcome the issues with IE6. Place the following code in between the &lt;head&gt;&lt;/head&gt; tag of your page.</p>
<pre class="brush: css; title: ; notranslate">
&lt;style type=&quot;text/css&quot;&gt;
    /*fix dropdown z-index problem. Credit to http://hedgerwow.blogspot.com/ */
    .select-free
    {
        position: absolute;
        z-index: 10; /*any value*/
        overflow: hidden; /*must have*/
        width: 247px; /*must have for any value*/ /*width of area +5*/
    }
    .select-free iframe
    {
        display: none; /*sorry for IE5*/
        display: /**/ block; /*sorry for IE5*/
        position: absolute; /*must have*/
        top: 0px; /*must have*/
        left: 0px; /*must have*/
        z-index: -1; /*must have*/
        filter: mask(); /*must have*/
        width: 3000px; /*must have for any big value*/
        height: 3000px /*must have for any big value*/;
    }
    .select-free .bd
    {
        padding: 11px;
    }
&lt;/style&gt;
</pre>
<p>This is the Javascript used to display the value in the textbox when the user selects an option from the dropdown. This also goes in between your &lt;head&gt;&lt;/head&gt; tag.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
     function DropDownTextToBox(objDropdown, strTextboxId) {
        document.getElementById(strTextboxId).value = objDropdown.options[objDropdown.selectedIndex].value;
        DropDownIndexClear(objDropdown.id);
        document.getElementById(strTextboxId).focus();
    }
    function DropDownIndexClear(strDropdownId) {
        if (document.getElementById(strDropdownId) != null) {
            document.getElementById(strDropdownId).selectedIndex = -1;
        }
    }
&lt;/script&gt;
</pre>
<p>This is the HTML that includes the textbox, dropdown and the div that goes around it. You&#8217;ll notice IE conditional statements in commented area. This is part of the patch from Hedger Wang&#8217;s website. The style was placed on the actual control for simplicity, you can move it to a CSS file if you like.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div style=&quot;position: relative;&quot;&gt;
    &lt;!--[if lte IE 6.5]&gt;&lt;div class=&quot;select-free&quot; id=&quot;dd3&quot;&gt;&lt;div class=&quot;bd&quot; &gt;&lt;![endif]--&gt;
    &lt;input name=&quot;TextboxExample&quot; type=&quot;text&quot; maxlength=&quot;50&quot; id=&quot;TextboxExample&quot; tabindex=&quot;2&quot;
        onchange=&quot;DropDownIndexClear('DropDownExTextboxExample');&quot; style=&quot;width: 242px;
        position: absolute; top: 0px; left: 0px; z-index: 2;&quot; /&gt;
    &lt;!--[if lte IE 6.5]&gt;&lt;iframe&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/div&gt;&lt;![endif]--&gt;
    &lt;select name=&quot;DropDownExTextboxExample&quot; id=&quot;DropDownExTextboxExample&quot; tabindex=&quot;1000&quot;
        onchange=&quot;DropDownTextToBox(this,'TextboxExample');&quot; style=&quot;position: absolute;
        top: 0px; left: 0px; z-index: 1; width: 265px;&quot;&gt;
        &lt;option value=&quot;Value for Item 1&quot; title=&quot;Title for Item 1&quot;&gt;Item 1&lt;/option&gt;
        &lt;option value=&quot;Value for Item 2&quot; title=&quot;Title for Item 2&quot;&gt;Item 2&lt;/option&gt;
        &lt;option value=&quot;Value for Item 3&quot; title=&quot;Title for Item 3&quot;&gt;Item 3&lt;/option&gt;
    &lt;/select&gt;
    &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
        //Since the first &lt;option&gt; will be preselected the IndexClear function must fire once to clear that out.
        DropDownIndexClear(&quot;DropDownExTextboxExample&quot;);
    &lt;/script&gt;
&lt;/div&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/textbox-and-dropdown-combined/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Scroll to Object Without Leaving Page</title>
		<link>http://michaelapproved.com/articles/scroll-to-object-without-leaving-page</link>
		<comments>http://michaelapproved.com/articles/scroll-to-object-without-leaving-page#comments</comments>
		<pubDate>Mon, 28 Sep 2009 06:44:25 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=16</guid>
		<description><![CDATA[The most common way to scroll a page is to link the user to a URL with #AnchorId at the end. This method allows the browser to handle everything and there is no code needed. For times when you need a solution using code I&#8217;m going to demonstrate two other methods with Javascript. The first [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>The most common way to scroll a page is to link the user to a URL with <strong><em>#AnchorId</em></strong> at the end. This method allows the browser to handle everything and there is no code needed. For times when you need a solution using code I&#8217;m going to demonstrate two other methods with Javascript.<span id="more-16"></span></p>
<p>The first option is to use the built in Javascript function <strong><em>location.href</em></strong>. This function allows you to send the user to any URL or Anchor you&#8217;d like. Using this function we&#8217;re going to send the user to an Anchor on the current page with an Id of <strong><em>MyAnchor</em></strong>.</p>
<p>Place an Anchor tag with the Id <strong><em>MyAnchor</em></strong> on the part of the page you&#8217;d like to scroll to. The text &#8220;scroll to here&#8221; is optional.</p>
<pre class="brush: xml; title: ; notranslate">&lt;a id=&quot;MyAnchor&quot;&gt;Scroll to here&lt;/a&gt;</pre>
<p>Although you can call the <strong><em>location.href</em></strong> function at anytime after the page is loaded, for this example we&#8217;re going to call it right as the page loads. Place the code at the bottom of the BODY tag and right above <strong><em>&lt;/body&gt;</em></strong>.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
    location.href = '#MyAnchor';
&lt;/script&gt;
</pre>
<p>The second method is to scroll the user directly to an object. This can be almost any object and doesn&#8217;t have to be an Anchor. It&#8217;s useful when you don&#8217;t have an Anchor in the area or simply don&#8217;t want to put one there. The function below includes another function called <a href="http://michaelapproved.com/articles/object-position-top-and-left-offset-on-a-page/"><strong><em>ObjectPosition</em></strong></a>.</p>
<pre class="brush: jscript; title: ; notranslate">
function ScrollTo(obj){
    try{
        var objpos = ObjectPosition(obj);
    }catch(e){}
    try{
        scroll(0,objpos[1]);
    }catch(e){}
    try{
        window.scrollTo(0,objpos[1]);
    }catch(e){}
}
</pre>
<p><strong><em>Obj</em></strong> is an HTML object you&#8217;d like to scroll to.</p>
<p>The <strong><em>ObjectPosition</em></strong> returns both the left and top offset as a two item array. You&#8217;ll notice that I hard coded 0 in the two scroll functions. You can change that to <strong><em>objpos[0]</em></strong> if you need to scroll horizontally. I&#8217;m using two different scrolling methods because of browser issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/scroll-to-object-without-leaving-page/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Object Position (Top and Left Offset) on a Page</title>
		<link>http://michaelapproved.com/articles/object-position-top-and-left-offset-on-a-page</link>
		<comments>http://michaelapproved.com/articles/object-position-top-and-left-offset-on-a-page#comments</comments>
		<pubDate>Mon, 28 Sep 2009 06:40:42 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=14</guid>
		<description><![CDATA[Retrieves the left and top offset of an object using Javascript. I got this from Peter-Paul Koch. His description is more extensive. Pass in the object you&#8217;d like the position of and it&#8217;ll return a 2 item array. The first item is the left offset and the second item is the top offset. Javascript only [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Retrieves the left and top offset of an object using Javascript. I got this from <a href="http://www.quirksmode.org/js/findpos.html" target="_blank">Peter-Paul Koch</a>. His description is more extensive.<span id="more-14"></span></p>
<pre class="brush: jscript; title: ; notranslate">
function ObjectPosition(obj) {
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return [curleft,curtop];
}
</pre>
<p>Pass in the object you&#8217;d like the position of and it&#8217;ll return a 2 item array. The first item is the left offset and the second item is the top offset.</p>
<p>Javascript only lets us check the offset from the object&#8217;s parent. Since the object may be nested inside other elements, each of the parent&#8217;s offsets must be added to get the final offset result.</p>
<p>The example below shows how to get the offset of an element called <strong><em>MyElementId</em></strong>. Place the code at the bottom of the BODY tag and right above <strong><em>&lt;/body&gt;</em></strong>.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;div id=&quot;MyElementId&quot;&gt;My test element&lt;/div&gt;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
    var aryPosition = ObjectPosition(document.getElementById('MyElementId'));
    document.write('MyElementId left offset is ' + aryPosition[0] + '&lt;br /&gt;');
    document.write('MyElementId top offset is ' + aryPosition[1] + '&lt;br /&gt;');
&lt;/script&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/object-position-top-and-left-offset-on-a-page/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Timezone Dropdown Select List</title>
		<link>http://michaelapproved.com/articles/timezone-dropdown-select-list</link>
		<comments>http://michaelapproved.com/articles/timezone-dropdown-select-list#comments</comments>
		<pubDate>Mon, 28 Sep 2009 06:20:08 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Timezone]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=12</guid>
		<description><![CDATA[HTML of a Dropdown list with all the time zones already added.]]></description>
			<content:encoded><![CDATA[<p></p><p>HTML of a Dropdown list with all the time zones already added.<span id="more-12"></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;select name=&quot;DropDownTimezone&quot; id=&quot;DropDownTimezone&quot;&gt;
      &lt;option value=&quot;-12.0&quot;&gt;(GMT -12:00) Eniwetok, Kwajalein&lt;/option&gt;
      &lt;option value=&quot;-11.0&quot;&gt;(GMT -11:00) Midway Island, Samoa&lt;/option&gt;
      &lt;option value=&quot;-10.0&quot;&gt;(GMT -10:00) Hawaii&lt;/option&gt;
      &lt;option value=&quot;-9.0&quot;&gt;(GMT -9:00) Alaska&lt;/option&gt;
      &lt;option value=&quot;-8.0&quot;&gt;(GMT -8:00) Pacific Time (US &amp;amp; Canada)&lt;/option&gt;
      &lt;option value=&quot;-7.0&quot;&gt;(GMT -7:00) Mountain Time (US &amp;amp; Canada)&lt;/option&gt;
      &lt;option value=&quot;-6.0&quot;&gt;(GMT -6:00) Central Time (US &amp;amp; Canada), Mexico City&lt;/option&gt;
      &lt;option value=&quot;-5.0&quot;&gt;(GMT -5:00) Eastern Time (US &amp;amp; Canada), Bogota, Lima&lt;/option&gt;
      &lt;option value=&quot;-4.0&quot;&gt;(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz&lt;/option&gt;
      &lt;option value=&quot;-3.5&quot;&gt;(GMT -3:30) Newfoundland&lt;/option&gt;
      &lt;option value=&quot;-3.0&quot;&gt;(GMT -3:00) Brazil, Buenos Aires, Georgetown&lt;/option&gt;
      &lt;option value=&quot;-2.0&quot;&gt;(GMT -2:00) Mid-Atlantic&lt;/option&gt;
      &lt;option value=&quot;-1.0&quot;&gt;(GMT -1:00 hour) Azores, Cape Verde Islands&lt;/option&gt;
      &lt;option value=&quot;0.0&quot;&gt;(GMT) Western Europe Time, London, Lisbon, Casablanca&lt;/option&gt;
      &lt;option value=&quot;1.0&quot;&gt;(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris&lt;/option&gt;
      &lt;option value=&quot;2.0&quot;&gt;(GMT +2:00) Kaliningrad, South Africa&lt;/option&gt;
      &lt;option value=&quot;3.0&quot;&gt;(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg&lt;/option&gt;
      &lt;option value=&quot;3.5&quot;&gt;(GMT +3:30) Tehran&lt;/option&gt;
      &lt;option value=&quot;4.0&quot;&gt;(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi&lt;/option&gt;
      &lt;option value=&quot;4.5&quot;&gt;(GMT +4:30) Kabul&lt;/option&gt;
      &lt;option value=&quot;5.0&quot;&gt;(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent&lt;/option&gt;
      &lt;option value=&quot;5.5&quot;&gt;(GMT +5:30) Bombay, Calcutta, Madras, New Delhi&lt;/option&gt;
      &lt;option value=&quot;5.75&quot;&gt;(GMT +5:45) Kathmandu&lt;/option&gt;
      &lt;option value=&quot;6.0&quot;&gt;(GMT +6:00) Almaty, Dhaka, Colombo&lt;/option&gt;
      &lt;option value=&quot;7.0&quot;&gt;(GMT +7:00) Bangkok, Hanoi, Jakarta&lt;/option&gt;
      &lt;option value=&quot;8.0&quot;&gt;(GMT +8:00) Beijing, Perth, Singapore, Hong Kong&lt;/option&gt;
      &lt;option value=&quot;9.0&quot;&gt;(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk&lt;/option&gt;
      &lt;option value=&quot;9.5&quot;&gt;(GMT +9:30) Adelaide, Darwin&lt;/option&gt;
      &lt;option value=&quot;10.0&quot;&gt;(GMT +10:00) Eastern Australia, Guam, Vladivostok&lt;/option&gt;
      &lt;option value=&quot;11.0&quot;&gt;(GMT +11:00) Magadan, Solomon Islands, New Caledonia&lt;/option&gt;
      &lt;option value=&quot;12.0&quot;&gt;(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka&lt;/option&gt;
&lt;/select&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/timezone-dropdown-select-list/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Daylight Saving Time (DST) Detect</title>
		<link>http://michaelapproved.com/articles/daylight-saving-time-dst-detect</link>
		<comments>http://michaelapproved.com/articles/daylight-saving-time-dst-detect#comments</comments>
		<pubDate>Mon, 28 Sep 2009 06:15:12 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Daylight Saving Time]]></category>
		<category><![CDATA[DST]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=7</guid>
		<description><![CDATA[Detecting DST should be a basic function that&#8217;s included in Javascript. Sadly, along with many other basic functions, this one isn&#8217;t. For all my Google searches I wasn&#8217;t able to find a clear cut bullet proof DST detector. Many only worked in one hemisphere or specific timezones. I wrote this function to be bullet proof. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Detecting DST should be a basic function that&#8217;s included in Javascript. Sadly, along with many other basic functions, this one isn&#8217;t. For all my Google searches I wasn&#8217;t able to find a clear cut bullet proof DST detector. Many only worked in one hemisphere or specific timezones. <strong>I wrote this function to be bullet proof. It will detect the correct time zone no matter what.<span id="more-7"></span></strong></p>
<p>As you&#8217;ll see from the code and comments, I hunt for Daylight Saving Time using a broad search to keep from being a CPU hog. Once I found DST I roll back a few hours and go on a more detailed search for the exact time DST changes over.</p>
<p><strong>NOTE:</strong> This code is Dependant on my other function <strong><em><a title="Javascript - Time zone detect and ignore Daylight Saving Time (DST)" href="http://michaelapproved.com/articles/timezone-detect-and-ignore-daylight-saving-time-dst/" target="_blank">TimezoneDetect</a></em></strong>. You must use that function in conjunction with this one.</p>
<pre class="brush: jscript; title: ; notranslate">
//Find start and end of DST
function DstDetect(){
    var dtDstDetect = new Date();
    var dtDstStart = '';
    var dtDstEnd = '';
    var dtDstStartHold = ''; //Temp date hold
    var intYearDayCount = 732; //366 (include leap year) * 2 (for two years)
    var intHourOfYear = 1;
    var intDayOfYear;
    var intOffset = TimezoneDetect(); //Custom function. Make sure you include it.

    //Start from a year ago to make sure we include any previously starting DST
    dtDstDetect = new Date()
    dtDstDetect.setUTCFullYear(dtDstDetect.getUTCFullYear() - 1);
    dtDstDetect.setUTCHours(0,0,0,0);

    //Going hour by hour through the year will detect DST with shorter code but that could result in 8760
    //FOR loops and several seconds of script execution time. Longer code narrows this down a little.
    //Go one day at a time and find out approx time of DST and if there even is DST on this computer.
    //Also need to make sure we catch the most current start and end cycle.
    for(intDayOfYear = 1; intDayOfYear &lt;= intYearDayCount; intDayOfYear++){
        dtDstDetect.setUTCDate(dtDstDetect.getUTCDate() + 1);

        if ((dtDstDetect.getTimezoneOffset() * (-1)) != intOffset &amp;&amp; dtDstStartHold == ''){
            dtDstStartHold = new Date(dtDstDetect);
        }
        if ((dtDstDetect.getTimezoneOffset() * (-1)) == intOffset &amp;&amp; dtDstStartHold != ''){
            dtDstStart = new Date(dtDstStartHold);
            dtDstEnd = new Date(dtDstDetect);
            dtDstStartHold = '';

            //DST is being used in this timezone. Narrow the time down to the exact hour the change happens
            //Remove 48 hours (a few extra to be on safe side) from the start/end date and find the exact change point
            //Go hour by hour until a change in the timezone offset is detected.
            dtDstStart.setUTCHours(dtDstStart.getUTCHours() - 48);
            dtDstEnd.setUTCHours(dtDstEnd.getUTCHours() - 48);

            //First find when DST starts
            for(intHourOfYear=1; intHourOfYear &lt;= 48; intHourOfYear++){
                dtDstStart.setUTCHours(dtDstStart.getUTCHours() + 1);

                //If we found it then exit the loop. dtDstStart will have the correct value left in it.
                if ((dtDstStart.getTimezoneOffset() * (-1)) != intOffset){
                    break;
                }
            }

            //Now find out when DST ends
            for(intHourOfYear=1; intHourOfYear &lt;= 48; intHourOfYear++){
                dtDstEnd.setUTCHours(dtDstEnd.getUTCHours() + 1);

                //If we found it then exit the loop. dtDstEnd will have the correct value left in it.
                if ((dtDstEnd.getTimezoneOffset() * (-1)) != (intOffset + 60)){
                    break;
                }
            }

            //Check if DST is currently on for this time frame. If it is then return these values.
            //If not then keep going. The function will either return the last values collected
            //or another value that is currently in effect
            if ((new Date()).getTime() &gt;= dtDstStart.getTime() &amp;&amp; (new Date()).getTime() &lt;= dtDstEnd.getTime()){
                return new Array(dtDstStart,dtDstEnd);
            }

        }
    }
    return new Array(dtDstStart,dtDstEnd);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/daylight-saving-time-dst-detect/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Timezone Detect and Ignore Daylight Saving Time (DST)</title>
		<link>http://michaelapproved.com/articles/timezone-detect-and-ignore-daylight-saving-time-dst</link>
		<comments>http://michaelapproved.com/articles/timezone-detect-and-ignore-daylight-saving-time-dst#comments</comments>
		<pubDate>Mon, 28 Sep 2009 06:09:46 +0000</pubDate>
		<dc:creator>michaelkhalili</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Daylight Saving Time]]></category>
		<category><![CDATA[DST]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Timezone]]></category>

		<guid isPermaLink="false">http://michaelapproved.com/?p=5</guid>
		<description><![CDATA[When I needed a way to detect the browser time zone all I found were posts using getTimezoneOffset. The problem with that was it never took into account Daylight Saving Time (DST). If the user was currently in DST the function returns the time zone plus 60 minutes. Those extra minutes pushed the user into [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>When I needed a way to detect the browser time zone all I found were posts using <strong><em>getTimezoneOffset</em></strong>. The problem with that was it never took into account Daylight Saving Time (DST). If the user was currently in DST the function returns the time zone plus 60 minutes. Those extra minutes pushed the user into the next time zone incorrectly. There was no way to know if <strong><em>getTimezoneOffset</em></strong> included DST or not.</p>
<p>My solution was to go through each month of the current year and find its offset. Since DST adds an hour to the offset I just needed to keep the lowest offset of the year.<span id="more-5"></span></p>
<pre class="brush: jscript; title: ; notranslate">
function TimezoneDetect(){
    var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear());
    var intOffset = 10000; //set initial offset high so it is adjusted on the first attempt
    var intMonth;
    var intHoursUtc;
    var intHours;
    var intDaysMultiplyBy;

    //go through each month to find the lowest offset to account for DST
    for (intMonth=0;intMonth &lt; 12;intMonth++){
        //go to the next month
        dtDate.setUTCMonth(dtDate.getUTCMonth() + 1);

        //To ignore daylight saving time look for the lowest offset.
        //Since, during DST, the clock moves forward, it'll be a bigger number.
        if (intOffset &gt; (dtDate.getTimezoneOffset() * (-1))){
            intOffset = (dtDate.getTimezoneOffset() * (-1));
        }
    }

    return intOffset;
}
</pre>
<p>The function returns the correct offset, in minutes, from Coordinated Universal Time (UTC) in minutes and properly ignores DST. Remember, when calculating time zone, some time zones are set in half and three quarter hour increments.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelapproved.com/articles/timezone-detect-and-ignore-daylight-saving-time-dst/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

