
function smInfo(country) {
	
	if (country == undefined) country = "";	
	sm_country = country ;
	var infos = document.getElementById('mapcontainer').getElementsByTagName ('DIV') ;
	for (var i = 0 ; i < infos.length ; i ++ ) {
		infos[i].style.display = 'none' ; 
	}
	var infobg = document.getElementById('mapinfobg') ;
	infobg.style.display = 'none' ;
	var mselect = document.getElementById ('wmdrop') ;
	var cblock = document.getElementById ('countryinfo_' + country ) ;
	mselect.options[0].selected = true ;
	if (cblock){
		infobg.style.top = cblock.style.top;
		infobg.style.left = cblock.style.left;
		infobg.style.width = cblock.style.width;
		infobg.style.height = cblock.style.height;
		infobg.style.display = 'block' ;
		infobg.style.top =    ( parseInt( infobg.style.top ) - parseInt( infobg.style.height )) + 'px';
		cblock.style.zIndex = infobg.style.zIndex + 1 ;
		cblock.style.display = 'block' ;
		for (var i = 0 ; i < mselect.options.length ; i ++ ){
			if (mselect.options[i].value == country ) {
				mselect.options[i].selected = true ;
			}			
		}
	}
}



// test form
function testForm (ref){
	var allforms = new Array () ;
	allforms['cform'] = new Array (
		'email' , new Array ( 'is_email(value)' , 'Please enter a valid e-mail address' ) ,
		'subject' , new Array ( 'trim(value).length > 0' , 'What is the subject of your message?' ) ,
		'message' , new Array ( 'trim(value).length > 0' , 'What is your message?' ) 
	);
	allforms['jform'] = new Array (
		'name' , new Array ( 'trim(value).length > 0' , 'Please enter your name' ) ,
		'age' , new Array ( 'trim(value).length > 0' , 'Please enter your age' ) ,
		'mailing' , new Array ( 'trim(value).length > 0' , 'Please enter your mailing address' ) ,
		'email' , new Array ( 'is_email(value)' , 'Please enter a valid e-mail address' ) ,
		'what' , new Array ( 'trim(value).length > 0' , 'Please tell us what you can offer' ) ,
		'how' , new Array ( 'trim(value).length > 0' , 'Please let us know how you will benefit from joining' )
	);

	var f = document[ref] ;
	var cond , valname;
	for (var i = 0 ; i < allforms[ref].length ; i += 2 ) {
		valname =  (!f[allforms[ref][i]].type || f[allforms[ref][i]].type.indexOf('select') > -1 || f[allforms[ref][i]].type.indexOf('checkbox') > -1) ? '' : '.value'  ;
		cond = allforms[ref][i+1][0].replace (/value/g , "f." + allforms[ref][i] + valname);
		if (!eval (cond)){
			alert (allforms[ref][i+1][1]);
			return false ;
		}
	}
	return true ;

}

function trim (str){
	return str.replace(/^\s*|\s*$/g,"") ;
}

function is_email(str) {
	var str = trim (str) ;
	if (str.indexOf(" ") != -1){
		return false;
	}else if (str.indexOf("@") == -1){
		return false;
	}else if (str.indexOf("@") == 0){
		return false;
	}else if (str.indexOf("@") == (str.length-1)){
		return false;
	}
	var arrayString = str.split("@");
	if (arrayString[1].indexOf(".") == -1){
		return false;
	}else if (arrayString[1].indexOf(".") == 0){
		return false;
	}else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
		return false;
	}
	return true;
}



// preload images
function preloadImages(imgArr){
	if (document.images) {
		var preloaded = new Array ();
		for (var i=0; i<imgArr.length;i++) {
			preloaded[i] = new Image () ;
			preloaded[i].src  = imgArr[i];
		}
	}
}
//photo contest

function inlineImagePopup (img , img_w , img_h , img_title , img_caption ){
	hideProdImage();
	if (!img || !img_w || !img_h ) return ;
	var tmp_img = new Image(img_w, img_h);
	tmp_img.src = img ;
	if (img_title == undefined) {
		img_title = '' ;
	}
	if (img_caption == undefined) {
		img_caption = '' ;
	}
	document.getElementById ('image_placeholder').appendChild(tmp_img) ;
	document.getElementById ('image_placeholder_caption').innerHTML = img_caption + '&nbsp;';
	document.getElementById ('image_placeholder_title').innerHTML = '&nbsp;' + img_title ;
	setTimeout( 'setPImgeSrc(\''+img+'\')' , 1 );
	var container = document.getElementById ('image_placeholder_container') ;
	// handle tiny tiny images
	if (img_w < 200) img_w = 200 ;
	container.style.width=img_w + 'px' ; 
	var w = 5; 
	var h = 5 ;
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	w += scrOfX;
	h += scrOfY;
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if ( myWidth >  img_w) {
		w += parseInt( (myWidth -img_w) / 2) 
	}
	if ( myHeight >  img_h) {
		h += parseInt( (myHeight - img_h   ) / 2) ;
	}
	container.style.left = w + 'px' ;
	container.style.top = h + 'px' ;
	container.style.display='block' ; 
}

function setPImgeSrc(img){
	// stupid explder cannot fully show image right away
	document.getElementById ('image_placeholder').childNodes[0].src = img ;
}

function hideProdImage(){
	try {
		document.getElementById('image_placeholder_container').style.display='none';
		document.getElementById ('image_placeholder').removeChild(document.getElementById ('image_placeholder').childNodes[0]) ;
		document.getElementById ('image_placeholder').removeChild(document.getElementById ('image_placeholder').childNodes[0]) ;
	}catch (e){};
}
