
/**
 *	This function is intended to inform the portal gwt code if the
 *	browser at present has the popups blocked or not.
 */

arePopupsBlocked = function()
{
	var myTest = window.open("about:blank","_blank",
"directories=no,height=100,width=100,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
	if (!myTest)
	{
		//	Popups are blocked.
		return	true;
	}
	else
	{
		myTest.close();
		return	false;
	}
}

launchUrl = function(url)
{
//		var w = window.open(url,"_blank",
//			"menubar=no,toolbar=no,location=no,resizable="+resize+",scrollbars="
//			+scroll+",status=no,width="+width+",height="+height);
	window.open(url,"_blank","");
}

checkPopupsAndlaunchUrl = function(url)
{
	var popupsBlocked = true;
	try
	{
		var s = arePopupsBlocked();
		if (s != null && s.equals("false"))
		{
			popupsBlocked = false;
		}
	}
	catch(e)
	{
		popupsBlocked = true;
	}
	if (popupsBlocked)
	{
	   	directTopWindowToUrl(url);
	}
	else
	{
		launchUrl(url);
	}
}

function getTopWindow(w)
{
	if (w.parent == w)
	{
		return w;
	}
	else
	{
		return getTopWindow(w.parent);
	}
}

directTopWindowToUrl = function(url)
{
	getTopWindow(self).location.href = url
}

/**
 *	This function returns an integer as
 *	0 - good email,
 *	1 - bad email,
 *	2 - may be bad email.
 */
 
validateEmail_bkp  = function( givenEmail )
{
	var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
	//var regExpEmail = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/; 
	//var regExpEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
	
	if (!email.test(givenEmail))
	{
		return 1;
	}
	
	/*if (!regExpEmail.test(givenEmail))
	{
		return 2;
	}*/	
	var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
	if (!email2.test(givenEmail))
	{
		return 2;
	}
  
	return 0;
}

/**
 *	This function returns an integer as
 *	0 - good URL,
 *	1 - bad URL,
 */
validateUrl = function( givenUrl)
{
	var regUrl = /^(((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&//=]+$/;

	if(regUrl.test(givenUrl) == false)
	{
		return 1;
	}else{
		return 0;
	}	
}

/**
 *	This function returns an integer as
 *	0 - good email,
 *	1 - bad email,
 */
 
validateEmailNew  = function( givenEmail )
{
	
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|~`#$%&*<,>?';
	
	//alert(' givenEmail = '+givenEmail);
	 for (i=0; i<invalidChars.length; i++) {
		  badChar = invalidChars.charAt(i);

		  if (givenEmail.indexOf(badChar,0) > -1)
		  {
		  	//alert('Please enter a valid email & press go to receive invitation for Featured dimdim Meeting');
			  return 1;
		  }
	 }
	 
	 for (i=0; i<givenEmail.length; i++) {
		   if (givenEmail.charCodeAt(i)>127) {
		      //alert("email address contains non ascii characters.");
		      return 1;
		   }
	}
	 
	 var atPos = givenEmail.indexOf('@',0);
	 if (atPos == -1) {
	    //alert('email address must contain an @');
	    return 1;
	 }
	 if (atPos == 0) {
	    //alert('email address must not start with @');
	    return 1;
	 }
	 if (givenEmail.indexOf('@', atPos + 1) > - 1) {
	    //alert('email address must contain only one @');
	    return 1;
	 }
	 if (givenEmail.indexOf('.', atPos) == -1) {
	    //alert('email address must contain a period in the domain name');
	    return 1;
	 }
	 if (givenEmail.indexOf('@.',0) != -1) {
	    //alert('period must not immediately follow @ in email address');
	    return 1;
	 }
	 if (givenEmail.indexOf('.@',0) != -1){
	    //alert('period must not immediately precede @ in email address');
	    return 1;
	 }
	 if (givenEmail.indexOf('..',0) != -1) {
	    //alert('two periods must not be adjacent in email address');
	    return 1;
	 }

	return 0;
}

function copy(stringToCopy, divId) {
	try{
		//alert(stringToCopy);
		var flash = document.getElementById("movie");
		flash.SetVariable("a", stringToCopy);
		flash.thisMethod();
		return 1;
	}catch(err){
		//alert('inside exception....'+err);
		return 0;
	}
}

function handleClickPref()
{
	try{
		clickPref();
		}
	catch(e)
	{
		//alert(e);
	}
}

function showCopyMessage(s1)
{
	//alert('inside flash bridge showCopyMessage '+s1);
	try{
		//JSInterfaceCobrowse.init();
		JSInterface.callGWT2('COPY_MOVIE_EVENT','FLASH_MESSAGE_LOG',+s1);
	}catch(e){
		alert(e);
	}
}
