//$Id: common.js,v 1.11 2004/09/16 23:34:07 chenru Exp $
//------------------------------------------------------------------------------------------------------------

//  Filename: common.js

//	Comments:

//	This file contains global functions used to dynamically alter the Internet

//	World Web site. It first declares global variables, then contains functions.

//  Following is a list of what this file contains.

//

//	Global variables.

//	Functions.


//		selectAll() - selects/deselects all check boxes on the BOS admin form

//		ClearAll() - submits form to return email from BOS entry form

//		Delete_click(image, over) - swaps button named image in left nav to mouseover state (over: boolean) if over

//		swapMap(country) - swaps the map to country passed as its argument

//

//------------------------------------------------------------------------------------------------------------









//------------------------------------------------------------------------------------------------------------

// Global Variables

//------------------------------------------------------------------------------------------------------------

function SelectAction(strCheckBoxName,straction)
{
	if (typeof(document.all(strCheckBoxName).checked)=="undefined")
	{
		if(typeof(document.all(strCheckBoxName))!="undefined"){
			for (i = 0 ; document.all(strCheckBoxName).length > i ; i ++)
			{
				document.all(strCheckBoxName)[i].checked = straction;
			}
		}
	}
	 else
	 {
	  	document.all(strCheckBoxName).checked=straction;
	 }
}

function SeletAll(strCheckBoxName)
{	
	SelectAction(strCheckBoxName,true);
}
		
function ClearAll(strCheckBoxName)
{
	SelectAction(strCheckBoxName,false);
}

/*		
function Delete_click(frm,strCheckBoxName,strtype)
{
	flgCheck = 0;
	if (typeof(document.all(strCheckBoxName).checked)!="undefined")
	{//single
		if (!(document.all(strCheckBoxName).checked))
		{
			alert("{tr}Please select the{/tr} " + strtype + " {tr}which will be deleted!{/tr}");
			document.all(strCheckBoxName).focus();
			return false;
		}
		else
		{
			flgCheck = 1;
		}
	}
	else
	{//multiplue
		if(typeof(document.all(strCheckBoxName))!="undefined"){
			for (i = 0 ; document.all(strCheckBoxName).length > i ; i ++)
			{
				if(document.all(strCheckBoxName)[i].checked)
				{
					flgCheck = 1;
				}
			}
		}
	}

	if (flgCheck == 0)
	{
		alert("Please select the " + strtype + " which will be deleted!");
		document.all(strCheckBoxName)[0].focus();
		return false;
	}
	
	if (confirm('Do you sure to delete the ' + strtype + '?'))
	{		
		frm.action.value = "del";
		frm.submit();
	}
	else
		return false;
}
*/

function updatestatus(frm,strkey,id )
{
	document.all(strkey).value=id;
	document.all('action').value='update';	
	frm.submit();
}

/*************************************************************************************
*			Trim blank (right & left)							*
*************************************************************************************/
function lTrim(str) 
{ 
	if (str.charAt(0) == " ") 
	{ 
		str = str.slice(1);
		str = lTrim(str);  
	} 
	return str; 
} 

function rTrim(str) 
{ 
	var iLength; 
	iLength = str.length; 
	if (str.charAt(iLength - 1) == " ") 
	{ 
		str = str.slice(0, iLength - 1);
		str = rTrim(str);
	} 
	return str; 
} 

function trim(str) 
{ 
	return lTrim(rTrim(str)); 
}

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

function EmailCheck (emailStr) 
{

	var validcharsBefore = "abcdefghijklmnopqrstuvwxyz0123456789.-_";
	var validcharsAfter = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
	var email = emailStr;
	var emailBefore ;
	var emailAfter ;
	
	//	'@''s index must >=1
	IndexChar=email.indexOf("@");
	if (1>IndexChar)
		return false;
	
	emailBefore =email.substring(0,IndexChar);
	emailAfter =email.substring(IndexChar+1,email.length-1);
	
	if (1>emailAfter.indexOf("."))
		return false;
	
	for (var i=0; emailBefore.length>i; i++) 
	{
		var letter = emailBefore.charAt(i).toLowerCase();
		if (validcharsBefore.indexOf(letter) != -1)
			continue;
		return false;
	}
	for (var i=0; emailAfter.length>i; i++) 
	{
		var letter = emailAfter.charAt(i).toLowerCase();
		if (validcharsAfter.indexOf(letter) != -1)
			continue;
		return false;
	}
	return true;
}

function check_field_empty(obj,ms)
{
	if(trim(obj.value) == '')
	{
		alert(ms);
		obj.focus();
		return false;
	}
	return true;
}


function show(foo) {
	document.getElementById(foo).style.display = "block";
}

function hide(foo) {
	document.getElementById(foo).style.display = "none";
}

function toggle(foo) {
	if (document.getElementById(foo).style.display == "none") {
		show(foo);

		setCookie(foo, "o");
	} else {
		if (document.getElementById(foo).style.display == "block") {
			hide(foo);

			setCookie(foo, "c");
		} else {
			show(foo);

			setCookie(foo, "o");
		}
	}
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "")
		+ ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");

	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;

	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1) {
		begin = dc.indexOf(prefix);

		if (begin != 0)
			return null;
	} else begin += 2;

	var end = document.cookie.indexOf(";", begin);

	if (end == -1)
		end = dc.length;

	return unescape(dc.substring(begin + prefix.length, end));
}

// 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";
	}
}

//Open Interactive Booth.
function windowopen(companyid)
{
	var openurl;
	var windowwidth;
	var windowheight;
	//var windowwidth = parseInt(screen.width) * 0.8008;
	//var windowheight = parseInt(screen.width) * 0.8008 * 0.5634;
	
//	var windowwidth = parseInt(screen.width) * 0.78125;
//	var windowheight = parseInt(screen.height) * 0.78125;
	
	if (parseInt(screen.width)>800)
	{
		windowwidth = 703;
		windowheight = 528;
	}
	else
	{
		windowwidth = parseInt(screen.width)*0.9;
		windowheight = parseInt(screen.height)*0.9;
	}

	var windowleft = parseInt((screen.width - windowwidth)/2);
	var windowtop = parseInt((screen.height - windowheight)/2);
	var pagename = Math.random();
	pagename = pagename.toString();
	pagename = pagename.substr(2);
//	frmallexhibition2.submit();
	openurl = 'http://www.meetexpo.com.cn/ieptest/drv_ood/vb_drv.php?company_id='+companyid+'&amp;USERINSTANCEID_IB_MEETEXPO=&amp;PRODUCERID_IB_MEETEXPO=44721&amp;USERNAME_IB_MEETEXPO=&amp;FIRSTNAME_IB_MEETEXPO=&amp;LASTNAME_IB_MEETEXPO=&amp;EMAIL_IB_MEETEXPO=&amp;PHONE_IB_MEETEXPO=&amp;FROMOUTSITE_IB_MEETEXPO=1';
	window.open(openurl,pagename,'top=' + windowtop + ',left=' + windowleft + ',width='+(windowwidth)+',height= '+ windowheight + ',resizable=0,scrollbars=0,status=no,toolbar=no,location=no,menubar=no,titlebar=no,dependent')
	return false;
}