My Vietnam

My life in Vietnam, plain and simple

Archive for December 2007

How You Can Also Wear Your Helmet

without comments

This is going to be a short one… a colleague of mine send me a link to a page with some pictures showing how creative you can be when you have to wear a helmet, and even what might happen if you are not wearing it, I am sorry about the text in Vietnamese, if you need any help for a translation let me know, I will try my best though I think the pictures speak for them self :-)

How to wear your helmet

Please let me know if the link is no longer available, I don’t know if that page will exist forever.

Written by Thomas Bindzus

December 27, 2007 at 18:57:31

Posted in Vietnam

Tagged with , ,

Christmas in Vietnam

without comments

Christmas this year we stayed in Ho Chi Minh City, and, though that isn’t new we have done it before, this year we took the scooter into district one also know as Saigon, or downtown. We were looking for somewhere to eat our Christmas dinner a restaurant or something.

The original plan was to take a taxi downtown so we didn’t have to worry about parking the scooter, but with the taxi came quite a surprise, because when we told him we wanted to go downtown he looked at us and shook his head, no way was he going to drive us in there, way too crowded already he said and gone he was again.

Mary started to cry because she thought we weren’t going after all and we stopped a second to think about what we should do; we could wait for another taxi or we could take the scooter… and so we did. On with the helmets, preparing Mary’s chair and off we went downtown.

Well there were a lot of motorbikes already in the streets, but hey what can you expect, it was rush hour around five o’clock in a big city, it didn’t seem so bad! As we got closer and closer to district one the traffic got more and more dense, but still nothing special.

Driving down Nam Kì Khởi Nghĩa street we got stuck really stuck for the first time, 4 buses were trying to get through one of the street crosses each of them with motorbikes driving by like small mosquitoes around some big elephants. Anyway it’s nothing special, the traffic is crazy and that was what could be expected.

So the rest of the trip into the Notre Dame Cathedral went a bit slower because of all the motorbikes and as we arrived we decided spontaneously to go for some ice cream at a nice looking café on Hàn Thuyên street just behind the Cathedral, my wife had been there before and recommended their ice cream (New Zealand, good quality ice cream).

We got a table outside so we could enjoy the view of the park area and the motorbikes driving by. Once we got seated my wife was already hungry, so we had our Christmas dinner right there, lucky for us they also served some decent sandwiches for the kids, a good tenderloin for my wife and lamb cods for me. The waiter told us that we had to finish before 19 because someone had rented the café for an evening party, but no problem we had plenty of time.

Despite the very untraditional Christmas dinner it was pretty nice and we even had time to finish off with some scoops of ice cream, not bad. I was extremely full when we left the café (I had to finish my wife’s and Nhi’s ice cream too) and despite having been a little down over the Christmas time I felt very good with a full stomach.

We got the scooter, and one of my wife’s nieces, Trang, got the other motorbike and our plan was to continue down Đồng Khởi street. On the way into district one Trang’s motorbike had stopped several times already, and it didn’t seem to get any better. We had just got past the corner driving up alongside the Cathedral and there were a lot of motorbikes now, and a lot of people outside the Cathedral. It was almost impossible to see the street for motorbikes, and around 100 meters from Đồng Khởi people were stuck and of course Trang’s motorbike decided to make trouble again.

I thought it would be too much of a risk to continue down that street, so we turned left on Nguyễn Du street wanting to go back home. The trip home went pretty fast and I think we were home around 20:00. We hadn’t been home for more than 30 minutes when my wife asked me if I wanted to go into town again! I had to consider that for a minute, but thought “what the heck it is Christmas let’s do it the Vietnamese way!” because that is what they normally do on Christmas eve; take the motorbike and drive around downtown.

Back on the scooter again, and Mary sitting in her chair in front of me seemed to enjoy the opportunity to get an extra ride on the same day, I think she sang all the way into town. We didn’t want to risk anything with Trang’s bike so my wife took our other scooter. The trip downtown was more troublesome this time and when we reached the end of Nguyễn Văn Trỗi we were in trouble already, there were so many motorbikes now, all of them heading downtown. Did I mention all of them were of course wearing their shiny new helmet and it almost looked like a carpet of Christmas glass balls had been spread all over the street.

We followed the same route as the first time heading towards the Notre Dame Cathedral this time our intention was to drive down Đồng Khởi street, but of course that was rather naive to imagine that this would be possible. When we reached the cross between Nam Kì Khởi Nghĩa street and Nguyễn Thị Minh Khai street there were so many bikes that it was impossible to move more than around 25 cm at a time.

The streets were pure chaos, everyone trying to get before others and the addition of pedestrians jaywalking in the streets didn’t help anything at all. after spending around 15 – 20 minutes driving less than 100 meters we decided to drive up Alexander D. Rhode street, away from the main traffic chaos, but there were still a lot of motorbikes, people, smoke and dust from the motorbikes.

I could see that it would be impossible to get down Đồng Khởi, so we decided to get to Nguyễn Du street again and try to see if there were fewer people near Bến Thành market. When we got closer to the Cathedral we saw more and more pedestrians and they were running around in the middle of the street in groups of 5 to 10 spraying fake snow at each other and at the motorbikes.

There were joy and laughter everywhere and even though there were chaos, it was fun to watch and kind of nice. I wish I had brought my camera this second time so I could have taken a picture to show how the young people ran around. But on the other hand it could be risky too to take pictures because of thieves, which would easily get away on foot among the myriads of people.

Finally we got down Nguyễn Du street and it was possible to breath a little bit again. I don’t think it took us that long to get to Bến Thành market, but unfortunately the guys at the parking spot was afraid somebody would steal our light bulbs while the scooter was parked there, so they didn’t want us to enter. The worst part is that they were probably right, if we left our scooter there we could end up with a set of old scratched light bulbs, we have tried that once already!

I suggested to my wife that we headed home again, the second trip around the Cathedral was pretty tough and she was tired too so we headed home again for the second time this evening. I suggested that we stopped for a glass of ice coffee on the way home and we ended up eating ice cream once more, and continued with a bowl of phở bò (noodle soup) afterwards, and finally we were home again. Mary was so easy to get to sleep when we put her to bed obviously also very tired. We were home again at around midnight, I had one last thing to do which were to call home to my mother in Denmark to wish her a merry Christmas.

This was my Christmas eve in Vietnam, it was a very very interesting experience, next year I think we will settle for a nice dinner at home or perhaps we will go to Denmark again for Christmas, that is if I can persuade my wife to go in the cold and dark season, because Christmas wouldn’t be the same if it was held in the summertime.

Merry Christmas from Vietnam!

Written by Thomas Bindzus

December 25, 2007 at 23:58:48

Posted in Vietnam

Tagged with , , ,

Adding Dynamic Contents to IFrames

with 13 comments

I found myself in a situation this weekend where I needed to add some contents to an iframe dynamically, and naive as I were, I kind of assumed it was straight forward to do it using the DOM.

To try it out I created a simple HTML page adding a div element and a function onPageLoad which would be called when the page was loaded and here I would place my code to dynamically add some contents to the iframe which I also decided to create dynamically just for the sport of it.

<html>
   <head>
      <title>Adding Dynamic Contents to IFrames</title>

      <script type="text/javascript">
         function onPageLoad()
         {
            var iframe = document.createElement("iframe");
            var canvas = document.getElementById("canvas");
            canvas.appendChild(iframe);

            var div = iframe.document.createElement("div");
            div.style.width = "50px"; div.style.height = "50px";
            div.style.border = "solid 1px #000000";
            div.innerHTML = "Hello IFrame!";
            iframe.document.body.appendChild(div);
         }
      </script>
   </head>

   <body onload="onPageLoad();">
      <div id="canvas" style="border: solid 1px #000000; height: 500px; width: 500px;"></div>
   </body>
</html>

My first attempt failed both in Internet Explorer and Firefox, worst in Firefox which announced that iframe.document didn’t have any properties, and in Internet Explorer the div element was placed after the iframe element not inside intended.I did some research using Google in an attempt to get some qualified help and I learned that there are just as many ways to get the iframe’s document as there are browser platforms, almost. But happy to have found myself in some kind of progress I updated my code for the onPageLoad function.

function onPageLoad()
{
   var iframe = document.createElement("iframe");
   var canvas = document.getElementById("canvas");
   canvas.appendChild(iframe);

   var doc = null;
   if(iframe.contentDocument)
      // Firefox, Opera
      doc = iframe.contentDocument;
   else if(iframe.contentWindow)
      // Internet Explorer
      doc = iframe.contentWindow.document;
   else if(iframe.document)
      // Others?
      doc = iframe.document;

   if(doc == null)
      throw "Document not initialized";

   var div = doc.createElement("div");
   div.style.width = "50px"; div.style.height = "50px";
   div.style.border = "solid 1px #000000";
   div.innerHTML = "Hello IFrame!";
   doc.body.appendChild(div);
}

My progress was limited, I succeeded in eliminating the error when viewing the page with Firefox, but now it no longer worked in Internet Explorer which announced that doc.body was null.You might wonder why I choose to append the iframe to an element which already exists in the DOM before appending anything to the iframe’s document, that is because I found out that as long as the iframe is not appended to the DOM the document property will not be initialized, this happened both for Internet Explorer and Firefox.Reading the post, I had found, a little more thoroughly I found out that there was a way to write to the iframe’s document using the document.write method. Trying it out I changed my onPageLoad function to write a small text.

function onPageLoad()
{
   var iframe = document.createElement("iframe");
   var canvas = document.getElementById("canvas");
   canvas.appendChild(iframe);

   var doc = null;
   if(iframe.contentDocument)
      // Firefox, Opera
      doc = iframe.contentDocument;
   else if(iframe.contentWindow)
      // Internet Explorer
      doc = iframe.contentWindow.document;
   else if(iframe.document)
      // Others?
      doc = iframe.document;

   if(doc == null)
      throw "Document not initialized";

   doc.open();
   doc.write("Hello IFrame!");
   doc.close();
}

Finally I was able to render the page both in Internet Explorer and Firefox with the same result, I was doing some real progress. Now I could of course create all of my contents in the iframe this way, as the post I found using Google suggested, but it wouldn’t be that dynamic plus I would have to do a lot of string manipulation in order to add event handlers and so on.

My biggest problem being that I only had access to an amputated version of the document element in the iframe I started thinking about ways in which I could make a callback function from the iframe sending the document element to the parent. But in the end the solution was extremely simple and perhaps some of you who read this whill think that it is obvious.

The real trick for making this work only occurred to me while writing this, I tried to add my div element to the iframe’s document element right after the part where I write “Hello IFrame!” as shown above, this gave me the following changed onPageLoad function.

function onPageLoad()
{
   var iframe = document.createElement("iframe");
   var canvas = document.getElementById("canvas");
   canvas.appendChild(iframe);

   var doc = null;
   if(iframe.contentDocument)
      // Firefox, Opera
      doc = iframe.contentDocument;
   else if(iframe.contentWindow)
      // Internet Explorer
      doc = iframe.contentWindow.document;
   else if(iframe.document)
      // Others?
      doc = iframe.document;

   if(doc == null)
      throw "Document not initialized";

   doc.open();
   doc.write("Hello IFrame!");
   doc.close();

   var div = doc.createElement("div");
   div.style.width = "50px"; div.style.height = "50px";
   div.style.border = "solid 1px #000000";
   div.innerHTML = "Hello IFrame!";
   doc.body.appendChild(div);
}

The magic appeared, now I got my div element added to the iframe’s document element right after the text I wrote using the write method. The next natural step was to leave out the call to the write method. Calling the open method following by the close method will put the iframe’s document in such a state that you will be able to use the appendChild method.

The only thing left to do after this was to wrap it all up nicely in a class, below is a simplified version of what an IFrame class might look like. Notice that the parent element must be added to the DOM already, but in most cases that shouldn’t cause any problems.

function IFrame(parentElement)
{
   // Create the iframe which will be returned
   var iframe = document.createElement("iframe");

   // If no parent element is specified then use body as the parent element
   if(parentElement == null)
      parentElement = document.body;

   // This is necessary in order to initialize the document inside the iframe
   parentElement.appendChild(iframe);

   // Initiate the iframe's document to null
   iframe.doc = null;

   // Depending on browser platform get the iframe's document, this is only
   // available if the iframe has already been appended to an element which
   // has been added to the document
   if(iframe.contentDocument)
      // Firefox, Opera
      iframe.doc = iframe.contentDocument;
   else if(iframe.contentWindow)
      // Internet Explorer
      iframe.doc = iframe.contentWindow.document;
   else if(iframe.document)
      // Others?
      iframe.doc = iframe.document;

   // If we did not succeed in finding the document then throw an exception
   if(iframe.doc == null)
      throw "Document not found, append the parent element to the DOM before creating the IFrame";

   // Create the script inside the iframe's document which will call the
   iframe.doc.open();
   iframe.doc.close();

   // Return the iframe, now with an extra property iframe.doc containing the
   // iframe's document
   return iframe;
}

I saved the class in a file called IFrame.js, and using this class simplified my test page to the following.

<html>
   <head>
      <title>Adding Dynamic Contents to IFrames</title>

      <script type="text/javascript" src="IFrame.js"></script>
      <script type="text/javascript">
         function onPageLoad()
         {
            var canvas = document.getElementById("canvas");
            var iframe = new IFrame(canvas);

            var div = iframe.doc.createElement("div");
            div.style.width = "50px"; div.style.height = "50px";
            div.style.border = "solid 1px #000000";
            div.innerHTML = "Hello IFrame!";
            iframe.doc.body.appendChild(div);
         }
      </script>
   </head>

   <body onload="onPageLoad();">
      <div id="canvas" style="border: solid 1px #000000; height: 500px; width: 500px;"></div>
   </body>
</html>

Written by Thomas Bindzus

December 24, 2007 at 00:37:49

Remember Your Helmet!

without comments

Once again I see how fast time flies by and I have not yet written any posts about what I wanted to, but I need to write about this hmmm… event in Vietnamese history of traffic. From the 15th of December it became required by law for everyone riding a motorbike or scooter to wear helmet in the city, before helmet was only required when driving on the highways also a law which has been added within the last couple of years.

I started to wear my helmet a couple of days before to sort of get into the habit and my wife made sure to buy helmets for everybody in the family. Almost everyone continued to ride their motorbike or scooter without wearing a helmet up until and on the day before the 15th of December, so I thought well yeah, tomorrow might not be that different after all, but I was quite wrong! Monday when I was on my way to work I saw that almost everybody was now wearing a helmet, apparently no one saw any reason for wearing it before they really had to, and I must admit that I have heard some complaints about wearing the helmet none the less.

However I think it’s pretty cool that this law has been made because it is my impression that a lot of people looses their life caused by head injuries if they are involved in an accident (no hard facts just a hunch). I used to buy my daily ice coffees outside the company and the lady who owned the shop had a son who used to be a cook, but after an accident on his motorbike he bound to a wheelchair, and he suffered from some sort of brain damage. The fine you will get for driving without a helmet should also encourage all to wear the helmet, from one of my colleagues I learned that it costs over 200.000 VND if the police stops you without a helmet on, 200.000 VND is around 13 USD, and is plenty to actually buy a helmet.

The funny or scary thing is that besides from the helmet everything else about the Vietnamese traffic is its good old same, people are still driving hazardously through the streets, still against the direction of the traffic in the wrong side of the street or on the pavement where such even exists, but at least something is being done and that is great!

Wear your helmet folks!

Written by Thomas Bindzus

December 21, 2007 at 00:56:16

Posted in Vietnam

Tagged with , ,