/**********************************************************************************************
**********************************************************************************************/
var d = window.document;
function setCheckBox(theForm,theStatus) {
	var sus=eval("window.document."+theForm+".elements.length");
	for(j=0;j<sus;j++) {
		if(eval("window.document."+theForm+".elements["+j+"].type")=="checkbox") {
			eval("window.document."+theForm+".elements["+j+"].checked="+theStatus);
		}
	}
}
function getDeleteConfirm(theURL,theValue,theMsg) {
	var str="Are you sure you want to delete this "+theMsg+" : "+theValue+" ?    ";
	choice=confirm(str);
	if(choice) {
		window.location.href=theURL;
	} else {
		return false;
	}
}

function CheckFileField(theForm,theElement,theValue) {
	var fileVal=eval("window.document."+theForm+"."+theElement+".value");
	if(fileVal=="") {
		alert("Please provide a "+theValue+" Image    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	var ext=fileVal.substr(fileVal.lastIndexOf(".")).toLowerCase();
	if(ext!=".gif" && ext!=".jpeg" && ext!=".png" && ext!=".jpg") {
		alert("Image file should be .gif or .png or .jpeg format    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}

/*
function CheckAttachment(theForm,theElement) {
	var fileVal=eval("window.document."+theForm+"."+theElement+".value");
	var ext=fileVal.substr(fileVal.lastIndexOf(".")).toLowerCase();
	if(ext==".exe") {
		alert("EXE attachment not allowed    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function isEmpty(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
}

function isPassword(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	if(str.length < 6) {
		alert(""+theMess+" should not be less than six characters    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
}
function isEmail(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty !!! Please provide a valid email address    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	if(re.test(str)==false) {
		alert("That is not a valid Email address. Please enter again.    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function isPhone(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty !!! Please provide a valid phone number    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/;
	if(re.test(str)==false) {
		alert("That is not a valid phone number. Please enter again.    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function isURL(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty !!! Please provide a valid website url    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	var re = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
	if(re.test(str)==false) {
		alert("That is not a valid website address. Please enter again.    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}	
}
function isSpecialChar(theForm,theElement,theMsg) {
	var iChars = "!@#$%^&*~`()+=[]\\\';,/{}|\":<>?";
	for(var i=0;i<eval("window.document."+theForm+"."+theElement+".value.length");i++) {
		if(iChars.indexOf(eval("window.document."+theForm+"."+theElement+".value.charAt("+i+")"))!=-1) {
			alert(theMsg);
			eval("window.document."+theForm+"."+theElement+".focus()");
			eval("window.document."+theForm+"."+theElement+".select()");
			return false;
		}
	}
}
function setCombo(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".selectedIndex");
	if(str==0) {
		alert("Please select a value for "+theMess+"    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false
	}
}

*/ 

function IsNumeric(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	if(isNaN(str)==true || parseInt(str) <= 0) {
		alert(""+theMess+" should not be alpha numeric and always greater than Zero    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}


function _doPagination(page,query) {
	var str = d.getElementById('cmbPage')[d.getElementById('cmbPage').selectedIndex].value;
	if(query == "") {
		window.location.href = page + "?page=" + str;
	} else {
		window.location.href = page + "?page=" + str + "&" + query;
	}
}
function _doPaging(param,pWebsite,pCategory,pPage,pRecord) {
	if(param == "record") {
		var str = d.getElementById('cRecord')[d.getElementById('cRecord').selectedIndex].value;
		var goto = pWebsite + "/portfolio/" + pCategory + "/" + pPage + "/" + str + ".xml";
	} else if(param == "category") {
		var str = d.getElementById('cCategory')[d.getElementById('cCategory').selectedIndex].value;
		var goto = pWebsite + "/portfolio/" + str + "/1/" + pRecord + ".xml";
	} else {
		var str = d.getElementById('cPage')[d.getElementById('cPage').selectedIndex].value;
		var goto = pWebsite + "/portfolio/" + pCategory + "/" + str + "/" + pRecord + ".xml";
	}
	window.location.href = goto;
}
function LoadPopup(getFileName,getWindowName,getHeight,getWidth) {
	var _file = getFileName;
	var _window = getWindowName;
	var _toolbar = 0;
	var _menubar = 0;
	var _status = 1;
	var _resizable = 1;
	var _width = getWidth;
	var _height = getHeight;
	var _top = (screen.height - _height) / 2;
	var _left = (screen.width - _width) / 2;
	var _scrollbars = 1;
	
	var _condition = "toolbar=" + _toolbar + ",menubar=" + _menubar + ",status=" + _status + ",resizable=" + _resizable;
	_condition+=",width=" + _width + ",height=" + _height + ",left=" + _left + ",top=" + _top + ",scrollbars=" + _scrollbars + "";
	
	window.open(_file,_window,_condition);
}
function _doInputNumberOnly() {
	if(event.keyCode < 46 || event.keyCode > 57) {
		event.returnValue = false;
	}
}
function modelessDialogShow(url,width,height) {
	window.showModelessDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;");
}
function modalDialogShow(url,width,height) {
	window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;maximize:1");
}
function setImageClass(cId,cClassName) {
	window.document.getElementById(cId).className = cClassName;
}
/**** for timer ****/
var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer() {
    // Set the length of the timer, in seconds
    secs = 4
    StopTheClock()
    StartTheTimer()
}

function StopTheClock() {
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer() {
    if (secs==0) {
        //StopTheClock()
        // Put something that is supposed to happen after the allotted time.
        // For example, displaying a message:
		if(document.getElementById("msgId")) {
			document.getElementById("msgId").style.display='none';
			
			InitializeTimer();
		}
    }
    else {
        //self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function checkAll() {
	var len=document.getElementsByName('checkbx[]').length;
	if(document.getElementById('check_n').checked==true) {
		for(i=1;i<=len;i++)	{
			var chk='checkbx'+i;
			document.getElementById(chk).checked=true;
			var trElm = document.getElementById(chk).parentNode.parentNode;
			trElm.className="selectedRow";
		}
	}
	else {
		for(i=1;i<=len;i++)	{
			var chk='checkbx'+i;
			document.getElementById(chk).checked=false;
			var trElm=document.getElementById(chk).parentNode.parentNode;
			//var cnt;
			if(i%2==1) {
				trElm.className="alterClass1";
			} else {
				trElm.className="alterClass2";
			}
		}
	}
}

function chngTrClass() {
	var chk1 = document.getElementById("check_n").value;
	var len=document.getElementsByName('checkbx[]').length;
	var j = 0;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var trElm=document.getElementById(chk).parentNode.parentNode;
			trElm.className="selectedRow";
			j++;
		}
		else {
			var trElm=document.getElementById(chk).parentNode.parentNode;
			document.getElementById("check_n").checked=false;
			if(i%2==1) {
				trElm.className="alterClass1";
			} else {
				trElm.className="alterClass2";
			}
		}
	}
	if(j==len){
		document.getElementById("check_n").checked=true;
	}
}

function deleteChk(pageUrl,frmName) {
	//alert(frmName);
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=Delete"');
		//alert(eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=Delete"'));
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to delete!!');
	}
}
	
function activeChk(pageUrl,frmName) {
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=Active"');
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to change the status!!');
	}
}
	
function activeChkSub(pageUrl,frmName) {
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=ActiveSub"');
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to change the status!!');
	}
}
	
function activeChkMod(pageUrl,frmName) {
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=ActiveMod"');
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to change the status!!');
	}
}

function iActivChk(pageUrl,frmName) {
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=Inactive"');
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to change the status!!');
	}
}

function iActivChkSub(pageUrl,frmName) {
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=InactiveSub"');
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to change the status!!');
	}
}

function iActivChkMod(pageUrl,frmName) {
	var len=document.getElementsByName('checkbx[]').length;
	for(i=1;i<=len;i++)	{
		var chk='checkbx'+i;
		if(document.getElementById(chk).checked==true) {
			var flag=1;
		}
	}
	if(flag=="1") {
		eval('document.'+frmName+'.action = "'+pageUrl+'?index=List&action=InactiveMod"');
		eval('document.'+frmName+'.submit()');
	}
	else {
		document.getElementById("msgCntnr").innerHTML=getHtmlError('Please select an item to change the status!!');
	}
}

function getHtmlError(msg) {
	return "<div id=\"msgErId\" class=\"error\">"+msg+"<br />"+getCloseButton('msgErId')+"</div>";
}

function getHtmlMessage(msg) {
	return "<div id=\"msgScId\" class=\"message\">"+msg+"<br />"+getCloseButton('msgScId')+"</div>";
}
		
function getCloseButton(msgBoxId) {
	return "<div id=\"msgClBtn\" class=\"boxHideButton\" onclick=\"closeMsgBox('"+msgBoxId+"',1,'')\"></div>";
}

function closeMsgBox(boxId,step,presentHeight){
	var msgBxHgh;
	var heightDecreaseBy = 2;
	var hideSpeed = 10;
	if(step == 1){
		msgBxHgh = parseInt(d.getElementById(boxId).scrollHeight) - 20;
		d.getElementById('msgClBtn').style.display = 'none';
	}else{
		msgBxHgh = presentHeight;
	}
	var msgBxHgtD = msgBxHgh - heightDecreaseBy;
	d.getElementById(boxId).style.height = msgBxHgtD+"px";
	if(msgBxHgtD<=1){
		d.getElementById(boxId).style.display = 'none';
		return false
	}else{
		if(msgBxHgtD<heightDecreaseBy+1){
			msgBxHgtD = heightDecreaseBy+1;	
		}
		setTimeout("closeMsgBox('"+boxId+"','',"+msgBxHgtD+")", hideSpeed);
	}
}

function bttnActions(actOnBtn,idPrefix,classBtn,onClickFunc,onClickArg){
	var id_11 = idPrefix+'11';		var id_12 = idPrefix+'12';		var id_13 = idPrefix+'13';
	var id_21 = idPrefix+'21';		var id_22 = idPrefix+'22';		var id_23 = idPrefix+'23';
	var id_31 = idPrefix+'31';		var id_32 = idPrefix+'32';		var id_33 = idPrefix+'33';
	if(actOnBtn == 'over'){
		document.getElementById(id_11).innerHTML = '<img src="'+IMG_S_DIR+'ass_topleft.png" width="6" height="6" />';
		document.getElementById(id_12).className = classBtn;
		document.getElementById(id_13).innerHTML = '<img src="'+IMG_S_DIR+'ass_topright.png" width="6" height="6" />';
		
		document.getElementById(id_21).className = classBtn;
		document.getElementById(id_22).className = classBtn;
		document.getElementById(id_23).className = classBtn;
		
		document.getElementById(id_31).innerHTML = '<img src="'+IMG_S_DIR+'ass_bottomleft.png" width="6" height="6" />';
		document.getElementById(id_32).className = classBtn;
		document.getElementById(id_33).innerHTML = '<img src="'+IMG_S_DIR+'ass_bottomright.png" width="6" height="6" />';
	}
	else if(actOnBtn == 'out'){
		document.getElementById(id_11).innerHTML = '<img src="'+IMG_S_DIR+'red_topleft.png" width="6" height="6" />';
		document.getElementById(id_12).className = classBtn;
		document.getElementById(id_13).innerHTML = '<img src="'+IMG_S_DIR+'red_topright.png" width="6" height="6" />';
		
		document.getElementById(id_21).className = classBtn;
		document.getElementById(id_22).className = classBtn;
		document.getElementById(id_23).className = classBtn;
		
		document.getElementById(id_31).innerHTML = '<img src="'+IMG_S_DIR+'red_bottomleft.png" width="6" height="6" />';
		document.getElementById(id_32).className = classBtn;
		document.getElementById(id_33).innerHTML = '<img src="'+IMG_S_DIR+'red_bottomright.png" width="6" height="6" />';
	}
	else if(actOnBtn == 'click'){
		var funcArg = onClickArg.split(",");
		var argLine='';
		for(var i=0;i<funcArg.length;i++) {
			argLine = argLine+funcArg[i]+"','";
		}
		argLine = "'"+argLine.substring(0,argLine.length-2);
		onClickFunc = onClickFunc+"("+argLine+")";
		setTimeout(onClickFunc, 1);
	}
	else{
		return false;
	}
}
function CountWords(inputBoxId,maxCharLen,spanCharRemnInfoId,spnErrId,errMsg){
	maxCharLen = maxCharLen-1;
	var remainTxt = maxCharLen-(d.getElementById(inputBoxId).value.length);
	if(remainTxt<=0){
		remainTxt = 0;
	}
	d.getElementById(spanCharRemnInfoId).innerHTML=' '+remainTxt;
	var inputBoxId=d.getElementById(inputBoxId);
	var msg = "";
	var c = 0;
	var w = (inputBoxId.value.split(""));
	var no_words = w.length;
	for(var x = 0; x < no_words; x++){
		if(c >= maxCharLen){
			d.getElementById(spnErrId).innerHTML = ", "+errMsg;
			inputBoxId.value = msg;
			break;
		}
		msg = msg + w[x] + "";
		c++;
	}
	if((maxCharLen-remainTxt)<(maxCharLen)){
		d.getElementById(spnErrId).innerHTML = "";
	}
	return false;
}
function HideMessage(msgBoxId){
	d.getElementById(msgBoxId).innerHTML = "";
}
function doNothing(){
	//doNothing
}
function doFocus(textId,textValue,msg){
	if(textValue==msg){
		d.getElementById(textId).value = ''; 
	}else if(textValue==""){
		d.getElementById(textId).value = msg; 
	}
}

function doReplyTo(commentId,fieldId){
	if(d.getElementById(fieldId)){
		d.getElementById(fieldId).value = commentId;
		if(commentId=='0'){
			d.getElementById('tdRplyToId').innerHTML = '&nbsp;';
		}else{
			d.getElementById('tdRplyToId').innerHTML = 'In reply to #'+commentId;
		}
	}
	d.location.hash='cnmtit';// Just to change the hash call to something else before the actual call. 
							 //	Needed for Safari for the second call in the same page. 
	d.location.hash='cmntit';
	if(d.getElementById(fieldId)){
		d.frmComment.comment.focus();
	}
}
function doCmntToSbmsn(){
	d.getElementById('tdRplyToId').innerHTML = '&nbsp;';
	d.location.hash='cmntit';
}

