// JavaScript Document
var SURL = 'http://www.moody.pk/';
var IMGURL = SURL+'images/';
// email validator
function validateAddress(incoming) {
	var emailstring = incoming;
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
		// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAmp.indexOf(".");
		// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + ampIndex + 1;
		// afterAmp will be portion of string from ampersand to dot
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
		// afterDot will be portion of string from dot to end of string
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));
		//old regex did not allow subdomains and dots in names
		//var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
		// index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
		  return true;
	} else {
			//alert("Please check your email address!");
			return false;
	}
}

function HasInvalids(strValue){
	var objRegExp  = /[^a-zA-Z0-9_]/;
	var out = objRegExp.test(strValue);
  return out;
}

function show_err(){
	//err_str	
}

function openWin(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function strlen(str, num){
	if(str.length < num){
		return false;
	}else{
		return true;	
	}
	
}
function chkNum(value){
	
	if(isNaN(value) == false){
		return true;
	}else{
		return false;	
	}
}
function confirmLink(theLink, confirmMsg){
		//confirmMsg = confirmMsg;
		var is_confirmed = confirm(confirmMsg);
		/*if (is_confirmed) {
			theLink.href += '&confirmed=1';
		}*/
	return is_confirmed;
} // confirm links


// err toggle
function toggle_err(divID, todo){
	divStyle = (document.getElementById) ? document.getElementById(divID).style : ( document.all) ? document.all[divID].style : document.layers[divID];
	if(todo == 'block'){
		divStyle.display = 'block'; 
	}else{
		divStyle.display = 'none';
		
	}
	//digdiv(divID);
}

function showProfile(prof_type){
	var s = $('social');
	var pl = $('personal');
	if(prof_type == 'social'){
			s.show();
			pl.hide();
			return true;
	}
	if(prof_type == 'personal'){
		s.hide();
		pl.show();
		return true;
	}
	
	return false;
}

// xmlhttprequest
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function validSrch(){
	if(document.srch.q.value == ""){
		alert("please enter cell name");
		document.srch.q.focus();
		return false;
	}
	return true;
}

function zoomimg(obj) {
	var zoom=parseInt(obj.style.zoom,10) || 100;
	zoom += event.wheelDelta / 24;
	imgW = obj.clientWidth*zoom/100;
	if (zoom>15 && imgW<1200) obj.style.zoom = zoom + "%";
	return false;
}

var origin_width=0;
var max_width=800;
function adjustImage(init)
{
    if(document.getElementById("img_obj").width>max_width)
    {
        origin_width = document.getElementById("img_obj").width;
        document.getElementById("img_obj").width = max_width;
        document.getElementById("resized").style.display='';
    }
    else
    if(document.getElementById("img_obj").width<=max_width)
    {
        if(init==1) origin_width = document.getElementById("img_obj").width;
        document.getElementById("img_obj").width = origin_width;
        document.getElementById("resized").style.display='none';
    }
}
function autoResize(id){
    var newheight;
    if(document.getElementById){
        newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
    }
    document.getElementById(id).height= (newheight + 16) + "px";
}

function gotoPage(page){
	if(page == ''){
			window.location = SURL+'index';
			return false;
	}
	window.location = page;
}

function countChecks(thisbox){
		var total_checked = 0;
		for(i = 1; i <= total_pic; i++){
				var box = $('pic'+i);
				if(box.checked == true){
					total_checked++;
				}
		}
		
		if(total_checked > max_select){
				thisbox.checked = false;
				total_checked--;
				alert("You have already selected maximum allowed pictures for this contest.");
				
		}
		
		$('csel').innerHTML = total_checked;
}
