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 toggledisplay(id){
	show_tr=eval("TR"+id);
	
	if (show_tr.style.display == 'none') {
		show_tr.style.display='block';
		}
	else {
		show_tr.style.display='none';
	}
}

function rateMemberPopup (c_id){
	Popup=window.open('/easyconsole.cfm?page=rate_me&c_id='+c_id,'Popup','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no, width=670,height=310,left=430,top=300'); 
}

function chatroom() {
	window.open('/easyconsole.cfm?page=chatpopup','Chat','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no, width=650,height=375,left=430,top=300');
}


function chatLogin() {
	if (formIsValid()) {		
		document.login.submit();
	}
}


function submitRateForm() {
	document.forms.rateForm.submit();
}


function ValidateSubscription () {
	var errorCheck=0;

	if ((newsletterfrm.emailaddress.value.length==0) || (newsletterfrm.emailaddress.value==null)) {
		alert('Please enter your email address');
		errorCheck=1
		return false;
	} 
	
   if (! isValidEmail(newsletterfrm.emailaddress.value)) {
       alert('Please enter a valid email address');
	   errorCheck=1
       return false;
   }
	
	if (errorCheck==0) {
		document.newsletterfrm.submit();
	}
}

function mv (id) {
	id.className=id.className+'Over';
}

function mo (id) {
	var myclass = id.className;
	id.className=myclass.replace("Over","");
}

function url(id) {
	location.href='/easyconsole.cfm/id/'+id;
}


function openImageWindow(image_loc,img)
{
	HTML = "<html><style>body{margin:0px 0px 0px 0px}</style><body onBlur='top.close()'><img src='"+ image_loc +"' border=0 name=load_image onLoad='window.resizeTo(document.load_image.width+30,document.load_image.height+60)'></body></html>";
	popupImage = window.open('','_blank','height=200, width=300,toolbar=no,scrollbars=yes');
	popupImage.document.open();
	popupImage.document.write(HTML);
	popupImage.document.close();
}

function read(msg_id) {
	document.reclist.actionTemp.value='read';
	document.reclist.readMsgID.value=msg_id;
	document.reclist.submit();
}


function writeMessage(recipient_id,login) {
  popupwindow=window.open('/easyconsole.cfm?page=composer&recipient_id='+recipient_id+'&login='+login+'','Composer','width=590,height=400,scrollbars=no');
  popupwindow.focus();
  return true;
}



function togglesmsNumber (mode) {
	if (mode==1) {
		formAlerts.smsNumber.disabled = false;
	} else {
		formAlerts.smsNumber.disabled = true;
	}
}

function toggleemail(mode){
	if (mode==1) {
		formAlerts.email.disabled = false;
	} else {
		formAlerts.email.disabled = true;
	}
}

function enableall()
{
	formAlerts.smsNumber.disabled = false;
	formAlerts.email.disabled = false;
}

function checkThis(id) {
	a=eval("formProfiles.pr_id"+id);
	if (a.checked) a.checked=false;
	else a.checked=true;
}

function enableEdit(type){
	togglesmsNumber (type)
	toggleemail(type)
}


/* regular expression to allow only Cyta and Areeba numbers */
function alertValidCellNumber() {
	var re = new RegExp("(99|96)[0-9]{6}$"); 
	if (formAlerts.smsNumber.value.match(re))
	    return true;
	return false;
}

/*regular expression for checking valid email syntax*/
function alertValidEmail(){
	var re =  new RegExp("^[a-zA-Z][a-zA-Z_.0-9]*@[a-zA-Z0-9][a-zA-Z_.-0-9]*.[a-zA-Z][a-zA-Z_.0-9]*");
 	if (formAlerts.email.value.match(re))
		return true;
	return false;
}

function mySubmit() {

	var is_valid_email = false;
	var is_valid_sms = false;

	if (alertValidEmail()) {
		is_valid_email = true;
	}

    if (alertValidCellNumber()){
		is_valid_sms = true;
	}
	
	if (is_valid_email==true && is_valid_sms==true ) {
		enableall();
		formAlerts.submit();
	} 
	else 
	{
	
		if (!is_valid_email) {
			alert('Invalid Email Address');
		}
	
		if (!is_valid_sms) {
			alert('Invalid Mobile Number. The number should begin with 99 for CYTA or 96 for Areeba');
		}
	}
}


function visit(target_id,c_id) {
	if (!c_id) {	
   location.href='/easyconsole.cfm/id/'+target_id;
 	} else {
   location.href='/easyconsole.cfm/id/'+target_id+'/c_id/'+c_id;
	}
 }
 function blocking(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}



var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 900
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
		refresh('/easyconsole.cfm?id=1&logout=true');
		
    }
    else
    {
        self.status = ' Logging out in '+secs + ' seconds ...'
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

 
function refresh(url)
{
    //  This version does NOT cause an entry in the browser's
    //  page view history.  Most browsers will always retrieve
    //  the document from the web-server whether it is already
    //  in the browsers page-cache or not.
    //  
    window.location.replace( url );
}
function ViewPhoto (image_loc,image_name) {
  /*var img_width=document.getElementById('+image_name+').getAttribute('width');	
  alert(img_width);
  var img_height=document.getElementById('+image_name+').getAttribute('height');	
  alert(img_height);*/
  
  HTML = "<html><style>body{margin:0px 0px 0px 0px}</style><body onBlur='top.close()'><img src='"+ image_loc +"' border=0 name='image_name' id='image_name' onLoad='window.resizeTo(img_width,img_height)' /></body></html>";
  popupImage = window.open('','_blank','height=200, width=300,toolbar=no,scrollbars=no,statusbar=no,location=no');
  popupImage.document.open();
  popupImage.document.write(HTML);
  popupImage.document.close();
  obj_img = popupImage.document.getElementById('image_name');
  obj_img.src= obj_img.src;
}


