/*-------------------DEFINITIONS-----------------------------*/
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInPhoneNumber = 10;
/*-------------------END DEFINITIONS-----------------------------*/

/*EMAIl VALIDATION*/
function echeck(str)
{

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
	return false;
	}

	if (str.indexOf(" ")!=-1){
	return false;
	}

	if(str.substring(str.indexOf(dot)).length <= 1)
	{
		return false;
	}
 	return true;					
}
/*END EMAIL VALIDATION*/

/*INTEGER VALIDATION*/
function isInteger(s)
{
	var i = 0;
	for(i = 0; i < s.length; i++)
	{
	var c = s.charAt(i);
	if(((c < "0") || (c > "9")))
	{
	return false;
	}
	}
	return true;
}
/*END INTEGER VALIDATION*/

function stripCharsInBag(s, bag)
{
	var i = 0;
	var returnString = "";
	for(i = 0; i < s.length; i++)
	{
	var c = s.charAt(i);
	if(bag.indexOf(c) == -1)
	{
	returnString += c;
	}
	}
	return returnString;
}

/*PHONE NUMBER VALIDATION*/
function checkInternationalPhone(strPhone)
{
	var s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInPhoneNumber);
}
/*END PHONE NUMBER VALIDATION*/


/*IFRAME RELATED FUNCTIONS*/

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function ShowForm(url,place_holder,dx,dy,width,height)
{
	var iframe = document.getElementById('myiframe');
	iframe.src = url;
	ShowFrame('myiframe',place_holder,dx,dy,width,height);
	return false;
}
	

function ShowForm1(url,place_holder,dx,dy,width,height)
{
	var iframe = document.getElementById('myiframe');
	iframe.src = url;
	ShowFrame1('myiframe',place_holder,dx,dy,width,height);
	return false;
}
	


var bIgnoreFirst;

function ShowFrame(ifr,parent_place_holder,dx,dy,width,height)
{
	var element = document.getElementById(ifr);
	element.style.display = "block";
	var place_holder = document.getElementById(parent_place_holder);
	element.style.pixelLeft = findPosX(place_holder) + dx;
	element.style.pixelTop = findPosY(place_holder) + dy;
	element.width=width;
	element.height=height;
	document.body.onclick=HideFrame;
	bIgnoreFirst = false;
}

function HideFrame()
{	

	var ifr= 'myiframe';

	
	//if (bIgnoreFirst)
	//{
	//	bIgnoreFirst = false;
		//alert('On Hide avoiding');
	//	return;
	//}
	
	//alert('On Hide');

	var element = document.getElementById(ifr);
	if (element.style.display == "none")
	{
		//alert('Already Hidden');
		return;
	}

	element.style.display = "none";
	document.body.onclick=null;
}

var bIgnoreFirst1;
function ShowFrame1(ifr,parent_place_holder,dx,dy,width,height)
{
	var element = document.getElementById(ifr);
	element.style.display = "block";
	var place_holder = document.getElementById(parent_place_holder);
	element.style.pixelLeft = findPosX(place_holder) + dx;
	element.style.pixelTop = findPosY(place_holder) + dy;
	element.width=width;
	element.height=height;
	document.body.onclick=HideFrame1;
	bIgnoreFirst1 = true;
}
function HideFrame1()
{	

	var ifr= 'myiframe';

	
	if (bIgnoreFirst1)
	{
		bIgnoreFirst1 = false;
		return;
	}
	
	var element = document.getElementById(ifr);
	if (element.style.display == "none")
	{
		//alert('Already Hidden');
		return;
	}

	element.style.display = "none";
	document.body.onclick=null;
}
/*END IFRAME RELATED FUNCTIONS*/

/*MAIL WINDOW OPEN*/
function doPopUp(windowname,windowURL,windowWidth,windowHeight,windowLeft,windowTop,directories,menubar,resizable,status,toolbar,scrollbars)
{
	
	try
	{
		//try to close and then focus the popup window
		windowname.close();
		windowname.focus();
	}
	catch(err)
	{
		//do nothing on error
	}

	w = windowWidth;
	h = windowHeight;

	if(windowLeft=='center')
	{
		l = (screen.width) ? (screen.width-w)/2 : 0;
		} else {
		l = windowLeft;
	}

	if(windowTop=='center')
	{
		t = (screen.height) ? (screen.height-h)/2 : 0;
	}
	else
	{
		t = windowTop;
	}


	settings = 'directories='+directories+',menubar='+menubar+',resizable='+resizable+',status='+status+',toolbar='+toolbar+',height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scrollbars;
	windowname = window.open(windowURL,windowname,settings)

	
	try
	{
		//try to resize the popup window
		windowname.resizeTo(w,h);
	}
	catch(err)
	{
		//do nothing on error
	}
	

	if(windowname.focus)
	{
		windowname.focus();
	}

	return windowname;
}
/*END MAIL WINDOW OPEN*/