function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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; }
    obj.visibility=v; }
}

function ChangeSize(classname,divname){
	var divsize = MM_findObj(divname);
	divsize.className = classname;
}

function popImage(img, caption)
{
	caption = escape(caption);
	openIT('pop_gl.htm?img='+img+"&caption="+caption,800,550,true);
}

function openIT(u,W,H, sc) {
		var x = (screen.width - W) / 2;
		var y = (screen.height - H) / 2;
		window.open(u, '',"width="+W+",height="+H+",scrollbars="+(sc ? "yes" : "no")+",resizable=Yes, left="+x+",top="+y);
		//window.open(u, '',"width="+W+",height="+H+",scrollbars=yes,resizable=Yes, left="+x+",top="+y);
}

function printArticle() {
	if (window.print) {
		setTimeout('window.print();',200);
	}
	else if (agt.indexOf("mac") != -1) {
		alert("Press 'Cmd+p' on your keyboard to print article.");
	}
	else {
		alert("Press 'Ctrl+p' on your keyboard to print article.")
		}

}

function OpenEmail(URL){
     OpenWnd('Forward.aspx?URL='+URL, 'Email', 670, 570, 'no');
}
function OpenWnd(mypage, myname, w, h, scroll)

{
      var winl = (screen.width - w) / 2;
      var wint = (screen.height - h) / 2;
      winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=No'
      win = window.open(mypage, myname, winprops)
      if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}

function toggleBlock(d, i)
{
	var e = MM_findObj(d);
	var img = MM_findObj(i);
	if (!e) return;
	if (e.style.display == "block"){
		e.style.display = "none";
		img.src = "images/btn_more.gif";
	} else {
		e.style.display = "block";
		img.src = "images/btn_close.gif";
	}
}

function HighlightButton(count,index){
	var itemindex;
	for (var i=0;i<count;i++){
		itemindex=i+2;
		if (itemindex<10)
			itemindex="0"+itemindex;
		if(i==index){
			document.getElementById("ControlLatestNews1_gvNews_ctl"+itemindex+"_lbtnTitle").className="news-cat-on";
		}
		else{
			document.getElementById("ControlLatestNews1_gvNews_ctl"+itemindex+"_lbtnTitle").className="";
			}
	}
}

function Checkvote(btns, ItemsCount, lang)
{
	var i;
	var ItemChecked=false;
	i=0;
	for (i=0; i< ItemsCount;i++){
		if (document.getElementById(btns + "_" + i ).checked==true)
			ItemChecked=true
	}
	
	if (ItemChecked==true){
			return true;
	}
	else {
		alert("Please select an answer")
		return false;
	}
 }
 
function ValidateSearchPrograms(strid){
	if (Trim(document.getElementById(strid+"txtkeyword").value)==""){
		alert("The following fields are required:\n - Keyword");
		return false;
	}
	else{
		if(Trim(document.getElementById(strid+"txtkeyword").value).length<3){
			alert("Keyword must be at least 3 characters");
			return false;
		}
		else{
			return true;
		}
	}	
}

function CheckLogin(username, password){
		if (Trim(document.getElementById(username).value)=="" || Trim(document.getElementById(password).value)==""){
			alert("Please enter your Username and your Password");
			return false;
		}
		else{
			return true;
		}
	}
	function LoggedInAlert(){
		alert("This account is already logged in")
	}
function SubmitLogin(btn) {
		// process only the Enter key 
		if (event.keyCode == 13) {
			// cancel the default submit 
			event.returnValue=false; 
			event.cancel = true; 
			// submit the form by programmatically clicking the specified button 
			document.getElementById(btn).click();
		} 
	 }
function CheckDateFilter(){
   if (document.Form1.txtFromDate.value==""){
       alert("Please select a date");
       return false;
    }
	else
		return true;

}
function ValidateForward(){
	var msg="";
	var msg1="";
	var strvalmail=""
	if (document.Form1.txtSender.value=="")
		msg+="Sender Name\n";
	if (document.Form1.txtSenderMail.value=="")
		msg+="Sender Email\n";
	else{
		strvalmail=IsValidEmail(document.Form1.txtSenderMail);
	    if (strvalmail.length>0)
			msg1+="Invalid Sender Email Address\n";
	    } 
	if (document.Form1.txtReceiver.value=="")
		msg+="Receiver Name\n";
	if (document.Form1.txtReceiverMail.value=="")
		msg+="Receiver Email\n";
	else{
		strvalmail=IsValidEmail(document.Form1.txtReceiverMail);
	    if (strvalmail.length>0)
			msg1+="Invalid Receiver Email Address\n";
	    } 
	if (document.Form1.txtSubject.value=="")
		msg+="Subject\n";
	
	if (msg==""){
		if (msg1=="")
		   return true
        else
		{
			alert(msg1);
			return false;}
	}
	else{  
	   alert("The following fields are required,\n please be sure to fill them and try again:\n\n" + msg )
		return false;
		}	
	
	}


function ValidateRegister()
{
	var msg="";
	var msg1="";
	if (Trim(document.Form1.txtUserName.value)=="")
		msg+="- User Name\n"
	if (Trim(document.Form1.txtPassword.value)=="")
		msg+="- Password\n"
	if (Trim(document.Form1.txtConfirm.value)=="")
		msg+="- Confirm Password\n"	
	if (Trim(document.Form1.txtPassword.value)!=Trim(document.Form1.txtConfirm.value))
	    msg1+="- New password and its confirmation do not match.\n"	
	if (Trim(document.Form1.txtFName.value)=="")
		msg+="- First Name\n"
	if (Trim(document.Form1.txtLName.value)=="")
		msg+="- Last Name\n"
		if (Trim(document.Form1.txtNickName.value)=="")
		msg+="- Nick Name\n"
	if (CheckRadioButtons(document.Form1.rdGender)==false)
		msg+="- Gender\n"
	if (document.Form1.lstAge.selectedIndex==0)
		msg+="- Age Group\n"
	if (document.Form1.lstCountry.selectedIndex==0)
	   msg+="- Country\n"
	if (document.Form1.lstNationality.selectedIndex==0)
	   msg+="- Nationality\n"
	if (Trim(document.Form1.txtEmail.value)==""){
		msg+="- Email\n"
		}
    else{
		var strvalmail=IsValidEmail(document.Form1.txtEmail);
	    if (strvalmail.length>0)
	     msg1+=strvalmail
	    } 
	if (Trim(document.Form1.txtConfirmEmail.value)=="")
		msg+="- Confirm Email\n"
	if (Trim(document.Form1.txtEmail.value)!=Trim(document.Form1.txtConfirmEmail.value))
	    msg1="Email and its confirmation do not match.\n"	
	    	
	if (msg==""){
		if (msg1=="")
		   return true
        else
		{
			alert(msg1);
			return false;}
	}
	else{  
	   alert("The following fields are required,\n please be sure to fill them and try again:\n\n" + msg )
		return false;
		}
}

function ValidateEdit()
{
	var msg="";
	var msg1="";
	if (Trim(document.Form1.txtUserName.value)=="")
		msg+="- User Name\n"
	if (Trim(document.Form1.txtFName.value)=="")
		msg+="- First Name\n"
	if (Trim(document.Form1.txtLName.value)=="")
		msg+="- Last Name\n"
		if (Trim(document.Form1.txtNickName.value)=="")
		msg+="- Nick Name\n"
	if (CheckRadioButtons(document.Form1.rdGender)==false)
		msg+="- Gender\n"
	if (document.Form1.lstAge.selectedIndex==0)
		msg+="- Age Group\n"
	if (document.Form1.lstCountry.selectedIndex==0)
	   msg+="- Country\n"
	if (document.Form1.lstNationality.selectedIndex==0)
	   msg+="- Nationality\n"
	if (Trim(document.Form1.txtEmail.value)==""){
		msg+="- Email\n"
		}
    else{
		var strvalmail=IsValidEmail(document.Form1.txtEmail);
	    if (strvalmail.length>0)
	     msg1+=strvalmail
	    } 
  	
	if (msg==""){
		if (msg1=="")
		   return true
        else
		{
			alert(msg1);
			return false;}
	}
	else{  
	   alert("The following fields are required,\n please be sure to fill them and try again:\n\n" + msg )
		return false;
		}
}

function ValidateChangePassword(){
    if (Trim(document.Form1.txtOldpwd.value)=="" || Trim(document.Form1.txtNewPwd.value)=="" || Trim(document.Form1.txtConfirm.value)=="")
	{
		alert("The following fields are required:\n - Old Password \n - New Password \n - Confirm New Password");
	    return false;
	  }
	else{
		if (document.Form1.txtNewPwd.value!=document.Form1.txtConfirm.value){
			alert("New Password and Confirm New Password do not match");
			return false;
			}
		else{
			return true;
		}
	}
}

function CheckSubSelection(Count){
	var radiochecked=false;
	var itemindex;
	for (i=0;i<Count;i++){
		itemindex=i+2;
		if (itemindex<10)
			itemindex="0"+itemindex;
		if (document.getElementById("dgSubscription_ctl" + itemindex + "_rdSubScription").checked==true)
			radiochecked=true;
      }   
    
    if (radiochecked==false){
    	alert("Please choose a plan");
    	return false;
    }
      
}

function ChangeSubSelection(Count, Index){
		var itemindex;
		var currentindex;
		Index=Index+2
		if (Index<10)
			currentindex="0" + Index;
		for (i=0;i<Count;i++){
			itemindex=i+2;
			if (itemindex<10)
				itemindex="0"+itemindex;
			document.getElementById("dgSubscription_ctl" + itemindex + "_rdSubScription").checked=false;       
        	document.getElementById("dgSubscription_ctl" + currentindex + "_rdSubScription").checked=true;
        }
}



function CheckRadioButtons(rbtn){
   var check=false;
   var i=0;
   
   for (i=0;i<rbtn.length;i++){
       if(rbtn[i].checked==true) 
       check=true
   } 
  
   if (check==false)
      return false;
   else
      return true;
}

function IsValidEmail(txt){
    var stremail="";
	if(txt.value !=""){ 
		var goodEmail = txt.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail){
		    return true;
		} else {
			stremail="- The Email address is not valid\n";
			return stremail;
		}
	}
}
 
//TRIM Functions
function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

