

function newWindow(location,w,h,scroll,status,resize) 
{ 
window.open(location, 'contentsWin', "width="+w+",height="+h+",menubar=no,toolbar=no,status=yes,scrollbars="+scroll+",screenX=30,screenY=30,left=30,top=30,status="+status+",resize="+resize) 
}

function replaceAndTrim(string) {
	//Removes Blank Spaces
    var i; 
	var bag1 
	bag1 = " " 
	var returnString1 = "" 
	for (i=0;i<string.length;i++){ 
	var c1 = string.charAt(i); 
	if (bag1.indexOf(c1) == -1) returnString1 += c1;}

	document.forms[0].Company_temp.value = returnString1;
}

function replaceAndTrim2(string,string2) {
	//Removes Apostrophes
	var j; 
	var bag2  
	bag2 = "'" 
	var returnString2 = "" 
	for (j=0;j<string.length;j++){ 
	var c2 = string.charAt(j); 
	if (bag2.indexOf(c2) == -1) returnString2 += c2;} 
	
	//document.forms[0].Username.value = returnString;
	
	//Udpates Username Value with Trimmed String
	var Company_Name = returnString2;
	var id = string2;
	var username = Company_Name.substring(0,5) + id;
	document.forms[0].Username.value = username.toLowerCase();
}

function replaceAndTrim3() {
	
	//Udpates Username Value with Trimmed String
	var Company_Name = document.forms[0].Company_temp.value;
	var id = document.forms[0].CompanyID.value;
	var username = Company_Name.substring(0,5) + id;
	document.forms[0].Username.value = username.toLowerCase();
}

function replaceAndTrim4() {
	//Removes Apostrophes
	var j; 
	var bag2;
	var string;
	string = document.forms[0].Company_temp.value;
	bag2 = "'" 
	var returnString2 = "" 
	for (j=0;j<string.length;j++){ 
	var c2 = string.charAt(j); 
	if (bag2.indexOf(c2) == -1) returnString2 += c2;} 
	
	var k; 
	var bag3
	bag3 = " " 
	var returnString3 = "" 
	for (i=0;i<returnString2.length;i++){ 
	var c3 = returnString2.charAt(i); 
	if (bag3.indexOf(c3) == -1) returnString3 += c3;}
	
	//document.forms[0].Username.value = returnString;
	
	//Udpates Username Value with Trimmed String
	var Company_Name = returnString3;
	var id = document.forms[0].CompanyID.value;
	var username = Company_Name.substring(0,5) + id;
	document.forms[0].Username.value = username.toLowerCase();
}

function formHandler(form)
{
var URL = form.options[form.selectedIndex].value;
window.location.href = URL; 
}

function checkExtension(string) {

	// Getting File Extension off of String
	var extension_temp = string.split(".");
	var extension = extension_temp[1];
	// Setting a list of uploadable file extensions to an array
	var acceptable_extensions = new Array("gif", "jpeg", "jpg", "png", "");
	// Setting the Initial Acceptance value to false
	var accept = "false";
	
		// Starting a Loop through the array
		for (i = 0;i < acceptable_extensions.length;++i) {
		// Checking to see of extension of file is in the Array
		if (extension == acceptable_extensions[i]) {
		// Sets the Acceptance value to true if found
		accept = "true" };
		};
	
	if (accept == "false") {
		alert("That file type is not supported");
		var new_value = "";
		document.ChangeImage.reset();
	}
}

function deleteConfirm(name,id,returnlocation) {
	//Setting Confirm Message
	var confirmstatus = confirm("This will delete all entries associated with '"+name+"'.  Are you sure you want to do this?");

	if (confirmstatus == true) {
	var url = "delete_company.cfm?CompanyID="+id;
	var message = "<p>Deleting Company...</p>";
	}
	
	if (confirmstatus == false) {
	var url = "delete_companies.cfm";
	var message = "<p>Cancelling Delete</p>";
	}
	
	document.write(message);
	window.location.href = returnlocation+url;
}

function deleteBranchConfirm(name,id,returnlocation) {
	//Setting Confirm Message
	var confirmstatus = confirm("This will delete all entries associated with the Branch '"+name+"'.  Are you sure you want to do this?");

	if (confirmstatus == true) {
	var url = "delete_branch_sub.cfm?BranchID="+id;
	var message = "<p>Deleting Company...</p>";
	}
	
	if (confirmstatus == false) {
	var url = "delete_branch.cfm";
	var message = "<p>Cancelling Delete</p>";
	}
	
	document.write(message);
	window.location.href = returnlocation+url;
}

function deleteActivityConfirm(name,id) {
	//Setting Confirm Message
	var confirmstatus = confirm("This will delete the activity '"+name+"'.  Are you sure you want to do this?");

	if (confirmstatus == true) {
	var url = "activities_delete.cfm?ActivityID="+id;
	var message = "<p>Deleting Activity...</p>";
	}
	
	if (confirmstatus == false) {
	var url = "activities_delete.cfm";
	var message = "<p>Cancelling Delete</p>";
	}
	
	document.write(message);
	window.location.href = "http://www.pipedir.com/admin/directory/"+url;
}

function deleteMemberConfirm(memberid,companyid,membername,returnlocation) {
	//Setting Confirm Message
	var confirmstatus = confirm("This will delete all entries associated with '"+membername+"'.  Are you sure you want to do this?");

	if (confirmstatus == true) {
	var url = "delete_member_sub.cfm?MemberID="+memberid;
	var message = "<p>Deleting ...</p>";
	}
	
	if (confirmstatus == false) {
	var url = "delete_member.cfm?CompanyID="+companyid;
	var message = "<p>Cancelling ...</p>";
	}
	
	document.write(message);
	window.location.href = returnlocation+url;
}


function rollover(name,over)
{
	if(document.images) 
	{ 
	if (over) {
			document.images[name].src = "images/buttons/" + name + ".gif";
		} else {
			document.images[name].src =  "images/buttons/" + name + "_f2.gif"; }
	}
}

function AntiSpam1(who,where,subject) 
{
	window.location="mailto:"+who+"@"+where+"?subject="+subject;
}


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 Email Address");
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid Email Address");
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   alert("Invalid Email Address");
	    return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid Email Address");
	    return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid Email Address");
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid Email Address");
	    return false
	 }
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid Email Address");
	    return false
	 }
		 return true					
}

function ImageSize(image_number,FileExtension,Name,location) 
{
var logo_image = new Image();

	if (image_number == '1'){
	logo_image.src = 'https://' + location+ 'logo-01.' + FileExtension;
	}
	else if (image_number == '2') {
	logo_image.src = 'https://' + location+ 'logo-02.' + FileExtension;
	}
	
original_height = logo_image.height;
original_width = logo_image.width;

var height_ratio = original_height / 100;
var width_ratio = original_width / 300;

	if (original_height > 100 || original_width > 300) {
	
		if (height_ratio > width_ratio) {
		var height_difference = original_height - 100;
		var height_percentage = height_difference / original_height;
		var width_reduced = original_width * (1 - height_percentage);
		var new_height = '100';
		var new_width = width_reduced;
		}
		else 
		{
		var width_difference = original_width - 300;
		var width_percentage = width_difference / original_width;
		var height_reduced = original_height * (1 - width_percentage);
		var new_height = height_reduced;
		var new_width = '300';
		}
		
	}
	else 
	{
	var new_height = original_height;
	var new_width = original_width;
	}
	
	document.write("<img src='" + logo_image.src + "' width='" + new_width + "' height='" + new_height + "' alt='" + Name + "'>");
}

function submit_Page(location) {
	document.location.href = location;
}


