/*
**
**
**
**
**
*/


//setting
var EVENT_PHOTO_SHOW_WIDTH = 800;
var EVENT_PHOTO_DIR = "../img/photos/";
var IMG_DIR = "../img/";
var XML_SERVER = "./admin.server.php";


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


// namespace placeholder
Class = {};

/**
 * A function used to extend one class with another
 * 
 * @param {Object} subClass
 * 		The inheriting class, or subclass
 * @param {Object} baseClass
 * 		The class from which to inherit
 */
Class.extend = function(subClass, baseClass) {
   function inheritance() {}
   inheritance.prototype = baseClass.prototype;

   subClass.prototype = new inheritance();
   subClass.prototype.constructor = subClass;
   subClass.baseConstructor = baseClass;
   subClass.superClass = baseClass.prototype;
}


var messageStr = "Yes";


Number.prototype.NaN0=function(){return isNaN(this)?0:this;}


function httpRequest()
{
	var xmlhttp;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) 
		{
			xmlhttp.overrideMimeType('text/xml');
		}
	}// code for ie
	else if (window.ActiveXObject)
	{
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			//
		}
	}
	return xmlhttp;
}


function getUrl( url,  cb, data ) 
{
	var xmlhttp = httpRequest();//getXMLDoc();
	
	xmlhttp.open("GET", url);
	xmlhttp.onreadystatechange = function () 
	{
		if ( xmlhttp.readyState == 4 )
		{
			//alert( xmlhttp.responseText );
			
			cb(xmlhttp.status, xmlhttp.getAllResponseHeaders(), xmlhttp.responseXML ,url);
		}
	};

	xmlhttp.send(data);
}


function sendRequest( url , cb , data )
{
	var timestamp = new Date().getTime();
	url = url + "?timeStamp=" + timestamp;
	var xmlhttp = httpRequest();//getXMLDoc();
	
	xmlhttp.onreadystatechange = function () 
	{
		if (xmlhttp.readyState == 4)
		{
			cb( xmlhttp );
		}
	};

	xmlhttp.open("POST", url, true );
	//xmlhttp.setRequestHeader( "Content-Type" , "charset=UTF-8" );
	xmlhttp.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded; charset=UTF-8" );
	
	xmlhttp.send(data);
	
	return timestamp;
}


/* class search bar
** Ver: 1.1.2
** Author: Jia Yu
**
** Change log
** support Safari
*/
function SearchBar( parent , themenu, close_Button_On_Click , textBoxKeyPress, resDir )
{	
	var _this = this;
	var RES_DIR = resDir || "../img/";

	var IMG_CLOSE = RES_DIR + "close.png";
	var IMG_LEFT = RES_DIR + "serleft.png";
	var IMG_RIGHT = RES_DIR + "serright.png";
	var IMG_CENTER = RES_DIR +  "sercenter.png";
	var USER_AGENT = "Safari";
	var theRow = null;
	var infoRow = null;

	var leftCell = null;
	var centerCell = null;
	var rightCell = null;
	var textBox = document.createElement("INPUT");
	
	var searchScop = document.createElement("INPUT");

//public prop
	this.parent = parent;
	this.themenu = themenu;
	this.thebody = document.createElement("TABLE");
	this.theform = null;
	this.disableSubmit = false;
	
//ini---
	if( navigator.userAgent.indexOf("Safari") == -1 ) USER_AGENT = "Other";
	
	if( typeof parent == "string" ) this.parent = document.getElementById( parent );
	this.parent.innerHTML = "";
	
	this.theform = this.parent;
	while( this.theform.tagName != "BODY"  )
	{		
		this.theform = this.theform.parentNode;
		if( this.theform.tagName == "FORM"   ) break;
	}
	
	
	if(  this.theform.tagName != "FORM" )
	{
		this.theform =  document.createElement("FORM");
		this.theform.id = "form_search";
		//this.theform.method = "post";
		//this.theform.action = "#";
		this.parent.appendChild( this.theform );
		this.theform.appendChild( this.thebody );
		this.theform.onsubmit = function()
		{
			return false;	
		};
	}
	
	//debug info
	if(  this.theform == null )
	{
		alert( "Can not found form for search bar class ini failed." );	
	}
	//alert( this.theform );

	this.parent.appendChild( this.thebody );
	this.thebody.name = "searchbar";
	this.thebody.border = 0;
	this.thebody.cellPadding = 0;
	this.thebody.cellSpacing = 0;
  
	theRow = this.thebody.insertRow(-1);
	infoRow = this.thebody.insertRow(-1);
	
	infoRow.insertCell(-1);
	infoCell = infoRow.insertCell(-1);
	infoCell.align = "center";
	infoCell.style.padding = "1px";
	
	infoRow.insertCell(-1);
	
	leftCell = theRow.insertCell(-1);
	
	textBox.style.background = "url( ../img/searchbg.png ) no-repeat left center";
	
	if(  USER_AGENT == "Other"  )
	{
		leftCell.style.width = "24px";
		leftCell.style.height = "24px";

		leftCell.style.backgroundImage = "url("+IMG_LEFT+")";
		leftCell.style.backgroundRepeat = "no-repeat";
		leftCell.style.backgroundPosition = "center right";
		//leftCell.align = "right";
		//leftCell.valign = "middle";
		leftCell.style.cursor="pointer";
		leftCell.style.whiteSpace = "nowrap";
		leftCell.innerHTML = "<div style='width:24px;'></div>";
	}
	else if(  USER_AGENT == "Safari" )
	{
		leftCell.style.visibility = "hidden";
	}
	
	centerCell = theRow.insertCell(-1);
	centerCell.style.width = "150px";
	centerCell.style.height = "24px";
	if( USER_AGENT == "Other" )
	{
		centerCell.style.backgroundImage = "url("+IMG_CENTER+")";
		centerCell.style.backgroundRepeat = "repeat-x";
		centerCell.style.backgroundPosition = "center";
		centerCell.style.paddingLeft = "2px";
	}
	else if(  USER_AGENT == "Safari" )
	{
		//centerCell.class="search";
	}
	
	rightCell = theRow.insertCell(-1);
	
	if(  USER_AGENT == "Other"  )
	{
		rightCell.style.width = "24px";
		rightCell.style.backgroundImage = "url("+IMG_RIGHT+")";
		rightCell.style.backgroundRepeat = "no-repeat";
		rightCell.style.backgroundPosition = "center left";
		rightCell.style.whiteSpace = "nowrap";
		rightCell.innerHTML = "<div style='width:24px;'></div>";
	}
	else if(  USER_AGENT == "Safari" )
	{
		//rightCell.style.visibility = "hidden";
	}
	
	if( USER_AGENT == "Safari" )
	{
		textBox.type = "search";
		textBox.setAttribute( "autosave", "bsn_srch" );
		textBox.setAttribute( "results", "5" );

		textBox.onclick = function( event )
		{
			//alert( event.layerX );
		};
	}
	else
	{
		textBox.type = "text";		
		textBox.style.borderWidth = "0px";
		textBox.style.borderStyle = "none";
		textBox.style.borderColor = "#FFFFFF";
		textBox.style.fontFamily= "Arial, Helvetica, sans-serif";
		textBox.style.fontSize="11px";
		textBox.style.height = "12px";
	}
	
	//textBox.style.width = "200px";
	textBox.id = "searchkey";
	textBox.name="q";
		
	centerCell.appendChild(textBox);
	
	searchScop.type = "hidden";	
	this.theform.appendChild( searchScop );
	searchScop.id = "searchScop";
	searchScop.name = "searchScop";
	searchScop.value ="";
		
	
	//event--		
	if(  USER_AGENT == "Other"  )
	{
		//closebutton.onclick = closebuttononclick;
		leftCell.onclick = mgonclick;
		rightCell.onclick = closebuttononclick;
	}
	
	textBox.onchange = change;
	
	function mgonclick()
	{
		if(  _this.themenu != null )
		{
			_this.themenu.showpop( this ,10, -3 );
		}
	}
	
	function change()
	{
		if( textBox.value != ""  )
		{
			//closebutton.style.visibility = "visible";
			rightCell.style.backgroundImage = "url("+IMG_CLOSE+")";
		}
		else
		{
			//closebutton.style.visibility = "hidden";
			rightCell.style.backgroundImage = "url("+IMG_RIGHT+")";
		}
	}
	
	function closebuttononclick()
	{
		if( textBox.value != "" )
		{
			//closebutton.style.visibility = "hidden";
			rightCell.style.backgroundImage = "url("+IMG_CLOSE+")";
			
			textBox.value = "";
			change();
			
			if( _this.disableSubmit == false )  
			{	
				_this.theform.submit();
			}
			else
			{
				//_this.close_Button_On_Click(); 
				close_Button_On_Click();
			}
			
		}
	}
	
	textBox.onkeypress = keypress;
	function keypress( event )
	{		
		if ( window.event ) event = window.event;	
		var key = event.charCode || event.keyCode;
		
		change();
		
		if( key == 13 ) 
		{
			if( _this.disableSubmit == false )  
			{	
				_this.theform.submit();
			}
			else
			{
				textBoxKeyPress();
			}
		}
	}
	
	
	//publiuc method
	this.getTextBox = function()
	{
		return textBox;
	};
	
	this.getRightCell = function()
	{
		return rightCell;
	};
	
	this.setInfoText =  function( str )
	{
		infoCell.innerHTML = str;
		searchScop.value = str;
	};
	
	
	this.getInfoText = function()
	{
		return infoCell.innerHTML;
	};
	
	
	this.setText = function( str )
	{
		textBox.value = str;
		change();
	};
	
	this.getText = function()
	{
		return textBox.value;
	};
	
	this.setInfoTextClass = function( str )
	{
		infoCell.className = str;
	};
	
	this.setWidth = function( number )
	{
		if(  USER_AGENT == "Safari"  )
		{
				number += 40;
		}
		textBox.style.width = number +"px";
	};
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}



function GetCookie (name){
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal (j);

        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}



function getCookieVal (offset){
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}



function SetCookie (name, value ){
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
   
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
   
    document.cookie = name + "=" + escape (value) +
     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
     ((path == null) ? "" : ("; path=" + path)) +
     ((domain == null) ? "" : ("; domain=" + domain)) +
     ((secure == true) ? "; secure" : "");
}



function setTextboxOverOut()
{
	
	var inputs = document.body.getElementsByTagName("input");
	for( var i=0;i<inputs.length; i++ )
	{
		inputs[i].onmouseover = over;
		inputs[i].onmouseout = out;
	}
	
	function over()
	{
		this.style.borderColor = "#333333";
		this.style.	backgroundColor= "#EEEEEE";

	}
	
	function out()
	{
		this.style.borderColor = "";
		this.style.	backgroundColor= "#DDDDDD";
	}	
}



function getNodeData( childNodes )
{
	var value = "";	
	if( childNodes )
	{
		for(var j=0;j<childNodes.length;j++ )
		{
			value += childNodes[j].data;
		}
	}
	return value;
}




function getXmlText( xml, string )
{
	var text = "";
	
	
	
	try
	{
		text = getNodeData( xml.getElementsByTagName( string ).item(0).childNodes );
		
		//if( text  == undefined ) text = "";;
	}
	catch( e ) 
	{
		text = "";	
	}
	
	return text;
}



function getText( obj )
{
	var value = "";
	
	//alert (  obj.textContent  );
	
	if( typeof obj.textContent == "string" )
	{
		value = obj.textContent;
	}
	else if( document.all )
	{
		value = obj.innerText;
	}
	else
	{
		value = obj.innerHTML;
	}

	return new String( value ); 
}




//trim()

String.prototype.trim = function()
{
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
};


function $( str )
{
	
	return document.getElementById( str );
		
}


function takeoutthelet( data )
{
		data = data.replace(/-/gi, "");
		data = data.replace(/\./gi, "");
		data = data.replace(/\+/gi, "");
		data = data.replace(/T/gi, "");
		data = data.replace(/:/gi, "");
				
	return data;
}


/*
** FileName:	TextShow.js
** Author:		Jia Yu
** Date:		11-09-2006
** Ver:			1.1
** Path:		
** Purpose:		The text show
*/


function TextShow( data, shower )
{
	var _this = this;
	
	this.items = data;
	this.hotNewsCell = shower;
	this.intervalTime = 4000;
	var intervalID = 0;
	var newsIndex = 1;
	var chatWidth = -1;

	
	if( this.items[0].getElementsByTagName('title').item(0)  )
	{
		_this.hotNewsCell.innerHTML = _this.items[0].getElementsByTagName('title').item(0).childNodes[0].data;
	}
	 _this.hotNewsCell.href = "news.html";


	this.hotNewsCell.onmouseover = function()
	{
			if( _this.items.length > 0 )
			{
				window.clearInterval( intervalID );
			}
			if( _this.href !== "" ){
				_this.hotNewsCell.style.textDecoration = "underline";
			}
	};
	
	
	this.hotNewsCell.onmouseout = function()
	{
			if( _this.items.length > 0 )
			{
				intervalID = window.setInterval( _this.run, _this.intervalTime ); 
			}
			_this.hotNewsCell.style.textDecoration = "none";
	};

	//alert( _this.items[ 1 ].getElementsByTagName('title').item(0) );
	this.run = function()
	{
		if( _this.items[ newsIndex ].getElementsByTagName('title').item(0).childNodes[0]  != null )
		{
			
			if( chatWidth == -1 )
			{
				_this.hotNewsCell.innerHTML = _this.items[ newsIndex ].getElementsByTagName('title').item(0).childNodes[0].data;
			}
			else
			{
				_this.hotNewsCell.innerHTML = chopString( _this.items[ newsIndex ].getElementsByTagName('title').item(0).childNodes[0].data ,  chatWidth  ) ;
			}
		}
		
		_this.hotNewsCell.href = "news.html";

		newsIndex ++;
		if ( newsIndex >= _this.items.length ) newsIndex = 0;	
	};
	
	intervalID = window.setInterval( _this.run, _this.intervalTime ); 
	 
	 function chopString( str , num)
	 {
		 str = new String( str );
		 if( num >0 )
		 {
			 if( str.length > num  )
			 {
				str = str.substring(0 , num ) + "...";
				 
			 }
		 }
		 return str;
	 }
	 
	 this.setChatWidth = function( num )
	 {
		 chatWidth = num;
		_this.hotNewsCell.innerHTML = 	chopString( 	_this.hotNewsCell.innerHTML , num );
	 };
}

//email subscription

var YOUR_EMAIL_ADDRESS = "Your email address here."


//class infobox

var infoboxid = 0;

function InfoBox( parent )
{
	var YOUR_EMAIL_ADDRESS = "Your email address here."
	
	var _this = this;
	var parent = parent;
	this.thebody = document.createElement("div");
	
	var title;
	var age;
	var areyou = [];
	var otherText;
	var email;
	var nationality;
	var term;
	var submit;
	
	var marginTop = 10;
	
	this.isready = false;

	//ini
	if( typeof parent == "string" ) parent = document.getElementById( parent );
	parent.innerHTML = "";
	parent.appendChild( this.thebody );
	this.thebody.border = "0";
	this.thebody.className ="cotext";
	//this.thebody.style.display = "none";

	this.thebody.innerHTML = '<img  src="../img/specialoffer.gif" alt="Enter Your Email to Get Our Special Offer" ' +
			' border="0" style="position:relative;  right:-5px;  top:-30px;"  />';
	
	title = this.thebody.appendChild(document.createElement("div") );
	
	//age group
	var ageText = this.thebody.appendChild( document.createElement("div") );
	ageText.innerHTML = "Age Group:";	
	age = this.thebody.appendChild( document.createElement("select") );
	age.id = "so_age";
	age.className = "textbox";
	age.style.width = "180px";
	age.style.fontSize = "11px";
	
	var op0 = age.appendChild( document.createElement("option") );
	op0.innerHTML = "- Select your age group -";
	//op0.className = "offsetcol2";
	op0.value = "0";
	op0.selected = true;
	
	var op1 = age.appendChild( document.createElement("option") );
	op1.innerHTML = "13 - 18";
	op1.className = "offsetcol";
	op1.value = "1";
	
	var op2 = age.appendChild( document.createElement("option") );
	op2.innerHTML = "19 - 30";
	op2.className = "offsetcol2";
	op2.value = "2";
	
	var op3 = age.appendChild( document.createElement("option") );
	op3.innerHTML = "30 +";
	op3.className = "offsetcol";
	op3.value = "3";
	
	//Nationality get from the server
	var NationalityText = this.thebody.appendChild( document.createElement("div") );
	NationalityText.innerHTML = "Nationality:";
	NationalityText.style.marginTop = marginTop+"px";
	//the data
	nationality = this.thebody.appendChild( document.createElement("select") );
	nationality.className = "textbox";
	nationality.style.width = "180px";
	nationality.style.fontSize = "11px";
	var optemp = nationality.appendChild( document.createElement("option") );
	optemp.innerHTML = "- Loading nationality -";
	optemp.value = 0;
	optemp.selected = true;
	
	var nationalityxmlhttp = httpRequest();//getXMLDoc();
	var data = "null";
	var url = "../script/getnationality.php" + "?timeStamp=" + new Date().getTime();

	nationalityxmlhttp.onreadystatechange = function() 
	{
		if ( nationalityxmlhttp.readyState == 4 )
		{
			if( nationalityxmlhttp.status == 200 )
			{
				//alert( nationalityxmlhttp.responseText );
				var xml = nationalityxmlhttp.responseXML;
				var node = xml.documentElement;
				
				//alert( node );
				
				if( node )
				{
					var data = node.getElementsByTagName('data').item(0).getElementsByTagName('nationality');
					var status = node.getElementsByTagName('status').item(0).childNodes[0].data;

					if( status == "ok"  )
					{
						nationality.innerHTML = "";
						var op0 = nationality.appendChild( document.createElement("option") );
						op0.innerHTML = "- Select your nationality -";
						op0.value = 0;
						op0.selected = true;
					
						for(var i = 0; i< data.length; i++ )
						{
							var op1 = nationality.appendChild( document.createElement("option") );
							op1.innerHTML = data[i].getAttribute("name");
							if( (i%2 + 1) == 2 ) op1.className = "offsetcol"; else  op1.className = "offsetcol2";
							op1.value = data[i].getAttribute("id");	
						}
					}
					else
					{
						//ERROR: can not load the nationality.
					}
				}
			}
			else if( nationalityxmlhttp.status == 404 )
			{
				//ERROR: nationality page not found.
			}
		}
	};
	
	nationalityxmlhttp.open("GET", url ,true);
	nationalityxmlhttp.send(data);
	
	//Are you
	var areyouText = this.thebody.appendChild( document.createElement("div") );
	areyouText.innerHTML = "Are you:";

	areyouText.style.marginTop = marginTop+"px";
	//var areyouopt = new Array;
	var tempname = new Array( "Student","Parent","Agent","Other" );

	for(var i=0 ; i<4 ; i++  )
	{	
		this.thebody.appendChild(document.createElement("br"));
		areyou[i] = document.createElement("input");
		areyou[i].type = 'checkbox';
		areyou[i].name = 'so_areyou';
		areyou[i].onclick = function()
		{
			for(var j=0;j<areyou.length ;j++ )
			{
				areyou[j].checked = false;
			}
			this.checked = true;
		};
		
		this.thebody.appendChild( areyou[i] );
		areyou[i].value = tempname[i];
		this.thebody.appendChild(document.createTextNode(" "+tempname[i]+" "));
	}
	

	otherText = this.thebody.appendChild( document.createElement("input") );
	otherText.type="text";
	otherText.className = "textbox"; 
	otherText.style.width = "115px";
	otherText.style.fontSize = "11px";
	otherText.size = 20;
	//event
	otherText.onclick = function()
	{
		for(var j=0;j<areyou.length ;j++ )
		{
			areyou[j].checked = false;
		}
		areyou[3].checked = true;
	};
	
	//email
	var emailText = this.thebody.appendChild( document.createElement("div") );
	emailText.innerHTML = "Email:";
	emailText.style.marginTop = marginTop+"px";
	
	email = this.thebody.appendChild( document.createElement("input") );
	email.type = "text";
	email.style.width = "180px";
	email.className = "textbox";
	email.style.fontSize = "11px";
	email.id = "so_email";
	email.maxlength = 50;
	email.value = YOUR_EMAIL_ADDRESS;
	
	var termDiv = this.thebody.appendChild( document.createElement("div") );
	termDiv.style.marginTop = marginTop+"px";
	
	/*
	var termCell = termDiv.appendChild( document.createElement("label") );
	term = document.createElement("input");
	term.setAttribute("type","checkbox");
	termCell.appendChild( term );
	term.setAttribute("value","agree");
	term.id = 'so_checkbox';
	
	var agreetext = termCell.appendChild( document.createElement("span") );
	agreetext.innerHTML = "Agree with Privacy Policy.";
	*/
	
	var submitCell = document.createElement("p");
	this.thebody.appendChild( submitCell );
	submitCell.align = "right";
	
	
	submit = document.createElement("input"); 
	submit.type = "button";
	submit.value = "Submit";

	submitCell.appendChild( submit );
	submit.name = "Submit";
	
	submit.className = "textbox";
	submit.style.fontSize = "11px";

	submit.style.paddingLeft = "8px";
	submit.style.paddingRight = submit.style.paddingLeft;

	//event
	submit.onclick = function(event)
	{
		//alert( age.value );
		submit.value = "Loading...";	
		if( age.value == "0" || age.value == "" )
		{
			alert("Please select your age group.");
			return false;
		}
		
		if( nationality.value == "0" || nationality.value == ""  )
		{
			alert("Please select your nationality.");
			return false;
		}
		
		var areyouValue = "";
		for(var i=0; i<areyou.length; i++)
		{
			//alert( areyou[i].checked );
			if( areyou[i].checked == true )
			{
				areyouValue = areyou[i].value;
			}
		}
		
		if( areyouValue == ""  )
		{
			alert("Please select one.");
			return false;
		}
		else if( areyouValue == tempname[3]  )
		{
			if( otherText.value == "" )
			{
				alert("Please Fill in the \"other\" ");
				return false;
			}
			else
			{
				areyouValue = otherText.value;
			}
		}
		
		if( !email.value.match(/^[\w\W]+\@[\w\W]+[\w]$/) )
		{
			alert("The email address you gave us is invalid.");
			return false;
		}
		
		/*
		if( term.checked == false  )
		{
			alert("You have to agree with the Privacy Policy");
			return false;
		}
		*/
		
		this.disabled = true;
		
	 	var data = "email="+email.value+"&areyou="+areyouValue+"&nationality="+nationality.value+"&age="+age.value;
	 	var url = "../script/addemail.php" + "?timeStamp=" + new Date().getTime();
	 	var addemailxmlhttp = httpRequest();//getXMLDoc();
	 	
	 	addemailxmlhttp.onreadystatechange = function () 
	 	{
			if ( addemailxmlhttp.readyState == 4 )
			{
				if( addemailxmlhttp.status == 200 )
				{	
					//alert( addemailxmlhttp.responseText );
					var node = addemailxmlhttp.responseXML.documentElement;
					if( node )
					{
						var status = node.getElementsByTagName('status').item(0).childNodes[0].data;
						if( status == "ok"  )
						{
							//the clear up
							age.value = 0;
							
							for(var i=0;i<areyou.length; i++)
							{
								areyou[i].checked = false ;
							}
							
							email.value = "";
							otherText.value == "";
							nationality.value = 0;
							//term.checked = false;
							submit.disabled = false;
							submit.value = "Submit";
							addemailxmlhttp
							alert( "Thank you for subscribing with us."  );
						}
						else
						{
							var error = node.getElementsByTagName('error').item(0).childNodes[0].data;
							alert( error );
							
							//ERROR: error on getting the data to the server
							submit.disabled = false;
							submit.value = "Submit";
						}
					}
				}
				else if( addemailxmlhttp.status == 404 )
				{
					//ERROR: addmail page not found.
				}
			}
	 	};
	 	addemailxmlhttp.open("POST", url, true );
	 	addemailxmlhttp.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" );
	 	addemailxmlhttp.send(data);
	};
	
	
	email.onfocus = function(event)
	{
		if( this.value == YOUR_EMAIL_ADDRESS ) 
		{
			this.value ='';
			this.style.color = "#000000";
		}
	};
	
	email.style.color = "#666666";
    email.onblur = function( event )
    {	
    	if( this.value == "" )
    	{
    		this.value = YOUR_EMAIL_ADDRESS;
			this.style.color = "#666666";
    	}
    };
    

    
    
	//showing the body
	//parent.innerHTML = "";
	//parent.appendChild(this.thebody);
	//this.thebody.style.display = "";
}

//class rte
function RTE( parent, html , parentNode )
{
	var _this = this;
	this.parent = parent;
	if( typeof parent == "string" ) this.parent = document.getElementById( parent );
	this.thebody = document.createElement("div");
	this.toolbar = document.createElement( "div" );
	
	if( document.all )
		this.editarea = document.createElement( "div" );
	else		
		this.editarea = document.createElement( "iframe" );
	
	var thetextarea = document.createElement("textarea");

	this.html = html;
	var HEIGHT = 300;
	
	//ini
	parentNode.appendChild( this.thebody );
	this.thebody.appendChild( this.toolbar );
	this.thebody.appendChild( thetextarea );
	this.thebody.appendChild( this.editarea );
	
	this.toolbar.style.width = "100%";
	this.toolbar.style.paddingLeft = "2px";
	this.toolbar.style.paddingTop = this.toolbar.style.paddingBottom = "4px";
	this.toolbar.style.backgroundColor = "#EEEEEE";

	var buttonHTML = NEW_BUTTON( "&lt;HTML&gt;", this.toolbar );
	//buttonHTML.style.border = "1px "+ buttonHTML.style.backgroundColor +" solid";
	//buttonHTML.style.backgroundColor = "#eeeeee";

	buttonHTML.onclick = function(event)
	{
		if( thetextarea.style.display == "none" )
		{
			_this.showHTML( true );
			//this.style.border = "1px "+ this.style.backgroundColor +" solid";
		}
		else
		{
			_this.showHTML( false );
			//this.style.border = "1px #333333 solid";
		}
		
	};
	
	
	thetextarea.style.display = "none";
	thetextarea.style.width = "100%";
	thetextarea.style.height = HEIGHT +"px";
	thetextarea.style.border = "1px #666666 solid";
	thetextarea.style.backgroundColor = "#FFFFFF";
	thetextarea.style.fontFamily= "Arial, Helvetica, sans-serif";
	thetextarea.style.fontSize="10pt";
	thetextarea.style.padding= "2px";
	
	thetextarea.value = this.html;
	
	this.editarea.style.width = "100%";
	this.editarea.style.height = HEIGHT +"px";
	this.editarea.style.border = "1px #666666 solid";
	this.editarea.style.cursor = "text";
								//alert( "yes" );
	if( document.all )							
	{
		this.editarea.contentEditable = "true";		
	}
	else
	{
		this.editarea.contentWindow.document.designMode = "on";
		this.editarea.contentWindow.document.body.contentEditable = "true";
	
		this.editarea.contentWindow.document.open();
	 	this.editarea.contentWindow.document.writeln('<html><head>');
	 	this.editarea.contentWindow.document.writeln('<style>body {	font-family: Arial, Helvetica, sans-serif;font-size:10pt;margin: 2px; padding: 2px;}</style>');
	 	this.editarea.contentWindow.document.writeln('</head><body></body></html>');
	 	this.editarea.contentWindow.document.close();
	}
	
	this.innerHTML = function( html )
	{
		this.html = html;
		if( document.all )
			this.editarea.innerHTML = html;
		else
			this.editarea.contentWindow.document.body.innerHTML = html;
		
		thetextarea.value = html;
	};
	
	this.getHTML = function()
	{
		if( this.editarea.style.display != "none" )
		{
			if( document.all )
				return this.editarea.innerHTML;
			else
				return this.editarea.contentWindow.document.body.innerHTML;
		}
		else
		{
			return thetextarea.value;
		}
	};
	
	this.showHTML = function( bool )
	{
		if( bool )
		{
			_this.editarea.style.display = "none";
			if( document.all )
				thetextarea.value = this.editarea.innerHTML;
			else
				thetextarea.value = this.editarea.contentWindow.document.body.innerHTML;
			
			thetextarea.style.display = "";
			
		}
		else
		{
			thetextarea.style.display = "none";
			if( document.all )
				this.editarea.innerHTML;
			else
				this.editarea.contentWindow.document.body.innerHTML = thetextarea.value;
			
			_this.editarea.style.display = "";
		}
	};
	
	this.setSize = function( width , height )
	{
		thetextarea.style.width = width;
		thetextarea.style.height = height;
		this.editarea.style.width = width;
		this.editarea.style.height = height;
	};
	
}





//class msgQueue
function MsgQueue()
{
	var _this = this;
	var msgs = new Array();
	var msgid = 0;
	var theMsgTop = 0;
	var lastHeight = 0;
	
	this.shownext = function()
	{
		document.body.removeChild( msgs[0].thebody )
		msgs.remove( msgs[0] );
		
		if( msgs.length > 0 ) 
		{
			msgs[0].run();
		}
	};
	
	this.getNextID = function()
	{
		msgid ++;
		return msgid
	};
		
	this.pushMsg = function( html, type )
	{
		
		if( msgs.length > 0 && ( document.body.scrollTop + document.documentElement.clientHeight ) > theMsgTop + lastHeight + 30   ) 
		{
			lastHeight = msgs[ msgs.length -1 ].thebody.offsetHeight;
			theMsgTop = theMsgTop + lastHeight+5;
		}
		else
		{
			//theMsgTop = pageYOffset + 10;
			theMsgTop = document.body.scrollTop + 10;
		}
		
		msgs[msgs.length] = new MsgFly( _this, html , type, _this.getNextID(), theMsgTop  );
		if( msgs.length == 1 ) msgs[0].run();	
	};

}


//class msgfly
function MsgFly( parent,  html, type ,id, top )
{
	
	var _this = this;
	var MSG_TYPE_ERROR = "error";
	var MSG_TYPE_MSG = "msg";
	var TIME_INTV = 100;

	var max = 60; 
	var count = 140;
	var theTop = top;
	
	this.id = id;
	this.thebody = document.createElement("div")
	document.body.appendChild( this.thebody  );
	this.thebody.style.display = "none";
	this.thebody.style.width = "200px";
	this.thebody.style.left = 10 +"px";
	this.thebody.style.position = "absolute";
	this.thebody.style.top  = theTop+"px";
	
	this.thebody.innerHTML = html;
	
	this.thebody.style.paddingLeft = this.thebody.style.paddingRight =  "10px";
	this.thebody.style.paddingTop = this.thebody.style.paddingBottom =  "5px";
	this.thebody.style.display = "";
	

	var intervalID = "0";
	
	if( type == MSG_TYPE_ERROR ) 
	{
		this.thebody.className = "error";
	}
	else
	{
		this.thebody.className = "msg";
	}
	
	this.flyout = function()
	{
		
		if( count <= max )
		{
			setOpacity( _this.thebody , count / max * 90 );
				
			if( count <= 0 ) 
			{			
				window.clearInterval( intervalID );
				parent.shownext();
				delete _this;
			}
		}
		
		count = count - 10;
	};	
	
	this.run= function()
	{
		//_this.thebody.style.top = ( window.pageYOffset + 10 )+"px";
		_this.thebody.style.top = theTop+"px";
		//_this.thebody.style.left = document.documentElement.clientWidth - this.thebody.offsetWidth - 10 +"px";
		_this.thebody.style.left = 10 +"px";
		
		//alert( theTop );
		_this.setDisplay( true );
		intervalID = setInterval( _this.flyout , TIME_INTV );
	};
	
	this.setDisplay = function( bool )
	{
		if( bool )
		{
			//this.thebody.style.left = document.documentElement.clientWidth - this.thebody.offsetWidth - 10 +"px";
			this.thebody.style.display = "";
		}
		else
		{
			this.thebody.style.display = "none";	
		}
	};
}





Array.prototype.remove=function( obj ){
  for(i=0;i<this.length;i++)
  {
    if( obj == this[i] ) this.splice(i, 1);
  }
}




//0/100
function setOpacity( obj,value ){
	//alert( value );
	
	
	if( document.all ){
		
				obj.style.filter = "alpha(opacity="+value+")";
	}
	else{
		value = value * 0.01;
		obj.style.opacity = value;
	}	
}
	
var MSG_OUTPUT = new MsgQueue();




function AddEventListener(obj, eventString, eventmethod )
{
	if( document.all )
	{
		obj.attachEvent( "on"+eventString, eventmethod );	
	}
	else
	{
		obj.addEventListener( eventString, eventmethod,false );
	}

}






//functions for drag event

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

function getMouseOffset(target, ev){
	ev = ev || window.event;

	var docPos  = getPosition(target);
	//document.getElementById(  "disp" ).innerHTML += "docPos.y:"+docPos.y;
	
	var mousePos  = mouseCoords(ev);
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}

function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		e     = e.offsetParent;

		//document.getElementById(  "disp" ).innerHTML +=  e.tagName + ": " + e.offsetTop + "< br />"; 
	}


	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
	
	//document.getElementById(  "disp" ).innerHTML +=  e.tagName + ": " + e.offsetTop + "< br />"; 
	
	return {x:left, y:top};

}






	disableSelection = function (element) {

			
		var b = BrowserDetect.browser;
		
 	        if ( b == "Firefox" || b == "Mozilla" ) {
 	                element.style.MozUserSelect = "none";
 	        } else {
 	                if ( b == "Safari" ) {
 	                        element.style.KhtmlUserSelect = "none";
 	                } else {
 	                        if ( b == "Explorer") {
 	                                element.unselectable = "on";
 	                        } else {
 	                                return false;
 	                        }
 	                }
 	        }
 	        return true;
 	};
 	
 	
 	enableSelection = function (element) {
		
		var b = BrowserDetect.browser;
		
 	        if ( b == "Firefox" || b == "Mozilla" ) {
 	                element.style.MozUserSelect = "";
 	        } else {
 	                if ( b == "Safari" ) {
 	                        element.style.KhtmlUserSelect = "";
 	                } else {
 	                        if ( b == "Explorer") {
 	                                element.unselectable = "off";
 	                        } else {
 	                                return false;
 	                        }
 	                }
 	        }
 	        return true;
 	};


function clearNumber( str )
{
	return str.replace(",","");
}


Number.prototype.toCurrency = function()
{
	//if( isNaN( this ) ) return this.toString();
	
	var num = this.toString();
	var tempNum = "";
	var end = "00";
		
	//check for decimal number
	if ( num.indexOf('.') != -1)
	{  //number ends with a decimal point
		if (num.indexOf('.') == this.length-1)
	    {
	    	num += "00";
	    }
	    if ( num.indexOf('.') == this.length-2)
	    { //number ends with a single digit
	   		num += "0";
	    }
		
	    var a = num.split(".");
	   	num = new String( a[0] );   //the part we will commify
	    end = a[1] //the decimal place we will ignore and add back later
	    
	}
	
	if( num.length > 3 )
	{
		var i;
		for( i = num.length - 3 ; i >= 0 ;i = i - 3 )    
		{
			tempNum  = "," + num.substr( i , 3  ) + tempNum; 
		}
		tempNum = num.substr(0, 3+i)  +tempNum;
	}
	else
	{
		tempNum = num;	
	}
		
	return "$ " + tempNum +"."+end.substr(0,2);
};


function transform( inprogress , complete , intv,  sce )
{
	if( typeof inprogress != "function" ) 
	{
		alert( "inprogress needs to be function( count )" );
		return null;
	}
	
	if( typeof complete != "function" ) 
	{
		alert( "complete needs to be function" );
		return null;
	}
	
	var _this = this;
	var timerID = 0;
	//0 - 100;
	var count = 0;
	
	this.intv = intv || 20;
	if( this.intv <=0 || this.intv >=100 ) this.intv = 20;
	
	this.sce = sce || 100;
	if( this.sce <= 0  ) this.sce = 100;
	
	var runner = function()
	{
		
		if( count > 100 )
		{
			window.clearTimeout( timerID );
			complete();
		}
		else
		{
			inprogress( count );
			count = count + _this.intv;
			_this.intv = _this.intv * 0.9;
			//先快后慢
			if( _this.intv < 2  ) _this.intv = 2;
			timerID = window.setTimeout( runner , _this.sce );
		}	
		
	};
	
	this.run = function()
	{
		runner();
	};
	
	this.stop = function()
	{
		window.clearTimeout( timerID );
	}
	
	
}







function transform( inprogress , complete , intv,  sce )
{
	if( typeof inprogress != "function" ) 
	{
		alert( "inprogress needs to be function( count )" );
		return null;
	}
	
	if( typeof complete != "function" ) 
	{
		alert( "complete needs to be function" );
		return null;
	}
	
	var _this = this;
	var timerID = 0;
	//0 - 100;
	var count = 0;
	
	this.intv = intv || 20;
	if( this.intv <=0 || this.intv >=100 ) this.intv = 20;
	
	this.sce = sce || 100;
	if( this.sce <= 0  ) this.sce = 100;
	
	var runner = function()
	{
		
		if( count > 100 )
		{
			window.clearTimeout( timerID );
			complete();
		}
		else
		{
			inprogress( count );
			count = count + _this.intv;
			_this.intv = _this.intv * 0.9;
			//先快后慢
			if( _this.intv < 2  ) _this.intv = 2;
			timerID = window.setTimeout( runner , _this.sce );
		}	
		
	};
	
	this.run = function()
	{
		runner();
	};
	
	this.stop = function()
	{
		window.clearTimeout( timerID );
	}
	
	
}





//ie6 tested
function tableLayout(parent,parentNode )
{
	var _this = this;
	
	this.parent = parent;
	//if( typeof parent == "string" ) this.parent = document.getElementById( parent );
	//this.thebody = document.createElement("div");
	this.parentNode = parentNode;
	if( typeof this.parentNode == "string" ) this.parentNode = document.getElementById( this.parentNode );
	
	this.table = this.parentNode.appendChild( document.createElement("table") );
	this.table.border = 0;
	this.table.cellPadding = this.table.cellSpacing = 0;
	this.table.width = "100%";
	
	this.tbody = this.table.appendChild(  document.createElement("tbody")  );

	var temprow = this.tbody.appendChild( document.createElement("tr") ); 

	this.cells = new Array();
	
	this.addCell = function( html )
	{
		var cell = temprow.appendChild( document.createElement("td") );
		_this.cells[_this.cells.length] = cell;
		
		if( typeof html == "string" )
		{
			cell.innerHTML = html || "";
		}
		else if( typeof html == "object" )
		{
			cell.appendChild( html );
		}
		
		return cell;
	};
	
	this.addRow = function()
	{
		return _this.addSeparateRow();
	};
	
	this.addSeparateRow = function()
	{
		temprow = _this.tbody.appendChild( document.createElement("tr") );
		return temprow;
	};
	
	this.clear = function()
	{
		this.table.removeChild( this.tbody );
		this.tbody = this.table.appendChild( document.createElement("tbody") );
		temprow = this.tbody.appendChild( document.createElement("tr") );
	}
	
}





//调用一个远程服务器的函数
function RPC( SERVER_XML, functionName, debug , callBackMethod )
{
	if( arguments.length >= 4 )
	{
		var data = "&com="+functionName;
		for(var i=4; i< arguments.length ;i++)
		{
			if( arguments[i] instanceof Array )
			{
				//data += "&arg[]="+ encodeURIComponent( arguments[i] );
				//传递 array 到服务器。
				
			}
			else
			{
				data += "&arg[]="+ encodeURIComponent( arguments[i] );
			}
			
		}
		
		var timestamp = sendRequest( SERVER_XML , 
		function( xmlhttp )
		{
			if( xmlhttp.status == 200 )
			{
				
				var msg = new serverMsg( xmlhttp, debug );

				if( timestamp == msg.timestamp ) 
				{						
					callBackMethod( msg, xmlhttp );
				}
			}
			else if( xmlhttp.status == 404 )
			{
				if( MSG_OUTPUT ) MSG_OUTPUT.pushMsg( SERVER_ERROR_404 , "error" );
			}
		}
		, data );
		
	}
	return false;
}





function File( path )
{
	this.filename = path.substring( path.lastIndexOf( "/" )+1, path.lastIndexOf( "." ) );
	this.path = path.substr( 0, path.lastIndexOf( "/" )+1 );
	this.ext = 	path.substr( path.lastIndexOf( "." ), path.length );
	this.fullpath = path;
}





//class
function serverMsg( xml, debug )
{
	var _this = this;
	
	if( debug ) alert(  xml.responseText );
	this.error = "";
	this.status = "";
	this.data = "";
	this.timestamp = "";
	this.items = new Array();
	
	var node = xml.responseXML.documentElement;

	try
	{
		if( node.getElementsByTagName('status').item(0) )
		{
			if( node.getElementsByTagName('status').item(0) )
			{
				this.status = node.getElementsByTagName('status').item(0).childNodes[0].data;
				this.isOk = ( this.status == "ok" );
			}
			else
			{
				this.status = "error";
				//this.error = "The status is unknow.";
			}
			
			if( node.getElementsByTagName('data').item(0) )
			{
				this.data = node.getElementsByTagName('data').item(0);
				this.items = this.data.getElementsByTagName('item');
			}
			
			if( node.getElementsByTagName('error').item(0) )
			{
				this.error = node.getElementsByTagName('error').item(0);
			}
			
			if( node.getElementsByTagName('timestamp').item(0).childNodes[0]  )
			{
				this.timestamp = node.getElementsByTagName('timestamp').item(0).childNodes[0].data;
			}
			
		}
	}
	catch( e )
	{
		this.status = "error";	
		this.error = "The server does not return valid XML file.";
		alert( "error:"+xml.responseText );
	}
	
	
}



function transform( inprogress , complete , intv,  sce )
{
	if( typeof inprogress != "function" ) 
	{
		alert( "inprogress needs to be function( count )" );
		return null;
	}
	
	if( typeof complete != "function" ) 
	{
		alert( "complete needs to be a function" );
		return null;
	}
	
	var _this = this;
	var timerID = 0;
	//0 - 100;
	var count = 0;
	
	this.intv = intv || 20;
	if( this.intv <=0 || this.intv >=100 ) this.intv = 20;
	
	this.sce = sce || 100;
	if( this.sce <= 0  ) this.sce = 100;
	
	var runner = function()
	{
		
		if( count > 100 )
		{
			window.clearTimeout( timerID );
			complete();
		}
		else
		{
			inprogress( count );
			count = count + _this.intv;
			//_this.intv = _this.intv * 0.9;
			//先快后慢
			//if( _this.intv < 2  ) _this.intv = 2;
			timerID = window.setTimeout( runner , _this.sce );
		}	
		
	};
	
	this.run = function()
	{
		runner();
	};
	
	this.stop = function()
	{
		window.clearTimeout( timerID );
	}
	
}


//0/100
function setOpacity( obj,value ){
	//alert( value );
	value  = parseInt( value );
	if( document.all )
	{
		obj.style.filter = "alpha(opacity="+value+")";	
		//obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+ value +")";
		if( value >= 100 ) try{ obj.style.removeAttribute("filter"); } catch(err) {}
	}
	else{
		value = value * 0.01;
		obj.style.opacity = value;
	}	
}




function RemoveEventListener(obj, eventString, eventmethod )
{
	if( document.all )
	{
		obj.detachEvent( "on"+eventString, eventmethod );	
	}
	else
	{
		obj.removeEventListener( eventString, eventmethod , false );
	}
} 

function getLeft( obj ) 
{
	var x = 0;
	// Return the x coordinate of an element relative to the page.	
	while (obj.offsetParent)
	{
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	
	return x;
}

function getTop( obj ) 
{
	// Return the y coordinate of an element relative to the page.
	var y =  0;
	
	while (obj.offsetParent)
	{
		//document.getElementById( "t" ).innerHTML += obj.offsetTop+"-";
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return y;
}




function resizeImg( img , width, height )
{
	var imgWidth = img.offsetWidth;
	var imgHeight = img.offsetHeight;
		
		//alert( img.src );
		
			if( imgWidth > width )
			{
				img.style.width = width + "px";
				img.style.height =  parseInt( (width * imgHeight) / imgWidth ) + "px";
			}
	
	imgHeight = img.offsetHeight;
	imgWidth = img.offsetWidth;
	
			if( imgHeight > height )
			{
				 img.style.height = height + "px";
				 img.style.width = parseInt( ( height * imgWidth ) / imgHeight ) + "px";			 
			}
	
}


function twoDigs( num )
{
	num = num+"";
	if( num.length <=1 ) num = "0"+num;
	if( num.length >2 ) num = num.substring( 0,2 );
	return num;
}




function tohex( num )
{
	return Number( num ).toString(16); 
}
function todec( num )
{
	return  parseInt( num ,16);
}

