function MM_preloadImages(img_arr) { //v3.0
    var d = new Array();
    for(i = 0; i < img_arr.length; i++){
        d[i] = new Image; 
        d[i].src = img_arr[i];
    }
}
function hide_show(id){
    if(document.getElementById(id)){
        var it = document.getElementById(id);
    }
   if(it.style.visibility != 'hidden'){
        it.style.display = 'none';
        it.style.visibility = 'hidden';
   }else{
        it.style.display = 'block';
        it.style.visibility = 'visible';
   }
}
function chkchk(){
    if(document.getElementById('chk_fname').value != ''){
        if(document.getElementById('chk_lname').value != ''){
            if(document.getElementById('chk_email').value != ''){
                if(echeck(document.getElementById('chk_email').value) == true){
                    if(document.getElementById('chk_password').value != ''){
                        if(document.getElementById('chk_password').value.length > 4){
                            if(document.getElementById('chk_password').value == document.getElementById('chk_repassword').value){
                                if((document.getElementById('chk_weekly_sms').checked == true) && (document.getElementById('chk_cell').value.length < 10)){
                                    alert('Your cell number provided for the weekly sms should be 10 digits');
                                    return false;
                                }else{	
                                }                                
                            }else{
                                alert('Your Password and Re-Password do not match');
                                return false;	
                            }
                        }else{
                            alert('Please supply a password of 5 characters or more');
                            return false;	
                        }
                    }else{
                        alert('Please supply a password');
                        return false;	
                    }
                }else{
                    alert('Please supply a valid email address');
                    return false;	
                }                    
            }else{
                alert('Please supply an email address');
                return false;	
            }
        }else{
            alert('Please supply a surname');
            return false;	
        }
    }else{
        alert('Please supply a name');
        return false;	
    }                
}

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){
        //alert("Invalid E-mail ID")
        return false
    }
    
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        //alert("Invalid E-mail ID")
        return false
    }
    
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
    //alert("Invalid E-mail ID")
    return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    //alert("Invalid E-mail ID")
    return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
    //alert("Invalid E-mail ID")
    return false
    }

    if (str.indexOf(" ")!=-1){
    //alert("Invalid E-mail ID")
    return false
    }

    return true					
}

/* AJAX  */
var xmlhttp;
function loadXMLDoc(url){
    if (window.XMLHttpRequest){// code for Mozilla, etc.
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=xmlhttpChange;
      //alert(url);
      xmlhttp.open("GET",url,true);
      xmlhttp.send(null);
    }else if (window.ActiveXObject){// code for IE
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp){
            xmlhttp.onreadystatechange=xmlhttpChange;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        }
    }
}

function postXMLDoc(url,formname){
    if (window.XMLHttpRequest){// code for Mozilla, etc.
      xmlhttp=new XMLHttpRequest();
        if (xmlhttp){
            var fields = new Array();
            if(formname){
                var ajax = formname;
            }
            //loop through form elements and retrieve field NAMEs and Values
            for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
                // join them into a string.
                eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
            }
            elem = 'errors';
            //sendf looks like "username=myusername&password=mypass"
            var sendf = fields.join('&');
            
            
            xmlhttp.open("POST", url, true);
            xmlhttp.onreadystatechange=xmlhttpChange;
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//          xmlhttp.setRequestHeader('Content-Type', 'multipart/form-data');
            xmlhttp.send(sendf);                
        }
    }else if (window.ActiveXObject){// code for IE
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp){
            var fields = new Array();
            if(formname){
                var ajax = formname;
            }
            //loop through form elements and retrieve field NAMEs and Values
            for (var x = 0; x < eval("document."+ajax+".elements.length"); x++){
                // join them into a string.
                eval("fields.push(document."+ajax+".elements[x].name+'='+document."+ajax+".elements[x].value)");
            }
            elem = 'errors';
            //sendf looks like "username=myusername&password=mypass"
            var sendf = fields.join('&');
            
            
            xmlhttp.open("POST", url, true);
            xmlhttp.onreadystatechange=xmlhttpChange;
            xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//          xmlhttp.setRequestHeader('Content-Type', 'multipart/x-www-form-urlencoded');

            
            xmlhttp.send(sendf);                
        }
    }
}



function xmlhttpChange(){
    //alert(xmlhttp.status);
    if (xmlhttp.readyState==4){// if xmlhttp shows "loaded"
        if (xmlhttp.status==200){// if "OK"
            //document.getElementById('comments').innerHTML = xmlhttp.responseText;
            //alert(xmlhttp.responseText);
            //eval(xmlhttp.responseText);
            var temp = new Array();
            temp = xmlhttp.responseText.split('|');
            for(i = 0; i < temp.length;i = i + 2){
                if(temp[i] == 'script'){
                    eval(temp[(i + 1)]);
                }else{
                    document.getElementById(temp[i]).innerHTML= temp[(i + 1)];
                }
            }
        
        }else{
            alert("Problem retrieving data Comment Data")
        }
    }
}


function click_post(form_name){
    postXMLDoc('/inc/ajax_gateway.inc.php',form_name);
}
function click_get(query_str){
    loadXMLDoc('/inc/ajax_gateway.inc.php' + query_str);
}
/* AJAX */










/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(num){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	
	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).className = "on";
				//document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("_"+i).className = "";
				//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			rating(preSet);
			//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me){
	if(!rated){
		//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		preSet = me;
		rated=1;
		sendRate(me);
		rating(me);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
    var the_rating = sel.id.split('_');
    var final_rating = the_rating[1];
    click_get('?rating=' + final_rating + '&article_id=' + gup('article_id'));
    //alert("Your rating was: " + final_rating);
}

function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null ){
    return "";
  }else{
    return results[1];
  }
}

