//Gino:AI-8917
var isOnCloseBtn=false;
$(document).ready(function() {
	var isCloseAnnouncement = getCookie("isCloseAnnouncement");
	if(isCloseAnnouncement!="1"){
	 $("#announcement").css("display", "");
  }
	$('.see-demo').click(function() {
		state = 'toolbar=none,scrollbar=none,location=none,left=0,top=0,width=810,height=570';
		window.open('/qi/aiweb.nsf/2k8Demo?openForm&lang=EN', 'Demo', state);
	});
	$('.see-demo-sp').click(function() {
		state = 'toolbar=none,scrollbar=none,location=none,left=0,top=0,width=810,height=570';
		window.open('/qi/aiweb.nsf/2k8Demo?openForm&lang=sp', 'Demo', state);
	});
	$(".content-expander").toggle(function() {
		$(this).parent().next("div").slideDown();
		return false;
	}, function() {
		$(this).parent().next("div").slideUp();
		return false;
	});

	$("input.watermark, textarea.watermark").each(function() {
		$(this).attr("ovalue", $(this).val());
		$(this).addClass("light");
	});
	$("input.watermark, textarea.watermark").focus(function() {
		if ($(this).val() == $(this).attr("ovalue")) {
			$(this).val("");
			$(this).removeClass("light");
		}
	});
	//Gino:AI-8917
	$("#close_button").mouseout(function() {
		isOnCloseBtn=false;
	});
	$("#close_button").mouseover(function() {
		isOnCloseBtn=true;
	});
	$("#announcement a").mouseout(function() {
		isOnCloseBtn=false;
	});
	$("#announcement a").mouseover(function() {
		isOnCloseBtn=true;
	});
	//end Gino:AI-8917
	//Gino:AI-8917
	$("#announcement").click(function() {
	  if($("#announcement").attr("type")=="AIFood"&&isOnCloseBtn==false){
		window.open('http://www.asiafoodinspection.com/', '', "");
	}
	});
	if($("#close_button").length > 0) {
		$("#close_button").click(function() {
			$("#announcement").css("display", "none");
			setCookie("isCloseAnnouncement","1",365);
		});
	}	
	
});

function setTelFromCountry(source, target) {
	var CodeArray = new Array();
	CodeArray[0] = '';
	CodeArray[1] = '93';
	CodeArray[2] = '355';
	CodeArray[3] = '213';
	CodeArray[4] = '376';
	CodeArray[5] = '244';
	CodeArray[6] = '1264';
	CodeArray[7] = '54';
	CodeArray[8] = '374';
	CodeArray[9] = '297';
	CodeArray[10] = '61';
	CodeArray[11] = '43';
	CodeArray[12] = '994';
	CodeArray[13] = '973';
	CodeArray[14] = '880';
	CodeArray[15] = '375';
	CodeArray[16] = '32';
	CodeArray[17] = '501';
	CodeArray[18] = '229';
	CodeArray[19] = '1441';
	CodeArray[20] = '975';
	CodeArray[21] = '591';
	CodeArray[22] = '387';
	CodeArray[23] = '267';
	CodeArray[24] = '55';
	CodeArray[25] = '1284';
	CodeArray[26] = '673';
	CodeArray[27] = '359';
	CodeArray[28] = '226';
	CodeArray[29] = '257';
	CodeArray[30] = '855';
	CodeArray[31] = '237';
	CodeArray[32] = '001';
	CodeArray[33] = '238';
	CodeArray[34] = '1345';
	CodeArray[35] = '236';
	CodeArray[36] = '235';
	CodeArray[37] = '56';
	CodeArray[38] = '86';
	CodeArray[39] = '57';
	CodeArray[40] = '269';
	CodeArray[41] = '242';
	CodeArray[42] = '682';
	CodeArray[43] = '506';
	CodeArray[44] = '385';
	CodeArray[45] = '53';
	CodeArray[46] = '357';
	CodeArray[47] = '420';
	CodeArray[48] = '243';
	CodeArray[49] = '45';
	CodeArray[50] = '246';
	CodeArray[51] = '253';
	CodeArray[52] = '1809';
	CodeArray[53] = '593';
	CodeArray[54] = '20';
	CodeArray[55] = '503';
	CodeArray[56] = '240';
	CodeArray[57] = '291';
	CodeArray[58] = '372';
	CodeArray[59] = '251';
	CodeArray[60] = '691';
	CodeArray[61] = '500';
	CodeArray[62] = '298';
	CodeArray[63] = '679';
	CodeArray[64] = '358';
	CodeArray[65] = '33';
	CodeArray[66] = '689';
	CodeArray[67] = '241';
	CodeArray[68] = '220';
	CodeArray[69] = '995';
	CodeArray[70] = '49';
	CodeArray[71] = '233';
	CodeArray[72] = '350';
	CodeArray[73] = '30';
	CodeArray[74] = '299';
	CodeArray[75] = '590';
	CodeArray[76] = '502';
	CodeArray[77] = '594';
	CodeArray[78] = '224';
	CodeArray[79] = '245';
	CodeArray[80] = '592';
	CodeArray[81] = '509';
	CodeArray[82] = '504';
	CodeArray[83] = '852';
	CodeArray[84] = '36';
	CodeArray[85] = '354';
	CodeArray[86] = '91';
	CodeArray[87] = '62';
	CodeArray[88] = '98';
	CodeArray[89] = '964';
	CodeArray[90] = '353';
	CodeArray[91] = '972';
	CodeArray[92] = '39';
	CodeArray[93] = '225';
	CodeArray[94] = '1876';
	CodeArray[95] = '81';
	CodeArray[96] = '962';
	CodeArray[97] = '7';
	CodeArray[98] = '254';
	CodeArray[99] = '686';
	CodeArray[100] = '850';
	CodeArray[101] = '82';
	CodeArray[102] = '965';
	CodeArray[103] = '996';
	CodeArray[104] = '856';
	CodeArray[105] = '371';
	CodeArray[106] = '961';
	CodeArray[107] = '266';
	CodeArray[108] = '231';
	CodeArray[109] = '218';
	CodeArray[110] = '423';
	CodeArray[111] = '370';
	CodeArray[112] = '352';
	CodeArray[113] = '853';
	CodeArray[114] = '389';
	CodeArray[115] = '261';
	CodeArray[116] = '265';
	CodeArray[117] = '60';
	CodeArray[118] = '960';
	CodeArray[119] = '223';
	CodeArray[120] = '356';
	CodeArray[121] = '692';
	CodeArray[122] = '596';
	CodeArray[123] = '222';
	CodeArray[124] = '230';
	CodeArray[125] = '52';
	CodeArray[126] = '373';
	CodeArray[127] = '377';
	CodeArray[128] = '976';
	CodeArray[129] = '382';
	CodeArray[130] = '1664';
	CodeArray[131] = '212';
	CodeArray[132] = '258';
	CodeArray[133] = '95';
	CodeArray[134] = '264';
	CodeArray[135] = '674';
	CodeArray[136] = '977';
	CodeArray[137] = '31';
	CodeArray[138] = '599';
	CodeArray[139] = '687';
	CodeArray[140] = '64';
	CodeArray[141] = '505';
	CodeArray[142] = '227';
	CodeArray[143] = '234';
	CodeArray[144] = '683';
	CodeArray[145] = '47';
	CodeArray[146] = '968';
	CodeArray[147] = '92';
	CodeArray[148] = '680';
	CodeArray[149] = '970';
	CodeArray[150] = '507';
	CodeArray[151] = '675';
	CodeArray[152] = '595';
	CodeArray[153] = '51';
	CodeArray[154] = '63';
	CodeArray[155] = '48';
	CodeArray[156] = '351';
	CodeArray[157] = '1809';
	CodeArray[158] = '974';
	CodeArray[159] = '995';
	CodeArray[160] = '40';
	CodeArray[161] = '7';
	CodeArray[162] = '250';
	CodeArray[163] = '290';
	CodeArray[164] = '378';
	CodeArray[165] = '239';
	CodeArray[166] = '966';
	CodeArray[167] = '221';
	CodeArray[168] = '381';
	CodeArray[169] = '248';
	CodeArray[170] = '232';
	CodeArray[171] = '65';
	CodeArray[172] = '421';
	CodeArray[173] = '386';
	CodeArray[174] = '677';
	CodeArray[175] = '252';
	CodeArray[176] = '27';
	CodeArray[177] = '34';
	CodeArray[178] = '94';
	CodeArray[179] = '508';
	CodeArray[180] = '249';
	CodeArray[181] = '597';
	CodeArray[182] = '268';
	CodeArray[183] = '46';
	CodeArray[184] = '41';
	CodeArray[185] = '963';
	CodeArray[186] = '886';
	CodeArray[187] = '992';
	CodeArray[188] = '255';
	CodeArray[189] = '66';
	CodeArray[190] = '670';
	CodeArray[191] = '228';
	CodeArray[192] = '690';
	CodeArray[193] = '676';
	CodeArray[194] = '1809';
	CodeArray[195] = '216';
	CodeArray[196] = '90';
	CodeArray[197] = '993';
	CodeArray[198] = '1649';
	CodeArray[199] = '688';
	CodeArray[200] = '256';
	CodeArray[201] = '380';
	CodeArray[202] = '971';
	CodeArray[203] = '44';
	CodeArray[204] = '1';
	CodeArray[205] = '1340';
	CodeArray[206] = '598';
	CodeArray[207] = '998';
	CodeArray[208] = '678';
	CodeArray[209] = '39';
	CodeArray[210] = '58';
	CodeArray[211] = '84';
	CodeArray[212] = '681';
	CodeArray[213] = '685';
	CodeArray[214] = '967';
	CodeArray[215] = '260';
	CodeArray[216] = '263';
	
	$("#" + target).val("+ " + CodeArray[source.selectedIndex]);
}

function isPhoneNumber(value) {
	var pattern = /^\+?[\s\d-]{5,}$/;
	return pattern.test(value);
}

$(function () {
	$('a[tooltip]').each(function (i, e) {
	
		var bubbleInfo = $(e).parent().addClass('bubbleInfo');
		var trigger = $(e).addClass('trigger');
		trigger.after('<div class="popup"></div>');
		var popup = trigger.next().css('opacity', 0);
		popup.append("<div class='top'><div class='biContent'></div></div>");
		popup.append("<div class='bottom'></div>");
		
		var source = $("#" + $(trigger).attr("tooltip")).html();
		bubbleInfo.find(".biContent").html(source);
		
		// options
		var distance = 0;
		var time = 250;
		var hideDelay = 0;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;		

		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				popup.css({
					top: 20,
					left: 20,
					zIndex: 2000,
					display: 'block' // brings the popup back in to view
				})

				// (we're using chaining on the popup) now animate it's opacity and position
				.animate({
					top: '-=' + distance + 'px',
					opacity: 1,filter:''
				}, time, 'swing', function() {
					// once the animation is complete, set the tracker variables
					beingShown = false;
					shown = true;
				});
			}
		}).mouseout(function () {
			// reset the timer if we get fired again - avoids double animations
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
		  
			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					top: '-=' + distance + 'px',
					opacity: 0,filter:''
				}, time, 'swing', function () {
					// once the animate is complete, set the tracker variables
					shown = false;
					// hide the popup entirely after the effect (opacity alone doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});
});
