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 
	var formName = 'ShowForm';
	
	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(oArgs){
		if(oArgs.indexOf('return=true') > -1){
			formName = 'ShowFormNew'
		}
	}
	
	if (ShowPrefix){
		var myShowForm = window.open('Show'+ShowPrefix+'Form.asp?a='+thisAction+'&b='+thisOID+'&c='+thisIDname+'&d='+thisIDvalue+oArgs,formName,'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,formName,'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,fullSize){
	if ((confirmAction) && (confirm != "-1")){
		if (confirm(confirmAction) == false){
			return false;
		}
	}
			var Args = '?pFn='+thisFileName+'&'+theseArgs
			Args = Args.replace(/&&/g,'&')
			if(fullSize){
				var myPopUp = window.open('/admin/PopUpController.asp'+Args,thisFileName,'fullscreen=yes, scrollbars=yes');
			}else{
				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 UpdateQuery(thislocation,thisValue,thisId,thisTable){
	var myParent = thislocation 
	// determine opened field
	if (thisValue == false){
		for(i=0;i<50;i++){
			var thisName = "Field"+i
			var myField = myParent.getElementById(thisName).Tag
			if (myField == thisId){
				myParent.getElementById('Field'+i).value = ""
				myParent.getElementById('Table'+i).value = ""
				myParent.getElementById('OrderBy'+i).value=""
				myParent.getElementById('WhereClause'+i).value=""
				myParent.getElementById('ColumnName'+i).value=""
				break;
			}	
		}
	}else{
		for (i=0;i<50;i++){
			var thisName = "Field"+i
			var myField = myParent.getElementById(thisName).value
			if (myField == ""){
				myParent.getElementById('Field'+i).value = thisId
				myParent.getElementById('Field'+i).Tag = thisId
				myParent.getElementById('Table'+i).value = thisTable
				myParent.getElementById('ColumnName'+i).value = "0||" + thisId
				break;
			}
		}
	}	
	

}

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].name)){
				errorMessage = document.getElementById('Cell_'+PassedForm[i].name).innerHTML
				errorMessage = errorMessage.substring(0,errorMessage.length-7).replace('&','');
				}else{
				errorMessage = PassedForm[i].name
				}
			
		
		
		 if((PassedForm[i].value == "") || (PassedForm[i].type == "select-one" && PassedForm[i].value == 0)) {
			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('<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('window.resizeTo(thisImage.width+100,thisImage.height+100)\n')
	imageWin.document.writeln('}else if(thisH == ""){\n')
	imageWin.document.writeln('window.resizeTo(500,300)\n')
	imageWin.document.writeln('}else{\n')
	imageWin.document.writeln('		if(thisImage.width == "" || thisImage.width == 0){\n');
	imageWin.document.writeln('			window.resizeTo(500,250)\n');
	imageWin.document.writeln('		}else{\n');
	imageWin.document.writeln('			window.resizeTo(thisImage.width+100,thisImage.height+100)\n')
	imageWin.document.writeln('		}\n');
	imageWin.document.writeln('}\n')
	imageWin.document.writeln('if(navigator.appName == "Microsoft Internet Explorer"){\n');
	imageWin.document.writeln('if(window.innerWidth < 125){\n')
	imageWin.document.writeln('window.resizeTo(500,350);\n')
	imageWin.document.writeln('}else{\n')
	// put code here is other issues arise for other browsers
	imageWin.document.writeln('}\n')
	imageWin.document.writeln('}\n')
	imageWin.document.writeln(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){
	var thisLength = thisField.value.length;
	if(navigator.appName.indexOf('Internet Explorer') > 0){
		// do nothing for ie, it counts' CR as length 2
		}else{
			thisLength = parseInt(thisLength) + parseInt(returnCharCount(thisField.value,'\n'))
		}
		
	if (thisLength > thisMaxLength){
			if(navigator.appName.indexOf('Internet Explorer') > 0){
				thisField.value = trim(thisField.value.substring(0,parseInt(thisMaxLength-1)))
				}else{
				thisField.value = trim(thisField.value.substring(0,parseInt(thisField.value.length) - (parseInt(thisLength - thisMaxLength))))
				}
		alert('Max Length for this text area is ' + thisMaxLength + ', your data has been shortened.');
		thisField.focus();
	}
}

function returnCharCount(string, word){
  var substrings = string.split(word);
  return substrings.length - 1;
}
  

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function HideTalentFields(thisVal,hideAll,thisVal2){

// set types
var ShowThese = "";
var TypeArray = new Array();
TypeArray[0] = "ActorType";
TypeArray[1] = "BandType"
TypeArray[2] = "ComedianType"
TypeArray[3] = "DancerType"
TypeArray[4] = "DJType"
TypeArray[5] = "ModelType"
TypeArray[6] = "MusicianType"
TypeArray[7] = "PhotographerType"
TypeArray[8] = "SingerType"
TypeArray[9] = "ArtistType"
TypeArray[10] = "MCType"
TypeArray[11] = "DesignerType"
TypeArray[12] = "MagicianType"

var TypeFields = new Array()
TypeFields["Actor / Actress"] = "ActorType,Age,Gender,Language,Ethnicity,EyeColor,HairColor,HairLength,Height,Weight,Physique,ChestSize,HipSize,WaistSize,DressSize,ShoeSize,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Artist"] = "ArtistType,Classification,Experience,Management,Affiliations,Merchandise,NumberOfMembers"
TypeFields["Band"] = "BandType,Classification,Experience,Management,Affiliations,Merchandise,NumberOfMembers"
TypeFields["Comedian"] = "ComedianType,Age,Gender,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Dancer"] = "DancerType,Age,Gender,Language,Ethnicity,EyeColor,HairColor,HairLength,Height,Weight,Physique,ChestSize,HipSize,WaistSize,DressSize,ShoeSize,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["DJ / Producer"] = "DJType,Age,Gender,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Model"] = "ModelType,Age,Gender,Language,Ethnicity,EyeColor,HairColor,HairLength,Height,Weight,Physique,ChestSize,HipSize,WaistSize,DressSize,ShoeSize,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Musician"] = "MusicianType,Age,Gender,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Photographer"] = "PhotographerType,Age,Gender,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Singer"] = "SingerType,Age,Gender,Language,Ethnicity,EyeColor,HairColor,HairLength,Height,Weight,Physique,ChestSize,HipSize,WaistSize,DressSize,ShoeSize,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["MC"] = "MCType,Age,Gender,Language,Ethnicity,Classification,Experience,Management,Affiliations,Merchandise"
TypeFields["Designer"] = "DesignerType,Classification,Experience,Management,Affiliations,Merchandise,NumberOfMembers"
TypeFields["Magician"] = "MagicianType,Age,Gender,Classification,Experience,Management,Affiliations,Merchandise"

// set fields
var Fields = "Age,Gender,Language,Ethnicity,EyeColor,HairColor,Height,Weight,Physique,ChestSize,HipSize,WaistSize,DressSize,Classification,Experience,Management,Merchandise,ShoeSize,NumberofMembers";
var FieldArray = Fields.split(",")


// hide all
if (hideAll == true){
	
	// hide types
	for(i=0;i<TypeArray.length;i++){
		if (document.getElementById("Row_" + TypeArray[i])){
			if(navigator.appName == "Microsoft Internet Explorer"){
				document.getElementById("Row_" + TypeArray[i]).style.display='none';	
				}else{
				//document.getElementById("Row_" + TypeArray[i]).style.visibility= 'hidden'; // 'collapse';	
				document.getElementById("Row_" + TypeArray[i]).style.display= 'none';
			}
		}
	}
	// hide fields
	for (i=0;i<FieldArray.length;i++){
		if(document.getElementById("Row_" + FieldArray[i])){
			if(navigator.appName == "Microsoft Internet Explorer"){
				document.getElementById("Row_" + FieldArray[i]).style.display='none';
				}else{
				//document.getElementById("Row_" + FieldArray[i]).style.visibility='hidden';
				document.getElementById("Row_" + FieldArray[i]).style.display='none';
				}
		}
	}
	
}


	var thisPassedItem
	for (j=0;j<2;j++){
		if (j==0){
			thisPassedItem = thisVal;
		}else{
			thisPassedItem = thisVal2;
		}

			if (thisPassedItem == ""){
			// do nothing
			}else if(TypeFields[thisPassedItem] != undefined){
				FieldArray = TypeFields[thisPassedItem].split(",")
				for(i=0;i<FieldArray.length;i++){
					if (document.getElementById(FieldArray[i])){
							if(navigator.appName == "Microsoft Internet Explorer"){
								document.getElementById("Row_"+FieldArray[i]).style.display='inline';		
								}else{
						
								
								document.getElementById("Row_"+FieldArray[i]).style.display='inline';		
								
								}
					}
				}
			}
	} // end loop of mulitple values
}


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 unFormatCurrency(thisVal){
	var retVal = thisVal;
	retVal = retVal.replace('&nbsp;',"")
	retVal = retVal.replace('$',"")
	retVal = retVal.replace(/,/g,"")
	return retVal;
}

function unFormatPercent(thisVal){
	var retVal = thisVal;
	retVal = retVal.replace('&nbsp;',"")
	retVal = retVal.replace('%',"")
	retVal = parseFloat(retVal/100)
	return retVal;
}



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 AddToChart(thisField,thisProductNumber,thisDescription,thisUnitCost,thisQuantity,thisTableName,thisDiscount,thisShippingWeight,thisURL){
	var thisMessage = thisDescription.replace('Size:','\nSize: ')
	thisMessage = thisMessage.replace('Weight:','\nWeight: ')
	
	
	if (confirm('Would you like to add the following to your cart?\n\nProduct Name: '+thisMessage+' \nPrice: '+formatCurrency(thisUnitCost)+' ')==true){	
		var partDelimit = "||@#|!~"
		var lineDelimit = "%^&*@#@"

	// get free cookie for cart
		var currCart = Get_Cookie(thisField)
		
		// determine if this item belongs to any items in the car
		// if the item is for a different user, warn customer
		// &p= indexOf('&')
		var currUser = ""
		var oldUser = ""
		
		currUser = thisURL.substring(thisURL.indexOf('&p=')+3,thisURL.length)
		currUser = currUser.substring(0,currUser.indexOf('&'))
		// if != null then check
		if (currCart != null){
			var tempArray = currCart.split(lineDelimit);
			for(i=0;i<tempArray.length;i++){
				if(tempArray[i] != ""){
					oldUser = tempArray[i].substring(tempArray[i].indexOf('&p=')+3,tempArray[i].length)
					oldUser = oldUser.substring(0,oldUser.indexOf('&'))
					if (oldUser != currUser){
						if(confirm('It seems you are trying to add multiple products from different users. We are sorry, but you can only purchase from one user at a time.\n\nClick:\nOk --> To clear your cart and add this item\nCancel --> To not add this item and continue shopping')==true){
							currCart = null
							break;
							}else{
							return false;
						}										
					}
				}
			}
		}			
			
		// set the cookie to maintain the user
		Set_Cookie('currUser',currUser)

		
		
		
		if(thisDiscount == undefined){thisDiscount = 0}
		if (currCart == null){
			currCart = thisProductNumber + partDelimit + thisDescription + partDelimit + thisUnitCost  + partDelimit + thisTableName + partDelimit + thisDiscount + partDelimit + thisShippingWeight +partDelimit + thisURL + partDelimit + thisQuantity + lineDelimit
			}else{
			currCart = currCart + thisProductNumber + partDelimit + thisDescription + partDelimit + thisUnitCost + partDelimit + thisTableName + partDelimit + thisDiscount + partDelimit + thisShippingWeight + partDelimit + thisURL + partDelimit + thisQuantity + lineDelimit
		}
		
		if (currCart.length <= 2300){
			Set_Cookie(thisField,currCart,30)
			}else{
			alert('Cart is full, please checkout');
		}
	}
}


function ManageQuantity(thisField,thisLine,oldVal,newVal){
	if (ValidateTextbox(newVal,'Integer') == false){
		newVal.value = 1
		return true;
	}
	
	if (oldVal != newVal.value){
		var newLine = thisLine.substring(0,thisLine.length - oldVal.length)
		newLine = newLine + newVal.value
		var currCart = Get_Cookie(thisField)
		currCart = currCart.replace(thisLine,newLine)
		Set_Cookie(thisField,currCart);
		document.location.href = document.location.href;
	}
}

function ManageCartTotals(){
// Tax1, SubTotal0,SubTotal1
if (document.getElementById('TotalRows')){
	var TotalRows = document.getElementById('TotalRows').value
	var Tax = 0
	var SubTotal = 0
		for(i=0;i<TotalRows;i++){
			if (document.getElementById('linecost'+i)){
				var thisValue = document.getElementById('linecost'+i).innerHTML
				thisValue = thisValue.replace('$',"")
				thisValue = thisValue.replace(/,/g,"")
				SubTotal = SubTotal + parseFloat(thisValue)
			}
		}
		
			if (document.getElementById('totalProductCost')){
				document.getElementById('totalProductCost').innerHTML = formatCurrency(SubTotal)
			}
		
		
			if (document.getElementById('ShippingCost1')){
				var shippingCost = unFormatCurrency(document.getElementById('ShippingCost1').innerHTML)
				SubTotal = parseFloat(SubTotal) + parseFloat(shippingCost)
			}
		
		
		
			if (document.getElementById('TotalCostTop')){
				document.getElementById('TotalCostTop').innerHTML = formatCurrency(SubTotal)
			}
	
			if (document.getElementById('TotalCostBottom')){
				document.getElementById('TotalCostBottom').innerHTML = formatCurrency(SubTotal)
			}
			
			if (document.getElementById('xTotalCost')){
				document.getElementById('xTotalCost').value = SubTotal
			}
					
		}
}


function RemoveChartRow(thisField,thisLine,refreshPage){
	if(confirm('Click Ok to remove this item from your order.')==true){
		var currCart = Get_Cookie(thisField)
		currCart = currCart.replace(thisLine,"")
		Set_Cookie(thisField,currCart);
		if(refreshPage != false){
			document.location.href=document.location.href	
		}
	}
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}



function ValidateMinMax(thisField,MinVal,MaxValue){

	if(isCurrency(thisField.value)==false){
		thisField.value = MinVal
		return false;
	}

	if ((thisField.value >= MinVal) && (thisField.value <= MaxValue)){
		return true;
	}else{
		alert('Please enter a value between '+MinVal+' to '+MaxValue);
		thisField.value = MinVal
		return false;
	}
}


function ValidateAccount(thisForm){
	var FieldArray = new Array('FirstName','LastName','BankAccountNumber1','BankAccountNumber2','Routing1','Routing2','AccountType1','AccountType2');
	// make sure all fields are filled in
	for(i=0;i<FieldArray.length;i++){
		if(document.getElementById(FieldArray[i]).value == ""){
			alert(FieldArray[i] + ' is a required field.');
			document.getElementById(FieldArray[i]).focus();
			return false;
		}
	}
	
		if(document.getElementById('TermsOfUse').checked != true){
			alert('Terms of Use must be checked in order to add an account');
			return false;
		}
	
	// make sure Account Number 1 = Account Number 2
	if (document.getElementById('BankAccountNumber1').value != document.getElementById('BankAccountNumber2').value){
		alert('Your account numbers do not match, please correct');
		document.getElementById('BankAccountNumber1').focus();
		document.getElementById('BankAccountNumber1').value = "";
		document.getElementById('BankAccountNumber2').value = "";
		return false;
	}
	
	// make sure Routing1 = Routing 2
	if (document.getElementById('Routing1').value != document.getElementById('Routing2').value){
		alert('Your routing numbers do not match, please correct');
		document.getElementById('Routing1').focus();
		document.getElementById('Routing1').value = "";
		document.getElementById('Routing2').value = "";
		return false;
	}

	// final confirmation
	if(document.getElementById('FinalConfirm')){
		if(confirm(document.getElementById('FinalConfirm').value.replace(/\\n/g,'\n'))==true){
			return true;
		}else{
			return false;
		}
	}else{
		return true;
	}


}




function parseStyleValue(ElementName,thisValue){
// parse the following style elements
// font-family, font-size, font-weight,color
var ItemList = "font-family,font-size,font-weight,color,background-color,border,padding,text-align";
thisValue = thisValue.toLowerCase();
var myArray = thisValue.split(';');
var foundItem = false;
for(i=0;i<myArray.length;i++){
	
	var thisName = Trim(myArray[i].substring(0,myArray[i].indexOf(':')));
	var thisValue = Trim(myArray[i].substring(myArray[i].indexOf(':')+1,myArray[i].length));

	if(ItemList.indexOf(thisName) > -1){
		foundItem = true
		document.writeln('<tr>');
		document.writeln('<td style="width:100px;font-weight:bold;font-size:12px;" valign=top>'+thisName+'</td>');
		document.writeln('<td valign=top>');
		parseStyleInputType(ElementName,thisName,thisValue);
		document.writeln('</td>')
		document.writeln('</tr>');
	}		
}

	// hide any items that do not contain items
	if(foundItem == false){
		if(document.getElementById('Menu_'+ElementName)){
			document.getElementById('Menu_'+ElementName).style.display='none';
		}
	}
		

}


function parseStyleInputType(ElementName,thisInputType,thisValue){
	if (thisInputType == ''){
		return false;
	}else if(!StyleInputArray[thisInputType]){
		return false;
	}

	var currentObject = StyleInputArray[thisInputType]
	var thisType = currentObject['InputType']
	var thisNumericField = currentObject['NumericField']
	var thisMaxLength = currentObject['MaxLength']
	var thisInputSize = currentObject['thisInputSize']
	var thisExtraData = currentObject['ExtraData']
	
	if(thisType == 'GetColor'){
		document.writeln('<input type=text name="'+ElementName+'_'+thisInputType+'" id="'+ElementName+'_'+thisInputType+'" size="15" maxlength="7" value="'+thisValue.replace('"','"')+'"> <input type=button name=cmdAction value="Get Color" class=formButton onClick="GetColor('+unescape('%27')+ElementName+'_'+thisInputType+unescape('%27')+');">');
	}else if(thisType == 'GetFont'){
		document.writeln('<input type=text name="'+ElementName+'_'+thisInputType+'" id="'+ElementName+'_'+thisInputType+'" size="25" maxlength="25" value="'+thisValue.replace('"','"')+'"> <input type=button name=cmdAction value="Get Font" class=formButton onClick="GetFont('+unescape('%27')+ElementName+'_'+thisInputType+unescape('%27')+',document.getElementById('+unescape('%27')+ElementName+'_'+thisInputType+unescape('%27')+').value);">');
	}else if(thisType == 'Textbox'){
		document.writeln('<input type=text name="'+ElementName+'_'+thisInputType+'" id="'+ElementName+'_'+thisInputType+'" size="'+thisInputSize+'" maxlength="'+thisMaxLength+'" value="'+thisValue.replace('"','"')+'">');
	}else if(thisType == 'Select'){
		document.writeln('<select name="'+ElementName+'_'+thisInputType+'" id="'+ElementName+'_'+thisInputType+'">\n');
		var tempArray = thisExtraData.split(";")
		for(zItem=0;zItem<tempArray.length;zItem++){
			if (thisValue == tempArray[i]){
				document.writeln('<option value="'+tempArray[zItem]+'" selected>'+tempArray[zItem]+'</option>\n');		
			}else{
				document.writeln('<option value="'+tempArray[zItem]+'">'+tempArray[zItem]+'</option>\n');		
			}
		}
		document.writeln('</select>');
	}else if(thisType == 'Border'){
		var thisSize = Trim(thisValue.substring(0,thisValue.indexOf(' ')))
		var thisBorder = thisValue.substring(thisValue.indexOf(' ')+1,thisValue.length)
		thisBorder = Trim(thisBorder.substring(0,thisBorder.indexOf(' ')))
		var thisColor = Trim(thisValue.substring(thisValue.length,9))
		// display size
		document.writeln('<input type=text name="'+ElementName+'_'+thisInputType+'_size" id="'+ElementName+'_'+thisInputType+'_size" size="6" maxlength="4" value="'+thisSize+'" onBlur="UpdateComplexCSS('+unescape('%27')+ElementName+'_'+thisInputType+unescape('%27')+','+unescape('%27')+'size,border,color'+unescape('%27')+');">');
		// display border
		document.writeln('<select name="'+ElementName+'_'+thisInputType+'_border" id="'+ElementName+'_'+thisInputType+'_border" onChange="UpdateComplexCSS('+unescape('%27')+ElementName+'_'+thisInputType+unescape('%27')+','+unescape('%27')+'size,border,color'+unescape('%27')+');">\n');
		var tempArray = thisExtraData.split(";")
		for(zItem=0;zItem<tempArray.length;zItem++){
			if (thisBorder == tempArray[zItem]){
				document.writeln('<option value="'+tempArray[zItem]+'" selected>'+tempArray[zItem]+'</option>\n');		
			}else{
				document.writeln('<option value="'+tempArray[zItem]+'">'+tempArray[zItem]+'</option>\n');		
			}
		}
		document.writeln('</select>');
		// display color
		document.writeln('<input type=text name="'+ElementName+'_'+thisInputType+'_color" id="'+ElementName+'_'+thisInputType+'_color" size="8" maxlength="7" value="'+thisColor+'" onBlur="UpdateComplexCSS('+unescape('%27')+ElementName+'_'+thisInputType+unescape('%27')+','+unescape('%27')+'size,border,color'+unescape('%27')+');"> <input type=button name=cmdAction value="Get Color" class=formButton onClick="GetColor('+unescape('%27')+ElementName+'_'+thisInputType+'_color'+unescape('%27')+');">');
		document.writeln('<input type=hidden name="'+ElementName+'_'+thisInputType+'" id="'+ElementName+'_'+thisInputType+'" value="'+thisValue+'">\n');
		
	}


}

function GetColor(thisID){
	var myColor = window.open('/admin/PopUpController.asp?pFn=GetWebSafeColors&ID='+thisID,'WebSafeColors','width=225px,height=400px;resizeable=yes;scrollbars=no,menubar=no,location=no,address=no');
	myColor.focus();
}

function GetFont(thisID,CurrentValue){
	var myColor = window.open('/admin/PopUpController.asp?pFn=WebSafeFonts&ID='+thisID+'&Val='+CurrentValue,'WebSafeFonts','width=400px,height=225px;resizeable=yes;scrollbars=no,menubar=no,location=no,address=no,resizable=yes');
	myColor.focus();
}


function changecss(theClass,element,value,parentWindow) {

 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }

// create obj to determine if self or parent
var documentLocation;

	if(parentWindow){
		if(parentWindow == true){
			documentLocation = opener.document;
		}else{
			documentLocation = document;
		}
	}else{
		documentLocation = document;
	}


	 for (var S = 0; S < documentLocation.styleSheets.length; S++){
	  for (var R = 0; R < documentLocation.styleSheets[S][cssRules].length; R++) {
	   if (documentLocation.styleSheets[S][cssRules][R].selectorText == theClass) {
	   		if(documentLocation.styleSheets[S][cssRules][R].style[element]){
				documentLocation.styleSheets[S][cssRules][R].style[element] = value;
	   			}
	   }
	  }
	 }	

}


function UpdateCSSClass(StyleArray,FormName){
// this function will loop through the hash and determine which element is visibile
// then it will determine the elements of the current form and update the css classes
var currForm = "";
var currFormNameLength = 0;

for(var k in StyleArray){
	if (document.getElementById(k)){
		if(document.getElementById(k).style.display=='block'){
			currForm = k
		}
	}
}

currFormNameLength = currForm.length;

// process each element prefixed with currForm
var FormContainer = document.getElementById(FormName)
var ElementArray = FormContainer.elements
var ClassProperty = "";
var ClassValue = "";
var midChar = "";


for(i=0;i<FormContainer.length;i++){
	if(FormContainer.elements[i].id.substring(0,currFormNameLength)==currForm){
		// determine class property
		ClassProperty = Trim(FormContainer.elements[i].id.substring(parseFloat(currFormNameLength+1),FormContainer.elements[i].id.length))
		// determine if '-' exists, if so, remove each, and uppercase the following left
	//	alert(ClassProperty)
		if(ClassProperty.indexOf('-') > -1){
		//	while(ClassProperty.indexOf('-') > 0){
				midChar = ClassProperty.substring(ClassProperty.indexOf('-')+1,ClassProperty.length)
				midChar = midChar.substring(0,1).toUpperCase()
				ClassProperty = ClassProperty.substring(0,ClassProperty.indexOf('-')) + midChar + ClassProperty.substring(parseFloat(ClassProperty.indexOf('-')+2),ClassProperty.length)
		//	}
		}
		// determine class value
		ClassValue = FormContainer.elements[i].value
		// change values
		changecss("."+currForm,ClassProperty,ClassValue,true)
	}
}



alert('Successfully updated');

}





function UpdateComplexCSS(hiddenElement,ElementParts){
    var retVal = "";
    var tempArray = ElementParts.split(',')
    for(i=0;i<tempArray.length;i++){
       tempArray[i] = Trim(tempArray[i])
        if(document.getElementById(hiddenElement+'_'+tempArray[i])){
            if(retVal != ""){
                retVal = retVal + ' '
            }
            retVal = retVal + document.getElementById(hiddenElement+'_'+tempArray[i]).value
        }
    }
    if(document.getElementById(hiddenElement)){
        document.getElementById(hiddenElement).value = retVal
    }

}


function DisplayForm(ElementHash,ShowThisOne){
	for (var k in ElementHash){
		if (document.getElementById(k)){
			if (k == ShowThisOne){
				document.getElementById(k).style.display='block';
			}else{
				document.getElementById(k).style.display='none';
			}
		}
	}
}




function returnHyperLink(){
		var retVal = "";

		if (document.getElementById('ExternalLink').style.display == "block"){
			// process external link
			var myExternalUrl = document.getElementById('ExternalUrl')
			var myExternalText = document.getElementById('ExternalText')
			var myExternalTarget = document.getElementById('ExternalTarget')
			// validation
			if (myExternalUrl.value == ""){
				alert("Please enter the Url")
				myExternalUrl.focus();
				return false;
			}else if(myExternalText.value == ""){
				alert("Please enter text for the link")
				myExternalText.focus();
				return false;
			}
			
			if (myExternalTarget.value == "ajax"){
				retVal = '<a href="javascript:void(0)" onClick="go('+unescape('%27')+myExternalUrl.value+unescape('%27')+'");">'+myExternalText.value+'</a>'
			}else{
				// create the link
				retVal = '<a href="'+myExternalUrl.value+'" target="'+myExternalTarget.value+'">'+myExternalText.value+'</a>'
			}

		}else if (document.getElementById('InternalLink').style.display == "block"){

			if (document.getElementById('Internal0').style.display == "block"){ // Select Page
				var myInternalPage =  document.getElementById('InternalPage')
				var myInternalPageText = document.getElementById('InternalPageText')
				var myInternalPageTarget = document.getElementById('InternalPageTarget')
				var myPagePrefix = document.getElementById('PagePrefix');
				var myPageType = document.getElementById('PageType');
				
				// validation
				if (myInternalPage.value == 0){
					alert("Please select a Page")
					//myInternalPage.focus();
					return false;
				}else if(myInternalPageText.value == ""){
					alert("Please enter link text")
					//myInternalPageText.focus();
					return false;
				}

				if (myInternalPageTarget.value == "ajax"){
					retVal = '<a href="javascript:void(0);" onClick="go('+unescape('%27')+'/admin/adminApp.asp?OID='+myInternalPage.value+'&PageType='+myPageType.value+unescape('%27')+');">'+myInternalPageText.value+'</a>'			
				}else{
					var rootURL = '';

					if(document.getElementById('xPageType')){
						if(document.getElementById('xPageType').value == 'AdminPage'){
							rootURL = '/admin/adminIndex.asp?';
						}else{
							rootURL = '/index.asp?';
						}
					}else{
						rootURL = '/index.asp?';
					}
					// create string
					retVal = '<a href="'+rootURL+'OID='+myInternalPage.value+'&PageType=Page" target="'+myInternalPageTarget.value+'">'+myInternalPageText.value+'</a>'
				}

			}else if (document.getElementById('Internal1').style.display == "block"){ // Select Image
				var myInternalImageText = document.getElementById('InternalImageText')
				var myInternalImageTarget = document.getElementById('InternalImageTarget')
				var myInternalImagePath = document.getElementById('InternalImagePath')

				if (myInternalImageText.value == ""){
					alert("Please enter text for the link")
					myInternalImageText.focus();
					return false;
				}else if(myInternalImagePath.src == ""){
					alert("Please select an image from the list")
					myInternalImagePath.focus();
					return false;
				}
			
			// create string
			retVal = '<a href="'+myInternalImagePath.src.substring(myInternalImagePath.src.indexOf('/pub/images'),myInternalImagePath.src.length)+'" target="'+myInternalImageTarget.value+'">'+myInternalImageText.value+'</a>'

			}else if (document.getElementById('Internal2').style.display == "block"){ // Select File
				var myInternalFileText = document.getElementById('InternalFileText')
				var myInternalFileTarget =  document.getElementById('InternalFileTarget')
				var myInternalFilePath	 = document.getElementById('InternalFilePath')	
		
				if (myInternalFileText.value == ""){
					alert("Please enter text for the link")
					myInternalFileText.focus();
					return false;
				}else if(myInternalFilePath.innerHTML == ""){
					alert("Please select a file from the list")
					myInternalFilePath.focus();
					return false;
				}
				
			// create string
			retVal = '<a href="/pub/files/'+myInternalFilePath.innerHTML+'" target="'+myInternalFileTarget.value+'">'+myInternalFileText.value+'</a>'
			
			} // end internal selection
		}
		returnValue = retVal
		window.close();
}







function ChangeProductsPerRow(selectObj){
	// detremine the current product table width
	// determine the current product image width
	// reset the columns
	
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }

// create obj to determine if self or parent
var documentLocation = document;

	
	var ElementArray = new Array(2);
	var ClassArray = new Array(".productTable",".productImage",".productTableContainer");
	ElementArray[".productTable"] = new Array();
	ElementArray[".productImage"] = new Array();
	ElementArray[".productTableContainer"] = new Array();
	var currProducts = document.getElementById('ProductsPerRow').value
	var colPerRow = selectObj.value;
	for (i = 0;i<ClassArray.length;i++){
		for (var S = 0; S < documentLocation.styleSheets.length; S++){
			for (var R = 0; R < documentLocation.styleSheets[S][cssRules].length; R++) {
					if (documentLocation.styleSheets[S][cssRules][R].selectorText == ClassArray[i]) {
						ElementArray[ClassArray[i]]["width"] = documentLocation.styleSheets[S][cssRules][R].style["width"].replace('px','');
						ElementArray[ClassArray[i]]["height"] = documentLocation.styleSheets[S][cssRules][R].style["height"].replace('px','');
						ElementArray[ClassArray[i]]["padding"] = documentLocation.styleSheets[S][cssRules][R].style["padding"].replace('px','');
						ElementArray[ClassArray[i]]["margin"] = documentLocation.styleSheets[S][cssRules][R].style["margin"].replace('px','');
					}
			}
		}
	}


	// determine the new properties to set the item at which percent
	var currProductContainerWidth = ElementArray[".productTableContainer"]["width"]
	if (ElementArray[".productTableContainer"]["padding"]){currProductContainerWidth -= (colPerRow * ElementArray[".productTableContainer"]["padding"] * 2);}
	if (ElementArray[".productTable"]["margin"]){currProductContainerWidth -= (colPerRow * ElementArray[".productTable"]["margin"] * 2);}
	
	var currProductTablePercent = parseFloat(ElementArray[".productTable"]["width"]/ElementArray[".productTableContainer"]["width"])
	var currProductImagePercent = parseFloat(ElementArray[".productImage"]["width"]/ElementArray[".productTableContainer"]["width"]) 
	
	// set the proudct Table style
//	var thisValue = parseFloat(parseInt(ElementArray[".productTableContainer"]["width"]/colPerRow) * parseFloat(currProductTablePercent))
	thisValue = parseInt(currProductContainerWidth/colPerRow) - 100
	changecss(".productTable","width",thisValue)
	// set the product Image Percent
	var thisValue = parseFloat(parseInt(ElementArray[".productTableContainer"]["width"]/colPerRow) * parseFloat(currProductImagePercent))
	//alert(thisValue)
	thisValue = parseInt(currProductContainerWidth/colPerRow)
	changecss(".productImage","width",thisValue)
	

}

function GetStylesFromParent(thisData){
// obtain the styles from the passed data and return string
var retVal = thisData.substring(thisData.indexOf('<STYLE>')+7,thisData.indexOf('</STYLE>')-thisData.indexOf('<STYLE>'))
retVal = retVal.replace(/(\n|\r|\f|\t)/g,' ')
retVal = retVal.replace(/\"/g,'&quot;')
return retVal
}

function Trim(str){	while(str.charAt(0) == (" ") )	{	str = str.substring(1);	}	while(str.charAt(str.length-1) == " " )	{	str = str.substring(0,str.length-1);	}	return str;}


function SetFieldDate(checkboxBoolean,DateField){
	var dateObj = new Date();
	var FieldObj = document.getElementById(DateField);
	if(checkboxBoolean == true){
		FieldObj.value = dateObj.getMonth()+1 + '/' + dateObj.getDate() + '/' + dateObj.getYear()	
	}else{
		FieldObj.value = "";
	}
}


function addBookmark(title,url) {
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
alert('Sorry your browser does not support this feature');
return true;
}
}

function ValidateComment(thisForm){
	var name = document.getElementById('Username');
	var comments = document.getElementById('Comments');

	if (name.value == ''){
		alert('Please enter a valid name');
		name.focus();
		return false;
	}else if(comments.value ==''){
		alert('Please enter a comment');
		comments.focus();
		return false;
	}

	// strip html
	comments.value = stripHTML(comments.value);
	return true;
	

}