var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var imageWin = "";

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function jsDataManagement(thisData,thisType,thisName){
	if (thisData != undefined){
		var tempArray = thisData.split(",")
			for(i=0;i<tempArray.length;i++){
				if (thisType == "Select"){
					document.writeln ('<option value="' + tempArray[i] + '">'+tempArray[i]+'</option>')
				}else if(thisType == "Radio"){
					document.writeln ('<input type=radio name="'+thisName+'" id="'+thisName+'" value="'+tempArray[i]+'"> ' + tempArray[i]) 
				}
			}
	}

}

function ValidateFormOnClose(PassedForm){
	// checks to see if current form is of type Add
	// if any images exist, user must delete images before closing
	var caught = false;

		for(i=0;i<PassedForm.elements.length;i++){
			var thisElement = PassedForm.elements[i]
			if (thisElement.id.indexOf('Image') > -1){
				// check value if not <> then stop user
				if(((thisElement.value != "") && (PassedForm.id == "fromAdd")) || ((thisElement.value == "") && (PassedForm.id == "fromUpdate"))) {
					if (PassedForm.id == "fromAdd"){
						alert('Please delete the image before closing');
					}else{
						alert('Please upload an image and then click update');
					}
				caught = true;
				return false;
				}
			}else if(thisElement.id.indexOf('Video') > -1){
				// check value if not <> then stop user
				if(((thisElement.value != "") && (PassedForm.id == "fromAdd")) || ((thisElement.value == "") && (PassedForm.id == "fromUpdate"))) {
					if (PassedForm.id == "fromAdd"){
						alert('Please delete the file before closing');
					}else{
						alert('Please upload a file and then click update');
					}
					caught = true;
					return false;
				}
			}
		}

	// if still here return true
	if (caught == false){
		return true;	
	}

}


function ValidateTextbox(thisField,thisType){

if (thisField.value == "" || thisField == null){
	return true;
}else{

	if (thisType == "Date"){
		if (isDate(thisField.value)==false){
			thisField.value = "";
			thisField.focus();
			return false;
		}
		return true;
	} else if (thisType == "Integer"){
		if (isInteger(thisField.value)==false){
			alert("Please enter numbers only");
			thisField.value = ""
			thisField.focus();
			return false
		}
	} else if (thisType == "Currency"){
		 thisField.value = isCurrency(thisField.value);
	} else if (thisType == "Zip Code"){
		var temp = isZipCode(thisField.value);
		if (temp != thisField.value){
			thisField.focus();
		}
	} else if (thisType == "Social Security Number"){
		var temp = isSSN(thisField.value);
		if (temp != thisField.value){
			thisField.focus();
		}
	} else if (thisType == "Phone"){
		var temp = isPhone(thisField.value);
		if (temp != thisField.value){
			thisField.value = temp
			thisField.focus();
		}
	} else if (thisType == "Email"){
		var temp = isEmail(thisField.value);
		if (temp == false){
			thisField.focus();
		}
	} else if (thisType == "Website"){
		var temp = isWebsite(thisField.value);
		if (temp != thisField.value){
			thisField.focus();
		}			
	} else {
		alert("Currently " + thisType + " is not supported.")
		return true
	}
 }
}


function isWebsite(thisVal){
	if (thisVal.substring(0,7) != "http://"){
		alert("Prefix the website with http://")
		return "";
	}else{
		return thisVal;
	}
}


function isEmail(thisVal){
	// number of characters before @
		var at="@"
		var dot="."
		var str = thisVal
		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 HandlePassword(thisField){
	if (thisField.value == ""){
		return;
	}else if (thisField.value.length < 6){
		alert("Password must be greater then 6 characters")
		thisField.value = ""
		thisField.focus();
	}else if (thisField.value.length > 12){
		alert("Password cannot be greater then 12 characters")
		thisField.value = ""
		thisField.focus();
	}else if (thisField.value != "**********"){
		var x = window.showModalDialog("code/PopUp/checkPassword.asp","","dialogHeight:100px;dialogWidth:300px;center:yes;resizable:no;status:no;");
		if (x != thisField.value){
			alert("Passwords do not match")
			thisField.value = ""
			thisField.focus();
		}
	}
}

function isPhone(thisVal){
	var temp = "";
	var thisTemp = "";
	thisTemp = thisVal.replace(/\(/g,'')
	thisTemp = thisTemp.replace(/\)/g,'')
	thisTemp = thisTemp.replace(/\s/g,'')
	thisTemp = thisTemp.replace(/\-/g,'')
	for(i=0;i<thisTemp.length;i++){
	
		var zchar = thisTemp.charAt(i)
		var charInt = thisTemp.charCodeAt(i)
		if (charInt < 47 || charInt > 58){
			alert("Please enter only numbers or '(' '-'")
			return "";
			break;	
		}
	
		
		if (temp.length == 0){
			temp = "(" + zchar
		}else if (temp.length == 4){
			temp = temp + ') ' + zchar
		}else if (temp.length == 9){
			temp = temp + '-' + zchar
		}else if (temp.length > 13){
		alert("Phone # cannot be larger than (000)-000-0000")
		return "";
		}
		else{
			temp = temp + zchar
		}
		
		
	}

	return temp;

}

function isSSN(thisVal){
	if (thisVal.length == 11 && thisVal.indexOf('-') == 3){
		return thisVal;
	}else if (thisVal.length >= 11){
		alert("Social Security # must be formatted 000-00-0000")
		return "";
	}else if (thisVal.length < 9){
		alert("Social Security # must be formatted 000-00-0000")
		return "";
	} else {
			
		var temp = "";
		for(i=0;i<thisVal.length;i++){
			var zchar = thisVal.charCodeAt(i)
				if ((zchar < 47 || zchar > 58) && zchar != 45){
					alert("Social Security # can only contain numbers and '-'")
					thisVal = ""
					return thisVal;
					break;
					} else {
						if (temp.length == 3){
							temp = temp + "-" + thisVal.charAt(i)
						}else if (temp.length == 6){
							temp = temp + "-" + thisVal.charAt(i)
						}else{
							temp = temp + thisVal.charAt(i)
						}
				}
					
			
		}
	if (temp != ""){
				return temp;
			}
	
	} 
	
}


 function VerifyPassword(Password2,Password){
            if (Password.value == Password2.value){
                return true;
            }else{
                alert("Passwords do not match");
				Password2.value = ""
				Password.value = ""
                Password.focus();
               return false;
            }
    }

function isZipCode(thisVal){

	for(i=0;i<thisVal.length;i++){
		var zchar = thisVal.charCodeAt(i)
			if ((zchar < 47 || zchar > 58) && zchar != 45){
				alert("Zip Code can only contain numbers and '-'")
				thisVal = "00000"
				return thisVal;
				break;
			}
	} 

	if(thisVal.length == 5){
		return thisVal;
	} else if (thisVal.length == 9 && thisVal.indexOf("-") != 4){
		return thisVal.substr(0,5) + "-" + thisVal.substr(6,9); 
	} else{
	
		if (thisVal.length < 5){
			alert("Zip Codes must be at least five characters in length")
			return "00000";
		} else if (thisVal.length < 10){
			var temp = thisVal.substr(0,5)
			temp = temp + "-0000"
			return temp;
		} else if (thisVal.length > 10){
			var temp = thisVal.substr(0,5) + "-" + thisVal.substr(6,9)
			return temp;
		} else {
			return thisVal;
		}

	}		
}

function isCurrency(thisVal){
	var temp = thisVal.replace(/\$/g,'')
	for(i=0;i<temp.length;i++){
		var zchar = temp.charCodeAt(i)
		if ((zchar < 47 || zchar > 58) && zchar != 46){
			alert("Please enter only numbers and one decimal point")
			return "";
		} 
	}
	
	return temp;
}


function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


function ShowForm(thisAction,thisOID,thisIDname,thisIDvalue,OtherArgs,ShowPrefix){
	var oArgs = OtherArgs
	var isMac = navigator.userAgent.indexOf('Mac') != -1 
	
	if (isMac){
		if (oArgs){
			if(oArgs.substring(1,1) != "&"){
				oArgs = '&'+oArgs
			}
		}else{
			oArgs = ''
		}	
	}else{
		if ((oArgs != undefined) && (oArgs != '')){
			if(oArgs.substring(1,1) != "&"){
			oArgs = '&'+oArgs
			}
		}else{
			oArgs = ''
		}
	}
	
	
	if (ShowPrefix){
		var myShowForm = window.open('Show'+ShowPrefix+'Form.asp?a='+thisAction+'&b='+thisOID+'&c='+thisIDname+'&d='+thisIDvalue+oArgs,'ShowForm','toolbars=no,scrollbars=yes,status=yes,location=no,width=600,height=575,resizable=yes,left=10,top=10');
		myShowForm.focus();
		}else{
		var myShowForm = window.open('ShowForm.asp?a='+thisAction+'&b='+thisOID+'&c='+thisIDname+'&d='+thisIDvalue+oArgs,'ShowForm','toolbars=no,scrollbars=yes,status=yes,location=no,width=600,height=575,resizable=yes,left=10,top=10');
		myShowForm.focus();
	}
}



function ConfirmDelete(alertName,thisOID,thisIDname,thisIDvalue,theseArgs){
	if(confirm("Are you sure you want to delete " + alertName + "?") == true){
		// process delete
		var oArgs = ""
		var isMac = navigator.userAgent.indexOf('Mac') != -1 
		
		if (isMac){
			if(oArgs){
				if (oArgs.substring(0,1) != "&"){
					oArgs = "&" + theseArgs
					}else{
					oArgs = theseArgs
				}
			}else{
				oArgs = ""
			}	
		}else if (theseArgs == undefined){
			oArgs = ""
		}else{
			if (oArgs.substring(0,1) != "&"){
				oArgs = "&" + theseArgs
				}else{
				oArgs = theseArgs
			}
		}

		var DeleteWin = window.open('DeleteForm.asp?a='+thisOID+'&b='+thisIDname+'&c='+thisIDvalue+oArgs,'DeleteWin','toolbars=no,width=350,height=250,resizable=yes,status=yes,location=no');
		DeleteWin.focus()
	}
}


function ChangeObject (thisOID,thisIDname,thisIDvalue,retVal,OtherArgs){
	var temp = 'adminIndex.asp?OID='+thisOID
	if (thisIDname != undefined && thisIDname != ''){
		temp = temp + '&thisIDname='+thisIDname+'&thisIDvalue='+thisIDvalue
		}
	if (retVal != undefined){
		temp = temp + '&retVal='+retVal
	}
	if (OtherArgs != undefined){
		temp = temp + '&'+OtherArgs
	}
	window.location.href=temp
}



function DisplayPopUp(thisFileName,theseArgs,confirmAction){
	if (confirmAction){
		if (confirm(confirmAction) == false){
			return false;
		}
	}
			var Args = '?pFn='+thisFileName+'&'+theseArgs
			Args = Args.replace(/&&/g,'&')
			var myPopUp = window.open('/admin/PopUpController.asp'+Args,thisFileName,'toolbar=no,scrollbars=yes,status=yes,location=no,width=300,height=250,resizable=yes');
			myPopUp.focus();
		
}



function MoveRow(thisAction,thisRowID){
	var TotalRows = document.getElementById('TotalRows').value
	var FieldVal = document.getElementById('Field'+thisRowID).value
	if (thisAction == "Up"){
		if (thisRowID == 0 || FieldVal == ""){
			return
		} else {
			var RowDown = parseInt(thisRowID - 1)
		}
	}else if (thisAction == "Down"){
		if (thisRowID == TotalRows || FieldVal == ""){
			return
		} else {
			var RowDown = parseInt(thisRowID + 1)
		}	
	}
		FieldUp = document.getElementById('Field'+thisRowID).value
		TableUp= document.getElementById('Table'+thisRowID).value
		OrderByUp= document.getElementById('OrderBy'+thisRowID).value
		WhereClauseUp= document.getElementById('WhereClause'+thisRowID).value
		ColumnNameUp = document.getElementById('ColumnName'+thisRowID).value
		
		document.getElementById('Field'+thisRowID).value = document.getElementById('Field'+RowDown).value
		document.getElementById('Table'+thisRowID).value = document.getElementById('Table'+RowDown).value
		document.getElementById('OrderBy'+thisRowID).value = document.getElementById('OrderBy'+RowDown).value
		document.getElementById('WhereClause'+thisRowID).value = document.getElementById('WhereClause'+RowDown).value
		document.getElementById('ColumnName'+thisRowID).value = document.getElementById('ColumnName'+RowDown).value

		document.getElementById('Field'+RowDown).value = FieldUp
		document.getElementById('Table'+RowDown).value = TableUp
		document.getElementById('OrderBy'+RowDown).value = OrderByUp
		document.getElementById('WhereClause'+RowDown).value = WhereClauseUp
		document.getElementById('ColumnName'+RowDown).value = ColumnNameUp

}



function NoSpaces(thisField){
var retVal = ""
var x = thisField.value
	for(i=0;i<x.length;i++){
		if(x.charCodeAt(i) != 32){
			retVal = retVal + x.charAt(i)
		}
	}
	thisField.value = retVal
}


function ProcessMCheckbox(thisVal, ColumnName,thisData){
	if (document.getElementById(ColumnName)){
		var thisField = document.getElementById(ColumnName)
		if (thisVal == true){			// add 
			thisField.value = thisField.value + ',' + thisData				
		}else if (thisVal == false){			// remove
			thisField.value = thisField.value.replace(','+thisData,'')
		}
	}else{
		alert("Error incorrect setup of Multiple Checkbox field")
	}

}

function ValidateForm(PassedForm){
var browserType = navigator.appName
var required = 0;
var errorMessage = "";
var caught = false;


if(document.getElementById('isWYSIWYG')){
	if (document.getElementById('isWYSIWYG').value=='true'){
		if (UpdateWYSIWYGEditor() == false){
			caught = false;
			return false;
		}
	}
}


  for(i=0;i<PassedForm.elements.length;i++){
  
  	if (PassedForm.elements[i].accessKey){
		required = PassedForm[i].accessKey.substring(0,1)
		}else{
		required = 0
		}		
		
   if (required == 1){
			if (document.getElementById('Cell_'+PassedForm[i].id)){
				errorMessage = document.getElementById('Cell_'+PassedForm[i].name).innerHTML
				errorMessage = errorMessage.replace('&nbsp;','');
				}else{
				errorMessage = PassedForm[i].name
				}
			
		
		 if(PassedForm[i].value == ""){
			alert(errorMessage + " is a required field.")
			if (PassedForm[i].type != "hidden"){
				PassedForm[i].focus()
			}
			var caught = true;
		 	return false;
			}
   		}
  }
  	if (caught==false){
  		return true;
	 	}else{
		return false;
		}
}



function CheckAll(thisFieldPrefix,TotalRows){
	if (TotalRows){
			for(i=0;i<TotalRows;i++){
				document.getElementById(thisFieldPrefix+i).checked = true
			}
	}else{
		alert("Error -> in code, seek administrator!!!")
	}
}

function PreviewProject(){
	if (document.getElementById('CurrentClient')){
		var currClient = document.getElementById('CurrentClient').innerHTML

		currClient = currClient.substring(9,currClient.length)
		var clientName = currClient.substring(0,currClient.indexOf("#"))
		var clientID = currClient.substring(currClient.indexOf("#")+1,currClient.indexOf("&gt;")-1)
		var clientProject = currClient.substring(currClient.indexOf("&gt;")+5,currClient.length)
		var preWin = window.open('http://192.168.0.52:'+clientID+'/'+clientProject+'/index.asp','preWin','width=600,height=600,status=yes,resizable=yes,scrollbars=yes,location=yes,toolbar=yes');
		preWin.focus();	
		}else{
		alert('You must first select a Client and then a Project to Preview');
		}
}

function MoveFile(Destination,thisName,thisPath,thisSize,thisType,thisDateCreate){
	if ((Destination) && (thisName)){
			Destination.src = thisName
	}
	
	if ((document.getElementById('thisName')) && (thisName != undefined)){
		document.getElementById('thisName').innerHTML = thisName
	}
	
	if ((document.getElementById('thisPath')) && (thisPath != undefined)){
		document.getElementById('thisPath').innerHTML = thisPath
	}
	
	if ((document.getElementById('thisSize')) && (thisSize != undefined)){
		document.getElementById('thisSize').innerHTML = thisSize
	}
	
	if ((document.getElementById('thisType')) && (thisType != undefined)){
		document.getElementById('thisType').innerHTML = thisType
	}
	
	if ((document.getElementById('thisDateCreated')) && (thisDateCreated != undefined)){
		document.getElementById('thisDateCreated').innerHTML = thisDateCreate
	}
}

function HideAndSeekRow(thisElement,thisSeek,thisTotal){
	// if thisTotal is empty find total by TotalRows
	if (thisTotal){
		var thisCount = parseInt(thisTotal) + 1
	}else{
		if (document.getElementById('TotalRows')){
			var thisCount = document.getElementById('TotalRows').value
		}else{
			alert('No Count was passed and Total Rows could not be found')
			return;
		}
	}
		// hide

		for(i=0;i<thisCount;i++){
			if (document.getElementById(thisElement+i)){
				var thisItem = document.getElementById(thisElement+i).innerHTML
				var thisRow = document.getElementById('Row'+i)
					if (thisSeek != -1){
						if (thisItem.indexOf("&nbsp;") > -1){
							thisItem = thisItem.replace(/\&nbsp\;/g,"")
						}

						if (thisItem == thisSeek){
							thisRow.style.display = 'block'
						}else{
							thisRow.style.display = 'none'
						}
					}else{
						thisRow.style.display = 'block';
					}
				}else{
				// do nothing 
				window.status = "error - unable to find " + thisElement+i
			}
		}

}

function MoveValueFromChildToParent(thisParentElement,thisValue){
	if (thisValue){
		if (window.opener.document.getElementById(thisParentElement)){
			var thisParent = window.opener.document.getElementById(thisParentElement)
			thisParent.value = thisValue
		}else{
			return false;
		}

	}else{
		return false;
	}

}


function HideAndSeek(thisElement,thisSeek,thisTotal){

	// if thisTotal is empty find total by TotalRows
	if (thisTotal){
		var thisCount = parseInt(thisTotal) + 1
	}else{
		if (document.getElementById('TotalRows')){
			var thisCount = document.getElementById('TotalRows').value
		}else{
			alert('No Count was passed and Total Rows could not be found')
			return;
		}
	}
		

	// hide
		for(i=0;i<thisCount;i++){
			if (document.getElementById(thisElement+i)){
					var thisItem = document.getElementById(thisElement+i)
					if (thisSeek != -1){
						if (i == thisSeek){
							thisItem.style.display = 'block'
						}else{
							thisItem.style.display = 'none'
						}
					}else{
						thisItem.style.display = 'none';
					}
				}else{
				// do nothing 
				window.status = "error - unable to find " + thisElement+i
			}
		}

}

function PreviewImage(thisPath){
	if (!thisPath){
		return false;
	}else if(thisPath == '/pub/images/noimage.gif'){
		return false;
	}
	
	if (imageWin){
		imageWin.close()
	}
	// opens a window and writes to the document
	imageWin = window.open('','imageWin','toolbars=no,resizable=yes,scrollbars=yes,status=no,location=no')
	imageWin.document.writeln('<body bgcolor=#000000><p></p><input type=button name=cmdAction style="color:#FFFFFF;font-family:arial;font-size:12px;color:#00000;border:1px solid #CCCCC;" value="Close" onClick="window.close();""><BR>')
	imageWin.document.writeln('<img src="'+thisPath+'" id=thisImage name=thisImage>')
	imageWin.document.writeln('<p></p><input type=button name=cmdAction style="color:#FFFFFF;font-family:arial;font-size:12px;color:#00000;border:1px solid #CCCCC;" value="Close" onClick="window.close();"">')
	imageWin.document.writeln(unescape('%3C') + 'script>\n')
	imageWin.document.writeln('var thisH = thisImage.height\n')
	imageWin.document.writeln('var thisW = thisImage.width\n')
	imageWin.document.writeln('if(thisW > 600){\n')
	imageWin.document.writeln('thisImage.height = parseInt((thisH * 600)/thisW)\n')
	imageWin.document.writeln('thisImage.width = 600;\n')
	imageWin.document.writeln('}\n')
	imageWin.document.writeln('window.resizeTo(thisImage.width+100,thisImage.height+100)\n'+unescape('%3C')+'/script>')
	imageWin.focus();

}


function UpdateHiddenField(thisElement,thisBoolean,thisValue,seperator){

	if (document.getElementById(thisElement)){
		if (seperator == undefined){
			seperator = ";"
		}


		// get string
		var thisStr = document.getElementById(thisElement)
	
		if (thisBoolean == true){
			// add this value to list
			thisStr.value = thisStr.value + seperator + thisValue			
		}else{
			// remove this value from list
			var findStr = seperator+thisValue
			if (thisStr.value.indexOf(findStr) > -1){
				thisStr.value = thisStr.value.replace(findStr,"")
				}
		}
	}else{
		return false;
	}
}

function ProcessHyperLink(){
	var thisLinkType = document.getElementById('LinkType').value
	var retVal = "";
	
	if (thisLinkType == 'Internal'){
		var thisInternalType = document.getElementById('InternalLinkType').value
		
		if (thisInternalType == 'Page'){
			var thisValue = document.getElementById(InternalPage).value
			var thisText = document.getElementById(InternalPageText).value
			var thisTarget = document.getElementById(InternalPageTarget).value
			
		}else if (thisInternalType == 'Image'){
			var thisText = document.getElementById(InternalImageText).value
			var thisTarget = document.getElementById(InternalImageTarget).value
			var thisValue = document.getElementById(InternalImagePath).value
			
		}else if (thisInternalType == 'File'){
			var thisText = document.getElementById(InternalFileText).value
			var thisTarget = document.getElementById(InternalFileTarget).value
			var thisValue = document.getElementById(InternalFilePath).value
			
		}else{
			alert('Please select an Internal Link Type')
			return false;
		}

		
		
	}else if (thisLinkType == 'External'){
		ExternalUrl
		ExternalText
		ExternalTarget


	}else{

		alert('Please select a Link Type');
		return false;
	}

}

function ValidateByDataType(thisField,thisDataType){
	// process the field value by the data type
	

}


function PreviewFile(thisFileName){
	var thisFile = window.open(thisFileName,'thisFile','resizable=yes,width=600,height=600,toolbars=yes,scrollbars=yes,status=yes');
	thisFile.focus();
}

               
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

function DisplayGetJavaScript(thisField){
	var JavaWin = window.open('GetJSFunctionCall.asp?retVal='+thisField,'JavaWin','height=100,width=400,resizable=yes,status=yes,location=no,toolbars=no,scrollbars=yes');
	JavaWin.focus();
}	

function ShowThisHideThat(showMe,hideMe){
	
	if (document.getElementById(showMe)){
		//document.getElementById(showMe).style.display='block';
		//document.getElementById(showMe).style.visibility='visible';
		document.getElementById(showMe).style.display='inline';
		document.getElementById(showMe).style.visibility='visible';
	}
	
	if (document.getElementById(hideMe)){
		document.getElementById(hideMe).style.display='none';
		//document.getElementById(hideMe).style.display='hidden';
	}
}

function ShowPortfolio(thisUsername){
	if (thisUsername != ""){
		thisUsername = "p=" + thisUsername
	}else{
//		thisUsername = "p=" + window.status.substring(14,window.status.length)
	}

	var myPortfolio = window.open('/admin/ShowPortfolio.asp?'+thisUsername,'myPortfolioView','width=825,height=600,scrollbars=yes,status=yes,location=yes,address=no,toolbar=yes,resizable=yes');
	myPortfolio.focus();

}
function ValidateTextarea(thisField,thisMaxLength){
	if (thisField.value.length > thisMaxLength){
		alert('Max Length for this text area is ' + thisMaxLength + ', your data has been shortened.');
		thisField.value = thisField.value.substring(0,parseInt(thisMaxLength-1))
		thisField.focus();
	}
}



function ShowHiddenItem(thisField){
	if ((thisField != undefined) && (thisField != '')){
		if(document.getElementById(thisField)){
			if (document.getElementById(thisField).className == "hiddenInput"){
				document.getElementById(thisField).className = "pageContent";
			}else if(document.getElementById(thisField).className == "pageContent"){
				document.getElementById(thisField).className= "hiddenInput";
			}
		}
	}
}

function MoveText(thisContainer,thisAction,speed,thisToggle,timeoutSpeed,maxTop,maxBottom){
	var myContainer = document.getElementById(thisContainer)
	var myTop = myContainer.style.top.replace('px','')
	if(myTop == ""){
		myTop = 0
	}else{
		myTop = parseFloat(myTop)
	}

	if(thisAction == "Up"){
		if(myTop <= maxBottom){
			return false;
		}else{
			myContainer.style.top = parseFloat(myTop - speed)
		}
	}else if(thisAction == "Down"){
		if(myTop >= maxTop){
			return false;
		}else{	
			myContainer.style.top = parseFloat(myTop + speed) 
		}
	}
	
	if(document.getElementById(thisToggle).value == '1'){
		setTimeout("MoveText('"+thisContainer+"','"+thisAction+"',"+speed+",'"+thisToggle+"',"+timeoutSpeed+","+maxTop+","+maxBottom+")",timeoutSpeed)
	}

}


function MoveProducts(thisContainer,thisSpeed,pixelOffset,endLocation){
	// moves the products in to the end location , right or left
	var myContainer = document.getElementById(thisContainer)
	var myCurrLocation = eval('myContainer.style.'+endLocation)
	myCurrLocation = myCurrLocation.replace('px','');
	
	
	
		if(myCurrLocation < 0){
			myContainer['style'][endLocation] = parseFloat(myCurrLocation + pixelOffset)	
		}else if(myCurrLocation > 0){
			myContainer['style'][endLocation] = parseFloat(myCurrLocation - pixelOffset)	
		}else{
			return false;
		}
	
		setTimeout("MoveProducts('"+thisContainer+"',"+thisSpeed+","+pixelOffset+",'"+endLocation+"')",thisSpeed)
}


function WhichProductToShow(currProperty,currValue,MaxItems,CurrentItemObj,ContainerPrefix){
	var obj = document.getElementById(CurrentItemObj)
	
	
	
	// set the current property and currvalue for the item in focus
	var ContainerObj = document.getElementById(ContainerPrefix+obj.value)
	// determine if the item hit the ending point
	ContainerObj['style'][currProperty] = currValue


	if(obj.value >= MaxItems){
		obj.value = 1
		document.getElementById('MoreProductsBack').style.visibility='hidden';
		document.getElementById('MoreProductsNext').style.visibility='visible';
	}else{
		obj.value = parseFloat(obj.value) + 1
		document.getElementById('MoreProductsBack').style.visibility='visible';
		if(obj.value >= MaxItems){
			document.getElementById('MoreProductsNext').style.visibility='hidden';
		}
	}
	return false;
}


function ShowContactForm(){
var optionValues = "";
var optionArray = Array('','Builder','Architect','Consumer','Spa Consultant','Interior Designer');
for(j=0;j<optionArray.length;j++){
	optionValues+='<option value="'+optionArray[j]+'">'+optionArray[j]+'</option>';
}


var ret = '<form action="/index.asp?OID=4&PageType=FrontPage" onSubmit="return ValidateForm(this);" method="post"><table width="95%" cellspacing="0" cellpadding="1" bordercolor="" border=0 align=center><tr><td style="padding-top:5px;" colspan=2 class="MoreText" align=center>(*) Denotes required field</td></tr>'
ret += '<tr> <td width="40%"></td><td width="60%" height="15" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #990000"></td></tr><tr><td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Select One *</td><td><select name="Consumer Type" id="Consumer Type" accessKey="1">'+optionValues+'</select></td></tr><tr > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Name *</td><td ><input type="textbox" size="25" maxlength=50 name="Name"  accessKey=1  ></td></tr>'
ret += '<tr> <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Address</td><td ><input name="Address" type="text" id="Address"  accessKey=0 size="25" maxlength=50  ></td></tr><tr  >'
ret += '<td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">City</td><td ><input name="City" type="text" id="City"  accessKey=0 size="25" maxlength=50  >';
ret += '</td></tr><tr  > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">State *</td><td ><input name="State" type="text" id="State"  accessKey=1 size="25" maxlength=50  ></td></tr><tr  ><td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Postal Code </td><td ><input name="PostalCode" type="text" id="State"  accessKey=0 size="15" maxlength=25  ></td></tr><tr  > ';
ret += '<td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Country *</td><td ><input name="Country" type="text" id="Country"  accessKey=0 size="25" maxlength=50  ></td></tr><tr  > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Telephone *</td><td ><input type="textbox" size="25" maxlength=25 name="Telephone"  accessKey=1  ></td></tr><tr > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Email *</td><td ><input type="textbox" size="25" maxlength=50 name="Email"  accessKey=1  ></td></tr>';
ret += '<tr><td  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Website</td><td><input type=text name="Website" id="Website" accessKey=0 size="25" maxlength="80"></td></tr>'
ret += '<tr><td  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">How did you hear about us?</td><td><input type=text name="How did you hear about us" id="How did you hear about us" accessKey=1 size="25" maxlength="25"></td></tr>'
ret += '<tr > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Comments *</td><td valign="top"><textarea name="Comments"  accessKey=1  rows=4 cols=19></textarea></td></tr>'
ret += '<tr> <td></td><td><input type=submit name=cmdAction value=Send class="FormButton"></td></tr></table>';
ret += '<input type=hidden name=EmailID value="2A11356"></form>';

//var ret = '<form action="/index.asp?OID=4&PageType=FrontPage" onSubmit="return ValidateForm(this);" method="post"><table width="95%" cellspacing="0" cellpadding="1" bordercolor="" border=0 align=center><tr> <td width="32%"></td><td width="68%" height="15" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #990000"></td></tr><tr > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Name *</td><td ><input type="textbox" size="25" maxlength=50 name="Name"  accessKey=1  ></td></tr><tr  > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Phone No. *</td><td ><input type="textbox" size="25" maxlength=25 name="PhoneNumber"  accessKey=1  ></td></tr><tr > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Email</td><td ><input type="textbox" size="25" maxlength=50 name="Email"  accessKey=1  ></td>';
//ret += '</tr><tr > <td valign="top"  style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #000000">Comments</td><td valign="top"><textarea name="Comments"  accessKey=1  rows=5 cols=></textarea></td></tr><tr> <td></td><td><input type=submit name=cmdAction value=Send class="FormButton"></td></tr></table><input type=hidden name=EmailID value="2A11356"></form>'
return ret;
}


function PlayMusic(){
		if(Get_Cookie('musicState')){
			var myCookie = Get_Cookie('musicState');
			if(myCookie == 'on'){
				alert(musicWin.closed)
				return false;
			}else if(myCookie == 'off'){
				musicWin = window.open('/Music.asp','musicWindow','width=300,height=15');
				window.focus();
				Set_Cookie('musicState','on',1);
			}else{
				return false;
			}
		}else{
			var musicWin = window.open('/Music.asp','musicWindow','width=300,height=15');
			window.focus();
			Set_Cookie('musicState','on',1);
		}
}


function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie( name, value, expires, path, domain, secure ){
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/

if ( expires )
{
expires = expires * 1000 * 60 //* 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 

function ToggleMusic(state){
	var musicObj = parent.document.getElementById('Music')
	alert(musicObj.id);
	return false
//	var quickTimeObj = document.frames['Music'].document.getElementById('MainQuickTime')

	if (state == false){
		// turn music off
		musicObj.stop();
	}else{
		// turn music on
		musicObj.start();
	}
}