var http=window.XMLHttpRequest? new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
var A=0, B=0, adds=1, auto=1, divs, hidp=1, hist, lock, page=1, pmax=0, pnt1, pnt2, pnt3, ptz1, ptz2, ptz3, redo=0, str1, str2, time, tiny, top1, top2, top3, media;
var Ajax=new Array();
var hid=new Array();
var pid=new Array();
hid[0]='page=1';

for(i=0; i<10; i++) pid[i]=i? '':1;

function dofind(query)
{
  request(query);
  time=0;
}

function dosend(i, vl)
{
  nm=fields(i);
  checkid('A'+i+'0').style.height='0px';
  request('page=1&'+nm+'='+(checkid('s'+nm).value=vl));
}

function fields(i)
{
  switch(i)
  {
    case 1: return 'company';
    case 2: return 'keyword';
    case 3: return 'location';
  }
}
 
function search(i)
{
  if(i==0)
  {
    request('page=1&category=&company=&keyword=&location=');
    return true;
  }

  if(i==9)
  {
    request('page=1&company='+checkid('scompany').value+'&keyword='+checkid('skeyword').value+'&location='+checkid('slocation').value);
    return true;
  }

  id='A'+i;
  nm=fields(i);

  if(checkid('s'+nm).value.length>1)
  {
    var1='auto';
    if(!time && auto) setTimeout("dofind('load='+id+'0&file=home&search='+valueof('s'+nm))", (time=400));
  } else {
    var1='0px';
    checkid(id+'0').innerHTML='';
  }

  checkid(id+'0').style.height=var1;
}

function checkid(name)
{
  return typeof name!='string'? name.style:(document.all? document.all(name):document.getElementById(name));
}

function display(id, vl)
{
  checkid(id).style.display=(vl? 'block':'none');
  return vl;
}

function locking(vl)
{
  if(vl)
  {
    lock=var2=1;
    var1=0;
  } else {
    lock=var2=redo=0;
    var1=1;
  }

  if(checkid('show'))
  {
    setmenu(page);
    display('show', var1);
    display('wait', var2);
  }
}

function profile(id, vl)
{
  checkid((id? 'SIndividual':'SCompany')).checked=true;

  if(id)
  {
    var1='Individual';
    var2=var1+' IC';
    var3='hidden';
    var4='I';
  } else {
    var1=var2='Company';
    var3='visible';
    var4='We';
  }

  checkid('F01').innerHTML=checkid('F05').innerHTML=var1;
  checkid('F02').innerHTML=var2;
  checkid('F04').innerHTML=var4;
  checkid('F03').style.visibility=var3;
}

function request(post, load)
{
  if(!lock)
  {
    var flag;
    locking(1);

    if(post=='back')
    {
      flag=1;
      post=hid[(hidp-=2)];

      if(checkid('next'))
      {
	display('next', 1);
	if(checkid('back') && !hidp) display('back', 0);
      }
    }

    if(post=='next')
    {
      flag=1;
      post=hid[hidp];

      if(checkid('next'))
      {
	if(hid[(hidp+1)])
	{
	  display('back', 1);
	  display('next', 1);
	}
	else display('next', 0);
      }
    }

    hist=post;
    divs=(name=hist.substr(0, 4))=='load'? hist.substr(5, 3):name;

    if(divs=='html' || divs=='page')
    {
      page=hist.substr(5, 2);
      media='';

      if(!flag)
      {
	hid[hidp]=hist;
	hidp++;

        if(checkid('back')) display('back', 1);
      }
      else hidp++;
    }

    if(tiny && (divs=='html' || divs=='page' || divs=='A21' || divs=='T55'))
    {
      tinyMCE.execCommand('mceRemoveControl', true, tiny);
      tiny='';
    }

    if(load) tiny=load;
    setTimeout('sending(hist)', 0);
  } else {
    Ajax[(A++)]=post;
    setTimeout('resends()', 100);
  }
}

function replace()
{
  if(checkid(divs) && http.readyState==4 && http.status==200)
  {
    var html=http.responseText;
    setTimeout('locking(0)', 0);

    if(html)
    {
      html.substr(0, 1)=='_'? window.location='.':checkid(divs).innerHTML=html;
      if(checkid('newsBar-bar'))
      {
	checkid('newsBar-bar').innerHTML=str1;
	checkid('advs').innerHTML=str2;
      }

      if(tiny && (divs=='html' || divs=='page' || divs=='A21' || divs=='T55'))
	tinyMCE.execCommand('mceAddControl', true, tiny);
    }
  }
  else hist='';

  if(redo) B++;
  locking(0);
}

function resends()
{
  if(A!=B)
  {
    if(!lock)
    {
      redo=1;
      request(Ajax[B]);
    }

    setTimeout('resends()', 100);
  }
}

function sending(post)
{
  http.open('post', 'index.php');
  http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http.onreadystatechange=replace;
  http.send(post);
}

function setmenu(id)
{
  page=id;
  id=id>0? id:id.substr(0, 1);

  for(i=1; i<8; i++)
  {
    if(checkid('menu'+i)) checkid('menu'+i).style.textDecoration=id==i? 'underline':'none';
  }
}

function scroll1()
{
  if(checkid('icon') && !pnt1) 
  {
    checkid('icon').scrollTop+=ptz1? -5:5;
    topz=checkid('icon').scrollTop;

    if(topz==top1) ptz1=1;
    if(ptz1 && !topz) ptz1=0;
    top1=topz;
  }
}

function scroll2()
{
  if(checkid('bann') && !pnt2) 
  {
    checkid('bann').scrollTop+=ptz2? -102:102;
    topz=checkid('bann').scrollTop;

    if(topz==top2) ptz2=1;
    if(ptz2 && !topz) ptz2=0;
    top2=topz;
  }
}

function scroll3()
{
  if(checkid('comp') && !pnt3) 
  {
    checkid('comp').scrollTop+=ptz3? -80:80;
    topz=checkid('comp').scrollTop;

    if(topz==top3) ptz3=1;
    if(ptz2 && !topz) ptz3=0;
    top3=topz;
  }
}

function settabs(id)
{
  for(i=1; i<6; i++)
  {
    if(checkid('tabs'+i))
    {
      display('form'+i, (id==i? 1:0));
      checkid('tabs'+i).style.textDecoration=id==i? 'underline':'none';
    }
  }
}

function settool(id)
{
  for(i=1; i<21; i++)
  {
    if(checkid('tool'+i)) checkid('tool'+i).style.height=id==i? 'auto':'0px';
  }
}

function setdata(id)
{
  id+='A';
  for(i=1; i<101; i++)
  {
    j=i>9? i:'0'+i;
    if(checkid('data'+(port=id.substr(0, 2)+j))) display('data'+port, (id.substr(2, 2)==j? 1:0));
  }
}

function valueof(id)
{
  return checkid(id).value.replace(/&/g, '>%');
}

function agreement()
{
  if(checkid('agreed').checked)
  {
    var1=0;
    var2=false;
  } else {
    var1=1;
    var2=true;
  }

  display('submit', var1);
  checkid('agreed').checked=var2;
}

function findmatch(data)
{
  scrolling();
  display('F10', 1);
  request('load=F10&file=match&task='+data);
}

function scrolling()
{
  if(self.innerWidth)
  {
    s=self.pageYOffset;
  }
  else if(document.documentElement && document.documentElement.clientHeight)
  {
    s=document.documentElement.scrollTop;
  }
  else if(document.body)
  {
    s=document.body.scrollTop;
  }

  checkid('F10').style.top=s+270+'px';
}

function signature(id)
{
  if(checkid(id).style.display!='none')
  {
    var1=0;
    var2='Show';
  } else {
    var1=1;
    var2='Hide';
  }

  display(id, var1);
  checkid('i'+id).innerHTML=var2;
}

function validate(stat)
{
  var j, flag=1, egot=0;

  switch(stat)
  {
    case 2:

	if(!checkid('Package').value) for(i=0; i<10; i++) pid[i]='';
	if(!checkid('Company').value)
	{
	  flag=0;
	  display('warn1', 1);
	}

	for(i=0; i<5; i++)
	{
	  j=i? i:'';

	  if(!i || checkid('branch'+j).style.display=='block')
	  {
	    j=i? j+'X':'';
	    if(!checkid('Address'+j).value || !checkid('City'+j).value || !checkid('Phone'+j).value)
	    {
	      flag=0;
	      display('warn2', 1);
	    }
	  }
	}
	break;

    case 3:

	if(!checkid('Category').value)
	{
	  flag=0;
	  display('warn3', 1);
	}
	if(!checkid('Keyword1').value)
	{
	  flag=0;
	  display('warn4', 1);
	}
	break;

    case 'contact':

	for(i=0; i<5; i++)
	{
	  j=i? i:'';

	  if(!i || checkid('branch'+j).style.display=='block')
	  {

	    j=i? j+'X':'';
	    if(!checkid('Address'+j).value || !checkid('City'+j).value || !checkid('Phone'+j).value)
	    {
	      egot++;
	    }
	  }
	}

	if(!egot) display('warn2', 0);
	flag=0;
	break;

    case 'enquiry':

	email_ok=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(checkid('Email').value)? 1:0;
	if(checkid('Email').value) display('warn1', (email_ok? 0:1));
	display('submit', (email_ok && checkid('Name').value && checkid('Request').value? 1:0));
	flag=0;
	break;

    case 'mailing':
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(checkid('mailadd').value))
	{
	  request('mailadd='+checkid('mailadd').value);
	  display('mail1', 0);
	  display('mail2', 1);
	}
	else alert('The email address given above is not valid!');
	flag=0;
	break;

    case 'message':
	if(!display('warn1', (checkid('Message').value? 0:1))) request('page=6&Message='+checkid('Message').value);
	flag=0;
	break;

    case 'password':

	flag=0;
	flag1=display('warn2', (checkid('OldPassword').value? 0:1));
	flag2=display('warn3', (checkid('NewPassword').value.length>5? 0:1));
	flag3=display('warn4', (checkid('ConfirmPassword').value==checkid('NewPassword').value? 0:1));

	if(!flag1 && !flag2 && !flag3)
	{
	  request('page=6&OldPassword='+checkid('OldPassword').value+'&NewPassword='+checkid('NewPassword').value);
	  return true;
	}
	else break;
  }

  if(flag)
  {
    display('form'+(stat>0? stat-1:1-stat), 0);
    display('form'+(stat>0? stat:-stat), 1);
  }
}

function calculate(stat, pyid, cost, name, xcst)
{
  if(!pid[0]) pid[0]=1;
  var free=0, keys=0, pids=0, sums=0;

  switch(stat)
  {
    case 1:

	pid[0]=pyid;
	if(media)
	{
	  checkid('frec').innerHTML=', Power Package';
	  cost='0';
	}
	else checkid('frec').innerHTML='';
	checkid('price1').innerHTML=cost;
	checkid('core').innerHTML=name;
	cost=xcst;

    case 2:

	pid[1]=3;
 	free=(checkid('core').innerHTML.indexOf('Power')!=-1)? 2:1;
	keys=3-(checkid('Keyword1').value? 0:1)-(checkid('Keyword2').value? 0:1)-(checkid('Keyword3').value? 0:1);
	checkid('free').innerHTML=free;
	checkid('keys').innerHTML=keys;
	if((xtra=keys-free)<0) xtra=0;
	checkid('price2').innerHTML=xtra*cost;
	break;

    default:

	if(checkid('price'+stat).innerHTML==0)
	{
	  if(name=='Media') media++;
	  checkid('price'+stat).innerHTML=cost;
	  checkid('act'+stat).innerHTML='Yes';
	  pid[pyid]=pyid;
	} else {
	  if(name=='Media') media--;
	  checkid('price'+stat).innerHTML='0';
	  checkid('act'+stat).innerHTML='No';
	  pid[pyid]='';
	}
  }

  for(i=1; i<9; i++)
  {
    if(checkid('price'+i)) sums-=-checkid('price'+i).innerHTML;
  }

  checkid('Payment').value=checkid('d_Sum').innerHTML=checkid('sum').innerHTML=sums;
  for(i=0; i<10; i++) if(pid[i]) pids+=':'+pid[i];
  checkid('Package').value=pids+':';
}

function initialize()
{
  setInterval('scroll1()', 100);
  setInterval('scroll2()', 4000);
  setInterval('scroll3()', 5000);
  setTimeout('str1=checkid("newsBar-bar").innerHTML;str2=checkid("advs").innerHTML;', 1500);
}

function browsefile(v1, v2, v3)
{
  win=window.open('http://mycontact2u.com/browse.php?img=', 'popup', 'top='+((screen.height-250)/2)+',left='+((screen.width-625)/2)+',width=625,height=250,status=0,menubar=0,toolbar=0,statusbar=0,scrollbars=1,location=0,resizable=0');
  win.window.focus();
}

tinyMCE.init({
	mode : 'none',
	theme : 'advanced',
	plugins : 'style,layer,table,save,advimage,advlink,insertdatetime,media,searchreplace,contextmenu,paste,preview,fullscreen,xhtmlxtras',
	theme_advanced_buttons1_add : 'fontselect,fontsizeselect,|,cut,copy,pastetext,pasteword,|,forecolor,backcolor',
	theme_advanced_buttons1_add_before : 'save,|',
	theme_advanced_buttons3_add_before : 'preview,|,tablecontrols,separator',
	theme_advanced_buttons2_add_before : 'fullscreen,|,insertlayer,moveforward,movebackward,absolute,|,cite,abbr,acronym,del,ins,attribs,|',
	theme_advanced_buttons3_add : 'inserttime,insertdate,media,|,search,replace',
	theme_advanced_toolbar_location : 'top',
	theme_advanced_toolbar_align : 'left',
	theme_advanced_path_location : 'bottom',
	plugin_insertdate_dateFormat : '%d-%m-%Y',
	plugin_insertdate_timeFormat : '%H:%M:%S',
	extended_valid_elements : 'hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]',
	file_browser_callback : 'browsefile',
	theme_advanced_resize_horizontal : false,
	theme_advanced_resizing : true,
	apply_source_formatting : true
});

google_ad_client = "pub-7757615367180727";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
google_ad_channel='3842742538';

id = '48cba686fe041718';
num = '5';
size = '10';
bullet = 'D6E2EF';
target = '_blank';
colour = '000000';
bs = 'square';
