/**
 * Common_script - Version 1.0.4
 * (c) 2009 Nguyen Hoang
 * Update : 16/04/2009
 *
 * All common functions in system.
 */

// JavaScript Document
	if (typeof sStartup == 'undefined') sStartup = "";
	if (typeof sResize == 'undefined') sResize = "";
  	if (typeof bStartup == 'undefined') bStartup = false;
  	if (typeof bAdd_jQuery == 'undefined') bAdd_jQuery = false;
	
	if (typeof ROOT_URL == 'undefined') ROOT_URL = "http://" + location.hostname + "/";
		
	onload="Startup();";
	
function Startup(sfunc) {
	if (sfunc != null) {
		if (!bAdd_jQuery) {
			if (typeof jQuery != 'undefined'){
				(function($) { /* some code that uses $ */ 
					jQuery(document).ready( function () { 
						window.$ = function(id) { 
									return document.getElementById(id); } 
						
						Startup(); 
						
						window.$ = jQuery; } );
					})(jQuery)
			}else onload = Startup;
			
			bAdd_jQuery = true;	
		}
		
		if (!bStartup) {				// If before onload event
			sStartup += sfunc + ";";
			
		}else {							// Run directly
			try {
			 	var function1 = sfunc.substr(0, sfunc.indexOf("("));
			
	       		if (function1.length) {
		   			eval("var function1Exists = (window." + function1 + ") ? true : false;");
		   			
		   			if (function1Exists) { 
					 	eval("try { " + sfunc + ";} catch(ex) { /*alert(ex.message);*/}" );
					}
				}
			}catch(ex) {
				
			}
		}
	}else {
       
       bStartup = true;
     
       	var funcArray = sStartup.split(";");
       	for(var i=0; i < funcArray.length; i++) {
       		if (funcArray[i].length)	{
       			var function1 = funcArray[i].substr(0, funcArray[i].indexOf("("));
       			if (function1.length) {
	       			eval("var function1Exists = (window." + function1 + ") ? true : false;");
	       			if (function1Exists) {   
	       				eval("try { " + funcArray[i] + ";} catch(ex) { alert(ex.message + funcArray[i]);}" ); 
	       			} 
	       		}      			       			
       		}
    	}

      //  window.onresize = Resize_event;
      //  Resize_event();
    }
}

function Resize_event(sfunc) {
    //alert(typeof sfunc );
    if (sfunc != null && typeof sfunc == "string") {
			sResize += sfunc + ";";
            
	}else {
       
       	var funcArray = sResize.split(";");
       	for(var i=0; i < funcArray.length; i++) {
       		if (funcArray[i].length)	{
                //alert(funcArray[i]);
       			eval("try { " + funcArray[i] + ";} catch(ex) { alert(ex.message);}" );
       		}
    	}
    }
}

if (!window.$) {
      window.$ = function(id) { return document.getElementById(id); }
}

if (!window.$ele) {
      window.$ele = function(id) { return document.getElementById(id); }
}

function removeLeadingAndTrailingChar (inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	return returnString;
}

function openlink(URLStr)
{	
	location = URLStr;
}
// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  
  if(document.cookie.length > 0)
  { 
    var search = name + "=";
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }else {		// For process array
    	var str = document.cookie + ";";
    	
    	var re = new RegExp(name + "\\[([\\w\\W]*?)\\]=([\\w\\W]*?);", ["gi"]);
		var matches = "";
		
		var match1;
		var i =0;
		while (match1 = re.exec(str)) {			
			matches += "cookieValue[" + i + "]= new Array('" + match1[1] + "', '" + match1[2] + "');";
			i++;
		}
		
		if (matches.length) {
			matches = "var cookieValue= new Array();" + matches ;
			//alert(matches);					
			eval(matches);	
			
		}
    }
  }
  return cookieValue;
}
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  //document.write(expire);
  document.cookie = name + "=" + escape(value) + expire;
  
}

function trimString(inputString) {
	return inputString.replace(/^\s+|\s+$/g, '') ;
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');

	return str;
}
function stripslashes(str) {
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	return str;
}


function getOffsetLeft(inputObj) {
	var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
		if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	 return returnValue;		
}
function getOffsetTop(inputObj) {
	var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
		if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	 return returnValue;		
}



//  Detect browser---------------------------------------------------------------
var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(agt.indexOf("opera/5")!=-1||agt.indexOf("opera 5")!=-1){op5=1;}
	if(agt.indexOf("opera/6")!=-1||agt.indexOf("opera 6")!=-1){op6=1;}
	if(agt.indexOf("opera/7")!=-1||agt.indexOf("opera 7")!=-1){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}


document.write("<script language=\"JavaScript\" src=\"" + ROOT_URL + "js/ajax.js\" type='text/javascript'></script>");


//setInterval("ajaxRead('modules/consultant/turn.php')", 15000)
//---------------------------------------------------------------------------------------------
