// JavaScript Document
function addToFavorites(url,pagename){
	if(pagename==''){
		pagename = document.title;
	}
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(pagename, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, pagename); }
	else if(window.opera && window.print) { // Opera Hotlist
		alert('You need to press Ctrl + D to bookmark our site.');	
	}
}
function genRandom(){
	var drn = ""; var rand_no;
	for (x = 0; x < 20; x++){
		rand_no = Math.floor((10-4)*Math.random()) + 5;
		drn = drn + rand_no;
	}
	return (drn);
}
function removeHTMLTags(txtID){
 	if(document.getElementById && document.getElementById(txtID)){
 		var strInputCode = document.getElementById(txtID).value; 
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
		return strTagStrippedText;
 	}	
}
function visithome(){
	window.location.href = "index.php";
}
function showresult(){
	jQuery("#votesystem").hide();
	jQuery("#voteController_1").hide();
	jQuery("#resultsystem").show('slow');
	jQuery("#voteController_2").show('slow');
	window.scroll(0,800);
}
function showvote(){
	jQuery("#votesystem").show('slow');
	jQuery("#voteController_1").show();
	jQuery("#resultsystem").hide();
	jQuery("#voteController_2").hide();
	window.scroll(0,800);	
}
function doVote(sPath,qusid,noq){
	var sencmd = false;
	var senval = '';
	for(var a=0;a<noq;a++){
		if(jQuery("input[id='q"+a+"']").is(":checked")){
			sencmd = true;
			senval = jQuery("input[id='q"+a+"']").val();
			break;
		}
	}
	if(sencmd==true){
		jQuery.ajax({
			url : sPath+"postvote.php",
			cache: false,
			data: "tracker=vote&qusid="+qusid+"&chqus="+senval,
			success : function (data) {
				jQuery("#poll").html(data);
			}
		});
	}
}
function PopupCenter(pageURL, title,w,h) {
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		var set = "toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width="+w+", height="+h+", top="+top+", left="+left+", directories=no";
		var targetWin = window.open(pageURL,title,set);
} 

function getPreviewText(werb,repUrl,w,h,ids){
	var pandData;
	if(w==200){	
		w = w+12;
		pandData= 'padding-left:2px;';
	}
	var txtmsg = '<div style="text-align: center;'+pandData+'" id="player'+ids+'-parent"><div style=\'border-style: none; overflow: hidden; height: '+h+'px; width: '+w+'px; background-color:#000;\'><div id="player'+ids+'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.<div style="overflow: hidden; display: none; visibility: hidden; width: 0px; height: 0px;" id="player'+ids+'-config"></div></div><scr'+'ipt type="text/javascript">var s1 = new SWFObject("'+werb+'common/fckeditor/editor/plugins/flvPlayer/mediaplayer.swf","single","'+w+'","'+(h+19)+'","7");s1.addVariable("width","'+w+'"); s1.addVariable("height","'+(h+19)+'");	s1.addVariable("autostart","true");	s1.addVariable("file","'+repUrl+'");	s1.addVariable("repeat","true");	s1.addVariable("image","");  s1.addVariable("showdownload","false");	s1.addVariable("link","'+repUrl+'"); 	s1.addParam("allowfullscreen","true");	s1.addVariable("showdigits","false"); s1.addParam("wmode","transparent"); s1.addVariable("shownavigation","true");	s1.addVariable("logo",""); s1.addVariable("stretching","none"); s1.write("player'+ids+'");</scr'+'ipt></div></div>';
		return txtmsg;
}
function setFlash(repUrl,w,h,ids){
	var txtmsg_1 = '<div id="player_'+ids+'">\n';
    txtmsg_1 += '<a href="http://get.adobe.com/flashplayer/">\n';
    txtmsg_1 += 'Get the Flash Player</a> to see this player.\n';
    txtmsg_1 += '</div>';
	txtmsg_1 += '<script type="text/javascript">';
	txtmsg_1 += 'var FlashId = "player_'+ids+'";';
	txtmsg_1 += 'FO[FlashId] = {movie:"'+repUrl+'", width:"'+w+'", height:"'+h+'", majorversion:"9", build:"0",wmode:"transparent",menu:"false",bgcolor:"#fff",quality:"high",align :"middle", allowFullScreen:"false"};';
	txtmsg_1 += 'UFO.create( FO[FlashId] , FlashId );';
	txtmsg_1 += '</script>';
	return txtmsg_1;
}
function VSite(txturl,sTarger){
	if(txturl==''){ return;}
	if(sTarger=='_blank'){
		window.open(txturl,"Ads_Click");
	} else {
		window.location.href = txturl;	
	}
}
function setCookie(sName, sValue){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
  //GetCookie(sName,"Cookie Set: " + sName + "=" + sValue); //For debug output purposes.
}

function getcookietime(sName, msg){
  var aCookie = document.cookie.split("; ");
  var out = "Cookie string: " + aCookie; //For debug output purposes.
  for (var i=0; i < aCookie.length; i++){
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) {
		return unescape(aCrumb[1]);
    }
  }
  return null;
}
 
function DelCookie(sName){
  document.cookie = sName + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT;";
}

function setcookietime(sName,sValue,duration){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
}

function restclass(myID){
	if(document.getElementById(myID).value!=''){
		document.getElementById(myID).className = "input-text";
	} else {
		document.getElementById(myID).className = "input-text error";
	}
}

function FieldValided(sFrmName,sFieldName){
	return jQuery('#'+sFrmName).validate().element('#'+sFieldName);
}

//Valided the Form
function ValidForm(frmName){
	//Search for all Input Area with isreq=1
		jQuery.validator.addMethod("field", function(value, element) {
			return value != 0;
		}, "&nbsp;");
		jQuery("#form1").validate({
			errorPlacement: function(error, element) { 
				error.appendTo(element.next() ); 
			},			
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted below'
						: 'You missed ' + errors + ' fields.  They have been highlighted below';					
					alert(message);
				}
			},
			onkeyup: false,
			success: function(label) { 
				label.html("&nbsp;").toggleClass("valid"); 
	        },debug:true
		});
	if(jQuery("#form1").valid()){
		document.getElementById("form1").submit();
	}
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		try{
			return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
		} catch(err) { }
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});
function popImage(imageURL, caption){
  var windowTop = 100; var windowLeft = 100; var defaultWidth = 730;
  var defaultHeight = 532; var onLoseFocusExit = true; var undefined;
  var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft + ",resizable"  
  var myScript = "<html>\n" + 
    "<head>\n" + 
    "<title>" + caption + "\</title>\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
    "  var width = document.myimage.width;\n" + 
    "  var height = document.myimage.height;\n";
  if (navigator.appName.indexOf("Netscape") != -1) {  myScript = myScript +  "  window.innerHeight = height;\n  window.innerWidth = width;\n"
  }else if (navigator.appName.indexOf("Opera") != -1) {   myScript = myScript +  "  window.resizeTo (width+12, height+71);\n"
  }else if (navigator.appName.indexOf("Microsoft") != -1) { myScript = myScript + "  window.resizeTo (width+12, height+71);\n" 
  }else {   myScript = myScript + "  window.resizeTo (width+14, height+34);\n"  }
  myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";
  if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}
  myScript = myScript + "style=\"margin: 0px; padding: 0px;\">\n" +
    "<img src=\"" + imageURL + "\" alt=\"" + caption + "\" title=\"" + caption + "\" name=\"myimage\">\n" + 
    "</body>\n" +  "</html>\n";  
  var imageWindow = window.open ("","imageWin",Options);
  imageWindow.document.write (myScript)
  imageWindow.document.close ();
  if (window.focus) imageWindow.focus();
  return false;
}
function days_between(date1_str, date2_str) {
	date1_str = date1_str.replace(/-/gi,"/");
	date2_str = date2_str.replace(/-/gi,"/");
	var date1 = new Date(date1_str);
	var date2 = new Date(date2_str);
    var ONE_DAY = 1000 * 60 * 60 * 24
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()
    var difference_ms = Math.abs(date1_ms - date2_ms)
    return Math.round(difference_ms/ONE_DAY)
}
function notifymessage(txtmsg){
	jQuery.blockUI({message: txtmsg,fadeIn: 700,fadeOut: 700,timeout: 4000,showOverlay: false, centerY: false, 
		css: {
			width: '350px', top: '10px', left: '', right: '10px', border: 'none', padding: '5px', backgroundColor: '#000', '-webkit-border-radius': '10px',
			'-moz-border-radius': '10px', opacity: .6, color: '#fff'
			} 
	});
}
function cancelrole(p_txt,textbox,btn1,btn2){
	if(jQuery("#"+btn1).html()=="Cancel"){
		jQuery("#"+p_txt).html("Cancelled");
		jQuery("#"+btn1).html("Reset");
		jQuery("#"+textbox).val(8);
	} else {
		jQuery("#"+p_txt).html("Pending");
		jQuery("#"+btn1).html("Cancel");
		jQuery("#"+textbox).val(2);
	}
}
function active_role(p_txt,textbox,btn3){
	if(jQuery("#"+btn3).html()=="Add"){
		jQuery("#"+p_txt).html(" - Active");
   		jQuery("#"+btn3).html("Reset");
    	jQuery("#"+textbox).val(5);
   	} else {
		jQuery("#"+p_txt).html("");
    	jQuery("#"+btn3).html("Add");
   		jQuery("#"+textbox).val(0);
    }
}
function InActive_role(p_txt,textbox,btn3){
	if(jQuery("#"+btn3).html()=="Remove"){
		jQuery("#"+p_txt).html(" - InActive");
   		jQuery("#"+btn3).html("Reset");
    	jQuery("#"+textbox).val(9);
   	} else {
		jQuery("#"+p_txt).html("");
    	jQuery("#"+btn3).html("Remove");
   		jQuery("#"+textbox).val(1);
    }
}
function selectAll(){
    incount = document.getElementsByName('delete_id[]').length+1;
    if(document.getElementById("checkAll").checked==true){
        document.getElementById("checkAll").checked=true;
        for (i=1;i<incount;i++){
            document.getElementById("check"+i).checked=true;
            document.getElementById("row"+i).style.background='#D6DEEC'; 
        }
    }else{
        document.getElementById("checkAll").checked=false;
        for (i=1;i<incount;i++){
            document.getElementById("check"+i).checked=false;
            document.getElementById("row"+i).style.background='#F6F6F6'; 
        }
    }
}

function selectRow(row,optx){
	var isrowChecked = row.replace("row_","check_");
	if(document.getElementById(isrowChecked).checked==true){
    } else {
	    document.getElementById(row).style.background="#222";
    }
   	if(optx!=undefined){ document.getElementById("cmddelete").disabled = optx; }
}

function deselectRow(row){
	var isrowChecked = row.replace("row_","check_");
	if(document.getElementById(isrowChecked).checked==true){
    } else {
	    document.getElementById(row).style.background="#F6F6F6";
    }
}
function trim(strText) {
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);	

   return strText;
}
function isEnterKey(evt) {
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode == 13) {	return true; }
}
function gup( name ){  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp(regexS);  
	var results = regex.exec( window.location.href);  
	if( results == null )    
		return "";  
	else    
		return results[1];
}
// for Multi rows adding and delete
var counter = 0;
var formblock;
var forminputs;
var msg_txt = "";

function fn_check_last_tag(tag){
		try {		
			if(tag.previousSibling.id == 'header') return true;
            if ((!tag.previousSibling || tag.previousSibling.id == 'header' || typeof(tag.previousSibling.id) == 'undefined') && (!tag.nextSibling || typeof(tag.nextSibling.id) == 'undefined'))
            return true;
		    return false;
		}
		catch(err) {
            if(err=="TypeError: Object required"){
    	    	return true;
            } else {
	            alert(err);
            }
		}
}

		function fn_remove_tag(tag_id){
			if(document.getElementById) {
				src = document.getElementById("box_new_"+tag_id);
			if (!fn_check_last_tag(src))
				src.parentNode.removeChild(src);
			}
		}

		function fourceremove(tag_id){
			if(document.getElementById) {
				src = document.getElementById("box_"+tag_id);
				src.parentNode.removeChild(src);
			}
		}

		function fn_remove_tag1(tag_id){
			if(document.getElementById) {
				src = document.getElementById("box_"+tag_id);
			if (!fn_check_last_tag(src))
				src.parentNode.removeChild(src);
			}
		}

        function fn_str_get_front(mainStr,searchStr){
	        foundOffset = mainStr.indexOf(searchStr)
	        if (foundOffset == -1) {
		        return null
	        }
	        return mainStr.substring(0,foundOffset);
	    }

        function fn_str_get_end(mainStr,searchStr){
        	foundOffset = mainStr.indexOf(searchStr)
        	if (foundOffset == -1) {
        	    return null
        	}
		    return mainStr.substring(foundOffset+searchStr.length,mainStr.length);
		}

        
        // replace searchString with replaceString
        function fn_str_replace_string(mainStr,searchStr,replaceStr){
        	var front = fn_str_get_front(mainStr,searchStr);
        	var end = fn_str_get_end(mainStr,searchStr);
        	if (front != null && end != null) {
        	    return front + replaceStr + end;
        	}
		    return '';
        }

        function fn_replace(substring, level){
        	var re = new RegExp();
        	var i = 0;
        	re.compile("\\[\\d+\\]", "g");
        	for (i=1; i<=level; i++) {
        		re.exec(substring);
        	}
        	substring = RegExp.leftContext+'['+counter+']'+RegExp.rightContext;
        	return substring;
        }

function fn_add_tag(tag_id, level, clone)
{
	var j = 0;
	var i = 0;
	var re_names = new RegExp();
	var re_ids = new RegExp();
	if(document.getElementById) {
		counter++;
		new_id = tag_id+"_"+counter;
	
		src = document.getElementById("box_"+tag_id);
		var newNode = src.cloneNode(true);
		newNode.id = "box_"+new_id;

		re_names.compile("name=(\\\"|\\\')*\\w*(\\[\\w*\\])+(\\\"|\\\')*", "gi");
		var arr_names = newNode.innerHTML.match(re_names);
		
		node_elms = newNode.getElementsByTagName('*');

		for (i=0;i<node_elms.length;i++) {
			if (node_elms[i].id.length>0) {
				if (node_elms[i].type!='text'){
					node_elms[i].id = node_elms[i].id + '_'+counter;
				} else {
					var xt = node_elms[i].id;
					node_elms[i].id = xt.substring(0,6)+'['+counter+']';
				}
			}

			if (node_elms[i].nodeName=='TD') {
				if (node_elms[i].style.display == 'none' && clone != 'Y') {
					node_elms[i].style.display = '';
				}

				// Replace [%d] in nodes names
				for (j=0; j<arr_names.length; j++) {
					if (node_elms[i].innerHTML.indexOf(arr_names[j])!=-1) {
						str = fn_str_replace_string(node_elms[i].innerHTML,arr_names[j],fn_replace(arr_names[j],level));
						if (str.length>0) {
							node_elms[i].innerHTML = str;
						}
					}
				}
			}
		}

		// Insert node into the document
		newNode = src.parentNode.insertBefore(newNode,src.nextSibling);
		// Process INPUT types...
		child_inputs = newNode.getElementsByTagName('INPUT');
		parent_inputs = src.getElementsByTagName('INPUT');
		for (i=0;i<child_inputs.length;i++) {
			if (child_inputs[i].type!='file') { // Skip values assignment for file input type.
            	if(parent_inputs[i].getAttribute("rel").toString()=="amt"){
	                child_inputs[i].value = (clone == "Y")? parent_inputs[i].value : '0.00';
                } else {
                	if(parent_inputs[i].getAttribute("rel").toString()=="pos"){
	                    child_inputs[i].value = parseFloat(parent_inputs[i].value)+1;
                    } else {
           	        	child_inputs[i].value = (clone == "Y")? parent_inputs[i].value : '';
                    }
                }
			}
			if (child_inputs[i].type=='button' || child_inputs[i].type=='radio' || child_inputs[i].type=='checkbox') { // Skip values assignment for file input type.
				child_inputs[i].value = parent_inputs[i].value;
			}
			if (child_inputs[i].type == 'radio' || child_inputs[i].type == 'checkbox') { // Assignment checked state for checkboxes and radios.
				child_inputs[i].checked = (clone == "Y")? parent_inputs[i].checked : parent_inputs[i].defaultChecked; 
			}
		}

		child_inputs[0].focus();
		
		// Process TEXTAREA type...
		child_texts = newNode.getElementsByTagName('TEXTAREA');
		parent_texts = src.getElementsByTagName('TEXTAREA');
		for (i=0;i<child_texts.length;i++) {
			child_texts[i].value = (clone == "Y")? parent_texts[i].value : '';
		}

		// Process SELECT type...
		child_selects = newNode.getElementsByTagName('SELECT');
		parent_selects = src.getElementsByTagName('SELECT');
		for (i=0;i<child_selects.length;i++) {
			for (j=0;j<child_selects[i].options.length;j++) {
				child_selects[i].options[j].selected = (clone == "Y")? parent_selects[i].options[j].selected : parent_selects[i].options[j].defaultSelected;
			}
		}
  }
}

function fn_check_option_type_helper(tag_id, hide)
{
	trs = document.getElementById('variantsglobbo'+tag_id).getElementsByTagName('TR');
	if (trs.length>0) {
		document.getElementById('bulk_'+tag_id).style.display=hide;
		document.getElementById('nameen_'+tag_id).style.display=hide;
		document.getElementById('namear_'+tag_id).style.display=hide;
		document.getElementById('position_'+tag_id).style.display=hide;
		document.getElementById('hbulk_'+tag_id).style.display=hide;
		document.getElementById('hnameen_'+tag_id).style.display=hide;
		document.getElementById('hnamear_'+tag_id).style.display=hide;
		document.getElementById('hposition_'+tag_id).style.display=hide;
        //document.getElementById('contenten_'+tag_id).style.display=hide;
		for (i=1;i<trs.length;i++) {
			//if (trs[i].id.indexOf('no_hide') == -1) {
				trs[i].style.display=hide;
			//}
		}
	}
}

function fn_check_option_type(value, tag_id)
{
	var i = 0;
	if (document.getElementById(tag_id)) {
		if (value == 'S') {
	        document.getElementById('variantsglobbo'+tag_id).parentNode.style.display = '';
			document.getElementById('variantsglobbo'+tag_id).parentNode.parentNode.style.display = '';
			fn_check_option_type_helper(tag_id, '');
		}
		if (value == 'R') {
	        document.getElementById('variantsglobbo'+tag_id).parentNode.style.display = '';
			document.getElementById('variantsglobbo'+tag_id).parentNode.parentNode.style.display = '';
			fn_check_option_type_helper(tag_id, '');
		}
		if (value == 'C') {
	        document.getElementById('variantsglobbo'+tag_id).parentNode.style.display = '';
			document.getElementById('variantsglobbo'+tag_id).parentNode.parentNode.style.display = '';
			fn_check_option_type_helper(tag_id, 'none');
		}
		if (value == 'I') {
	        document.getElementById('variantsglobbo'+tag_id).parentNode.style.display = '';
			document.getElementById('variantsglobbo'+tag_id).parentNode.parentNode.style.display = 'none';
		}
		if (value == 'T') {
			document.getElementById('variantsglobbo'+tag_id).parentNode.style.display = 'none';
		}
	}
}

function fn_invert_row(tag_id, flag)
{
	fn_show_tag(tag_id, flag);
	fn_show_tag('plus' + tag_id, flag);
	fn_show_tag('minus' + tag_id, flag);
}

function fn_show_tag(id, status)
{
	if (document.getElementById(id)) {
		if (status == true || status == false) {
			document.getElementById(id).style.display = (status == true)?"none":"";
        } else {
			document.getElementById(id).style.display = (document.getElementById(id).style.display == "")?"none":"";
		}

	}
}
// End of the mulut rows