function open_country(obj)
{
	window.open(obj.value, '', '');
}

function open_w(popup,width,height)
{
	window.open(popup+'.php', '', 'toolbars=no,width='+width+',height='+height);
}


var bIsIE   = (document.all) ? true : false;
var bIsDOM  = (document.getElementById) ? true : false;



var bIsIE   = (document.all) ? true : false;
var bIsDOM  = (document.getElementById) ? true : false;


function checkDate(formname)
	{
			var x = document.forms[formname].date.value;
			var filter  = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
			if (filter.test(x)) return true;
			else 
			{
				document.forms[formname].date.value=x;
				alert('Incorrect date ');
				document.forms[formname].date.focus();
			}

	}

	function checkMail(formname)
	{
			var x = document.forms[formname].email.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(x)) return true;
			else 
			{
				document.forms[formname].email.value=x;
				alert('Invalid email address');
				document.forms[formname].email.focus();
			}

	}
	function checkPhoneNumber(formname)
	{
		 // matches phone ###-###-####
	     // valid.phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
        // International Phone Number
        // valid.phoneNumberInternational = /^\d(\d|-){7,20}/;	
			var x = document.forms[formname].tel.value;
			var filter  = /^\d(\d|-){7,20}/;	
			if (filter.test(x)) return true;
			else 
			{
				document.forms[formname].tel.value=x;
				alert('Invalid telephone number!\n( US: 800-555-1212     Intl: 1-12-3123-4141 )');
				document.forms[formname].tel.focus();
			}

	}
	
	
function notImplemented(){
	alert( "This functionality is not avaible in this version." );
}


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;     
	
	curleft = curleft - 115;
	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 adjustDropDownMenus() {

	var MenuWidth = new Array( 115, 115, 97, 95, 66);
	
	if(bIsIE)
		var StartingPoint = findPosX( document.all.menuanchor );
	else if(bIsDOM)
		var StartingPoint = findPosX( document.getElementById( "menuanchor" ) );
		
	if(bIsIE){
		for( i=1; i<=5; i++ ){
			Tmp = eval("document.all.dropdown"+i);
			Tmp.style.pixelLeft = (StartingPoint += MenuWidth[i-1]);
		}
	}
	else if(bIsDOM) {
		for( i=1; i<=5; i++ )
			document.getElementById( "dropdown"+i ).style.left = (StartingPoint += MenuWidth[i-1]);
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
		if ((obj=MM_findObj(args[i]))!=null) 
		{   v=args[i+2];
			if (obj.style) 
			{
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
			if (obj.visibility!=v)
				obj.visibility=v;
		}
}

function hideAll(SelectedMenu){
	MM_showHideLayers('dropdown1','','hide','dropdown2','','hide','dropdown3','','hide','dropdown4','','hide','dropdown5','','hide');
}

var timerID = null;
var timerOn = false;
var timecount = 200;
	
function startTime() {
       if (timerOn == false) {
              timerID = setTimeout( "hideAll()" , timecount);
              timerOn = true;
       }
}

function stopTime() {
       if (timerOn) {
  	        clearTimeout(timerID);
              timerID = null;
              timerOn = false;
       }
}

//window.onresize = adjustDropDownMenus;

function setImgSrc( ImgObj, Filename ){
	if( !ImgObj ) return false;
	ImgObj.src = Filename;
}


function collapseDiv( BoxName, Status ){
	if( !(Box=MM_findObj(BoxName)) )
		return false;
		
	if( Status ){
		if( Status == "show" )
			Box.style.display = "block";
		else
			Box.style.display = "none";
	}
	else{
		if(Box.style.display == "block"){
			Box.style.display = "none";
		}
		else{
			Box.style.display = "block";
		}
	}
}

function popupWindow( Page, Width, Height){
	/*if(isNaN(window.screenLeft))
	{
		popWindow = window.open( Page,"popWindow","width="+Width+",height="+Height+",scrollbars=0,left="+((document.width-Width)+window.screenX)+",top="+((document.height-Height)+window.screenY)).focus();		
		
	}
	else
	popWindow = window.open( Page,"popWindow","width="+Width+",height="+Height+",scrollbars=0,left="+((document.width-Width)+window.screenLeft)+",top="+((document.height-Height)+window.screenRight)).focus();		*/
	popWindow = window.open( Page,"popWindow","width="+Width+",height="+Height+",scrollbars=1,left="+((screen.width-Width)/2)+",top="+((screen.height-Height)/2)).focus();
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   if ((version >= 5.5) && (version < 7) && (document.body.filters))
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function calculate_amount(fields)
{
	var tokens = fields.split(",");
	Field_to_update = tokens[0];
	maxlimit = tokens.length-1;
	var i=1; var sum=0;
	while(i<=maxlimit)
	{
		//alert(i + ':' + tokens[i]);
		field = tokens[i];
		sum = sum*1 + document.getElementById(field).value*1;
		i++;
	}
	document.getElementById(Field_to_update).value=sum;
}
