//handle external links
//Enter "_blank" for new window (each time), "window2" for a set secondary window
var newwindow="_blank"

function hyperlinks(target){
   if (target) where = newwindow;
   else where = "_top";
   for (var i=0; i<=(document.links.length-1); i++){
	 var linkobj=document.links[i].href
	 // custom
	 DocURL = linkobj;
	protocolIndex=DocURL.indexOf("://",4);
	serverIndex=DocURL.indexOf("/",protocolIndex + 3);
	BeginURL=DocURL.indexOf("#",1) + 1;
	urlresult=DocURL.substring(BeginURL,serverIndex);
	displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);
		if((displayresult.indexOf("matrimonyconnection.com") == -1)&&(displayresult.indexOf("localhost") == -1)&&(displayresult.indexOf("nandurip.mysite4now.com") == -1) && (displayresult.indexOf("aussieindolanka.com") == -1)&&(displayresult.indexOf("eknazar.com") == -1))
		{
			if ( linkobj.indexOf("javascript:") ==-1 && linkobj.indexOf("#") ==-1){
   				if (target && where!="_blank") //DynamicDrive.com added routine- open window in set secondary window
      				document.links[i].onclick=function(){
						if (window.window2 && !window2.closed)
						window2.location=this.href
						else
        				window2=window.open(this.href)
						window2.focus()
      					return false
      						}
   				else{
      				if (newwindow=="window2") document.links[i].onclick = "";    
      				document.links[i].target = where;
       				}
   				}
		}else{
			
					document.links[i].onclick=function(){
					if (top.location != location)		top.location.href = this.href ;
  
					}
			
			}
	}
}

function inithyperlinks(){    //DynamicDrive.com added routine
	hyperlinks(true)
}

window.onload=inithyperlinks

var link;
var newwin;


function BackSpaceHandler() {
    if (event.keyCode == 8) {
	
        window.event.returnValue = false;
         // try to cancel the backspace
         var temp = document.forms[0].input1.value;
        document.forms[0].input1.value= temp.substring(0,temp.length-1);
        return false;
    }
}

function clickHandler(url, outsidelinksurl) {
	link = eval(url).href;
	// check the current sitename
	DocURL = document.URL;
	protocolIndex=DocURL.indexOf("://",4);
	serverIndex=DocURL.indexOf("/",protocolIndex + 3);
	BeginURL=DocURL.indexOf("#",1) + 1;
	urlresult=DocURL.substring(BeginURL,serverIndex);
	displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);
	//alert(displayresult);
	
	// check the passed in url
	protocolIndex1=link.indexOf("://",4);
	serverIndex1=link.indexOf("/",protocolIndex1 + 3);
	BeginURL1=link.indexOf("#",1) + 1;
	urlresult1=link.substring(BeginURL1,serverIndex1);
	displayresult1=link.substring(protocolIndex1 + 3 ,serverIndex1);
	//alert(displayresult1);
	
	// compare both the servernames, if they are equal then it is internal link else outside link
	if (displayresult == displayresult1){
		var containspdf = link.indexOf(".pdf");
		//alert(containspdf);
		if(containspdf != -1){
			newwin = window.open(link,"","width=500,height=400,resizable=yes");
			return false;
		}else{
			return true;
		}
	}else {
		if((link.indexOf("mailto:") == -1) && (link.indexOf("alcan.com") == -1)) {
				var redirecturl = outsidelinksurl + "?" + link ;
				//alert(redirecturl);
				newwin = window.open(redirecturl,"","width=750,height=400,Toolbar=yes,scrollbars=yes,location=yes,resizable=yes");
				return false;
		}else{
				return true;
		}
	}
}

function swap(imageobj, imgurl, state){
	
	if(state == 0){
		document.images[imageobj].src =  imgurl + "_over.gif"
	}else{
		document.images[imageobj].src =  imgurl + ".gif"
	}
}	
// generic functions 
function isInteger ()
		{   		
			a = event.keyCode
			return (a >= 48) && (a <= 57)
		}
		function isFloat (obj)
		{   	
			a = event.keyCode
			if(eval(obj).value.indexOf(".") == -1)
				return (((a >= 48) && (a <= 57)) || (a == 46))
			else
				return (a >= 48) && (a <= 57)
		}

// function for select box typing
function autoCompletenew (field, select) {
	var found = false;
	for (var i = 0; i < select.options.length; i++) {
	
	if (select.options[i].text.toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
	found=true; break;
	}		
	}	if (found) { select.selectedIndex = i; }		else { 		}		

return;	}

	function move(fbox,tbox) {
		var no = new Option();
	
		if (fbox.selectedIndex != -1)
		{
			no.value = fbox.options[fbox.selectedIndex].value;
			no.text = fbox.options[fbox.selectedIndex].text;
			tbox.options[tbox.options.length] = no;
			tbox.selectedIndex = tbox.options.length-1
			fbox.options[fbox.selectedIndex] = null;
		}
	}
	// used by claims pages
	function showDetail(topic){
			var displayed = document.getElementById(topic).style.display=='' ? 'yes' : 'no'
			if (displayed=='yes')
				{
				document.getElementById(topic).style.display='none'
				}
			else if (displayed=='no')
				{
				document.getElementById(topic).style.display=''
				}
		}
		function showPlusMinus(topic,imgurl){
				var displayed = document.getElementById("Content_" + topic).style.display=='' ? 'yes' : 'no'
				if (displayed=='yes')
				{
				document.images["Img_" + topic].src =  imgurl + "plus.gif"
				}else if (displayed=='no')
				{
				document.images["Img_" + topic].src =  imgurl + "minus.gif"
				}
		}
		
	function checkLength(obj,len){
	
	if(obj.value.length > len) {
	
		showBubble(obj,'Maximum length allowed in this field is ' + len + '.<br><br>Your Text has been truncated.',0, 100,'true');
		obj.value = obj.value.substring(0,len);
	}
	}	
	var d ;
	function hideLang(obj){
	d = document.getElementById(obj);
	setTimeout('hide()',5000);
	
	}
	function hide(){
	d.style.visibility='hidden';
	}
	
	// handle pictures
	function EditImage(url,_pictureNo,isIE){
		var Page = url + "?picture=" + _pictureNo + "&mode=edit&IE=" + isIE;
		if(isIE){
		var cResult = window.showModalDialog(Page,null,"dialogWidth:15.5em;dialogHeight:10em;status=no;Raised;center:Yes;help:No;");
		if(cResult != null)location.href = location.href;//window.location.reload();
		}else{
		var cResult = window.open(Page,"picture","width=15.5em,height=10em;status=no;resizable=yes;scrollbars=yes;location=no;toolbar=no;directories=no;menubar=no;copyhistory=no;");
		
		}
	}
	function AddImage(url,_pictureNo,isIE){
		var Page = url + "?picture=" + _pictureNo + "&mode=add&IE=" + isIE;
		var cResult = window.showModalDialog(Page,null,"dialogWidth:15.5em;dialogHeight:10em;status=no;Raised;center:Yes;help:No;");
		if(cResult != null)location.href = location.href; 
	}
	function openUrl123(url){
	
		var cResult = window.showModalDialog(url,null,"status=no;Raised;center:Yes;help:No;Resize=Yes");
		//alert(url);
		
	}
	function openInSelf(url){
	
		location.href=url;
		
		
	}
	function openChat(url){
	
		var cResult = window.open(url,"chatwin","status=no,resizable=yes,scrollbars=yes,location=no,toolbar=no,directories=no,menubar=no");
		if(cResult == 'failed' || cResult == null) alert("You have popup blocker turned on, you need to enable popup windows for this site.");
		
	}
	function openUrl(url){
	
		var cResult = window.open(url,"","status=no,resizable=yes,scrollbars=yes,location=no,toolbar=no,directories=no,menubar=no");
		if(cResult == 'failed' || cResult == null) alert("You have popup blocker turned on, you need to enable popup windows for this site.");
		
	}
	function openUrl(url,w,h){
	
		var sFeatures = "status=no,resizable=yes,scrollbars=yes,location=no,toolbar=no,directories=no,menubar=no,width=" + w + ",height=" + h;
		var cResult = window.open(url,"forward",sFeatures);
		if(cResult == 'failed' || cResult == null) alert("You have popup blocker turned on, you need to enable popup windows for this site.");
		
	}
	function search(url,gender,community,agefrom,ageto,photos){
	//alert(document.getElementById('gender').value);
	alert(document.getElementById('community').value);
	alert(document.getElementById('agefrom').value);
	alert(document.getElementById('ageto').value);
	alert(document.getElementById('photos').value);
	return false;
	}
	
//pop up code

var UserClicked=false;
document.onkeydown=spyclick;
document.onmousedown=spyclick;
function spyclick()
{
     UserClicked=true;
     setTimeout("UserClicked=false",2000);
}
function popup()
{
     if(!UserClicked)
     {
          
      //    var win=window.open("/MConnection/logout.aspx?mode=close","","width=0,height=0");
       //   setTimeOut(win.close(),3000);
         
          
     }
}
window.onbeforeunload=popup;

function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) 
{
    re = new RegExp(':' + aspCheckBoxID + '$') ; //generated control name starts with a colon
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') 
			{
	            if (re.test(elm.name)) elm.checked = checkVal;

            }
        
    }
}
 function ClientValidate(source, arguments)
{
    if((arguments.Value == "--select--")||(arguments.Value == "")) arguments.IsValid = false;
    else arguments.IsValid = true;
}

function ValidateLength(source, arguments)
{
	if((arguments.Value.length < 50)|| (arguments.Value.length > 4000))
	{
		
		arguments.IsValid = false;
	}else arguments.IsValid = true
   
}

function validatePassword(source, arguments)
{
	if((arguments.Value.length < 6)&& (arguments.Value.length != 0))
	{
		arguments.IsValid = false;
	}else arguments.IsValid = true
   
}
function CountryChange(obj){
	oName = obj.name;

	control = oName.substring(0,oName.indexOf("ddlCountryResidence"));
	us = control + "ddlUSStates";
	india = control + "ddlIndianStates";
	other = control + "tbOtherState";
	document.forms[0][india].disabled = true;
	document.forms[0][us].disabled = true;
	document.forms[0][other].disabled = true;

	if(obj.value == "United States of America"){
	document.forms[0][us].disabled = false;
	document.forms[0][india].disabled = true;
	document.forms[0][other].disabled = true;
	}else if(obj.value == "India"){
	document.forms[0][us].disabled = true;
	document.forms[0][india].disabled = false;
	document.forms[0][other].disabled = true;
	}else{
	document.forms[0][us].disabled = true;
	document.forms[0][india].disabled = true;
	document.forms[0][other].disabled = false;
}
	 

}

function updateProfileCount(objCountField,objField) {

if (objField.value.length > 4000) document.forms[0][objCountField].value = 0;
else document.forms[0][objCountField].value = 4000 - objField.value.length;

}
function disableEnterKey()
{
	//if (window.event.keyCode == 13) window.event.keyCode = 0;
}


	