function openEdit(closeDiv,openDiv){	
	document.getElementById(closeDiv).style.display="none";
	document.getElementById(openDiv).style.display="block";
	return false;
}
function closeEdit(closeDiv,openDiv){
	document.getElementById(closeDiv).style.display="none";
	document.getElementById(openDiv).style.display="block";
	return false;
}
function clickOrgSignIn(){
	document.getElementById('btnLoginGo1').click();
	return false;
}	
function openCloseLoginBox(flag){
	if(flag==true){
		setPosition(document.getElementById('loginClickDiv'));
		document.getElementById('loginDiv').style.display='block';
		document.getElementById('loginDiv').style.display='inline';
	}
	else{
		document.getElementById('loginDiv').style.display='none';
	}
	
}
function pressLoginButton(evt) {
	var keyCode = evt.keyCode ? evt.keyCode : evt.which ? evt.which
			: evt.charCode;
	if (keyCode == 13) {
		document.getElementById('btnLoginGo1').click();
		return false;
	}
	return true;
}
function opeLogo(url,orgId){
	popupOrg(url+"/uploadorgimage.jsf?orgId="+orgId);
	return false;
} 
function popupOrg(url) 
	{
	 var width  = 750;
	 var height = 600;
	 var left   = (screen.width  - width)/2;
	 var top    = (screen.height - height)/2;
	 var params = 'width='+width+', height='+height;
	 params += ', top='+top+', left='+left;
	 newwin=window.open(url,'upload_image', params);
	 if (window.focus) {newwin.focus()}
	 return false;
}	
function setPostionOfDescription(){
	var img = document.getElementById('orgLogo');	
	var totalWidth = (755-img.width);
	var workText = document.getElementById('form1:OtWorkDesc');
	workText.style.width = totalWidth+"px";
}
function setPosition(obj){
    var topValue= 0;    
    while(obj){	
	topValue= topValue+obj.offsetTop;
	obj= obj.offsetParent;
	document.getElementById('loginDiv').style.top=(topValue-75)+"px";
    }
}
function validateLocationData(emails,phno,locFax,locName,street,city,state,zip){
	var errorString = "";
	
		if(emails.length>0){
			if(emailCheck(emails)==false){
				errorString = "Please enter valid Email address<br/>";
			}
		}
	
	
			
		if(phno.length>0){			
			if( phno.length >15){
				errorString = errorString+"Please enter a valid Phone Number<br/>";
		    }
			else if(checkInternationalPhone(phno)==false){
				errorString = errorString+"Please enter a valid Phone Number<br/>";
			}
		}
	
	
			
		if(locFax.length>0){		
			if( locFax.length >15){
				errorString = errorString+"Please enter a valid Fax Number<br/>";
		    }
			else if(checkInternationalPhone(locFax)==false){
				errorString = errorString+"Please enter a valid Fax Number<br/>";
			}
		}
	
	
		
		locName=locName.trim();    
		if(locName.length<1){		
				errorString = errorString+"Please enter Location Name<br/>";			
		}
	
	
	street=street.trim();
	
	city=city.trim();
	
	state=state.trim();
	
	zip=zip.trim();    
	if(street.length<1 || city.length<1 || state.length<1 || zip.length<1){		
			errorString = errorString+"Please enter Full Address<br/>";			
	}
	return errorString;
	
}
function validateSubLocation(){
	var street= document.getElementById("locStreet").value;
	var emails= document.getElementById("locEmail").value;
	var city= document.getElementById("locCity").value;	
	var state = document.getElementById("locState").value;
	var zip = document.getElementById("locZip").value;
	var phno= document.getElementById("locPh").value;	
	var locFax= document.getElementById("locFax").value;
	var locName= document.getElementById("locName").value;		
	var errorString= validateLocationData(emails,phno,locFax,locName,street,city,state,zip);
	if(errorString!=''){
		document.getElementById("locMessage").style.display="block";
		document.getElementById("locMessage").innerHTML=errorString;
		return false;
	}
	else{
		return true;
	}
}
function emailCheck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){		 
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }
		 return true;					
}
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
function validateAllLocation(index){
	var street= document.getElementById("form1:locationList:"+index+":brStreet").value;
	var emails= document.getElementById("form1:locationList:"+index+":brEmail").value;
	var city= document.getElementById("form1:locationList:"+index+":brCity").value;	
	var state = document.getElementById("form1:locationList:"+index+":brState").value;
	var zip = document.getElementById("form1:locationList:"+index+":brZip").value;
	var phno= document.getElementById("form1:locationList:"+index+":brPh").value;	
	var locFax= document.getElementById("form1:locationList:"+index+":brFax").value;
	var locName;
	if(document.getElementById("form1:locationList:"+index+":brName")!=null){
		locName= document.getElementById("form1:locationList:"+index+":brName").value;
	}
	else{
		locName="Organization";
	}
	var errorString= validateLocationData(emails,phno,locFax,locName,street,city,state,zip);
	if(errorString!=''){
		document.getElementById("form1:locationList:"+index+":alllocMessage").style.display="block";
		document.getElementById("form1:locationList:"+index+":alllocMessage").innerHTML=errorString;
		return false;
	}
	else{
		return true;
	}
}


