/*
**
**
**
**
**
*/




var ADS_INTERVALS = 3000; 



// 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";


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" , "application/x-www-form-urlencoded" );
	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, res_dir )
{	
	var _this = this;
	var res_dir = res_dir || "../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.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);
	
	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";
		leftCell.align = "right";
		leftCell.valign = "middle";
		leftCell.style.cursor="pointer";
	}
	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.height = "24px";
		rightCell.style.backgroundImage = "url("+IMG_RIGHT+")";
		rightCell.style.backgroundRepeat = "no-repeat";
		rightCell.style.backgroundPosition = "center";
		rightCell.align = "center";
		rightCell.valign = "middle";
	}
	else if(  USER_AGENT == "Safari" )
	{
		rightCell.style.visibility = "hidden"
	}
	
	if( USER_AGENT == "Safari" )
	{
		textBox.type = "search";
	}
	else
	{
		textBox.type = "text";		
		textBox.style.borderWidth = "0px";
		textBox.style.borderStyle = "none";
		textBox.style.borderColor = "#FFFFFF";
		textBox.style.width = "100%";
		textBox.style.fontFamily= "Arial, Helvetica, sans-serif";
		textBox.style.fontSize="11px";
		textBox.style.height = "12px";
	}
	
	textBox.id = "searchkey";
	textBox.name = "searchkey";
	centerCell.appendChild(textBox);
	
	searchScop.type = "hidden";	
	this.theform.appendChild( searchScop );
	searchScop.id = "searchScop";
	searchScop.name = "searchScop";
	searchScop.value ="";
		
	
	//event--
	textBox.onkeypress = keypress;
			
	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();
			}
			
		}
	}
	

	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";
		
	};
	
}


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 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 );
	 };
}


	function popup(url1)
		{
		//window.open("google.com","new",'toolbar=1,scrollbars=1.resizeable=0,status=1,menubar=0,statusbar=0,width=300,height=300');
		
		
		window.open(url1,"new",'top=0,left=0,addressbar=no, menubar=no,toolbar=no,scrollbars=yes,width=400,height=250,resizable=yes');
		}
		
			function valid()
			{
		
				if(document.Form1.txtpincode.value!="")
				{ 	
					if(IsPostalCode(document.Form1.txtpincode.value) == false)
					{
						alert(" Please Enter a valid Pincode...")
						document.Form1.txtpincode.focus();
						return false
					}		
				}
				return true;
			}
			
///////To check Postal Code/////////////////////////////////////////////////
	function IsPostalCode(strString)
   //  check for valid numeric strings
   {
	 var strValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789()- ";
	 var strChar;
	 var blnResult = true;

	//  test strString consists of valid characters listed above
	 for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
   
   
var gAutoPrint=true;

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML><link href="../style_gray.css" type="text/css" rel="stylesheet"><HEAD>\n';

	/*	if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}*/
		html += '\n</HE' + 'AD>\n<BODY leftmargin=0>\n';
		var printReadyElem = document.getElementById("div1");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';		
		
		var printWin  = window.open("","printSpecial",'top=0,left=0,addressbar=no, menubar=no,toolbar=no,scrollbars=yes,width=500,height=500,resizable=yes');
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();			
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}


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;
}


//class
function serverMsg( xml, debug )
{
	var _this = this;
	
	if( debug ) alert(  xml.responseText );
	this.error = "";
	this.status = "";
	this.data = "";
	this.timestamp = "";
	
	var node = xml.responseXML.documentElement;
	
	if( node )
	{
		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);
			}
			
			
			if( node.getElementsByTagName('timestamp').item(0).childNodes[0]  )
			{
				this.timestamp = node.getElementsByTagName('timestamp').item(0).childNodes[0].data;
			}
		}
	}
	else
	{
		this.status = "error";	
		this.error = "The server does not return valid XML file.";
	}
	
	
}


function AddEventListener(obj, eventString, eventmethod )

{

	if( document.all )

	{

		obj.attachEvent( "on"+eventString, eventmethod );	

	}

	else

	{

		obj.addEventListener( eventString, eventmethod,false );

	}



}



function loadmenu()
{
	

	document.getElementById( "menu" ).innerHTML = "";
	//makeing menu from server data.
  	var menubar = new MenuBar( "menu","v" );
	
	var leftMenuItems = document.getElementsByName( "leftMenuItems" );
	
	for(var i=0;i< leftMenuItems.length; i++ )
	{
		menubar.addButton( leftMenuItems[i].innerHTML , "window.location='"+leftMenuItems[i].href  +"';" , (  theleftMenuItems[i].parentNode.parentNode.className == "active" ) );	
	} 	


}



function setOpacity( obj, value )
{
	if( document.all ){
		if( obj.filters.alpha ) obj.filters.alpha.opacity = value;
	}
	else{
		value = value * 0.01;
		obj.style.opacity = value;
	}	
};




