
function doLoadSideMenu(progID, vfilename, target_obj, keysn) {
	sideMenuOpen();
	parent.opFrame.location.href="/app/common/"+vfilename+"?pid="+progID+"&obj="+target_obj+"&keysn="+keysn;			

}

function sideMenuOpen() {
	parent.document.body.cols="*,250";
}

function sideMenuClose() {
	parent.document.body.cols="*,0";
}

function rootMenuOpen() {
	top.document.body.cols="130,*";
}

function rootMenuClose() {
	top.document.body.cols="0,130";
}





// ============== FOR WWW ==================================



function isLeapYear(yyyy)
{
	datea = parseInt(yyyy);

	if(datea%4 == 0) {
		if(datea%100 != 0) 	{
			return true;
		} else {
			if(datea%400 == 0)
				return true;
			else
				return false;
		}
	}	
	return false;

}


function checkRegForm(){
	
  var process = true;
  var message = '-Please check the following:\n\n';
  
  if (document.formregister.t_email.value == ''){
    message += '-Email address\n';
    process = false;}
  else{
    var iemail = document.formregister.t_email.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Email address is not valid\n';
      process = false;
    }
  }

	if (document.formregister.t_name_1.value == '') {
		message += '-Name\n';
		process = false;
	}
		
	if (document.formregister.t_userid.value == '') {
		message += '-User ID\n';
		process = false;
	}

	
	if (document.formregister.t_pswd.value == '' || document.formregister.txt_password.value == '') {
		message += '-Password cannot be blank\n';
		process = false;
	}
	
	if (document.formregister.t_pswd.value != document.formregister.txt_password.value) {
		message += '-Confirmed password does not match\n';
		process = false;
	}
	
	

  if (!process) {
  	alert(message);
	}
  return process;
}


// ================FORM INIT FUNC========================

function initRadio(obj, val){
	
	totalnumberelement = obj.length;
	for (t=0;t< totalnumberelement;t++){
			if (obj[t].value == val) {
					obj[t].checked = true;
			}
	}
	
}

function initSelect(obj,val) {
	totalnumberelement = obj.length;
	for (t=0;t< totalnumberelement;t++) {
			if (obj.options[t].value == val) {
				obj.options[t].selected = true;
			}
	}
}

// =================FORM USEFUL FUNCTION =============================

function verifyNumber(k) {
	
	if (isNaN(k.value)) {
		k.select();
		k.value = "";
		k.focus();
	}
	
}




// ================== DATA VERIFY FUNCTIONS (WWW) ===========================

function check_memberinfo_en(){
	
  var process = true;
  var message = '-Please check the following:\n\n';
  
  if (document.form.t_email.value == ''){
    message += '-Email address\n';
    process = false;}
  else{
    var iemail = document.form.t_email.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Email address is not valid\n';
      process = false;
    }
  }

	if (document.form.t_name.value == '') {
		message += '-Name\n';
		process = false;
	}
	
	if (document.form.t_pswd.value == '' || document.form.password.value == '') {
		message += '-Password cannot be blank\n';
		process = false;
	}
	
	if (document.form.t_pswd.value != document.form.password.value) {
		message += '-Confirmed password does not match\n';
		process = false;
	}
	

  if (!process) {
  	alert(message);
	}
  return process;
}


function check_searchform_en()
{
	if (document.form_quicksearch.search.value == '') {
		alert("Keyword cannot be empty");
		return false;
	} else {
		return true;
		}
}










// ********************** OLD FUNCTIONS **********************

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function topmenu_DoFSCommand(command, args)                {
  var myFlashObj = InternetExplorer ? topmenu : document.topmenu;

	  switchLang(args);
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('Sub topmenu_FSCommand(ByVal command, ByVal args)\n');
  document.write(' call topmenu_DoFSCommand(command, args)\n');
  document.write('end sub\n');
  document.write('</SCRIPT\> \n');
} 

function addThumbnailPath(p) {
	
	var ng = p.split("/");
	var s = "";
	
	for (var i=0;i< ng.length;i++) {
		if (i > ng.length-2) {
			s += "_pix/_"+ ng[i];
		} else {
			s += ng[i] + "/";			
		}
	}
	
	return s;
}


function checkSubscribeForm(){
	
  var process = true;
  var message = 'Your emaill address is not valid';
  
  if (document.formsubscribe.txtemail.value == ''){
    process = false;
  } else{
    var iemail = document.formsubscribe.txtemail.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      process = false;
    }
  }

  if (!process) {
  	alert(message);
	}
  return process;
}



function checkEmail() {
	
  var process = true;
  var message = '-Please check the following information:\n\n';
  
  if (document.formemail.txtemail.value == ''){
    message += '-Email address\n';
    process = false;}
  else{
    var iemail = document.formemail.txtemail.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Your email address is not valid\n';
      process = false;
    }
  }

  if (!process) {
  	alert(message);
	}
  return process;
}
	

function checkSend3(){
	
  var process = true;
  var message = '-Please check the information below:\n\n';
  
  if (document.formemail2friend.txtemailsend.value == ''){
    message += '-Your email address\n';
    process = false;}
  else{
    var iemail = document.formemail2friend.txtemailsend.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Your email address is not valid\n';
      process = false;
    }
  }
  
  if (document.formemail2friend.txtemail1.value != ''){
    var iemail = document.formemail2friend.txtemail1.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Your friend 1\' email is not valid \n';
      process = false;
    }
  }
  
    if (document.formemail2friend.txtemail2.value != ''){
    var iemail = document.formemail2friend.txtemail2.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Your friend 2\' email is not valid\n';
      process = false;
    }
  }
  
    if (document.formemail2friend.txtemail3.value != ''){
    var iemail = document.formemail2friend.txtemail3.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Your friend 3\' email is not valid\n';
      process = false;
    }
  }
  
   if (document.formemail2friend.txtemail1.value == '' && document.formemail2friend.txtemail2.value == '' && document.formemail2friend.txtemail3.value == ''){
      message += '-At least enter 1 of your friend\' email address\n';
      process = false;
    }
	
	
  if (!process) {
  	alert(message);
	}
  return process;
}


function getMenuName(id) {

	var h = Number(id);

	switch (h) {
		case 1:
			n = "Aircrafts";
			break;
		case 2:
			n = "Bikes";
			break;
		case 3 :
			n = "Cars";
			break;
		case 4:
			n="Helicopters";
			break;
		case 5:
			n= "Military Figures";
			break;
		case 6:
			n="Military Vechicles";
			break;
		case 7:
			n="Ships";
			break;
		case 8:
			n = "Others";
			break;
		default:
			n = "--";
	}

	return n;
}

function switchLang(w) {

	// valid w is 'chi' ,'eng' ,'sch'
	

	var url = location.href;
	var ok = false;
	
	if (url.indexOf('/gb') > 0 && !ok) {
		url1 = url.replace('/gb', '/'+w);
		ok = true;
	}
	
	if (url.indexOf('/b5') > 0 && !ok) {
		url1 = url.replace('/b5', '/'+w);
		ok = true;
	}
	
	if (url.indexOf('/en') > 0 && !ok) {
		url1 = url.replace('/en', '/'+w);
		ok = true;
	}
//	alert("Sorry! Chinese version is temporary not available");	

	location.href = url1;
}
	
function goPrevpage() {
	var x;
	x = Number(getCurrentpageindex());

	if (x > 1) {
		setPageindex(x-1);
		top.mainFrame.document.location.href=url[getCurrentpageindex()];
	} 
}

function goNextpage() {
	var x;
	x = Number(getCurrentpageindex());

	if (x < 19) {
		setPageindex(x+1);
		top.mainFrame.document.location.href=url[getCurrentpageindex()];
	} 
}

function setPageindex(v) {
	top.hiddenFrame.form.currentpageindex.value = v;
}

function getCurrentpageindex() {
	return top.hiddenFrame.form.currentpageindex.value;
}

function checkMemberInfoForm(){
	
  var process = true;
  var message = '-Please check the following:\n\n';
  
  if (document.form.t_email.value == ''){
    message += '-Email address\n';
    process = false;}
  else{
    var iemail = document.form.t_email.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Email address is not valid\n';
      process = false;
    }
  }

	if (document.form.t_realname.value == '') {
		message += '-Name\n';
		process = false;
	}
		
	if (document.form.t_username.value == '') {
		message += '-Alias\n';
		process = false;
	}

	
	if (document.form.t_password.value == '' || document.form.t_password.value == '') {
		message += '-Password cannot be blank\n';
		process = false;
	}
	
	if (document.form.t_password.value != document.form.txtpass2.value) {
		message += '-Confirmed password does not match\n';
		process = false;
	}
	
  if (!process) {
  	alert(message);
	}
  return process;
}

function addBasket(csn,lang) {


	location.href="/"+lang+"/cart/add2cart.php?sn="+csn;

}


function checkform(){
  var process = true;
  var message = 'Please provide information for the following field(s):\n\n';
  
  if (document.mailform.txtemail.value == ''){
    message += 'Email Address\n';
    process = false;}
  else{
    var iemail = document.mailform.txtemail.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += 'Invalid email address, please check email on email\n';
      process = false;
    }
  }

//	if (document.mailform.txtcompany.value == '') {
	//	message += 'Company Name\n';
//		process = false;
//	}

	if (document.mailform.txtname.value == '') {
		message += 'Name\n';
		process = false;
	}
		
	if (document.mailform.txttel.value == '') {
		message += 'Telelphone\n';
		process = false;
	}

	
	if (document.mailform.txtmsg.value == '') {
		message += 'Message\n';
		process = false;
	}

  if (!process) {
  	alert(message);
	}
  return process;
}


function modelesswin(url,fname,mwidth,mheight,lockscroll){
	if (document.all&&window.print) //if ie5
		eval('window.showModelessDialog(url,"'+fname+'","help:0;resizable:0;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
	else
		eval('window.open(url,"'+fname+'","width='+mwidth+'px,height='+mheight+'px,resizable=0,scrollbars='+lockscroll+'")')
}

function openWindow(page, framename, win_width, win_height,lockscroll)
{
	var w,h, para,sc;
	var absw, absh;
	
	w = screen.width;
	h = screen.height
	
	absw = (w-win_width) /2;
	
	if (win_height > 0) {
		absh = (h-win_height) / 2;	
	} else{
		absh = (h-(h * 0.7)) /2;
		}
		
	if (lockscroll == 1) { sc = "no" } else { sc = "YES" }

	para = "top="+absh+", left="+absw+ ",width="+win_width+", height="+win_height+", status=no, toolbar=no, menubar=no, location=no, scrollbars="+sc+", directories=no";
	
	//modelesswin(page,framename,win_width, win_height, lockscroll)
	window.open(page,framename,para);


}




function setSearch(t, rpath) {
	
	var kw = searchform.txtsearchkey.value;

	if (kw != 0) {
		location.href= "/php/admin/setsearch.php?searchkey=" + kw+"&searchmode="+t+"&rpath="+rpath;
	}
}

function convert(txtobj) 
{
	//apply only this page
	var txt = txtobj.value;
	
	y = '';
	i1 = 0;
	while(1) {
		i2 = txt.indexOf(unescape("%0A"),i1);
		if (i2 < 0) {
			y += txt.substring(i1);
			break;
		} else 
			y += txt.substring(i1,i2-1) +"<br>";
		i1 = i2 +1
	}
	txtobj.value = y;
}

function splitdesc(txt)
{
	//apply only this page
	
	y = '';
	i1 = 0;
	while(1) {
		i2 = txt.indexOf("<br>",i1);
		if (i2 < 0) {
			y += txt.substring(i1);
			break;
		} else {
			y += txt.substring(i1,i2) + unescape("%0A%0D");
			i2 += 3;
		}
		i1 = i2 +1
	}
	return y;
}

function selectAll(t) {

	for (i=1;i<=t;i++) {
		eval("form1.chkselect"+i).click();
	}
}


function checkOrderForm(){
	
  var process = true;
  var message = '-Please check the following:\n\n';
  
  if (document.form.t_email.value == ''){
    message += '-Email address\n';
    process = false;}
  else{
    var iemail = document.form.t_email.value;
    if ((iemail.indexOf('@') <= 0) || (iemail.indexOf('.') <= 0)){
      message += '-Email address is not valid\n';
      process = false;
    }
  }

	if (document.form.t_name.value == '') {
		message += '-Contact name\n';
		process = false;
	}

	if (document.form.t_bill_addr.value == '') {
		message += '-Billing Address\n';
		process = false;
	}
		
	if (document.form.t_deli_addr.value == '') {
		message += '-Delivery Address\n';
		process = false;
	}

	
	if (document.form.t_tel1.value == '' && document.form.t_tel2.value == '') {
		message += '-At least 1 contact number\n';
		process = false;
	}
	
	
  if (!process) {
  	alert(message);
	}
  return process;
}


// Dreamweaver functions *****************************
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}



function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=450,left = 540,top = 362');");
}
